コード例 #1
0
        //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
                           ));
            }
        }
コード例 #2
0
 protected override ParserState <ParserTreeState.Result> CreateInitialStateImpl(ParserNode grammarRoot, ParserNode omitRoot, ISourceTextReader source, ParserTreeState.Result oldResult, Location limit, bool enableLog)
 {
     return(oldResult == null
         ? ParserTreeState.ForStart(grammarRoot, omitRoot, source, null, limit, enableLog)
         : ParserTreeState.ForStart(grammarRoot, omitRoot, source, oldResult.Tree, limit, enableLog));
 }