Search in sources :

Example 91 with RecognitionException

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

the class DRL6StrictParser method enumerative.

/**
 * enumerative := ID ( LEFT_PAREN expression (COMMA expression)* RIGHT_PAREN )?
 */
private void enumerative(EnumDeclarationDescrBuilder declare) {
    EnumLiteralDescrBuilder literal = null;
    String lit = null;
    try {
        Token enumLit = match(input, DRL6Lexer.ID, null, null, DroolsEditorType.IDENTIFIER);
        lit = enumLit.getText();
        if (state.failed)
            return;
    } catch (RecognitionException re) {
        reportError(re);
    }
    try {
        literal = helper.start(declare, EnumLiteralDescrBuilder.class, lit);
        if (input.LA(1) == DRL6Lexer.LEFT_PAREN) {
            match(input, DRL6Lexer.LEFT_PAREN, null, null, DroolsEditorType.SYMBOL);
            if (state.failed)
                return;
            boolean more;
            do {
                int first = input.index();
                exprParser.conditionalExpression();
                if (state.failed)
                    return;
                if (state.backtracking == 0 && input.index() > first) {
                    // expression consumed something
                    String arg = input.toString(first, input.LT(-1).getTokenIndex());
                    literal.constructorArg(arg);
                }
                more = input.LA(1) == DRL6Lexer.COMMA;
                if (more) {
                    match(input, DRL6Lexer.COMMA, null, null, DroolsEditorType.SYMBOL);
                }
            } while (more);
            match(input, DRL6Lexer.RIGHT_PAREN, null, null, DroolsEditorType.SYMBOL);
            if (state.failed)
                return;
        }
    } catch (RecognitionException re) {
        reportError(re);
    } finally {
        helper.end(FieldDescrBuilder.class, literal);
    }
}
Also used : EnumLiteralDescrBuilder(org.drools.compiler.lang.api.EnumLiteralDescrBuilder) Token(org.antlr.runtime.Token) CommonToken(org.antlr.runtime.CommonToken) RecognitionException(org.antlr.runtime.RecognitionException)

Example 92 with RecognitionException

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

the class DRL6StrictParser method entryPointDeclaration.

/**
 * entryPointDeclaration := annotation* ENTRY-POINT stringId END
 *
 * @return
 * @throws org.antlr.runtime.RecognitionException
 */
public EntryPointDeclarationDescr entryPointDeclaration(DeclareDescrBuilder ddb) throws RecognitionException {
    EntryPointDeclarationDescrBuilder declare = null;
    try {
        declare = helper.start(ddb, EntryPointDeclarationDescrBuilder.class, null);
        setAnnotationsOn(declare);
        match(input, DRL6Lexer.ID, DroolsSoftKeywords.ENTRY, null, DroolsEditorType.KEYWORD);
        if (state.failed)
            return null;
        match(input, DRL6Lexer.MINUS, null, null, DroolsEditorType.KEYWORD);
        if (state.failed)
            return null;
        match(input, DRL6Lexer.ID, DroolsSoftKeywords.POINT, null, DroolsEditorType.KEYWORD);
        if (state.failed)
            return null;
        String ep = stringId();
        if (state.failed)
            return null;
        if (state.backtracking == 0) {
            declare.entryPointId(ep);
        }
        match(input, DRL6Lexer.ID, DroolsSoftKeywords.END, null, DroolsEditorType.KEYWORD);
        if (state.failed)
            return null;
    } catch (RecognitionException re) {
        reportError(re);
    } finally {
        helper.end(EntryPointDeclarationDescrBuilder.class, declare);
    }
    return (declare != null) ? declare.getDescr() : null;
}
Also used : EntryPointDeclarationDescrBuilder(org.drools.compiler.lang.api.EntryPointDeclarationDescrBuilder) RecognitionException(org.antlr.runtime.RecognitionException)

Example 93 with RecognitionException

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

the class DRL6StrictParser method defaultConsequence.

/**
 * defaultConsequence := THEN chunk
 * @param rule
 */
public void defaultConsequence(RuleDescrBuilder rule) {
    try {
        int first = input.index();
        Token t = match(input, DRL6Lexer.ID, DroolsSoftKeywords.THEN, null, DroolsEditorType.KEYWORD);
        if (state.failed)
            return;
        if (state.backtracking == 0) {
            rule.getDescr().setConsequenceLocation(t.getLine(), t.getCharPositionInLine());
            helper.emit(Location.LOCATION_RHS);
        }
        String chunk = getConsequenceCode(first);
        // remove the "then" keyword and any subsequent spaces and line breaks
        // keep indentation of 1st non-blank line
        chunk = chunk.replaceFirst("^then\\s*\\r?\\n?", "");
        rule.rhs(chunk);
    } catch (RecognitionException re) {
        reportError(re);
    }
}
Also used : Token(org.antlr.runtime.Token) CommonToken(org.antlr.runtime.CommonToken) RecognitionException(org.antlr.runtime.RecognitionException)

Example 94 with RecognitionException

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

the class DRL6StrictParser method query.

/* ------------------------------------------------------------------------------------------------
     *                         QUERY STATEMENT
     * ------------------------------------------------------------------------------------------------ */
/**
 * query := annotation* QUERY stringId parameters? lhsExpression END
 *
 * @return
 * @throws org.antlr.runtime.RecognitionException
 */
public RuleDescr query(PackageDescrBuilder pkg) throws RecognitionException {
    QueryDescrBuilder query = null;
    try {
        query = helper.start(pkg, QueryDescrBuilder.class, null);
        setAnnotationsOn(query);
        // 'query'
        match(input, DRL6Lexer.ID, DroolsSoftKeywords.QUERY, null, DroolsEditorType.KEYWORD);
        if (state.failed)
            return null;
        if (helper.validateIdentifierKey(DroolsSoftKeywords.WHEN) || helper.validateIdentifierKey(DroolsSoftKeywords.THEN) || helper.validateIdentifierKey(DroolsSoftKeywords.END)) {
            failMissingTokenException();
            // in case it is backtracking
            return null;
        }
        String name = stringId();
        if (state.backtracking == 0)
            query.name(name);
        if (state.failed)
            return null;
        if (state.backtracking == 0) {
            helper.emit(Location.LOCATION_RULE_HEADER);
        }
        if (speculateParameters(true)) {
            // parameters
            parameters(query, true);
            if (state.failed)
                return null;
            if (state.backtracking == 0) {
                helper.emit(Location.LOCATION_LHS_BEGIN_OF_CONDITION);
            }
        } else if (speculateParameters(false)) {
            // parameters
            parameters(query, false);
            if (state.failed)
                return null;
            if (state.backtracking == 0) {
                helper.emit(Location.LOCATION_LHS_BEGIN_OF_CONDITION);
            }
        }
        if (state.backtracking == 0 && input.LA(1) != DRL6Lexer.EOF) {
            helper.emit(Location.LOCATION_LHS_BEGIN_OF_CONDITION);
        }
        if (input.LA(1) != DRL6Lexer.EOF) {
            lhsExpression(query != null ? query.lhs() : null);
        }
        match(input, DRL6Lexer.ID, DroolsSoftKeywords.END, null, DroolsEditorType.KEYWORD);
        if (state.failed)
            return null;
        helper.emit(Location.LOCATION_RHS);
    } catch (RecognitionException re) {
        reportError(re);
    } finally {
        helper.end(QueryDescrBuilder.class, query);
    }
    return (query != null) ? query.getDescr() : null;
}
Also used : QueryDescrBuilder(org.drools.compiler.lang.api.QueryDescrBuilder) RecognitionException(org.antlr.runtime.RecognitionException)

Example 95 with RecognitionException

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

the class DRL6StrictParser method globalStatement.

/* ------------------------------------------------------------------------------------------------
     *                         GLOBAL STATEMENT
     * ------------------------------------------------------------------------------------------------ */
/**
 * globalStatement := GLOBAL type ID
 *
 * @return
 * @throws org.antlr.runtime.RecognitionException
 */
public GlobalDescr globalStatement(PackageDescrBuilder pkg) throws RecognitionException {
    GlobalDescrBuilder global = null;
    try {
        global = helper.start(pkg, GlobalDescrBuilder.class, null);
        // 'global'
        match(input, DRL6Lexer.ID, DroolsSoftKeywords.GLOBAL, null, DroolsEditorType.KEYWORD);
        if (state.failed)
            return null;
        // type
        String type = type();
        if (state.backtracking == 0)
            global.type(type);
        if (state.failed)
            return null;
        // identifier
        Token id = match(input, DRL6Lexer.ID, null, null, DroolsEditorType.IDENTIFIER_TYPE);
        if (state.failed)
            return null;
        if (state.backtracking == 0) {
            global.identifier(id.getText());
            helper.setParaphrasesValue(DroolsParaphraseTypes.GLOBAL, id.getText());
        }
    } catch (RecognitionException re) {
        reportError(re);
    } finally {
        helper.end(GlobalDescrBuilder.class, global);
    }
    return (global != null) ? global.getDescr() : null;
}
Also used : GlobalDescrBuilder(org.drools.compiler.lang.api.GlobalDescrBuilder) Token(org.antlr.runtime.Token) CommonToken(org.antlr.runtime.CommonToken) RecognitionException(org.antlr.runtime.RecognitionException)

Aggregations

RecognitionException (org.antlr.runtime.RecognitionException)257 Token (org.antlr.runtime.Token)169 CommonTree (org.antlr.runtime.tree.CommonTree)132 RewriteRuleSubtreeStream (org.antlr.runtime.tree.RewriteRuleSubtreeStream)98 RewriteRuleTokenStream (org.antlr.runtime.tree.RewriteRuleTokenStream)74 CommonToken (org.antlr.runtime.CommonToken)48 NoViableAltException (org.antlr.runtime.NoViableAltException)43 RewriteEarlyExitException (org.antlr.runtime.tree.RewriteEarlyExitException)21 ParserRuleReturnScope (org.antlr.runtime.ParserRuleReturnScope)14 CommonTokenStream (org.antlr.runtime.CommonTokenStream)11 EarlyExitException (org.antlr.runtime.EarlyExitException)10 MismatchedSetException (org.antlr.runtime.MismatchedSetException)10 ANTLRStringStream (org.antlr.runtime.ANTLRStringStream)8 MismatchedTokenException (org.antlr.runtime.MismatchedTokenException)7 TokenRewriteStream (org.antlr.runtime.TokenRewriteStream)7 FailedPredicateException (org.antlr.runtime.FailedPredicateException)6 MissingTokenException (org.antlr.runtime.MissingTokenException)6 UnwantedTokenException (org.antlr.runtime.UnwantedTokenException)6 BaseDescr (org.drools.compiler.lang.descr.BaseDescr)5 HashMap (java.util.HashMap)4