Search in sources :

Example 11 with AttributeDescrBuilder

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

the class DRL6StrictParser method booleanAttribute.

/**
 * booleanAttribute := attributeKey (BOOLEAN)?
 * @param key
 * @throws org.antlr.runtime.RecognitionException
 */
private AttributeDescr booleanAttribute(AttributeSupportBuilder<?> as, String[] key) throws RecognitionException {
    AttributeDescrBuilder<?> attribute = null;
    try {
        StringBuilder builder = new StringBuilder();
        for (String k : key) {
            if ("-".equals(k)) {
                match(input, DRL6Lexer.MINUS, k, null, // part of the keyword
                DroolsEditorType.KEYWORD);
                if (state.failed)
                    return null;
            } else {
                match(input, DRL6Lexer.ID, k, null, DroolsEditorType.KEYWORD);
                if (state.failed)
                    return null;
            }
            builder.append(k);
        }
        if (state.backtracking == 0) {
            attribute = helper.start((DescrBuilder<?, ?>) as, AttributeDescrBuilder.class, builder.toString());
        }
        String value = "true";
        if (input.LA(1) == DRL6Lexer.BOOL) {
            Token bool = match(input, DRL6Lexer.BOOL, null, null, DroolsEditorType.KEYWORD);
            if (state.failed)
                return null;
            value = bool.getText();
        }
        if (state.backtracking == 0) {
            attribute.value(value);
            attribute.type(AttributeDescr.Type.BOOLEAN);
        }
    } finally {
        if (attribute != null) {
            helper.end(AttributeDescrBuilder.class, attribute);
        }
    }
    return attribute != null ? attribute.getDescr() : null;
}
Also used : AttributeDescrBuilder(org.drools.compiler.lang.api.AttributeDescrBuilder) Token(org.antlr.runtime.Token) CommonToken(org.antlr.runtime.CommonToken) DescrBuilder(org.drools.compiler.lang.api.DescrBuilder) AccumulateImportDescrBuilder(org.drools.compiler.lang.api.AccumulateImportDescrBuilder) AccumulateDescrBuilder(org.drools.compiler.lang.api.AccumulateDescrBuilder) EnumDeclarationDescrBuilder(org.drools.compiler.lang.api.EnumDeclarationDescrBuilder) PatternContainerDescrBuilder(org.drools.compiler.lang.api.PatternContainerDescrBuilder) WindowDeclarationDescrBuilder(org.drools.compiler.lang.api.WindowDeclarationDescrBuilder) ForallDescrBuilder(org.drools.compiler.lang.api.ForallDescrBuilder) TypeDeclarationDescrBuilder(org.drools.compiler.lang.api.TypeDeclarationDescrBuilder) PackageDescrBuilder(org.drools.compiler.lang.api.PackageDescrBuilder) CEDescrBuilder(org.drools.compiler.lang.api.CEDescrBuilder) DeclareDescrBuilder(org.drools.compiler.lang.api.DeclareDescrBuilder) FunctionDescrBuilder(org.drools.compiler.lang.api.FunctionDescrBuilder) RuleDescrBuilder(org.drools.compiler.lang.api.RuleDescrBuilder) EntryPointDeclarationDescrBuilder(org.drools.compiler.lang.api.EntryPointDeclarationDescrBuilder) EnumLiteralDescrBuilder(org.drools.compiler.lang.api.EnumLiteralDescrBuilder) QueryDescrBuilder(org.drools.compiler.lang.api.QueryDescrBuilder) AnnotatedDescrBuilder(org.drools.compiler.lang.api.AnnotatedDescrBuilder) PatternDescrBuilder(org.drools.compiler.lang.api.PatternDescrBuilder) AnnotationDescrBuilder(org.drools.compiler.lang.api.AnnotationDescrBuilder) ImportDescrBuilder(org.drools.compiler.lang.api.ImportDescrBuilder) CollectDescrBuilder(org.drools.compiler.lang.api.CollectDescrBuilder) AttributeDescrBuilder(org.drools.compiler.lang.api.AttributeDescrBuilder) EvalDescrBuilder(org.drools.compiler.lang.api.EvalDescrBuilder) ConditionalBranchDescrBuilder(org.drools.compiler.lang.api.ConditionalBranchDescrBuilder) UnitDescrBuilder(org.drools.compiler.lang.api.UnitDescrBuilder) NamedConsequenceDescrBuilder(org.drools.compiler.lang.api.NamedConsequenceDescrBuilder) FieldDescrBuilder(org.drools.compiler.lang.api.FieldDescrBuilder) BehaviorDescrBuilder(org.drools.compiler.lang.api.BehaviorDescrBuilder) GlobalDescrBuilder(org.drools.compiler.lang.api.GlobalDescrBuilder)

Example 12 with AttributeDescrBuilder

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

the class DRL5Parser method stringAttribute.

/**
 * stringAttribute := attributeKey STRING
 * @param key
 * @throws RecognitionException
 */
private AttributeDescr stringAttribute(AttributeSupportBuilder<?> as, String[] key) throws RecognitionException {
    AttributeDescrBuilder<?> attribute = null;
    try {
        StringBuilder builder = new StringBuilder();
        for (String k : key) {
            if ("-".equals(k)) {
                match(input, DRL5Lexer.MINUS, k, null, // part of the keyword
                DroolsEditorType.KEYWORD);
                if (state.failed)
                    return null;
            } else {
                match(input, DRL5Lexer.ID, k, null, DroolsEditorType.KEYWORD);
                if (state.failed)
                    return null;
            }
            builder.append(k);
        }
        if (state.backtracking == 0) {
            attribute = helper.start((DescrBuilder<?, ?>) as, AttributeDescrBuilder.class, builder.toString());
        }
        Token value = match(input, DRL5Lexer.STRING, null, null, DroolsEditorType.STRING_CONST);
        if (state.failed)
            return null;
        if (state.backtracking == 0) {
            attribute.value(StringUtils.unescapeJava(safeStripStringDelimiters(value.getText())));
            attribute.type(AttributeDescr.Type.STRING);
        }
    } finally {
        if (attribute != null) {
            helper.end(AttributeDescrBuilder.class, attribute);
        }
    }
    return attribute != null ? attribute.getDescr() : null;
}
Also used : AttributeDescrBuilder(org.drools.compiler.lang.api.AttributeDescrBuilder) Token(org.antlr.runtime.Token) CommonToken(org.antlr.runtime.CommonToken) DescrBuilder(org.drools.compiler.lang.api.DescrBuilder) AccumulateDescrBuilder(org.drools.compiler.lang.api.AccumulateDescrBuilder) EnumDeclarationDescrBuilder(org.drools.compiler.lang.api.EnumDeclarationDescrBuilder) PatternContainerDescrBuilder(org.drools.compiler.lang.api.PatternContainerDescrBuilder) WindowDeclarationDescrBuilder(org.drools.compiler.lang.api.WindowDeclarationDescrBuilder) ForallDescrBuilder(org.drools.compiler.lang.api.ForallDescrBuilder) TypeDeclarationDescrBuilder(org.drools.compiler.lang.api.TypeDeclarationDescrBuilder) PackageDescrBuilder(org.drools.compiler.lang.api.PackageDescrBuilder) CEDescrBuilder(org.drools.compiler.lang.api.CEDescrBuilder) DeclareDescrBuilder(org.drools.compiler.lang.api.DeclareDescrBuilder) FunctionDescrBuilder(org.drools.compiler.lang.api.FunctionDescrBuilder) RuleDescrBuilder(org.drools.compiler.lang.api.RuleDescrBuilder) EntryPointDeclarationDescrBuilder(org.drools.compiler.lang.api.EntryPointDeclarationDescrBuilder) EnumLiteralDescrBuilder(org.drools.compiler.lang.api.EnumLiteralDescrBuilder) QueryDescrBuilder(org.drools.compiler.lang.api.QueryDescrBuilder) AnnotatedDescrBuilder(org.drools.compiler.lang.api.AnnotatedDescrBuilder) PatternDescrBuilder(org.drools.compiler.lang.api.PatternDescrBuilder) AnnotationDescrBuilder(org.drools.compiler.lang.api.AnnotationDescrBuilder) ImportDescrBuilder(org.drools.compiler.lang.api.ImportDescrBuilder) CollectDescrBuilder(org.drools.compiler.lang.api.CollectDescrBuilder) AttributeDescrBuilder(org.drools.compiler.lang.api.AttributeDescrBuilder) EvalDescrBuilder(org.drools.compiler.lang.api.EvalDescrBuilder) ConditionalBranchDescrBuilder(org.drools.compiler.lang.api.ConditionalBranchDescrBuilder) NamedConsequenceDescrBuilder(org.drools.compiler.lang.api.NamedConsequenceDescrBuilder) FieldDescrBuilder(org.drools.compiler.lang.api.FieldDescrBuilder) BehaviorDescrBuilder(org.drools.compiler.lang.api.BehaviorDescrBuilder) GlobalDescrBuilder(org.drools.compiler.lang.api.GlobalDescrBuilder)

Example 13 with AttributeDescrBuilder

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

the class DRL5Parser method intOrChunkAttribute.

/**
 * intOrChunkAttribute := attributeKey ( DECIMAL | chunk_(_) )
 * @param key
 * @throws RecognitionException
 */
private AttributeDescr intOrChunkAttribute(AttributeSupportBuilder<?> as, String[] key) throws RecognitionException {
    AttributeDescrBuilder<?> attribute = null;
    try {
        StringBuilder builder = new StringBuilder();
        for (String k : key) {
            if ("-".equals(k)) {
                match(input, DRL5Lexer.MINUS, k, null, // part of the keyword
                DroolsEditorType.KEYWORD);
                if (state.failed)
                    return null;
            } else {
                match(input, DRL5Lexer.ID, k, null, DroolsEditorType.KEYWORD);
                if (state.failed)
                    return null;
            }
            builder.append(k);
        }
        if (state.backtracking == 0) {
            attribute = helper.start((DescrBuilder<?, ?>) as, AttributeDescrBuilder.class, builder.toString());
        }
        if (input.LA(1) == DRL5Lexer.LEFT_PAREN) {
            String value = chunk(DRL5Lexer.LEFT_PAREN, DRL5Lexer.RIGHT_PAREN, -1);
            if (state.failed)
                return null;
            if (state.backtracking == 0) {
                attribute.value(safeStripDelimiters(value, "(", ")"));
                attribute.type(AttributeDescr.Type.EXPRESSION);
            }
        } else {
            String value = "";
            if (input.LA(1) == DRL5Lexer.PLUS) {
                Token sign = match(input, DRL5Lexer.PLUS, null, null, DroolsEditorType.NUMERIC_CONST);
                if (state.failed)
                    return null;
                value += sign.getText();
            } else if (input.LA(1) == DRL5Lexer.MINUS) {
                Token sign = match(input, DRL5Lexer.MINUS, null, null, DroolsEditorType.NUMERIC_CONST);
                if (state.failed)
                    return null;
                value += sign.getText();
            }
            Token nbr = match(input, DRL5Lexer.DECIMAL, null, null, DroolsEditorType.NUMERIC_CONST);
            if (state.failed)
                return null;
            value += nbr.getText();
            if (state.backtracking == 0) {
                attribute.value(value);
                attribute.type(AttributeDescr.Type.NUMBER);
            }
        }
    } finally {
        if (attribute != null) {
            helper.end(AttributeDescrBuilder.class, attribute);
        }
    }
    return attribute != null ? attribute.getDescr() : null;
}
Also used : AttributeDescrBuilder(org.drools.compiler.lang.api.AttributeDescrBuilder) Token(org.antlr.runtime.Token) CommonToken(org.antlr.runtime.CommonToken) DescrBuilder(org.drools.compiler.lang.api.DescrBuilder) AccumulateDescrBuilder(org.drools.compiler.lang.api.AccumulateDescrBuilder) EnumDeclarationDescrBuilder(org.drools.compiler.lang.api.EnumDeclarationDescrBuilder) PatternContainerDescrBuilder(org.drools.compiler.lang.api.PatternContainerDescrBuilder) WindowDeclarationDescrBuilder(org.drools.compiler.lang.api.WindowDeclarationDescrBuilder) ForallDescrBuilder(org.drools.compiler.lang.api.ForallDescrBuilder) TypeDeclarationDescrBuilder(org.drools.compiler.lang.api.TypeDeclarationDescrBuilder) PackageDescrBuilder(org.drools.compiler.lang.api.PackageDescrBuilder) CEDescrBuilder(org.drools.compiler.lang.api.CEDescrBuilder) DeclareDescrBuilder(org.drools.compiler.lang.api.DeclareDescrBuilder) FunctionDescrBuilder(org.drools.compiler.lang.api.FunctionDescrBuilder) RuleDescrBuilder(org.drools.compiler.lang.api.RuleDescrBuilder) EntryPointDeclarationDescrBuilder(org.drools.compiler.lang.api.EntryPointDeclarationDescrBuilder) EnumLiteralDescrBuilder(org.drools.compiler.lang.api.EnumLiteralDescrBuilder) QueryDescrBuilder(org.drools.compiler.lang.api.QueryDescrBuilder) AnnotatedDescrBuilder(org.drools.compiler.lang.api.AnnotatedDescrBuilder) PatternDescrBuilder(org.drools.compiler.lang.api.PatternDescrBuilder) AnnotationDescrBuilder(org.drools.compiler.lang.api.AnnotationDescrBuilder) ImportDescrBuilder(org.drools.compiler.lang.api.ImportDescrBuilder) CollectDescrBuilder(org.drools.compiler.lang.api.CollectDescrBuilder) AttributeDescrBuilder(org.drools.compiler.lang.api.AttributeDescrBuilder) EvalDescrBuilder(org.drools.compiler.lang.api.EvalDescrBuilder) ConditionalBranchDescrBuilder(org.drools.compiler.lang.api.ConditionalBranchDescrBuilder) NamedConsequenceDescrBuilder(org.drools.compiler.lang.api.NamedConsequenceDescrBuilder) FieldDescrBuilder(org.drools.compiler.lang.api.FieldDescrBuilder) BehaviorDescrBuilder(org.drools.compiler.lang.api.BehaviorDescrBuilder) GlobalDescrBuilder(org.drools.compiler.lang.api.GlobalDescrBuilder)

Aggregations

AccumulateDescrBuilder (org.drools.compiler.lang.api.AccumulateDescrBuilder)13 AttributeDescrBuilder (org.drools.compiler.lang.api.AttributeDescrBuilder)13 CEDescrBuilder (org.drools.compiler.lang.api.CEDescrBuilder)13 DeclareDescrBuilder (org.drools.compiler.lang.api.DeclareDescrBuilder)13 EntryPointDeclarationDescrBuilder (org.drools.compiler.lang.api.EntryPointDeclarationDescrBuilder)13 EnumDeclarationDescrBuilder (org.drools.compiler.lang.api.EnumDeclarationDescrBuilder)13 EnumLiteralDescrBuilder (org.drools.compiler.lang.api.EnumLiteralDescrBuilder)13 FieldDescrBuilder (org.drools.compiler.lang.api.FieldDescrBuilder)13 ForallDescrBuilder (org.drools.compiler.lang.api.ForallDescrBuilder)13 FunctionDescrBuilder (org.drools.compiler.lang.api.FunctionDescrBuilder)13 GlobalDescrBuilder (org.drools.compiler.lang.api.GlobalDescrBuilder)13 ImportDescrBuilder (org.drools.compiler.lang.api.ImportDescrBuilder)13 NamedConsequenceDescrBuilder (org.drools.compiler.lang.api.NamedConsequenceDescrBuilder)13 PackageDescrBuilder (org.drools.compiler.lang.api.PackageDescrBuilder)13 PatternDescrBuilder (org.drools.compiler.lang.api.PatternDescrBuilder)13 QueryDescrBuilder (org.drools.compiler.lang.api.QueryDescrBuilder)13 RuleDescrBuilder (org.drools.compiler.lang.api.RuleDescrBuilder)13 TypeDeclarationDescrBuilder (org.drools.compiler.lang.api.TypeDeclarationDescrBuilder)13 WindowDeclarationDescrBuilder (org.drools.compiler.lang.api.WindowDeclarationDescrBuilder)13 CommonToken (org.antlr.runtime.CommonToken)12