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); }
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(); }
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); } 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) { 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); } } }
/// <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 CSharpCodeWriter WriteStartInstrumentationContext( ChunkGeneratorContext context, SyntaxTreeNode syntaxNode, bool isLiteral) { return WriteStartInstrumentationContext( context, syntaxNode.Start.AbsoluteIndex, syntaxNode.Length, isLiteral); }
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; }
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(); }
/// <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);