public List <NodeParser> PathTo(NodeParser lookingFor) { if (this == lookingFor) { return new List <NodeParser>() { this } } ; if (this is IContainsChildren containsChildren) { foreach (NodeParser child in containsChildren.Children) { List <NodeParser> path = child.PathTo(lookingFor); if (path.Count() > 0) { path.Insert(0, this); return(path); } } } return(new List <NodeParser>()); }
public string ToStringRecursively(NodeParser highlighted = null, bool enableHighlighting = true) { List <NodeParser> referenced = new List <NodeParser>(); StringBuilder builder = new StringBuilder(); this.ToStringRecursively(builder, indent: "", isLast: true, referenced, highlighted, enableHighlighting); return(builder.ToString()); }
public static ManyNodeParser MakeMany(NodeParser parser) => new ManyNodeParser(parser);
public ManyNodeParser(NodeParser parser, bool allowEmpty = true) { this.Parser = parser; this.allowEmpty = allowEmpty; }
public static ForeverNodeParser Forever(NodeParser parser) => new ForeverNodeParser(parser);
public ForeverNodeParser(NodeParser parser) { this.Parser = parser; }
private void ToStringRecursively(StringBuilder builder, string indent, bool isLast, List <NodeParser> referenced, NodeParser highlighted, bool enableHighlighting) { if (this is ReferenceNodeParser referenceNodeParser) { NodeParser referencedParser = referenceNodeParser.Referenced; referencedParser.ToStringRecursively(builder, indent, isLast, referenced, highlighted, enableHighlighting); return; } builder.Append(indent); if (isLast) { builder.Append(Corner); indent += Space; } else { builder.Append(Cross); indent += Vertical; } if (referenced.Contains(this)) { string referencedLine = enableHighlighting ? $"{Output.BrightMagenta("referenced")}({this.formattedName(enableHighlighting)})" : $"referenced({this.formattedName(enableHighlighting)})"; if (highlighted == this) { builder.AppendLine(enableHighlighting ? referencedLine.Reversed() : referencedLine); } else { builder.AppendLine(referencedLine); } return; } referenced.Add(this); string prefix = this.formattedName(enableHighlighting); if (this.name != null) { prefix += enableHighlighting ? Output.BrightGreen(":") : ":"; } string fullLine = $"{prefix}{this.ToString()}"; if (highlighted == this) { builder.AppendLine(enableHighlighting ? $"{fullLine.Reversed()}{Output.Red(" <------ current parser")}" : $"{fullLine} <------ current parser"); } else { builder.AppendLine(fullLine); } if (this is IContainsChildren recursiveNode) { IEnumerable <NodeParser> children = recursiveNode.Children.Except(referenced); int childrenCount = children.Count(); IEnumerable <(NodeParser Child, bool)> joinedWithLast = children.Select((Child, Index) => (Child, Index == childrenCount - 1)); foreach ((NodeParser child, bool childIsLast) in joinedWithLast) { child.ToStringRecursively(builder, indent, childIsLast, referenced, highlighted, enableHighlighting); } } }
public MaybeNodeParser(NodeParser parser) { this.Parser = parser; }
public static MaybeNodeParser Maybe(NodeParser parser) => new MaybeNodeParser(parser);
public static WhileNodeParser While(NodeParser parser) => new WhileNodeParser(parser);
public WhileNodeParser(NodeParser parser) { this.Parser = parser; }
public FailedParsingResult(SourceLocation location, NodeParser parser) : base(parser, success: true) { this.location = location; }
public SuccessfulParsingResult(SourceContext context, NodeParser parser) : base(parser, success: true) { this.Context = context; }
public ParsingResult(NodeParser parser, bool success) { this.Parser = parser; this.Success = success; }