public ParsingTreeNodeInfo(IParsingTreeNode node, ISourceTextReader textReader, Func <IParsingTreeGroup, ParsingTreeNodeInfo, IEnumerable <ParsingTreeNodeInfo> > childsAccessor, bool fullInfo, ParsingTreeNodeInfo parent = null) { this.Node = node; this.Parent = parent; var terminal = node as IParsingTreeTerminal; if (terminal != null) { this.Text = "'" + textReader.GetText(terminal.From, terminal.To) + "'"; if (fullInfo) { this.Text = (node.Rule == null ? "<NULL>" : node.Rule.Name) + ": " + (node.Expression == null ? "<NULL>" : node.Expression.ToString()) + "; " + this.Text; } } var group = node as IParsingTreeGroup; if (group != null) { this.Childs = childsAccessor(group, this); this.Text = node.Rule == null ? "<NULL>" : node.Rule.Name; if (fullInfo) { this.Text += ": " + (node.Expression == null ? "<NULL>" : node.Expression.ToString()) + ";"; } } }
public static string GetContent(this IParsingTreeNode node, ISourceTextReader reader) { var from = node.GetFromLocation(); if (from.HasValue) { var to = node.GetToLocation(); return(reader.GetText(from.Value, to.Value)); } else { return(string.Empty); } }
protected override bool TryRunImpl(ISourceTextReader reader, out string content) { bool result; var text = reader.GetText(); var pos = reader.GetPosition(); var match = _regex.Match(text, pos); if (match.Success && match.Index == pos) { content = match.Value; result = reader.Move(match.Length); } else { content = null; result = false; } return(result); }