Search in sources :

Example 16 with RecognitionException

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

the class DRL6Parser method function.

/* ------------------------------------------------------------------------------------------------
     *                         FUNCTION STATEMENT
     * ------------------------------------------------------------------------------------------------ */
/**
 * function := FUNCTION type? ID parameters(typed) chunk_{_}
 *
 * @return
 * @throws org.antlr.runtime.RecognitionException
 */
public FunctionDescr function(PackageDescrBuilder pkg) throws RecognitionException {
    FunctionDescrBuilder function = null;
    try {
        function = helper.start(pkg, FunctionDescrBuilder.class, null);
        // 'function'
        match(input, DRL6Lexer.ID, DroolsSoftKeywords.FUNCTION, null, DroolsEditorType.KEYWORD);
        if (state.failed)
            return null;
        if (input.LA(1) != DRL6Lexer.ID || input.LA(2) != DRL6Lexer.LEFT_PAREN) {
            // type
            String type = type();
            if (state.failed)
                return null;
            if (state.backtracking == 0)
                function.returnType(type);
        }
        // name
        Token id = match(input, DRL6Lexer.ID, null, null, DroolsEditorType.IDENTIFIER);
        if (state.failed)
            return null;
        if (state.backtracking == 0) {
            function.name(id.getText());
            helper.setParaphrasesValue(DroolsParaphraseTypes.FUNCTION, "\"" + id.getText() + "\"");
        }
        // arguments
        parameters(function, true);
        if (state.failed)
            return null;
        // body
        String body = chunk(DRL6Lexer.LEFT_CURLY, DRL6Lexer.RIGHT_CURLY, -1);
        if (state.failed)
            return null;
        if (state.backtracking == 0)
            function.body(body);
    } catch (RecognitionException re) {
        reportError(re);
    } finally {
        helper.end(FunctionDescrBuilder.class, function);
    }
    return (function != null) ? function.getDescr() : null;
}
Also used : Token(org.antlr.runtime.Token) CommonToken(org.antlr.runtime.CommonToken) FunctionDescrBuilder(org.drools.compiler.lang.api.FunctionDescrBuilder) RecognitionException(org.antlr.runtime.RecognitionException)

Example 17 with RecognitionException

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

the class DRL6Parser method enumDeclaration.

/*
     * typeDeclaration := [ENUM] qualifiedIdentifier
     *                         annotation*
     *                         enumerative+
     *                         field*
     *                     END
     *
     * @return
     * @throws RecognitionException
     */
public EnumDeclarationDescr enumDeclaration(DeclareDescrBuilder ddb) throws RecognitionException {
    EnumDeclarationDescrBuilder declare = null;
    try {
        declare = helper.start(ddb, EnumDeclarationDescrBuilder.class, null);
        // type may be qualified when adding metadata
        String type = qualifiedIdentifier();
        if (state.failed)
            return null;
        if (state.backtracking == 0)
            declare.name(type);
        while (input.LA(1) == DRL6Lexer.AT) {
            // annotation*
            annotation(declare);
            if (state.failed)
                return null;
        }
        while (input.LA(1) == DRL6Lexer.ID) {
            int next = input.LA(2);
            if (next == DRL6Lexer.LEFT_PAREN || next == DRL6Lexer.COMMA || next == DRL6Lexer.SEMICOLON) {
                enumerative(declare);
                if (state.failed)
                    return null;
            }
            if (input.LA(1) == DRL6Lexer.COMMA) {
                match(input, DRL6Lexer.COMMA, null, null, DroolsEditorType.SYMBOL);
            } else {
                match(input, DRL6Lexer.SEMICOLON, null, null, DroolsEditorType.SYMBOL);
                break;
            }
        }
        // boolean qualified = type.indexOf( '.' ) >= 0;
        while (// ! qualified &&
        input.LA(1) == DRL6Lexer.ID && !helper.validateIdentifierKey(DroolsSoftKeywords.END)) {
            // field*
            field(declare);
            if (state.failed)
                return null;
        }
        match(input, DRL6Lexer.ID, DroolsSoftKeywords.END, null, DroolsEditorType.KEYWORD);
        if (state.failed)
            return null;
    } catch (RecognitionException re) {
        reportError(re);
    } finally {
        helper.end(TypeDeclarationDescrBuilder.class, declare);
    }
    return (declare != null) ? declare.getDescr() : null;
}
Also used : EnumDeclarationDescrBuilder(org.drools.compiler.lang.api.EnumDeclarationDescrBuilder) RecognitionException(org.antlr.runtime.RecognitionException)

Example 18 with RecognitionException

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

the class DRL6Parser 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)

Example 19 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 20 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)

Aggregations

RecognitionException (org.antlr.runtime.RecognitionException)375 Token (org.antlr.runtime.Token)215 CommonTree (org.antlr.runtime.tree.CommonTree)138 RewriteRuleSubtreeStream (org.antlr.runtime.tree.RewriteRuleSubtreeStream)112 CommonToken (org.antlr.runtime.CommonToken)95 RewriteRuleTokenStream (org.antlr.runtime.tree.RewriteRuleTokenStream)83 NoViableAltException (org.antlr.runtime.NoViableAltException)50 ParserRuleReturnScope (org.antlr.runtime.ParserRuleReturnScope)34 RewriteEarlyExitException (org.antlr.runtime.tree.RewriteEarlyExitException)27 CommonTokenStream (org.antlr.runtime.CommonTokenStream)22 ANTLRStringStream (org.antlr.runtime.ANTLRStringStream)16 EarlyExitException (org.antlr.runtime.EarlyExitException)16 MismatchedSetException (org.antlr.runtime.MismatchedSetException)14 MismatchedTokenException (org.antlr.runtime.MismatchedTokenException)12 Test (org.junit.Test)12 TokenRewriteStream (org.antlr.runtime.TokenRewriteStream)11 FailedPredicateException (org.antlr.runtime.FailedPredicateException)10 MissingTokenException (org.antlr.runtime.MissingTokenException)10 UnwantedTokenException (org.antlr.runtime.UnwantedTokenException)10 BoundIdentifiers (org.drools.compiler.compiler.BoundIdentifiers)8