Search in sources :

Example 6 with ImportDescrBuilder

use of org.drools.compiler.lang.api.ImportDescrBuilder in project drools by kiegroup.

the class DRL5Parser method importStatement.

/* ------------------------------------------------------------------------------------------------
     *                         IMPORT STATEMENT
     * ------------------------------------------------------------------------------------------------ */
/**
 * importStatement := IMPORT (FUNCTION|STATIC)? qualifiedIdentifier (DOT STAR)?
 *
 * @return
 * @throws RecognitionException
 */
public ImportDescr importStatement(PackageDescrBuilder pkg) throws RecognitionException {
    ImportDescrBuilder imp = null;
    try {
        imp = helper.start(pkg, ImportDescrBuilder.class, null);
        // import
        match(input, DRL5Lexer.ID, DroolsSoftKeywords.IMPORT, null, DroolsEditorType.KEYWORD);
        if (state.failed)
            return null;
        String kwd;
        if (helper.validateIdentifierKey(kwd = DroolsSoftKeywords.FUNCTION) || helper.validateIdentifierKey(kwd = DroolsSoftKeywords.STATIC)) {
            // function
            match(input, DRL5Lexer.ID, kwd, null, DroolsEditorType.KEYWORD);
            if (state.failed)
                return null;
        }
        // qualifiedIdentifier
        String target = qualifiedIdentifier();
        if (state.failed)
            return null;
        if (input.LA(1) == DRL5Lexer.DOT && input.LA(2) == DRL5Lexer.STAR) {
            // .*
            match(input, DRL5Lexer.DOT, null, null, DroolsEditorType.IDENTIFIER);
            if (state.failed)
                return null;
            match(input, DRL5Lexer.STAR, null, null, DroolsEditorType.IDENTIFIER);
            if (state.failed)
                return null;
            target += ".*";
        }
        if (state.backtracking == 0)
            imp.target(target);
    } catch (RecognitionException re) {
        reportError(re);
    } finally {
        helper.end(ImportDescrBuilder.class, imp);
    }
    return (imp != null) ? imp.getDescr() : null;
}
Also used : ImportDescrBuilder(org.drools.compiler.lang.api.ImportDescrBuilder) RecognitionException(org.antlr.runtime.RecognitionException)

Aggregations

ImportDescrBuilder (org.drools.compiler.lang.api.ImportDescrBuilder)6 AccumulateImportDescrBuilder (org.drools.compiler.lang.api.AccumulateImportDescrBuilder)5 RecognitionException (org.antlr.runtime.RecognitionException)3 CommonToken (org.antlr.runtime.CommonToken)2 Token (org.antlr.runtime.Token)2 AbstractClassTypeDeclarationBuilder (org.drools.compiler.lang.api.AbstractClassTypeDeclarationBuilder)1 AccumulateDescrBuilder (org.drools.compiler.lang.api.AccumulateDescrBuilder)1 AttributeDescrBuilder (org.drools.compiler.lang.api.AttributeDescrBuilder)1 CEDescrBuilder (org.drools.compiler.lang.api.CEDescrBuilder)1 DeclareDescrBuilder (org.drools.compiler.lang.api.DeclareDescrBuilder)1 EntryPointDeclarationDescrBuilder (org.drools.compiler.lang.api.EntryPointDeclarationDescrBuilder)1 EnumDeclarationDescrBuilder (org.drools.compiler.lang.api.EnumDeclarationDescrBuilder)1 EnumLiteralDescrBuilder (org.drools.compiler.lang.api.EnumLiteralDescrBuilder)1 FieldDescrBuilder (org.drools.compiler.lang.api.FieldDescrBuilder)1 ForallDescrBuilder (org.drools.compiler.lang.api.ForallDescrBuilder)1 FunctionDescrBuilder (org.drools.compiler.lang.api.FunctionDescrBuilder)1 GlobalDescrBuilder (org.drools.compiler.lang.api.GlobalDescrBuilder)1 NamedConsequenceDescrBuilder (org.drools.compiler.lang.api.NamedConsequenceDescrBuilder)1 PackageDescrBuilder (org.drools.compiler.lang.api.PackageDescrBuilder)1 PatternDescrBuilder (org.drools.compiler.lang.api.PatternDescrBuilder)1