use of org.drools.drl.ast.dsl.EnumDeclarationDescrBuilder in project drools by kiegroup.
the class DeclareDescrBuilderImpl method enumerative.
public EnumDeclarationDescrBuilder enumerative() {
EnumDeclarationDescrBuilder eddb = new EnumDeclarationDescrBuilderImpl(parent);
descr.addEnumDeclaration(eddb.getDescr());
return eddb;
}
use of org.drools.drl.ast.dsl.EnumDeclarationDescrBuilder 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;
}
use of org.drools.drl.ast.dsl.EnumDeclarationDescrBuilder in project drools by kiegroup.
the class DRL6StrictParser method enumDeclaration.
/*
* typeDeclaration := annotation* [ENUM] qualifiedIdentifier
* enumerative+
* field*
* END
*
* @return
* @throws RecognitionException
*/
public EnumDeclarationDescr enumDeclaration(DeclareDescrBuilder ddb) throws RecognitionException {
EnumDeclarationDescrBuilder declare = null;
try {
declare = helper.start(ddb, EnumDeclarationDescrBuilder.class, null);
setAnnotationsOn(declare);
// 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.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;
}
use of org.drools.drl.ast.dsl.EnumDeclarationDescrBuilder in project drools by kiegroup.
the class DRL5Parser 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) == DRL5Lexer.AT) {
// annotation*
annotation(declare);
if (state.failed)
return null;
}
while (input.LA(1) == DRL5Lexer.ID) {
int next = input.LA(2);
if (next == DRL5Lexer.LEFT_PAREN || next == DRL5Lexer.COMMA || next == DRL5Lexer.SEMICOLON) {
enumerative(declare);
if (state.failed)
return null;
}
if (input.LA(1) == DRL5Lexer.COMMA) {
match(input, DRL5Lexer.COMMA, null, null, DroolsEditorType.SYMBOL);
} else {
match(input, DRL5Lexer.SEMICOLON, null, null, DroolsEditorType.SYMBOL);
break;
}
}
// boolean qualified = type.indexOf( '.' ) >= 0;
while (// ! qualified &&
input.LA(1) == DRL5Lexer.ID && !helper.validateIdentifierKey(DroolsSoftKeywords.END)) {
// field*
field(declare);
if (state.failed)
return null;
}
match(input, DRL5Lexer.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;
}
use of org.drools.drl.ast.dsl.EnumDeclarationDescrBuilder 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;
}
Aggregations