Search in sources :

Example 11 with ParserRuleReturnScope

use of org.antlr.runtime.ParserRuleReturnScope in project hive by apache.

the class ParseDriver method parseTriggerExpression.

public ASTNode parseTriggerExpression(String command) throws ParseException {
    GenericHiveLexer lexer = GenericHiveLexer.of(command, null);
    TokenRewriteStream tokens = new TokenRewriteStream(lexer);
    HiveParser parser = new HiveParser(tokens);
    parser.setTreeAdaptor(adaptor);
    ParserRuleReturnScope r;
    try {
        r = parser.triggerExpressionStandalone();
    } catch (RecognitionException e) {
        throw new ParseException(parser.errors);
    }
    if (lexer.getErrors().size() != 0) {
        throw new ParseException(lexer.getErrors());
    } else if (parser.errors.size() != 0) {
        throw new ParseException(parser.errors);
    }
    return (ASTNode) r.getTree();
}
Also used : TokenRewriteStream(org.antlr.runtime.TokenRewriteStream) ParserRuleReturnScope(org.antlr.runtime.ParserRuleReturnScope) RecognitionException(org.antlr.runtime.RecognitionException)

Example 12 with ParserRuleReturnScope

use of org.antlr.runtime.ParserRuleReturnScope in project hive by apache.

the class ParseDriver method parseExpression.

public ASTNode parseExpression(String command) throws ParseException {
    LOG.debug("Parsing expression: {}", command);
    GenericHiveLexer lexer = GenericHiveLexer.of(command, null);
    TokenRewriteStream tokens = new TokenRewriteStream(lexer);
    HiveParser parser = new HiveParser(tokens);
    parser.setTreeAdaptor(adaptor);
    ParserRuleReturnScope r;
    try {
        r = parser.expression();
    } catch (RecognitionException e) {
        throw new ParseException(parser.errors);
    }
    if (lexer.getErrors().size() == 0 && parser.errors.size() == 0) {
        LOG.debug("Parse Completed");
    } else if (lexer.getErrors().size() != 0) {
        throw new ParseException(lexer.getErrors());
    } else {
        throw new ParseException(parser.errors);
    }
    return (ASTNode) r.getTree();
}
Also used : TokenRewriteStream(org.antlr.runtime.TokenRewriteStream) ParserRuleReturnScope(org.antlr.runtime.ParserRuleReturnScope) RecognitionException(org.antlr.runtime.RecognitionException)

Example 13 with ParserRuleReturnScope

use of org.antlr.runtime.ParserRuleReturnScope in project drools by kiegroup.

the class DSLMapParser method value_sentence.

// $ANTLR start "value_sentence"
// src/main/resources/org/drools/compiler/lang/dsl/DSLMap.g:172:1: value_sentence : ( variable_reference |vc= value_chunk -> VT_LITERAL[$vc.start, text] );
public final DSLMapParser.value_sentence_return value_sentence() throws RecognitionException {
    DSLMapParser.value_sentence_return retval = new DSLMapParser.value_sentence_return();
    retval.start = input.LT(1);
    Object root_0 = null;
    ParserRuleReturnScope vc = null;
    ParserRuleReturnScope variable_reference19 = null;
    RewriteRuleSubtreeStream stream_value_chunk = new RewriteRuleSubtreeStream(adaptor, "rule value_chunk");
    String text = "";
    try {
        // src/main/resources/org/drools/compiler/lang/dsl/DSLMap.g:176:5: ( variable_reference |vc= value_chunk -> VT_LITERAL[$vc.start, text] )
        int alt12 = 2;
        int LA12_0 = input.LA(1);
        if ((LA12_0 == LEFT_CURLY)) {
            alt12 = 1;
        } else if (((LA12_0 >= COLON && LA12_0 <= DOT) || LA12_0 == EQUALS || (LA12_0 >= LEFT_SQUARE && LA12_0 <= LITERAL) || LA12_0 == RIGHT_SQUARE)) {
            alt12 = 2;
        } else {
            if (state.backtracking > 0) {
                state.failed = true;
                return retval;
            }
            NoViableAltException nvae = new NoViableAltException("", 12, 0, input);
            throw nvae;
        }
        switch(alt12) {
            case 1:
                // src/main/resources/org/drools/compiler/lang/dsl/DSLMap.g:176:7: variable_reference
                {
                    root_0 = (Object) adaptor.nil();
                    pushFollow(FOLLOW_variable_reference_in_value_sentence703);
                    variable_reference19 = variable_reference();
                    state._fsp--;
                    if (state.failed)
                        return retval;
                    if (state.backtracking == 0)
                        adaptor.addChild(root_0, variable_reference19.getTree());
                }
                break;
            case 2:
                // src/main/resources/org/drools/compiler/lang/dsl/DSLMap.g:177:7: vc= value_chunk
                {
                    pushFollow(FOLLOW_value_chunk_in_value_sentence713);
                    vc = value_chunk();
                    state._fsp--;
                    if (state.failed)
                        return retval;
                    if (state.backtracking == 0)
                        stream_value_chunk.add(vc.getTree());
                    if (state.backtracking == 0) {
                        text = (vc != null ? input.toString(vc.start, vc.stop) : null);
                    }
                    // wildcard labels:
                    if (state.backtracking == 0) {
                        retval.tree = root_0;
                        RewriteRuleSubtreeStream stream_retval = new RewriteRuleSubtreeStream(adaptor, "rule retval", retval != null ? retval.getTree() : null);
                        root_0 = (Object) adaptor.nil();
                        // 178:5: -> VT_LITERAL[$vc.start, text]
                        {
                            adaptor.addChild(root_0, (Object) adaptor.create(VT_LITERAL, (vc != null ? (vc.start) : null), text));
                        }
                        retval.tree = root_0;
                    }
                }
                break;
        }
        retval.stop = input.LT(-1);
        if (state.backtracking == 0) {
            retval.tree = (Object) adaptor.rulePostProcessing(root_0);
            adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);
        }
    } catch (RecognitionException re) {
        reportError(re);
        recover(input, re);
        retval.tree = (Object) adaptor.errorNode(input, retval.start, input.LT(-1), re);
    } finally {
    // do for sure before leaving
    }
    return retval;
}
Also used : NoViableAltException(org.antlr.runtime.NoViableAltException) RewriteRuleSubtreeStream(org.antlr.runtime.tree.RewriteRuleSubtreeStream) ParserRuleReturnScope(org.antlr.runtime.ParserRuleReturnScope) RecognitionException(org.antlr.runtime.RecognitionException)

Example 14 with ParserRuleReturnScope

use of org.antlr.runtime.ParserRuleReturnScope in project drools by kiegroup.

the class DSLMapParser method mapping_file.

// $ANTLR start "mapping_file"
// src/main/resources/org/drools/compiler/lang/dsl/DSLMap.g:106:1: mapping_file : ( statement )* -> ^( VT_DSL_GRAMMAR ( statement )* ) ;
public final DSLMapParser.mapping_file_return mapping_file() throws RecognitionException {
    DSLMapParser.mapping_file_return retval = new DSLMapParser.mapping_file_return();
    retval.start = input.LT(1);
    Object root_0 = null;
    ParserRuleReturnScope statement1 = null;
    RewriteRuleSubtreeStream stream_statement = new RewriteRuleSubtreeStream(adaptor, "rule statement");
    try {
        // src/main/resources/org/drools/compiler/lang/dsl/DSLMap.g:107:5: ( ( statement )* -> ^( VT_DSL_GRAMMAR ( statement )* ) )
        // src/main/resources/org/drools/compiler/lang/dsl/DSLMap.g:107:7: ( statement )*
        {
            // src/main/resources/org/drools/compiler/lang/dsl/DSLMap.g:107:7: ( statement )*
            loop1: while (true) {
                int alt1 = 2;
                int LA1_0 = input.LA(1);
                if ((LA1_0 == EOL || LA1_0 == LEFT_SQUARE)) {
                    alt1 = 1;
                }
                switch(alt1) {
                    case 1:
                        // src/main/resources/org/drools/compiler/lang/dsl/DSLMap.g:107:7: statement
                        {
                            pushFollow(FOLLOW_statement_in_mapping_file275);
                            statement1 = statement();
                            state._fsp--;
                            if (state.failed)
                                return retval;
                            if (state.backtracking == 0)
                                stream_statement.add(statement1.getTree());
                        }
                        break;
                    default:
                        break loop1;
                }
            }
            // wildcard labels:
            if (state.backtracking == 0) {
                retval.tree = root_0;
                RewriteRuleSubtreeStream stream_retval = new RewriteRuleSubtreeStream(adaptor, "rule retval", retval != null ? retval.getTree() : null);
                root_0 = (Object) adaptor.nil();
                // 108:5: -> ^( VT_DSL_GRAMMAR ( statement )* )
                {
                    // src/main/resources/org/drools/compiler/lang/dsl/DSLMap.g:108:8: ^( VT_DSL_GRAMMAR ( statement )* )
                    {
                        Object root_1 = (Object) adaptor.nil();
                        root_1 = (Object) adaptor.becomeRoot((Object) adaptor.create(VT_DSL_GRAMMAR, "VT_DSL_GRAMMAR"), root_1);
                        // src/main/resources/org/drools/compiler/lang/dsl/DSLMap.g:108:25: ( statement )*
                        while (stream_statement.hasNext()) {
                            adaptor.addChild(root_1, stream_statement.nextTree());
                        }
                        stream_statement.reset();
                        adaptor.addChild(root_0, root_1);
                    }
                }
                retval.tree = root_0;
            }
        }
        retval.stop = input.LT(-1);
        if (state.backtracking == 0) {
            retval.tree = (Object) adaptor.rulePostProcessing(root_0);
            adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);
        }
    } catch (RecognitionException re) {
        reportError(re);
        recover(input, re);
        retval.tree = (Object) adaptor.errorNode(input, retval.start, input.LT(-1), re);
    } finally {
    // do for sure before leaving
    }
    return retval;
}
Also used : RewriteRuleSubtreeStream(org.antlr.runtime.tree.RewriteRuleSubtreeStream) ParserRuleReturnScope(org.antlr.runtime.ParserRuleReturnScope) RecognitionException(org.antlr.runtime.RecognitionException)

Example 15 with ParserRuleReturnScope

use of org.antlr.runtime.ParserRuleReturnScope in project drools by kiegroup.

the class DSLMapParser method key_section.

// $ANTLR start "key_section"
// src/main/resources/org/drools/compiler/lang/dsl/DSLMap.g:149:1: key_section : (ks= key_sentence )+ -> ^( VT_ENTRY_KEY ( key_sentence )+ ) ;
public final DSLMapParser.key_section_return key_section() throws RecognitionException {
    DSLMapParser.key_section_return retval = new DSLMapParser.key_section_return();
    retval.start = input.LT(1);
    Object root_0 = null;
    ParserRuleReturnScope ks = null;
    RewriteRuleSubtreeStream stream_key_sentence = new RewriteRuleSubtreeStream(adaptor, "rule key_sentence");
    try {
        // src/main/resources/org/drools/compiler/lang/dsl/DSLMap.g:150:5: ( (ks= key_sentence )+ -> ^( VT_ENTRY_KEY ( key_sentence )+ ) )
        // src/main/resources/org/drools/compiler/lang/dsl/DSLMap.g:150:7: (ks= key_sentence )+
        {
            // src/main/resources/org/drools/compiler/lang/dsl/DSLMap.g:150:9: (ks= key_sentence )+
            int cnt8 = 0;
            loop8: while (true) {
                int alt8 = 2;
                int LA8_0 = input.LA(1);
                if ((LA8_0 == COLON || (LA8_0 >= LEFT_CURLY && LA8_0 <= LITERAL) || LA8_0 == RIGHT_SQUARE)) {
                    alt8 = 1;
                }
                switch(alt8) {
                    case 1:
                        // src/main/resources/org/drools/compiler/lang/dsl/DSLMap.g:150:9: ks= key_sentence
                        {
                            pushFollow(FOLLOW_key_sentence_in_key_section568);
                            ks = key_sentence();
                            state._fsp--;
                            if (state.failed)
                                return retval;
                            if (state.backtracking == 0)
                                stream_key_sentence.add(ks.getTree());
                        }
                        break;
                    default:
                        if (cnt8 >= 1)
                            break loop8;
                        if (state.backtracking > 0) {
                            state.failed = true;
                            return retval;
                        }
                        EarlyExitException eee = new EarlyExitException(8, input);
                        throw eee;
                }
                cnt8++;
            }
            // wildcard labels:
            if (state.backtracking == 0) {
                retval.tree = root_0;
                RewriteRuleSubtreeStream stream_retval = new RewriteRuleSubtreeStream(adaptor, "rule retval", retval != null ? retval.getTree() : null);
                root_0 = (Object) adaptor.nil();
                // 151:5: -> ^( VT_ENTRY_KEY ( key_sentence )+ )
                {
                    // src/main/resources/org/drools/compiler/lang/dsl/DSLMap.g:151:8: ^( VT_ENTRY_KEY ( key_sentence )+ )
                    {
                        Object root_1 = (Object) adaptor.nil();
                        root_1 = (Object) adaptor.becomeRoot((Object) adaptor.create(VT_ENTRY_KEY, "VT_ENTRY_KEY"), root_1);
                        if (!(stream_key_sentence.hasNext())) {
                            throw new RewriteEarlyExitException();
                        }
                        while (stream_key_sentence.hasNext()) {
                            adaptor.addChild(root_1, stream_key_sentence.nextTree());
                        }
                        stream_key_sentence.reset();
                        adaptor.addChild(root_0, root_1);
                    }
                }
                retval.tree = root_0;
            }
        }
        retval.stop = input.LT(-1);
        if (state.backtracking == 0) {
            retval.tree = (Object) adaptor.rulePostProcessing(root_0);
            adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);
        }
    } catch (RecognitionException re) {
        reportError(re);
        recover(input, re);
        retval.tree = (Object) adaptor.errorNode(input, retval.start, input.LT(-1), re);
    } finally {
    // do for sure before leaving
    }
    return retval;
}
Also used : RewriteRuleSubtreeStream(org.antlr.runtime.tree.RewriteRuleSubtreeStream) EarlyExitException(org.antlr.runtime.EarlyExitException) RewriteEarlyExitException(org.antlr.runtime.tree.RewriteEarlyExitException) RewriteEarlyExitException(org.antlr.runtime.tree.RewriteEarlyExitException) ParserRuleReturnScope(org.antlr.runtime.ParserRuleReturnScope) RecognitionException(org.antlr.runtime.RecognitionException)

Aggregations

ParserRuleReturnScope (org.antlr.runtime.ParserRuleReturnScope)35 RecognitionException (org.antlr.runtime.RecognitionException)35 RewriteRuleSubtreeStream (org.antlr.runtime.tree.RewriteRuleSubtreeStream)18 Token (org.antlr.runtime.Token)16 CommonToken (org.antlr.runtime.CommonToken)14 EarlyExitException (org.antlr.runtime.EarlyExitException)10 NoViableAltException (org.antlr.runtime.NoViableAltException)10 RewriteEarlyExitException (org.antlr.runtime.tree.RewriteEarlyExitException)10 RewriteRuleTokenStream (org.antlr.runtime.tree.RewriteRuleTokenStream)8 TokenRewriteStream (org.antlr.runtime.TokenRewriteStream)5 CommonTokenStream (org.antlr.runtime.CommonTokenStream)4 GrammarASTAdaptor (org.antlr.v4.parse.GrammarASTAdaptor)4 ToolANTLRParser (org.antlr.v4.parse.ToolANTLRParser)4 ANTLRStringStream (org.antlr.runtime.ANTLRStringStream)2 RewriteEmptyStreamException (org.antlr.runtime.tree.RewriteEmptyStreamException)2 ANTLRLexer (org.antlr.v4.parse.ANTLRLexer)2 ToolANTLRLexer (org.antlr.v4.parse.ToolANTLRLexer)2 org.antlr.v4.parse.v3TreeGrammarException (org.antlr.v4.parse.v3TreeGrammarException)2 GrammarAST (org.antlr.v4.tool.ast.GrammarAST)2 GrammarRootAST (org.antlr.v4.tool.ast.GrammarRootAST)2