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); }
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(); }
private static void AddNullActualError(ErrorCollector collector, SyntaxTreeNode actual, SyntaxTreeNode expected) { collector.AddError("{0} - FAILED :: Actual: << Null >>", expected); }
private static void AddMismatchError(ErrorCollector collector, SyntaxTreeNode actual, SyntaxTreeNode expected) { collector.AddError("{0} - FAILED :: Actual: {1}", expected, actual); }
private static void AddPassedMessage(ErrorCollector collector, SyntaxTreeNode expected) { collector.AddMessage("{0} - PASSED", expected); }
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); } } }
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); } } }
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; }
public CSharpCodeWriter WriteStartInstrumentationContext( ChunkGeneratorContext context, SyntaxTreeNode syntaxNode, bool isLiteral) { return WriteStartInstrumentationContext( context, syntaxNode.Start.AbsoluteIndex, syntaxNode.Length, isLiteral); }
/// <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); }
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()); }