public static ParserState <Result> ForStart(ParserNode root, ISourceTextReader reader, bool enableLog) { IndentedWriter w; if (enableLog) { w = new IndentedWriter(" "); w.Push().WriteLine("Start @{0} {1}", reader.GetPosition(), root).Push(); } else { w = null; } if (root.Parent != null) { throw new ArgumentException(); } return(new LinearParserState( w, root, null, new ParserStep.EnterNode(null, root, reader.Location), StatefullStackNode.ForRoot(), null, reader )); }
public ParserState <TResult> EnterNode(ParserNode nextNode, bool offTree = false) { if (nextNode.Parent != this.CurrNode && !(this.CurrNode is ParserNode.RecursiveParserNode) && !offTree) { throw new InvalidOperationException(); } if (_log != null) { _log.Push().WriteLine("EnterNode @{2} {0} --> {1}", this.CurrNode, nextNode, this.Reader.Location).Push(); if (this.CurrNode is ParserNode.RecursiveParserNode) { _log.WriteLine("Enter to recursion"); } } return(this.EnterNodeImpl(nextNode)); }
string CollectImpl(IParserStep node) { var stack = new Stack <IParserStep>(); for (var step = node; step != null; step = step.Prev) { stack.Push(step); } _w = new IndentedWriter(" "); _w.Push().Push(); while (stack.Count > 0) { stack.Pop().Visit(this); } var result = _w.GetContentAsString(); _w = null; return(result); }
void IParserStepVisitor.VisitEnterNode(IEnterStep enterNode) { _w.Push(); _w.WriteLine(enterNode.ToString()); }
//public static ParserTreeState ForStart(ParserNode root, ISourceTextReader reader, bool enableLog) //{ // IndentedWriter w; // if (enableLog) // { // w = new IndentedWriter(" "); // w.Push().WriteLine("Start @{0} {1}", reader.GetPosition(), root).Push(); // } // else // { // w = null; // } // if (root.Parent != null) // throw new ArgumentException(); // return new ParserTreeState( // w, // null, // ParsingTreeNode.CreateRootGroup(root, reader.Location), // null, // reader // ); //} public static ParserState <Result> ForStart(ParserNode grammarRoot, ParserNode omitRoot, ISourceTextReader reader, IParsingTreeNode oldRoot, Location limit, bool enableLog) { IndentedWriter w; if (enableLog) { w = new IndentedWriter(" "); if (oldRoot != null) { w.WriteLine("Incrementally"); } w.Push().WriteLine("Start @{0} {1}", reader.GetPosition(), grammarRoot).Push(); } else { w = null; } if (oldRoot != null) { ParserNode prevGrammarNode = null; bool insideOmittedFragment; var treeNode = ParsingTreeNode.CreateRootGroup(oldRoot, omitRoot, reader.Location, limit, out prevGrammarNode, out insideOmittedFragment); if (!reader.MoveTo(treeNode.Location)) { throw new NotImplementedException(""); } if (w != null) { w.WriteLine("Reconstructing log indentation..."); var t = treeNode; var path = new List <ParsingTreeNode.TemporaryGroup>(); while (t != null) { path.Add(t); t = t.Parent; } path.Reverse(); for (int i = 0; i < path.Count - 1; i++) { w.Push().WriteLine("EnterNode @{2} {0} --> {1}", path[i].GrammarNode, path[i + 1].GrammarNode, path[i].Location).Push(); if (path[i].GrammarNode is ParserNode.RecursiveParserNode) { w.WriteLine("Enter to recursion"); } } w.WriteLine("...Identation reconstructed."); } ParserState <Result> state = new ParserTreeState( w, prevGrammarNode, treeNode, null, reader ); state.InsideOmittedFragment = insideOmittedFragment; if (state.LastTerminalFailed == false) { state = state.ExitNode(); } else { System.Diagnostics.Debug.Print(string.Empty); } return(state); } else { return(new ParserTreeState( w, null, ParsingTreeNode.CreateRootGroup(grammarRoot, reader.Location), null, reader )); } }