in drools-drl/drools-drl-parser/src/main/java/org/drools/drl/parser/lang/DRL6Parser.java [3321:3467]
private BaseDescr lhsGroupBy(PatternContainerDescrBuilder<?, ?> ce) throws RecognitionException {
PatternDescrBuilder<?> pattern;
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
}
GroupByDescrBuilder<?> groupBy = helper.start(pattern,
GroupByDescrBuilder.class,
null);
try {
if (helper.validateIdentifierKey(DroolsSoftKeywords.GROUPBY)) {
match(input,
DRL6Lexer.ID,
DroolsSoftKeywords.GROUPBY,
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 = groupBy.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 = 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;
}
// grouping functions
groupByKeyFunction(groupBy);
if (state.failed)
return null;
match(input,
DRL6Lexer.SEMICOLON,
null,
null,
DroolsEditorType.SYMBOL);
if (state.failed)
return null;
// accumulate functions
accumulateFunctionBinding(groupBy);
while (input.LA(1) == DRL6Lexer.COMMA) {
match(input,
DRL6Lexer.COMMA,
null,
null,
DroolsEditorType.SYMBOL);
if (state.failed)
return null;
accumulateFunctionBinding(groupBy);
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(GroupByDescrBuilder.class,
groupBy);
if (state.backtracking == 0 && input.LA(1) != DRL6Lexer.EOF) {
helper.emit(Location.LOCATION_LHS_BEGIN_OF_CONDITION);
}
}
} finally {
helper.end(PatternDescrBuilder.class,
pattern);
}
return result;
}