Esempio n. 1
0
        void IParsingTreeNodeVisitor.VisitGroup(IParsingTreeGroup group)
        {
            _rules.AddLast(group.Rule == null ? string.Empty : group.Rule.Name);

            foreach (var item in group.GetRuleChilds())
            {
                item.Visit(this);
            }

            _rules.RemoveLast();
        }
Esempio n. 2
0
        void IParsingTreeNodeVisitor.VisitGroup(IParsingTreeGroup group)
        {
            PrintNode(group);

            _i++;
            foreach (var item in group.GetRuleChilds())
            {
                item.Visit(this);
            }

            _i--;
        }
Esempio n. 3
0
        static IEnumerable <IParsingTreeNode> GetRuleChildsImpl(this IParsingTreeGroup node, bool disableExpanding, bool skipOmitFragments, int depth)
        {
            foreach (var item in node.Childs)
            {
                //if (item is IParsingTreeTerminal || (
                //    node.Expression is RuleExpression.RuleUsage && (
                //        item.Rule != node.Rule && !item.Rule.IsExpandable
                //    )
                //))

                //if (skipOmitFragments && item.Rule == null && depth > 1)
                //{
                //    continue;
                //}
                if ((item as ParsingTreeNode).GrammarNode is ParserNode.RecursiveParserNode)
                {
                    foreach (var subitem in (item as IParsingTreeGroup).GetRuleChildsImpl(disableExpanding, skipOmitFragments, depth + 1))
                    {
                        yield return(subitem);
                    }
                }
                else if (!disableExpanding && node.Expression is RuleExpression.RuleUsage && item.Rule != node.Rule && item.Rule != null && !item.Rule.IsExpandable)
                {
                    yield return(item);
                }
                else if (disableExpanding && node.Expression is RuleExpression.RuleUsage && item.Rule != node.Rule && item.Rule != null)
                {
                    yield return(item);
                }
                else if (!disableExpanding && (item is IParsingTreeTerminal))
                {
                    if (item.Rule != null && !item.Rule.IsExpandable)
                    {
                        yield return(item);
                    }
                }
                else if (disableExpanding && (item is IParsingTreeTerminal))
                {
                    yield return(item);
                }
                else if (item is IParsingTreeGroup)
                {
                    foreach (var subitem in (item as IParsingTreeGroup).GetRuleChildsImpl(disableExpanding, skipOmitFragments, depth + 1))
                    {
                        yield return(subitem);
                    }
                }
                else
                {
                    throw new NotImplementedException("");
                }
            }
        }
Esempio n. 4
0
            void IParsingTreeNodeVisitor.VisitGroup(IParsingTreeGroup group)
            {
                _depth++;

                foreach (var item in group.Childs.Reverse())
                {
                    if (this.Result == null && group.Rule != null && _depth > 0)
                    {
                        item.Visit(this);
                    }
                }

                _depth--;
            }
Esempio n. 5
0
        void IParsingTreeNodeVisitor.VisitGroup(IParsingTreeGroup group)
        {
            var compensator = new RecursionRewritingCompensator((ParsingTreeNode.Group)group, _alternativesInfo);

            RuleAlternativeInfo info;

            if (group.Rule != null && _alternativesInfo.TryGetInfo(group.Rule, out info))
            {
                _currChild = compensator.RestoreRecursion(_currChild, info);
            }
            else
            {
                _currChild = compensator.Recreate(_currChild);
            }
        }
Esempio n. 6
0
        private static TemporaryReparsingGroup CreateItemToReparse(IParsingTreeGroup oldGroup, TemporaryReparsingGroup parent, Location fromLoc, Location toLoc)
        {
            IParsingTreeGroup prevGroup = null;

            foreach (var oldChild in oldGroup.Childs)
            {
                if (oldChild.Location <= fromLoc)
                {
                    var childTerm  = oldChild as IParsingTreeTerminal;
                    var childGroup = oldChild as IParsingTreeGroup;

                    if (childTerm != null)
                    {
                        prevGroup = null;

                        if (childTerm.To > fromLoc)
                        {
                            break; // this term need to be reparsed and so forth
                        }
                        else
                        {
                            // skip
                        }
                    }
                    else if (childGroup != null)
                    {
                        prevGroup = childGroup;
                    }
                    else
                    {
                        throw new NotImplementedException("");
                    }
                }
                else
                {
                    break; // prev child item need to be processed
                }
            }

            return(prevGroup == null ? null : new TemporaryReparsingGroup(
                       prevGroup, (prevGroup as ParsingTreeNode).GrammarNode, fromLoc, toLoc, parent, null
                       ));
        }
Esempio n. 7
0
 public static IEnumerable <IParsingTreeNode> GetRuleChilds(this IParsingTreeGroup node, bool disableExpanding = false, bool skipOmitFragments = true)
 {
     return(node.GetRuleChildsImpl(disableExpanding, skipOmitFragments, 0));
 }