示例#1
0
        private static void WriteTree(SyntaxTreeNode node, StringBuilder treeBuilder, int depth = 0)
        {
            if (node == null)
            {
                return;
            }
            if (depth > 1)
            {
                WriteIndent(treeBuilder, depth);
            }

            if (depth > 0)
            {
                treeBuilder.Append("|-- ");
            }

            treeBuilder.AppendLine(ConvertEscapseSequences(node.ToString()));
            if (node.IsBlock)
            {
                foreach (SyntaxTreeNode child in ((Block)node).Children)
                {
                    WriteTree(child, treeBuilder, depth + 1);
                }
            }
        }
        private bool IsLiteralAttributeValue(SyntaxTreeNode node)
        {
            if (node.IsBlock)
            {
                return false;
            }
            var span = node as Span;
            Debug.Assert(span != null);

            var litGen = span.ChunkGenerator as LiteralAttributeChunkGenerator;

            return span != null &&
                   ((litGen != null && litGen.ValueGenerator == null) ||
                    span.ChunkGenerator == SpanChunkGenerator.Null ||
                    span.ChunkGenerator is MarkupChunkGenerator);
        }
示例#3
0
        public Block TagHelperBlock(
            string tagName,
            TagMode tagMode,
            SourceLocation start,
            Block startTag,
            SyntaxTreeNode[] children,
            Block endTag)
        {
            var builder = new TagHelperBlockBuilder(
                tagName,
                tagMode,
                attributes: new List<KeyValuePair<string, SyntaxTreeNode>>(),
                children: children)
            {
                Start = start,
                SourceStartTag = startTag,
                SourceEndTag = endTag
            };

            return builder.Build();
        }
示例#4
0
 private static void AddNullActualError(ErrorCollector collector, SyntaxTreeNode actual, SyntaxTreeNode expected)
 {
     collector.AddError("{0} - FAILED :: Actual: << Null >>", expected);
 }
示例#5
0
 private static void AddMismatchError(ErrorCollector collector, SyntaxTreeNode actual, SyntaxTreeNode expected)
 {
     collector.AddError("{0} - FAILED :: Actual: {1}", expected, actual);
 }
示例#6
0
 private static void AddPassedMessage(ErrorCollector collector, SyntaxTreeNode expected)
 {
     collector.AddMessage("{0} - PASSED", expected);
 }
示例#7
0
        private static void EvaluateSyntaxTreeNode(ErrorCollector collector, SyntaxTreeNode actual, SyntaxTreeNode expected)
        {
            if (actual == null)
            {
                AddNullActualError(collector, actual, expected);
            }

            if (actual.IsBlock != expected.IsBlock)
            {
                AddMismatchError(collector, actual, expected);
            }
            else
            {
                if (expected.IsBlock)
                {
                    EvaluateBlock(collector, (Block)actual, (Block)expected);
                }
                else
                {
                    EvaluateSpan(collector, (Span)actual, (Span)expected);
                }
            }
        }
示例#8
0
 private void WriteNode(int indent, SyntaxTreeNode node)
 {
     string content = node.ToString().Replace("\r", "\\r")
         .Replace("\n", "\\n")
         .Replace("{", "{{")
         .Replace("}", "}}");
     if (indent > 0)
     {
         content = new String('.', indent * 2) + content;
     }
     WriteTraceLine(content);
     Block block = node as Block;
     if (block != null)
     {
         foreach (SyntaxTreeNode child in block.Children)
         {
             WriteNode(indent + 1, child);
         }
     }
 }
示例#9
0
文件: Span.cs 项目: rohitpoudel/Razor
 /// <summary>
 /// Checks that the specified span is equivalent to the other in that it has the same start point and content.
 /// </summary>
 public override bool EquivalentTo(SyntaxTreeNode node)
 {
     var other = node as Span;
     return other != null &&
         Kind.Equals(other.Kind) &&
         Start.Equals(other.Start) &&
         EditHandler.Equals(other.EditHandler) &&
         string.Equals(other.Content, Content, StringComparison.Ordinal);
 }
示例#10
0
 public CSharpCodeWriter WriteStartInstrumentationContext(
     ChunkGeneratorContext context,
     SyntaxTreeNode syntaxNode,
     bool isLiteral)
 {
     return WriteStartInstrumentationContext(
         context,
         syntaxNode.Start.AbsoluteIndex,
         syntaxNode.Length,
         isLiteral);
 }
示例#11
0
 public override bool EquivalentTo(SyntaxTreeNode node)
 {
     var other = node as Block;
     if (other == null || other.Type != Type)
     {
         return false;
     }
     return Enumerable.SequenceEqual(Children, other.Children, new EquivalenceComparer());
 }
        private static bool IsNullOrWhitespaceAttributeValue(SyntaxTreeNode attributeValue)
        {
            if (attributeValue.IsBlock)
            {
                foreach (var span in ((Block)attributeValue).Flatten())
                {
                    if (!string.IsNullOrWhiteSpace(span.Content))
                    {
                        return false;
                    }
                }

                return true;
            }
            else
            {
                return string.IsNullOrWhiteSpace(((Span)attributeValue).Content);
            }
        }
        private static SourceLocation GetAttributeNameStartLocation(SyntaxTreeNode node)
        {
            Span span;
            var nodeStart = SourceLocation.Undefined;

            if (node.IsBlock)
            {
                span = ((Block)node).FindFirstDescendentSpan();
                nodeStart = span.Parent.Start;
            }
            else
            {
                span = (Span)node;
                nodeStart = span.Start;
            }

            // Span should never be null here, this should only ever be called if an attribute was successfully parsed.
            Debug.Assert(span != null);

            // Attributes must have at least one non-whitespace character to represent the tagName (even if its a C#
            // expression).
            var firstNonWhitespaceSymbol = span
                .Symbols
                .OfType<HtmlSymbol>()
                .First(sym => sym.Type != HtmlSymbolType.WhiteSpace && sym.Type != HtmlSymbolType.NewLine);

            return nodeStart + firstNonWhitespaceSymbol.Start;
        }
示例#14
0
 public void WriteStartInstrumentationContext(CodeGeneratorContext context, SyntaxTreeNode syntaxNode, bool isLiteral)
 {
     WriteStartMethodInvocation(context.Host.GeneratedClassContext.BeginContextMethodName);
     Write(syntaxNode.Start.AbsoluteIndex.ToString(CultureInfo.InvariantCulture));
     WriteParameterSeparator();
     Write(syntaxNode.Length.ToString(CultureInfo.InvariantCulture));
     WriteParameterSeparator();
     Write(isLiteral ? "true" : "false");
     WriteEndMethodInvocation();
 }
示例#15
0
 /// <summary>
 /// Determines if the specified node is equivalent to this node
 /// </summary>
 /// <param name="node">The node to compare this node with</param>
 /// <returns>
 /// true if the provided node has all the same content and metadata, though the specific quantity and type of symbols may be different.
 /// </returns>
 public abstract bool EquivalentTo(SyntaxTreeNode node);
示例#16
0
 /// <summary>
 /// Determines if the specified node is equivalent to this node
 /// </summary>
 /// <param name="node">The node to compare this node with</param>
 /// <returns>
 /// true if the provided node has all the same content and metadata, though the specific quantity and type of symbols may be different.
 /// </returns>
 public abstract bool EquivalentTo(SyntaxTreeNode node);