Introducing RazorIRToken

This IR node will be part of the new token model for IR. It will be used
by all nodes that contain user content. Going forward, tokens will be the
thing that contains text and produces line mappings.

This commit just introduces the class.
This commit is contained in:
Ryan Nowak 2017-02-17 09:05:52 -08:00
parent de6bfa480f
commit 965ae5490f
4 changed files with 69 additions and 0 deletions

View File

@ -19,6 +19,11 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Intermediate
VisitDefault(node);
}
public virtual void VisitToken(RazorIRToken node)
{
VisitDefault(node);
}
public virtual void VisitDirectiveToken(DirectiveTokenIRNode node)
{
VisitDefault(node);

View File

@ -20,6 +20,11 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Intermediate
return VisitDefault(node);
}
public virtual TResult VisitToken(RazorIRToken node)
{
return VisitDefault(node);
}
public virtual TResult VisitDirectiveToken(DirectiveTokenIRNode node)
{
return VisitDefault(node);

View File

@ -0,0 +1,54 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
namespace Microsoft.AspNetCore.Razor.Evolution.Intermediate
{
public sealed class RazorIRToken : RazorIRNode
{
public override IList<RazorIRNode> Children => RazorIRNode.EmptyArray;
public string Content { get; set; }
public bool IsCSharp => Kind == TokenKind.CSharp;
public bool IsHtml => Kind == TokenKind.Html;
public TokenKind Kind { get; set; } = TokenKind.Unknown;
public override RazorIRNode Parent { get; set; }
public override SourceSpan? Source { get; set; }
public override void Accept(RazorIRNodeVisitor visitor)
{
if (visitor == null)
{
throw new ArgumentNullException(nameof(visitor));
}
visitor.VisitToken(this);
}
public override TResult Accept<TResult>(RazorIRNodeVisitor<TResult> visitor)
{
if (visitor == null)
{
throw new ArgumentNullException(nameof(visitor));
}
return visitor.VisitToken(this);
}
public enum TokenKind
{
Unknown,
CSharp,
Html,
}
}
}

View File

@ -47,6 +47,11 @@ namespace Microsoft.AspNetCore.Razor.Evolution.IntegrationTests
WriteContentNode(node, node.Content);
}
public override void VisitToken(RazorIRToken node)
{
WriteContentNode(node, node.Kind.ToString(), node.Content);
}
public override void VisitDirective(DirectiveIRNode node)
{
WriteContentNode(node, node.Name);