Ejemplo n.º 1
0
        public LabelElementPair(Grammar g, GrammarAST label, GrammarAST element, int labelOp)
        {
            this.label   = label;
            this.element = element;
            // compute general case for label type
            if (element.GetFirstDescendantWithType(tokenTypeForTokens) != null)
            {
                if (labelOp == ANTLRParser.ASSIGN)
                {
                    type = LabelType.TOKEN_LABEL;
                }
                else
                {
                    type = LabelType.TOKEN_LIST_LABEL;
                }
            }
            else if (element.GetFirstDescendantWithType(ANTLRParser.RULE_REF) != null)
            {
                if (labelOp == ANTLRParser.ASSIGN)
                {
                    type = LabelType.RULE_LABEL;
                }
                else
                {
                    type = LabelType.RULE_LIST_LABEL;
                }
            }

            // now reset if lexer and string
            if (g.IsLexer())
            {
                if (element.GetFirstDescendantWithType(ANTLRParser.STRING_LITERAL) != null)
                {
                    if (labelOp == ANTLRParser.ASSIGN)
                    {
                        type = LabelType.LEXER_STRING_LABEL;
                    }
                }
            }
        }
Ejemplo n.º 2
0
        internal virtual bool HasTypeOrMoreCommand([NotNull] Rule r)
        {
            GrammarAST ast = r.ast;

            if (ast == null)
            {
                return(false);
            }

            GrammarAST altActionAst = (GrammarAST)ast.GetFirstDescendantWithType(ANTLRParser.LEXER_ALT_ACTION);

            if (altActionAst == null)
            {
                // the rule isn't followed by any commands
                return(false);
            }

            // first child is the alt itself, subsequent are the actions
            for (int i = 1; i < altActionAst.ChildCount; i++)
            {
                GrammarAST node = (GrammarAST)altActionAst.GetChild(i);
                if (node.Type == ANTLRParser.LEXER_ACTION_CALL)
                {
                    if ("type".Equals(node.GetChild(0).Text))
                    {
                        return(true);
                    }
                }
                else if ("more".Equals(node.Text))
                {
                    return(true);
                }
            }

            return(false);
        }