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);
        }
Example #2
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<TagHelperAttributeNode>(),
                children: children)
            {
                Start = start,
                SourceStartTag = startTag,
                SourceEndTag = endTag
            };

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

            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);
                }
            }
        }
Example #7
0
 private void WriteNode(int indent, SyntaxTreeNode node)
 {
     var content = node.ToString().Replace("\r", "\\r")
         .Replace("\n", "\\n")
         .Replace("{", "{{")
         .Replace("}", "}}");
     if (indent > 0)
     {
         content = new String('.', indent * 2) + content;
     }
     WriteTraceLine(content);
     var block = node as Block;
     if (block != null)
     {
         foreach (SyntaxTreeNode child in block.Children)
         {
             WriteNode(indent + 1, child);
         }
     }
 }
Example #8
0
        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);
            }
        }
Example #9
0
        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;
        }
Example #10
0
 public CSharpCodeWriter WriteStartInstrumentationContext(
     ChunkGeneratorContext context,
     SyntaxTreeNode syntaxNode,
     bool isLiteral)
 {
     return WriteStartInstrumentationContext(
         context,
         syntaxNode.Start.AbsoluteIndex,
         syntaxNode.Length,
         isLiteral);
 }
Example #11
0
 /// <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);
 }
Example #12
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());
        }