Search in sources :

Example 1 with PatternDescrBuilder

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

the class DRL6Parser method lhsPatternBind.

/**
 * lhsPatternBind := label?
 *                ( LEFT_PAREN lhsPattern (OR lhsPattern)* RIGHT_PAREN
 *                | lhsPattern )
 *
 * @param ce
 * @return
 * @throws org.antlr.runtime.RecognitionException
 */
@SuppressWarnings("unchecked")
private BaseDescr lhsPatternBind(PatternContainerDescrBuilder<?, ?> ce, final boolean allowOr) throws RecognitionException {
    PatternDescrBuilder<?> pattern = null;
    CEDescrBuilder<?, OrDescr> or = null;
    BaseDescr result = null;
    Token first = input.LT(1);
    pattern = helper.start((DescrBuilder<?, ?>) ce, PatternDescrBuilder.class, null);
    if (pattern != null) {
        result = pattern.getDescr();
    }
    String label = null;
    boolean isUnification = false;
    if (input.LA(1) == DRL6Lexer.ID && input.LA(2) == DRL6Lexer.COLON && !helper.validateCEKeyword(1)) {
        label = label(DroolsEditorType.IDENTIFIER_PATTERN);
        if (state.failed)
            return null;
    } else if (input.LA(1) == DRL6Lexer.ID && input.LA(2) == DRL6Lexer.UNIFY && !helper.validateCEKeyword(1)) {
        label = unif(DroolsEditorType.IDENTIFIER_PATTERN);
        if (state.failed)
            return null;
        isUnification = true;
    }
    if (input.LA(1) == DRL6Lexer.LEFT_PAREN) {
        try {
            match(input, DRL6Lexer.LEFT_PAREN, null, null, DroolsEditorType.SYMBOL);
            if (state.failed)
                return null;
            if (helper.validateCEKeyword(1)) {
                failMismatchedTokenException();
                // in case it is backtracking
                return null;
            }
            lhsPattern(pattern, label, isUnification);
            if (state.failed)
                return null;
            if (allowOr && helper.validateIdentifierKey(DroolsSoftKeywords.OR) && ce instanceof CEDescrBuilder) {
                if (state.backtracking == 0) {
                    // this is necessary because of the crappy bind with multi-pattern OR syntax
                    or = ((CEDescrBuilder<DescrBuilder<?, ?>, OrDescr>) ce).or();
                    result = or.getDescr();
                    helper.end(PatternDescrBuilder.class, pattern);
                    helper.start(or, CEDescrBuilder.class, null);
                    // adjust real or starting token:
                    helper.setStart(or, first);
                    // remove original pattern from the parent CE child list:
                    ((ConditionalElementDescr) ce.getDescr()).getDescrs().remove(pattern.getDescr());
                    // add pattern to the OR instead
                    or.getDescr().addDescr(pattern.getDescr());
                }
                while (helper.validateIdentifierKey(DroolsSoftKeywords.OR)) {
                    match(input, DRL6Lexer.ID, DroolsSoftKeywords.OR, null, DroolsEditorType.KEYWORD);
                    if (state.failed)
                        return null;
                    pattern = helper.start(or, PatternDescrBuilder.class, null);
                    // new pattern, same binding
                    lhsPattern(pattern, label, isUnification);
                    if (state.failed)
                        return null;
                    helper.end(PatternDescrBuilder.class, pattern);
                }
            }
            match(input, DRL6Lexer.RIGHT_PAREN, null, null, DroolsEditorType.SYMBOL);
            if (state.failed)
                return null;
        } finally {
            if (or != null) {
                helper.end(CEDescrBuilder.class, or);
            } else {
                helper.end(PatternDescrBuilder.class, pattern);
            }
        }
    } else {
        try {
            lhsPattern(pattern, label, isUnification);
            if (state.failed)
                return null;
        } finally {
            helper.end(PatternDescrBuilder.class, pattern);
        }
    }
    return result;
}
Also used : CEDescrBuilder(org.drools.drl.ast.dsl.CEDescrBuilder) PatternDescrBuilder(org.drools.drl.ast.dsl.PatternDescrBuilder) BaseDescr(org.drools.drl.ast.descr.BaseDescr) Token(org.antlr.runtime.Token) CommonToken(org.antlr.runtime.CommonToken) FunctionDescrBuilder(org.drools.drl.ast.dsl.FunctionDescrBuilder) DescrBuilder(org.drools.drl.ast.dsl.DescrBuilder) AccumulateImportDescrBuilder(org.drools.drl.ast.dsl.AccumulateImportDescrBuilder) ForallDescrBuilder(org.drools.drl.ast.dsl.ForallDescrBuilder) NamedConsequenceDescrBuilder(org.drools.drl.ast.dsl.NamedConsequenceDescrBuilder) DeclareDescrBuilder(org.drools.drl.ast.dsl.DeclareDescrBuilder) EvalDescrBuilder(org.drools.drl.ast.dsl.EvalDescrBuilder) AnnotationDescrBuilder(org.drools.drl.ast.dsl.AnnotationDescrBuilder) AccumulateDescrBuilder(org.drools.drl.ast.dsl.AccumulateDescrBuilder) WindowDeclarationDescrBuilder(org.drools.drl.ast.dsl.WindowDeclarationDescrBuilder) PatternDescrBuilder(org.drools.drl.ast.dsl.PatternDescrBuilder) FieldDescrBuilder(org.drools.drl.ast.dsl.FieldDescrBuilder) EntryPointDeclarationDescrBuilder(org.drools.drl.ast.dsl.EntryPointDeclarationDescrBuilder) EnumDeclarationDescrBuilder(org.drools.drl.ast.dsl.EnumDeclarationDescrBuilder) QueryDescrBuilder(org.drools.drl.ast.dsl.QueryDescrBuilder) UnitDescrBuilder(org.drools.drl.ast.dsl.UnitDescrBuilder) CollectDescrBuilder(org.drools.drl.ast.dsl.CollectDescrBuilder) ImportDescrBuilder(org.drools.drl.ast.dsl.ImportDescrBuilder) AnnotatedDescrBuilder(org.drools.drl.ast.dsl.AnnotatedDescrBuilder) BehaviorDescrBuilder(org.drools.drl.ast.dsl.BehaviorDescrBuilder) EnumLiteralDescrBuilder(org.drools.drl.ast.dsl.EnumLiteralDescrBuilder) GlobalDescrBuilder(org.drools.drl.ast.dsl.GlobalDescrBuilder) PackageDescrBuilder(org.drools.drl.ast.dsl.PackageDescrBuilder) AttributeDescrBuilder(org.drools.drl.ast.dsl.AttributeDescrBuilder) CEDescrBuilder(org.drools.drl.ast.dsl.CEDescrBuilder) PatternContainerDescrBuilder(org.drools.drl.ast.dsl.PatternContainerDescrBuilder) ConditionalBranchDescrBuilder(org.drools.drl.ast.dsl.ConditionalBranchDescrBuilder) TypeDeclarationDescrBuilder(org.drools.drl.ast.dsl.TypeDeclarationDescrBuilder) RuleDescrBuilder(org.drools.drl.ast.dsl.RuleDescrBuilder) OrDescr(org.drools.drl.ast.descr.OrDescr)

Example 2 with PatternDescrBuilder

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

the class DRL6StrictParser method lhsAccumulate.

/**
 * lhsAccumulate := (ACCUMULATE|ACC) LEFT_PAREN lhsAnd (COMMA|SEMICOLON)
 *                      accumulateFunctionBinding (COMMA accumulateFunctionBinding)*
 *                      (SEMICOLON constraints)?
 *                  RIGHT_PAREN SEMICOLON?
 *
 * @param ce
 * @return
 * @throws org.antlr.runtime.RecognitionException
 */
private BaseDescr lhsAccumulate(PatternContainerDescrBuilder<?, ?> ce) throws RecognitionException {
    PatternDescrBuilder<?> pattern = null;
    BaseDescr result = null;
    pattern = helper.start((DescrBuilder<?, ?>) ce, PatternDescrBuilder.class, null);
    if (pattern != null) {
        result = pattern.getDescr();
    }
    try {
        if (state.backtracking == 0) {
            pattern.type("Object[]");
            pattern.isQuery(false);
        // might have to add the implicit bindings as well
        }
        AccumulateDescrBuilder<?> accumulate = helper.start(pattern, AccumulateDescrBuilder.class, null);
        try {
            if (helper.validateIdentifierKey(DroolsSoftKeywords.ACCUMULATE)) {
                match(input, DRL6Lexer.ID, DroolsSoftKeywords.ACCUMULATE, null, DroolsEditorType.KEYWORD);
            } else {
                // might be using the short mnemonic
                match(input, DRL6Lexer.ID, DroolsSoftKeywords.ACC, null, DroolsEditorType.KEYWORD);
            }
            if (state.failed)
                return null;
            if (state.backtracking == 0 && input.LA(1) != DRL6Lexer.EOF) {
                helper.emit(Location.LOCATION_LHS_FROM_ACCUMULATE);
            }
            match(input, DRL6Lexer.LEFT_PAREN, null, null, DroolsEditorType.SYMBOL);
            if (state.failed)
                return null;
            CEDescrBuilder<?, AndDescr> source = accumulate.source();
            try {
                helper.start(source, CEDescrBuilder.class, null);
                lhsAnd(source, false);
                if (state.failed)
                    return null;
                if (source.getDescr() != null && source.getDescr() instanceof ConditionalElementDescr) {
                    ConditionalElementDescr root = (ConditionalElementDescr) source.getDescr();
                    BaseDescr[] descrs = root.getDescrs().toArray(new BaseDescr[root.getDescrs().size()]);
                    root.getDescrs().clear();
                    for (int i = 0; i < descrs.length; i++) {
                        root.addOrMerge(descrs[i]);
                    }
                }
            } finally {
                helper.end(CEDescrBuilder.class, source);
            }
            if (input.LA(1) == DRL6Lexer.COMMA) {
                match(input, DRL6Lexer.COMMA, null, null, DroolsEditorType.SYMBOL);
                if (state.failed)
                    return null;
            } else if (input.LA(-1) != DRL6Lexer.SEMICOLON) {
                // lhsUnary will consume an optional SEMICOLON, so we need to check if it was consumed already
                // or if we must fail consuming it now
                match(input, DRL6Lexer.SEMICOLON, null, null, DroolsEditorType.SYMBOL);
                if (state.failed)
                    return null;
            }
            // accumulate functions
            accumulateFunctionBinding(accumulate);
            if (state.failed)
                return null;
            while (input.LA(1) == DRL6Lexer.COMMA) {
                match(input, DRL6Lexer.COMMA, null, null, DroolsEditorType.SYMBOL);
                if (state.failed)
                    return null;
                accumulateFunctionBinding(accumulate);
                if (state.failed)
                    return null;
            }
            if (input.LA(1) == DRL6Lexer.SEMICOLON) {
                match(input, DRL6Lexer.SEMICOLON, null, null, DroolsEditorType.SYMBOL);
                if (state.failed)
                    return null;
                constraints(pattern);
            }
            match(input, DRL6Lexer.RIGHT_PAREN, null, null, DroolsEditorType.SYMBOL);
            if (state.failed)
                return null;
        } finally {
            helper.end(AccumulateDescrBuilder.class, accumulate);
            if (state.backtracking == 0 && input.LA(1) != DRL6Lexer.EOF) {
                helper.emit(Location.LOCATION_LHS_BEGIN_OF_CONDITION);
            }
        }
    } finally {
        helper.end(PatternDescrBuilder.class, pattern);
    }
    if (input.LA(1) == DRL6Lexer.SEMICOLON) {
        match(input, DRL6Lexer.SEMICOLON, null, null, DroolsEditorType.SYMBOL);
        if (state.failed)
            return null;
    }
    return result;
}
Also used : PatternDescrBuilder(org.drools.drl.ast.dsl.PatternDescrBuilder) AndDescr(org.drools.drl.ast.descr.AndDescr) AnnotatedBaseDescr(org.drools.drl.ast.descr.AnnotatedBaseDescr) BaseDescr(org.drools.drl.ast.descr.BaseDescr) FunctionDescrBuilder(org.drools.drl.ast.dsl.FunctionDescrBuilder) DescrBuilder(org.drools.drl.ast.dsl.DescrBuilder) AccumulateImportDescrBuilder(org.drools.drl.ast.dsl.AccumulateImportDescrBuilder) ForallDescrBuilder(org.drools.drl.ast.dsl.ForallDescrBuilder) NamedConsequenceDescrBuilder(org.drools.drl.ast.dsl.NamedConsequenceDescrBuilder) DeclareDescrBuilder(org.drools.drl.ast.dsl.DeclareDescrBuilder) EvalDescrBuilder(org.drools.drl.ast.dsl.EvalDescrBuilder) AnnotationDescrBuilder(org.drools.drl.ast.dsl.AnnotationDescrBuilder) AccumulateDescrBuilder(org.drools.drl.ast.dsl.AccumulateDescrBuilder) WindowDeclarationDescrBuilder(org.drools.drl.ast.dsl.WindowDeclarationDescrBuilder) PatternDescrBuilder(org.drools.drl.ast.dsl.PatternDescrBuilder) FieldDescrBuilder(org.drools.drl.ast.dsl.FieldDescrBuilder) EntryPointDeclarationDescrBuilder(org.drools.drl.ast.dsl.EntryPointDeclarationDescrBuilder) EnumDeclarationDescrBuilder(org.drools.drl.ast.dsl.EnumDeclarationDescrBuilder) QueryDescrBuilder(org.drools.drl.ast.dsl.QueryDescrBuilder) UnitDescrBuilder(org.drools.drl.ast.dsl.UnitDescrBuilder) CollectDescrBuilder(org.drools.drl.ast.dsl.CollectDescrBuilder) ImportDescrBuilder(org.drools.drl.ast.dsl.ImportDescrBuilder) AnnotatedDescrBuilder(org.drools.drl.ast.dsl.AnnotatedDescrBuilder) BehaviorDescrBuilder(org.drools.drl.ast.dsl.BehaviorDescrBuilder) EnumLiteralDescrBuilder(org.drools.drl.ast.dsl.EnumLiteralDescrBuilder) GlobalDescrBuilder(org.drools.drl.ast.dsl.GlobalDescrBuilder) PackageDescrBuilder(org.drools.drl.ast.dsl.PackageDescrBuilder) AttributeDescrBuilder(org.drools.drl.ast.dsl.AttributeDescrBuilder) CEDescrBuilder(org.drools.drl.ast.dsl.CEDescrBuilder) PatternContainerDescrBuilder(org.drools.drl.ast.dsl.PatternContainerDescrBuilder) ConditionalBranchDescrBuilder(org.drools.drl.ast.dsl.ConditionalBranchDescrBuilder) TypeDeclarationDescrBuilder(org.drools.drl.ast.dsl.TypeDeclarationDescrBuilder) RuleDescrBuilder(org.drools.drl.ast.dsl.RuleDescrBuilder) ConditionalElementDescr(org.drools.drl.ast.descr.ConditionalElementDescr)

Example 3 with PatternDescrBuilder

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

the class DRL6StrictParser method lhsPatternBind.

/**
 * lhsPatternBind := label?
 *                ( LEFT_PAREN lhsPattern (OR lhsPattern)* RIGHT_PAREN
 *                | lhsPattern )
 *
 * @param ce
 * @return
 * @throws org.antlr.runtime.RecognitionException
 */
@SuppressWarnings("unchecked")
private BaseDescr lhsPatternBind(PatternContainerDescrBuilder<?, ?> ce, final boolean allowOr) throws RecognitionException {
    PatternDescrBuilder<?> pattern = null;
    CEDescrBuilder<?, OrDescr> or = null;
    BaseDescr result = null;
    Token first = input.LT(1);
    pattern = helper.start((DescrBuilder<?, ?>) ce, PatternDescrBuilder.class, null);
    if (pattern != null) {
        result = pattern.getDescr();
    }
    String label = null;
    boolean isUnification = false;
    if (input.LA(1) == DRL6Lexer.ID && input.LA(2) == DRL6Lexer.COLON && !helper.validateCEKeyword(1)) {
        label = label(DroolsEditorType.IDENTIFIER_PATTERN);
        if (state.failed)
            return null;
    } else if (input.LA(1) == DRL6Lexer.ID && input.LA(2) == DRL6Lexer.UNIFY && !helper.validateCEKeyword(1)) {
        label = unif(DroolsEditorType.IDENTIFIER_PATTERN);
        if (state.failed)
            return null;
        isUnification = true;
    }
    if (input.LA(1) == DRL6Lexer.LEFT_PAREN) {
        try {
            match(input, DRL6Lexer.LEFT_PAREN, null, null, DroolsEditorType.SYMBOL);
            if (state.failed)
                return null;
            if (helper.validateCEKeyword(1)) {
                failMismatchedTokenException();
                // in case it is backtracking
                return null;
            }
            lhsPattern(pattern, label, isUnification);
            if (state.failed)
                return null;
            if (allowOr && helper.validateIdentifierKey(DroolsSoftKeywords.OR) && ce instanceof CEDescrBuilder) {
                if (state.backtracking == 0) {
                    // this is necessary because of the crappy bind with multi-pattern OR syntax
                    or = ((CEDescrBuilder<DescrBuilder<?, ?>, OrDescr>) ce).or();
                    result = or.getDescr();
                    helper.end(PatternDescrBuilder.class, pattern);
                    helper.start(or, CEDescrBuilder.class, null);
                    // adjust real or starting token:
                    helper.setStart(or, first);
                    // remove original pattern from the parent CE child list:
                    ((ConditionalElementDescr) ce.getDescr()).getDescrs().remove(pattern.getDescr());
                    // add pattern to the OR instead
                    or.getDescr().addDescr(pattern.getDescr());
                }
                while (helper.validateIdentifierKey(DroolsSoftKeywords.OR)) {
                    match(input, DRL6Lexer.ID, DroolsSoftKeywords.OR, null, DroolsEditorType.KEYWORD);
                    if (state.failed)
                        return null;
                    pattern = helper.start(or, PatternDescrBuilder.class, null);
                    // new pattern, same binding
                    lhsPattern(pattern, label, isUnification);
                    if (state.failed)
                        return null;
                    helper.end(PatternDescrBuilder.class, pattern);
                }
            }
            match(input, DRL6Lexer.RIGHT_PAREN, null, null, DroolsEditorType.SYMBOL);
            if (state.failed)
                return null;
        } finally {
            if (or != null) {
                helper.end(CEDescrBuilder.class, or);
            } else {
                helper.end(PatternDescrBuilder.class, pattern);
            }
        }
    } else {
        try {
            lhsPattern(pattern, label, isUnification);
            if (state.failed)
                return null;
        } finally {
            helper.end(PatternDescrBuilder.class, pattern);
        }
    }
    return result;
}
Also used : CEDescrBuilder(org.drools.drl.ast.dsl.CEDescrBuilder) PatternDescrBuilder(org.drools.drl.ast.dsl.PatternDescrBuilder) AnnotatedBaseDescr(org.drools.drl.ast.descr.AnnotatedBaseDescr) BaseDescr(org.drools.drl.ast.descr.BaseDescr) Token(org.antlr.runtime.Token) CommonToken(org.antlr.runtime.CommonToken) FunctionDescrBuilder(org.drools.drl.ast.dsl.FunctionDescrBuilder) DescrBuilder(org.drools.drl.ast.dsl.DescrBuilder) AccumulateImportDescrBuilder(org.drools.drl.ast.dsl.AccumulateImportDescrBuilder) ForallDescrBuilder(org.drools.drl.ast.dsl.ForallDescrBuilder) NamedConsequenceDescrBuilder(org.drools.drl.ast.dsl.NamedConsequenceDescrBuilder) DeclareDescrBuilder(org.drools.drl.ast.dsl.DeclareDescrBuilder) EvalDescrBuilder(org.drools.drl.ast.dsl.EvalDescrBuilder) AnnotationDescrBuilder(org.drools.drl.ast.dsl.AnnotationDescrBuilder) AccumulateDescrBuilder(org.drools.drl.ast.dsl.AccumulateDescrBuilder) WindowDeclarationDescrBuilder(org.drools.drl.ast.dsl.WindowDeclarationDescrBuilder) PatternDescrBuilder(org.drools.drl.ast.dsl.PatternDescrBuilder) FieldDescrBuilder(org.drools.drl.ast.dsl.FieldDescrBuilder) EntryPointDeclarationDescrBuilder(org.drools.drl.ast.dsl.EntryPointDeclarationDescrBuilder) EnumDeclarationDescrBuilder(org.drools.drl.ast.dsl.EnumDeclarationDescrBuilder) QueryDescrBuilder(org.drools.drl.ast.dsl.QueryDescrBuilder) UnitDescrBuilder(org.drools.drl.ast.dsl.UnitDescrBuilder) CollectDescrBuilder(org.drools.drl.ast.dsl.CollectDescrBuilder) ImportDescrBuilder(org.drools.drl.ast.dsl.ImportDescrBuilder) AnnotatedDescrBuilder(org.drools.drl.ast.dsl.AnnotatedDescrBuilder) BehaviorDescrBuilder(org.drools.drl.ast.dsl.BehaviorDescrBuilder) EnumLiteralDescrBuilder(org.drools.drl.ast.dsl.EnumLiteralDescrBuilder) GlobalDescrBuilder(org.drools.drl.ast.dsl.GlobalDescrBuilder) PackageDescrBuilder(org.drools.drl.ast.dsl.PackageDescrBuilder) AttributeDescrBuilder(org.drools.drl.ast.dsl.AttributeDescrBuilder) CEDescrBuilder(org.drools.drl.ast.dsl.CEDescrBuilder) PatternContainerDescrBuilder(org.drools.drl.ast.dsl.PatternContainerDescrBuilder) ConditionalBranchDescrBuilder(org.drools.drl.ast.dsl.ConditionalBranchDescrBuilder) TypeDeclarationDescrBuilder(org.drools.drl.ast.dsl.TypeDeclarationDescrBuilder) RuleDescrBuilder(org.drools.drl.ast.dsl.RuleDescrBuilder) OrDescr(org.drools.drl.ast.descr.OrDescr)

Example 4 with PatternDescrBuilder

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

the class DRL6Parser method lhsAccumulate.

/**
 * lhsAccumulate := (ACCUMULATE|ACC) LEFT_PAREN lhsAnd (COMMA|SEMICOLON)
 *                      accumulateFunctionBinding (COMMA accumulateFunctionBinding)*
 *                      (SEMICOLON constraints)?
 *                  RIGHT_PAREN SEMICOLON?
 *
 * @param ce
 * @return
 * @throws org.antlr.runtime.RecognitionException
 */
private BaseDescr lhsAccumulate(PatternContainerDescrBuilder<?, ?> ce) throws RecognitionException {
    PatternDescrBuilder<?> pattern = null;
    BaseDescr result = null;
    pattern = helper.start((DescrBuilder<?, ?>) ce, PatternDescrBuilder.class, null);
    if (pattern != null) {
        result = pattern.getDescr();
    }
    try {
        if (state.backtracking == 0) {
            pattern.type("Object");
            pattern.isQuery(false);
        // might have to add the implicit bindings as well
        }
        AccumulateDescrBuilder<?> accumulate = helper.start(pattern, AccumulateDescrBuilder.class, null);
        try {
            if (helper.validateIdentifierKey(DroolsSoftKeywords.ACCUMULATE)) {
                match(input, DRL6Lexer.ID, DroolsSoftKeywords.ACCUMULATE, null, DroolsEditorType.KEYWORD);
            } else {
                // might be using the short mnemonic
                match(input, DRL6Lexer.ID, DroolsSoftKeywords.ACC, null, DroolsEditorType.KEYWORD);
            }
            if (state.failed)
                return null;
            if (state.backtracking == 0 && input.LA(1) != DRL6Lexer.EOF) {
                helper.emit(Location.LOCATION_LHS_FROM_ACCUMULATE);
            }
            match(input, DRL6Lexer.LEFT_PAREN, null, null, DroolsEditorType.SYMBOL);
            if (state.failed)
                return null;
            CEDescrBuilder<?, AndDescr> source = accumulate.source();
            try {
                helper.start(source, CEDescrBuilder.class, null);
                lhsAnd(source, true);
                if (state.failed)
                    return null;
                if (source.getDescr() != null && source.getDescr() instanceof ConditionalElementDescr) {
                    ConditionalElementDescr root = (ConditionalElementDescr) source.getDescr();
                    BaseDescr[] descrs = root.getDescrs().toArray(new BaseDescr[root.getDescrs().size()]);
                    root.getDescrs().clear();
                    for (int i = 0; i < descrs.length; i++) {
                        root.addOrMerge(descrs[i]);
                    }
                }
            } finally {
                helper.end(CEDescrBuilder.class, source);
            }
            if (input.LA(1) == DRL6Lexer.COMMA) {
                match(input, DRL6Lexer.COMMA, null, null, DroolsEditorType.SYMBOL);
                if (state.failed)
                    return null;
            } else if (input.LA(-1) != DRL6Lexer.SEMICOLON) {
                // lhsUnary will consume an optional SEMICOLON, so we need to check if it was consumed already
                // or if we must fail consuming it now
                match(input, DRL6Lexer.SEMICOLON, null, null, DroolsEditorType.SYMBOL);
                if (state.failed)
                    return null;
            }
            // accumulate functions
            accumulateFunctionBinding(accumulate);
            if (state.failed)
                return null;
            while (input.LA(1) == DRL6Lexer.COMMA) {
                match(input, DRL6Lexer.COMMA, null, null, DroolsEditorType.SYMBOL);
                if (state.failed)
                    return null;
                accumulateFunctionBinding(accumulate);
                if (state.failed)
                    return null;
            }
            if (input.LA(1) == DRL6Lexer.SEMICOLON) {
                match(input, DRL6Lexer.SEMICOLON, null, null, DroolsEditorType.SYMBOL);
                if (state.failed)
                    return null;
                constraints(pattern);
            }
            match(input, DRL6Lexer.RIGHT_PAREN, null, null, DroolsEditorType.SYMBOL);
            if (state.failed)
                return null;
        } finally {
            helper.end(AccumulateDescrBuilder.class, accumulate);
            if (state.backtracking == 0 && input.LA(1) != DRL6Lexer.EOF) {
                helper.emit(Location.LOCATION_LHS_BEGIN_OF_CONDITION);
            }
        }
    } finally {
        helper.end(PatternDescrBuilder.class, pattern);
    }
    if (input.LA(1) == DRL6Lexer.SEMICOLON) {
        match(input, DRL6Lexer.SEMICOLON, null, null, DroolsEditorType.SYMBOL);
        if (state.failed)
            return null;
    }
    return result;
}
Also used : PatternDescrBuilder(org.drools.drl.ast.dsl.PatternDescrBuilder) AndDescr(org.drools.drl.ast.descr.AndDescr) BaseDescr(org.drools.drl.ast.descr.BaseDescr) FunctionDescrBuilder(org.drools.drl.ast.dsl.FunctionDescrBuilder) DescrBuilder(org.drools.drl.ast.dsl.DescrBuilder) AccumulateImportDescrBuilder(org.drools.drl.ast.dsl.AccumulateImportDescrBuilder) ForallDescrBuilder(org.drools.drl.ast.dsl.ForallDescrBuilder) NamedConsequenceDescrBuilder(org.drools.drl.ast.dsl.NamedConsequenceDescrBuilder) DeclareDescrBuilder(org.drools.drl.ast.dsl.DeclareDescrBuilder) EvalDescrBuilder(org.drools.drl.ast.dsl.EvalDescrBuilder) AnnotationDescrBuilder(org.drools.drl.ast.dsl.AnnotationDescrBuilder) AccumulateDescrBuilder(org.drools.drl.ast.dsl.AccumulateDescrBuilder) WindowDeclarationDescrBuilder(org.drools.drl.ast.dsl.WindowDeclarationDescrBuilder) PatternDescrBuilder(org.drools.drl.ast.dsl.PatternDescrBuilder) FieldDescrBuilder(org.drools.drl.ast.dsl.FieldDescrBuilder) EntryPointDeclarationDescrBuilder(org.drools.drl.ast.dsl.EntryPointDeclarationDescrBuilder) EnumDeclarationDescrBuilder(org.drools.drl.ast.dsl.EnumDeclarationDescrBuilder) QueryDescrBuilder(org.drools.drl.ast.dsl.QueryDescrBuilder) UnitDescrBuilder(org.drools.drl.ast.dsl.UnitDescrBuilder) CollectDescrBuilder(org.drools.drl.ast.dsl.CollectDescrBuilder) ImportDescrBuilder(org.drools.drl.ast.dsl.ImportDescrBuilder) AnnotatedDescrBuilder(org.drools.drl.ast.dsl.AnnotatedDescrBuilder) BehaviorDescrBuilder(org.drools.drl.ast.dsl.BehaviorDescrBuilder) EnumLiteralDescrBuilder(org.drools.drl.ast.dsl.EnumLiteralDescrBuilder) GlobalDescrBuilder(org.drools.drl.ast.dsl.GlobalDescrBuilder) PackageDescrBuilder(org.drools.drl.ast.dsl.PackageDescrBuilder) AttributeDescrBuilder(org.drools.drl.ast.dsl.AttributeDescrBuilder) CEDescrBuilder(org.drools.drl.ast.dsl.CEDescrBuilder) PatternContainerDescrBuilder(org.drools.drl.ast.dsl.PatternContainerDescrBuilder) ConditionalBranchDescrBuilder(org.drools.drl.ast.dsl.ConditionalBranchDescrBuilder) TypeDeclarationDescrBuilder(org.drools.drl.ast.dsl.TypeDeclarationDescrBuilder) RuleDescrBuilder(org.drools.drl.ast.dsl.RuleDescrBuilder) ConditionalElementDescr(org.drools.drl.ast.descr.ConditionalElementDescr)

Example 5 with PatternDescrBuilder

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

the class ParserHelper method start.

@SuppressWarnings("unchecked")
public <T extends DescrBuilder<?, ?>> T start(DescrBuilder<?, ?> ctxBuilder, Class<T> clazz, String param) {
    if (state.backtracking == 0) {
        if (PackageDescrBuilder.class.isAssignableFrom(clazz)) {
            pushParaphrases(DroolsParaphraseTypes.PACKAGE);
            beginSentence(DroolsSentenceType.PACKAGE);
            setStart(ctxBuilder);
        } else if (ImportDescrBuilder.class.isAssignableFrom(clazz)) {
            ImportDescrBuilder imp;
            if (validateLT(2, DroolsSoftKeywords.FUNCTION) || validateLT(2, DroolsSoftKeywords.STATIC)) {
                imp = ctxBuilder == null ? DescrFactory.newPackage().newFunctionImport() : ((PackageDescrBuilder) ctxBuilder).newFunctionImport();
            } else {
                imp = ctxBuilder == null ? DescrFactory.newPackage().newImport() : ((PackageDescrBuilder) ctxBuilder).newImport();
            }
            pushParaphrases(DroolsParaphraseTypes.IMPORT);
            beginSentence(DroolsSentenceType.IMPORT_STATEMENT);
            setStart(imp);
            return (T) imp;
        } else if (UnitDescrBuilder.class.isAssignableFrom(clazz)) {
            UnitDescrBuilder imp = ctxBuilder == null ? DescrFactory.newPackage().newUnit() : ((PackageDescrBuilder) ctxBuilder).newUnit();
            pushParaphrases(DroolsParaphraseTypes.UNIT);
            beginSentence(DroolsSentenceType.UNIT);
            setStart(imp);
            return (T) imp;
        } else if (AccumulateImportDescrBuilder.class.isAssignableFrom(clazz)) {
            AccumulateImportDescrBuilder imp = ctxBuilder == null ? DescrFactory.newPackage().newAccumulateImport() : ((PackageDescrBuilder) ctxBuilder).newAccumulateImport();
            pushParaphrases(DroolsParaphraseTypes.ACCUMULATE_IMPORT);
            beginSentence(DroolsSentenceType.ACCUMULATE_IMPORT_STATEMENT);
            setStart(imp);
            return (T) imp;
        } else if (GlobalDescrBuilder.class.isAssignableFrom(clazz)) {
            GlobalDescrBuilder global = ctxBuilder == null ? DescrFactory.newPackage().newGlobal() : ((PackageDescrBuilder) ctxBuilder).newGlobal();
            pushParaphrases(DroolsParaphraseTypes.GLOBAL);
            beginSentence(DroolsSentenceType.GLOBAL);
            setStart(global);
            return (T) global;
        } else if (DeclareDescrBuilder.class.isAssignableFrom(clazz)) {
            DeclareDescrBuilder declare = ctxBuilder == null ? DescrFactory.newPackage().newDeclare() : ((PackageDescrBuilder) ctxBuilder).newDeclare();
            return (T) declare;
        } else if (TypeDeclarationDescrBuilder.class.isAssignableFrom(clazz)) {
            TypeDeclarationDescrBuilder declare = ctxBuilder == null ? DescrFactory.newPackage().newDeclare().type() : ((DeclareDescrBuilder) ctxBuilder).type();
            pushParaphrases(DroolsParaphraseTypes.TYPE_DECLARE);
            beginSentence(DroolsSentenceType.TYPE_DECLARATION);
            setStart(declare);
            return (T) declare;
        } else if (EnumDeclarationDescrBuilder.class.isAssignableFrom(clazz)) {
            EnumDeclarationDescrBuilder declare = ctxBuilder == null ? DescrFactory.newPackage().newDeclare().enumerative() : ((DeclareDescrBuilder) ctxBuilder).enumerative();
            pushParaphrases(DroolsParaphraseTypes.ENUM_DECLARE);
            beginSentence(DroolsSentenceType.ENUM_DECLARATION);
            setStart(declare);
            return (T) declare;
        } else if (EntryPointDeclarationDescrBuilder.class.isAssignableFrom(clazz)) {
            EntryPointDeclarationDescrBuilder declare = ctxBuilder == null ? DescrFactory.newPackage().newDeclare().entryPoint() : ((DeclareDescrBuilder) ctxBuilder).entryPoint();
            pushParaphrases(DroolsParaphraseTypes.ENTRYPOINT_DECLARE);
            beginSentence(DroolsSentenceType.ENTRYPOINT_DECLARATION);
            setStart(declare);
            return (T) declare;
        } else if (WindowDeclarationDescrBuilder.class.isAssignableFrom(clazz)) {
            WindowDeclarationDescrBuilder declare = ctxBuilder == null ? DescrFactory.newPackage().newDeclare().window() : ((DeclareDescrBuilder) ctxBuilder).window();
            pushParaphrases(DroolsParaphraseTypes.WINDOW_DECLARE);
            beginSentence(DroolsSentenceType.WINDOW_DECLARATION);
            setStart(declare);
            return (T) declare;
        } else if (FieldDescrBuilder.class.isAssignableFrom(clazz)) {
            FieldDescrBuilder field = ((AbstractClassTypeDeclarationBuilder) ctxBuilder).newField(param);
            setStart(field);
            return (T) field;
        } else if (EnumLiteralDescrBuilder.class.isAssignableFrom(clazz)) {
            EnumLiteralDescrBuilder literal = ((EnumDeclarationDescrBuilder) ctxBuilder).newEnumLiteral(param);
            setStart(literal);
            return (T) literal;
        } else if (FunctionDescrBuilder.class.isAssignableFrom(clazz)) {
            FunctionDescrBuilder function;
            if (ctxBuilder == null) {
                function = DescrFactory.newPackage().newFunction();
            } else {
                PackageDescrBuilder pkg = (PackageDescrBuilder) ctxBuilder;
                function = pkg.newFunction().namespace(pkg.getDescr().getName());
                AttributeDescr attribute = pkg.getDescr().getAttribute("dialect");
                if (attribute != null) {
                    function.dialect(attribute.getValue());
                }
            }
            pushParaphrases(DroolsParaphraseTypes.FUNCTION);
            beginSentence(DroolsSentenceType.FUNCTION);
            setStart(function);
            return (T) function;
        } else if (RuleDescrBuilder.class.isAssignableFrom(clazz)) {
            RuleDescrBuilder rule = ctxBuilder == null ? DescrFactory.newPackage().newRule() : ((PackageDescrBuilder) ctxBuilder).newRule();
            pushParaphrases(DroolsParaphraseTypes.RULE);
            beginSentence(DroolsSentenceType.RULE);
            setStart(rule);
            return (T) rule;
        } else if (QueryDescrBuilder.class.isAssignableFrom(clazz)) {
            QueryDescrBuilder query = ctxBuilder == null ? DescrFactory.newPackage().newQuery() : ((PackageDescrBuilder) ctxBuilder).newQuery();
            pushParaphrases(DroolsParaphraseTypes.QUERY);
            beginSentence(DroolsSentenceType.QUERY);
            setStart(query);
            return (T) query;
        } else if (AttributeDescrBuilder.class.isAssignableFrom(clazz)) {
            AttributeDescrBuilder<?> attribute = ((AttributeSupportBuilder<?>) ctxBuilder).attribute(param);
            setStart(attribute);
            return (T) attribute;
        } else if (EvalDescrBuilder.class.isAssignableFrom(clazz)) {
            EvalDescrBuilder<?> eval = ((CEDescrBuilder<?, ?>) ctxBuilder).eval();
            pushParaphrases(DroolsParaphraseTypes.EVAL);
            beginSentence(DroolsSentenceType.EVAL);
            setStart(eval);
            return (T) eval;
        } else if (ForallDescrBuilder.class.isAssignableFrom(clazz)) {
            ForallDescrBuilder<?> forall = ((CEDescrBuilder<?, ?>) ctxBuilder).forall();
            setStart(forall);
            return (T) forall;
        } else if (CEDescrBuilder.class.isAssignableFrom(clazz)) {
            setStart(ctxBuilder);
            return (T) ctxBuilder;
        } else if (PatternDescrBuilder.class.isAssignableFrom(clazz)) {
            PatternDescrBuilder<?> pattern = ((PatternContainerDescrBuilder<?, ?>) ctxBuilder).pattern();
            pushParaphrases(DroolsParaphraseTypes.PATTERN);
            setStart(pattern);
            return (T) pattern;
        } else if (CollectDescrBuilder.class.isAssignableFrom(clazz)) {
            CollectDescrBuilder<?> collect = ((PatternDescrBuilder<?>) ctxBuilder).from().collect();
            setStart(collect);
            return (T) collect;
        } else if (AccumulateDescrBuilder.class.isAssignableFrom(clazz)) {
            AccumulateDescrBuilder<?> accumulate = ((PatternDescrBuilder<?>) ctxBuilder).from().accumulate();
            setStart(accumulate);
            return (T) accumulate;
        } else if (BehaviorDescrBuilder.class.isAssignableFrom(clazz)) {
            BehaviorDescrBuilder<?> behavior = ((PatternDescrBuilder<?>) ctxBuilder).behavior();
            setStart(behavior);
            return (T) behavior;
        } else if (NamedConsequenceDescrBuilder.class.isAssignableFrom(clazz)) {
            NamedConsequenceDescrBuilder<?> namedConsequence = ((CEDescrBuilder<?, ?>) ctxBuilder).namedConsequence();
            setStart(namedConsequence);
            return (T) namedConsequence;
        } else if (ConditionalBranchDescrBuilder.class.isAssignableFrom(clazz)) {
            ConditionalBranchDescrBuilder<?> conditionalBranch = ((CEDescrBuilder<?, ?>) ctxBuilder).conditionalBranch();
            setStart(conditionalBranch);
            return (T) conditionalBranch;
        }
    }
    return null;
}
Also used : PackageDescrBuilder(org.drools.drl.ast.dsl.PackageDescrBuilder) DeclareDescrBuilder(org.drools.drl.ast.dsl.DeclareDescrBuilder) AttributeDescrBuilder(org.drools.drl.ast.dsl.AttributeDescrBuilder) ForallDescrBuilder(org.drools.drl.ast.dsl.ForallDescrBuilder) NamedConsequenceDescrBuilder(org.drools.drl.ast.dsl.NamedConsequenceDescrBuilder) AccumulateImportDescrBuilder(org.drools.drl.ast.dsl.AccumulateImportDescrBuilder) ImportDescrBuilder(org.drools.drl.ast.dsl.ImportDescrBuilder) FunctionDescrBuilder(org.drools.drl.ast.dsl.FunctionDescrBuilder) CEDescrBuilder(org.drools.drl.ast.dsl.CEDescrBuilder) FieldDescrBuilder(org.drools.drl.ast.dsl.FieldDescrBuilder) QueryDescrBuilder(org.drools.drl.ast.dsl.QueryDescrBuilder) UnitDescrBuilder(org.drools.drl.ast.dsl.UnitDescrBuilder) GlobalDescrBuilder(org.drools.drl.ast.dsl.GlobalDescrBuilder) EntryPointDeclarationDescrBuilder(org.drools.drl.ast.dsl.EntryPointDeclarationDescrBuilder) WindowDeclarationDescrBuilder(org.drools.drl.ast.dsl.WindowDeclarationDescrBuilder) RuleDescrBuilder(org.drools.drl.ast.dsl.RuleDescrBuilder) AccumulateImportDescrBuilder(org.drools.drl.ast.dsl.AccumulateImportDescrBuilder) PatternDescrBuilder(org.drools.drl.ast.dsl.PatternDescrBuilder) AccumulateDescrBuilder(org.drools.drl.ast.dsl.AccumulateDescrBuilder) EnumDeclarationDescrBuilder(org.drools.drl.ast.dsl.EnumDeclarationDescrBuilder) EnumLiteralDescrBuilder(org.drools.drl.ast.dsl.EnumLiteralDescrBuilder) AbstractClassTypeDeclarationBuilder(org.drools.drl.ast.dsl.AbstractClassTypeDeclarationBuilder) TypeDeclarationDescrBuilder(org.drools.drl.ast.dsl.TypeDeclarationDescrBuilder) AttributeDescr(org.drools.drl.ast.descr.AttributeDescr)

Aggregations

AccumulateDescrBuilder (org.drools.drl.ast.dsl.AccumulateDescrBuilder)7 AttributeDescrBuilder (org.drools.drl.ast.dsl.AttributeDescrBuilder)7 CEDescrBuilder (org.drools.drl.ast.dsl.CEDescrBuilder)7 DeclareDescrBuilder (org.drools.drl.ast.dsl.DeclareDescrBuilder)7 EntryPointDeclarationDescrBuilder (org.drools.drl.ast.dsl.EntryPointDeclarationDescrBuilder)7 EnumDeclarationDescrBuilder (org.drools.drl.ast.dsl.EnumDeclarationDescrBuilder)7 EnumLiteralDescrBuilder (org.drools.drl.ast.dsl.EnumLiteralDescrBuilder)7 FieldDescrBuilder (org.drools.drl.ast.dsl.FieldDescrBuilder)7 ForallDescrBuilder (org.drools.drl.ast.dsl.ForallDescrBuilder)7 FunctionDescrBuilder (org.drools.drl.ast.dsl.FunctionDescrBuilder)7 GlobalDescrBuilder (org.drools.drl.ast.dsl.GlobalDescrBuilder)7 ImportDescrBuilder (org.drools.drl.ast.dsl.ImportDescrBuilder)7 NamedConsequenceDescrBuilder (org.drools.drl.ast.dsl.NamedConsequenceDescrBuilder)7 PackageDescrBuilder (org.drools.drl.ast.dsl.PackageDescrBuilder)7 PatternDescrBuilder (org.drools.drl.ast.dsl.PatternDescrBuilder)7 QueryDescrBuilder (org.drools.drl.ast.dsl.QueryDescrBuilder)7 RuleDescrBuilder (org.drools.drl.ast.dsl.RuleDescrBuilder)7 TypeDeclarationDescrBuilder (org.drools.drl.ast.dsl.TypeDeclarationDescrBuilder)7 WindowDeclarationDescrBuilder (org.drools.drl.ast.dsl.WindowDeclarationDescrBuilder)7 BaseDescr (org.drools.drl.ast.descr.BaseDescr)6