List <string> Print() { var parents = new List <ParserNode>(); for (var parent = this; parent != null; parent = parent.Parent) { parents.Insert(0, parent); } var parentTypes = string.Join("->", parents.Select(node => node.Type)); var attrs = string.Join(", ", attributes.Select(child => ($"{child.start}-{child.end} {child.Type} \"{(child.Text ?? "").Replace("\r", "").Replace("\n", "").Replace("\"", "\"\"")}\""))); var result = new List <string> { $"[{start}-{end}: {attrs} Path: \"{parentTypes}\"" }; result.AddRange(children.SelectMany(child => child.Print()).Select(str => $" {str}")); if (result.Count == 1) { result[0] += "]"; } else { result.Add("]"); } return(result); }
public void EnterEveryRule(ParserRuleContext ctx) { var node = new ParserNode { Type = ctx.GetType().ToString(), Parent = stack.Peek(), LocationParserRule = ctx }; node.AddAttr("Text", input, ctx); stack.Push(node); }