示例#1
0
        public static IList <Tree> getSeparators <T1>(ParserRuleContext ctx, IList <T1> siblings)
            where T1 : Antlr4.Runtime.ParserRuleContext
        {
            ParserRuleContext first = siblings[0] as ParserRuleContext;
            ParserRuleContext last  = siblings[siblings.Count - 1] as ParserRuleContext;
            int start = BuffUtils.indexOf(ctx, first);
            int end   = BuffUtils.indexOf(ctx, last);
            IEnumerable <ITree> xxxx     = Trees.GetChildren(ctx).Where((n, i) => i >= start && i < end + 1);
            IList <Tree>        elements = xxxx.ToList();

            return(BuffUtils.filter(elements, c => c is TerminalNode));
        }
示例#2
0
        public virtual void EnterEveryRule(ParserRuleContext ctx)
        {
            // Find sibling lists that are children of this parent node
            ISet <Type> completed = new HashSet <Type>(); // only count sibling list for each subtree type once

            for (int i = 0; i < ctx.ChildCount; i++)
            {
                ParseTree child = ctx.GetChild(i);

                if (completed.Contains(child.GetType()))
                {
                    continue; // avoid counting repeatedly
                }
                completed.Add(child.GetType());
                if (child is TerminalNode)
                {
                    continue; // tokens are separators at most not siblings
                }

                // found subtree child
                //JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
                //ORIGINAL LINE: java.util.List<? extends org.antlr.v4.runtime.ParserRuleContext> siblings = ctx.getRuleContexts(((org.antlr.v4.runtime.ParserRuleContext) child).getClass());

                var s = ctx.GetRuleContexts <ParserRuleContext>();
                IList <ParserRuleContext> siblings = s.Where((n) => n.GetType() == child.GetType()).ToList();

                //IList<ParserRuleContext> siblings = ctx.GetRuleContexts(((ParserRuleContext) child).GetType());
                if (siblings.Count > 1)
                { // we found a list
                  // check for separator by looking between first two siblings (assume all are same)
                    ParserRuleContext first    = siblings[0];
                    ParserRuleContext second   = siblings[1];
                    IList <ITree>     children = Trees.GetChildren(ctx);

                    int firstIndex  = children.IndexOf(first);
                    int secondIndex = children.IndexOf(second);

                    if (firstIndex + 1 == secondIndex)
                    {
                        continue; // nothing between first and second so no separator
                    }

                    ParseTree between = ctx.GetChild(firstIndex + 1);
                    if (between is TerminalNode)
                    { // is it a token?
                        Token separator = ((TerminalNode)between).Symbol;
                        visitNonSingletonWithSeparator(ctx, siblings, separator);
                    }
                }
            }
        }
示例#3
0
        public override ICollection <IParseTree> Evaluate(IParseTree t)
        {
            if (invert)
            {
                return(new List <IParseTree>());
            }
            // !* is weird but valid (empty)
            IList <IParseTree> kids = new List <IParseTree>();

            foreach (ITree c in Trees.GetChildren(t))
            {
                kids.Add((IParseTree)c);
            }
            return(kids);
        }
示例#4
0
        public override ICollection <IParseTree> Evaluate(IParseTree t)
        {
            // return all children of t that match nodeName
            IList <IParseTree> nodes = new List <IParseTree>();

            foreach (ITree c in Trees.GetChildren(t))
            {
                if (c is ParserRuleContext)
                {
                    ParserRuleContext ctx = (ParserRuleContext)c;
                    if ((ctx.RuleIndex == ruleIndex && !invert) || (ctx.RuleIndex != ruleIndex && invert))
                    {
                        nodes.Add(ctx);
                    }
                }
            }
            return(nodes);
        }
        public override ICollection <IParseTree> Evaluate(IParseTree t)
        {
            // return all children of t that match nodeName
            IList <IParseTree> nodes = new List <IParseTree>();

            foreach (ITree c in Trees.GetChildren(t))
            {
                if (c is ITerminalNode)
                {
                    ITerminalNode tnode = (ITerminalNode)c;
                    if ((tnode.Symbol.Type == tokenType && !invert) || (tnode.Symbol.Type != tokenType && invert))
                    {
                        nodes.Add(tnode);
                    }
                }
            }
            return(nodes);
        }