Пример #1
0
        protected override ParseTreeNode GetResultNode(ParsingContext context)
        {
            int childCount      = Production.RValues.Count;
            int firstChildIndex = context.ParserStack.Count - childCount;
            var span            = context.ComputeStackRangeSpan(childCount);
            var newNode         = new ParseTreeNode(Production.LValue, span);

            newNode.Tokens = context.ComputeTokenSubList(childCount);
            if (childCount > 0)                                      //if it is not empty production - might happen for MakeStarRule
            {
                var listNode = context.ParserStack[firstChildIndex]; //get the transient list with all members - it is the first child node
                newNode.ChildNodes.AddRange(listNode.ChildNodes);    //copy all list members
            }
            return(newNode);
        }
Пример #2
0
        protected virtual ParseTreeNode GetResultNode(ParsingContext context)
        {
            var childCount      = Production.RValues.Count;
            int firstChildIndex = context.ParserStack.Count - childCount;
            var span            = context.ComputeStackRangeSpan(childCount);
            var newNode         = new ParseTreeNode(Production.LValue, span);

            newNode.Tokens = context.ComputeTokenSubList(childCount);
            for (int i = 0; i < childCount; i++)
            {
                var childNode = context.ParserStack[firstChildIndex + i];
                if (childNode.IsPunctuationOrEmptyTransient())
                {
                    continue;                                    //skip punctuation or empty transient nodes
                }
                newNode.ChildNodes.Add(childNode);
            }//for i
            return(newNode);
        }
Пример #3
0
        protected override ParseTreeNode GetResultNode(ParsingContext context)
        {
            var topIndex   = context.ParserStack.Count - 1;
            var childCount = Production.RValues.Count;

            for (int i = 0; i < childCount; i++)
            {
                var child = context.ParserStack[topIndex - i];
                if (child.IsPunctuationOrEmptyTransient())
                {
                    continue;
                }
                return(child);
            }
            //Otherwise return an empty transient node; if it is part of the list, the list will skip it
            var span = context.ComputeStackRangeSpan(childCount);

            return(new ParseTreeNode(Production.LValue, span)
            {
                Tokens = context.ComputeTokenSubList(childCount)
            });
        }