Search in sources :

Example 1 with ImportDescrBuilder

use of org.drools.drl.ast.dsl.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.drl.ast.dsl.ImportDescrBuilder) RecognitionException(org.antlr.runtime.RecognitionException)

Example 2 with ImportDescrBuilder

use of org.drools.drl.ast.dsl.ImportDescrBuilder in project drools by kiegroup.

the class PackageDescrBuilderImpl method newFunctionImport.

public ImportDescrBuilder newFunctionImport() {
    ImportDescrBuilder impl = new ImportDescrBuilderImpl(this, true);
    descr.addFunctionImport((FunctionImportDescr) initDescr(impl));
    return impl;
}
Also used : AccumulateImportDescrBuilder(org.drools.drl.ast.dsl.AccumulateImportDescrBuilder) ImportDescrBuilder(org.drools.drl.ast.dsl.ImportDescrBuilder)

Example 3 with ImportDescrBuilder

use of org.drools.drl.ast.dsl.ImportDescrBuilder in project drools by kiegroup.

the class DRL6Parser method importStatement.

/* ------------------------------------------------------------------------------------------------
     *                         IMPORT STATEMENT
     * ------------------------------------------------------------------------------------------------ */
/**
 * importStatement := IMPORT ((FUNCTION|STATIC)? qualifiedIdentifier ((DOT STAR)?
 *                           |(ACC|ACCUMULATE) qualifiedIdentifier ID)
 *
 * @return
 * @throws org.antlr.runtime.RecognitionException
 */
public ImportDescr importStatement(PackageDescrBuilder pkg) throws RecognitionException {
    try {
        String kwd;
        if (helper.validateLT(2, kwd = DroolsSoftKeywords.ACC) || helper.validateLT(2, kwd = DroolsSoftKeywords.ACCUMULATE)) {
            AccumulateImportDescrBuilder imp = helper.start(pkg, AccumulateImportDescrBuilder.class, null);
            try {
                // import
                match(input, DRL6Lexer.ID, DroolsSoftKeywords.IMPORT, null, DroolsEditorType.KEYWORD);
                if (state.failed)
                    return null;
                // import accumulate
                match(input, DRL6Lexer.ID, kwd, null, DroolsEditorType.KEYWORD);
                if (state.failed)
                    return null;
                // qualifiedIdentifier
                String target = qualifiedIdentifier();
                if (state.failed)
                    return null;
                // function name
                Token id = match(input, DRL6Lexer.ID, null, null, DroolsEditorType.IDENTIFIER);
                if (state.failed)
                    return null;
                if (state.backtracking == 0) {
                    imp.target(target).functionName(id.getText());
                }
                return (imp != null) ? imp.getDescr() : null;
            } finally {
                helper.end(AccumulateImportDescrBuilder.class, imp);
            }
        } else {
            ImportDescrBuilder imp = helper.start(pkg, ImportDescrBuilder.class, null);
            try {
                // import
                match(input, DRL6Lexer.ID, DroolsSoftKeywords.IMPORT, null, DroolsEditorType.KEYWORD);
                if (state.failed)
                    return null;
                if (helper.validateIdentifierKey(kwd = DroolsSoftKeywords.FUNCTION) || helper.validateIdentifierKey(kwd = DroolsSoftKeywords.STATIC)) {
                    // function
                    match(input, DRL6Lexer.ID, kwd, null, DroolsEditorType.KEYWORD);
                    if (state.failed)
                        return null;
                }
                // qualifiedIdentifier
                String target = qualifiedIdentifier();
                if (state.failed)
                    return null;
                if (input.LA(1) == DRL6Lexer.DOT && input.LA(2) == DRL6Lexer.STAR) {
                    // .*
                    match(input, DRL6Lexer.DOT, null, null, DroolsEditorType.IDENTIFIER);
                    if (state.failed)
                        return null;
                    match(input, DRL6Lexer.STAR, null, null, DroolsEditorType.IDENTIFIER);
                    if (state.failed)
                        return null;
                    target += ".*";
                }
                if (state.backtracking == 0)
                    imp.target(target);
                return (imp != null) ? imp.getDescr() : null;
            } finally {
                helper.end(ImportDescrBuilder.class, imp);
            }
        }
    } catch (RecognitionException re) {
        reportError(re);
    }
    return null;
}
Also used : AccumulateImportDescrBuilder(org.drools.drl.ast.dsl.AccumulateImportDescrBuilder) Token(org.antlr.runtime.Token) CommonToken(org.antlr.runtime.CommonToken) AccumulateImportDescrBuilder(org.drools.drl.ast.dsl.AccumulateImportDescrBuilder) ImportDescrBuilder(org.drools.drl.ast.dsl.ImportDescrBuilder) RecognitionException(org.antlr.runtime.RecognitionException)

Example 4 with ImportDescrBuilder

use of org.drools.drl.ast.dsl.ImportDescrBuilder in project drools by kiegroup.

the class DRL6StrictParser method importStatement.

/* ------------------------------------------------------------------------------------------------
     *                         IMPORT STATEMENT
     * ------------------------------------------------------------------------------------------------ */
/**
 * importStatement := IMPORT ((FUNCTION|STATIC)? qualifiedIdentifier ((DOT STAR)?
 *                           |(ACC|ACCUMULATE) qualifiedIdentifier ID)
 *
 * @return
 * @throws org.antlr.runtime.RecognitionException
 */
public ImportDescr importStatement(PackageDescrBuilder pkg) throws RecognitionException {
    try {
        String kwd;
        if (helper.validateLT(2, kwd = DroolsSoftKeywords.ACC) || helper.validateLT(2, kwd = DroolsSoftKeywords.ACCUMULATE)) {
            AccumulateImportDescrBuilder imp = helper.start(pkg, AccumulateImportDescrBuilder.class, null);
            try {
                // import
                match(input, DRL6Lexer.ID, DroolsSoftKeywords.IMPORT, null, DroolsEditorType.KEYWORD);
                if (state.failed)
                    return null;
                // import accumulate
                match(input, DRL6Lexer.ID, kwd, null, DroolsEditorType.KEYWORD);
                if (state.failed)
                    return null;
                // qualifiedIdentifier
                String target = qualifiedIdentifier();
                if (state.failed)
                    return null;
                // function name
                Token id = match(input, DRL6Lexer.ID, null, null, DroolsEditorType.IDENTIFIER);
                if (state.failed)
                    return null;
                if (state.backtracking == 0) {
                    imp.target(target).functionName(id.getText());
                }
                return (imp != null) ? imp.getDescr() : null;
            } finally {
                helper.end(AccumulateImportDescrBuilder.class, imp);
            }
        } else {
            ImportDescrBuilder imp = helper.start(pkg, ImportDescrBuilder.class, null);
            try {
                // import
                match(input, DRL6Lexer.ID, DroolsSoftKeywords.IMPORT, null, DroolsEditorType.KEYWORD);
                if (state.failed)
                    return null;
                if (helper.validateIdentifierKey(kwd = DroolsSoftKeywords.FUNCTION) || helper.validateIdentifierKey(kwd = DroolsSoftKeywords.STATIC)) {
                    // function
                    match(input, DRL6Lexer.ID, kwd, null, DroolsEditorType.KEYWORD);
                    if (state.failed)
                        return null;
                }
                // qualifiedIdentifier
                String target = qualifiedIdentifier();
                if (state.failed)
                    return null;
                if (input.LA(1) == DRL6Lexer.DOT && input.LA(2) == DRL6Lexer.STAR) {
                    // .*
                    match(input, DRL6Lexer.DOT, null, null, DroolsEditorType.IDENTIFIER);
                    if (state.failed)
                        return null;
                    match(input, DRL6Lexer.STAR, null, null, DroolsEditorType.IDENTIFIER);
                    if (state.failed)
                        return null;
                    target += ".*";
                }
                if (state.backtracking == 0)
                    imp.target(target);
                return (imp != null) ? imp.getDescr() : null;
            } finally {
                helper.end(ImportDescrBuilder.class, imp);
            }
        }
    } catch (RecognitionException re) {
        reportError(re);
    }
    return null;
}
Also used : AccumulateImportDescrBuilder(org.drools.drl.ast.dsl.AccumulateImportDescrBuilder) Token(org.antlr.runtime.Token) CommonToken(org.antlr.runtime.CommonToken) AccumulateImportDescrBuilder(org.drools.drl.ast.dsl.AccumulateImportDescrBuilder) ImportDescrBuilder(org.drools.drl.ast.dsl.ImportDescrBuilder) RecognitionException(org.antlr.runtime.RecognitionException)

Example 5 with ImportDescrBuilder

use of org.drools.drl.ast.dsl.ImportDescrBuilder in project drools by kiegroup.

the class PackageDescrBuilderImpl method newImport.

public ImportDescrBuilder newImport() {
    ImportDescrBuilder impl = new ImportDescrBuilderImpl(this, false);
    descr.addImport(initDescr(impl));
    return impl;
}
Also used : AccumulateImportDescrBuilder(org.drools.drl.ast.dsl.AccumulateImportDescrBuilder) ImportDescrBuilder(org.drools.drl.ast.dsl.ImportDescrBuilder)

Aggregations

ImportDescrBuilder (org.drools.drl.ast.dsl.ImportDescrBuilder)6 AccumulateImportDescrBuilder (org.drools.drl.ast.dsl.AccumulateImportDescrBuilder)5 RecognitionException (org.antlr.runtime.RecognitionException)3 CommonToken (org.antlr.runtime.CommonToken)2 Token (org.antlr.runtime.Token)2 AttributeDescr (org.drools.drl.ast.descr.AttributeDescr)1 AbstractClassTypeDeclarationBuilder (org.drools.drl.ast.dsl.AbstractClassTypeDeclarationBuilder)1 AccumulateDescrBuilder (org.drools.drl.ast.dsl.AccumulateDescrBuilder)1 AttributeDescrBuilder (org.drools.drl.ast.dsl.AttributeDescrBuilder)1 CEDescrBuilder (org.drools.drl.ast.dsl.CEDescrBuilder)1 DeclareDescrBuilder (org.drools.drl.ast.dsl.DeclareDescrBuilder)1 EntryPointDeclarationDescrBuilder (org.drools.drl.ast.dsl.EntryPointDeclarationDescrBuilder)1 EnumDeclarationDescrBuilder (org.drools.drl.ast.dsl.EnumDeclarationDescrBuilder)1 EnumLiteralDescrBuilder (org.drools.drl.ast.dsl.EnumLiteralDescrBuilder)1 FieldDescrBuilder (org.drools.drl.ast.dsl.FieldDescrBuilder)1 ForallDescrBuilder (org.drools.drl.ast.dsl.ForallDescrBuilder)1 FunctionDescrBuilder (org.drools.drl.ast.dsl.FunctionDescrBuilder)1 GlobalDescrBuilder (org.drools.drl.ast.dsl.GlobalDescrBuilder)1 NamedConsequenceDescrBuilder (org.drools.drl.ast.dsl.NamedConsequenceDescrBuilder)1 PackageDescrBuilder (org.drools.drl.ast.dsl.PackageDescrBuilder)1