Skip to content

drools: DRL10 ANTLR4 parser does not support lambdas and methods in functions #6891

Description

@drccrd

Describe the bug

The ANTLR4 DRL parser (DRL10ParserWrapper) cannot parse Java 8 functional syntax inside a function declaration's body, while the legacy parser accepts it. Rules using such functions compile today only because drools.drl.antlr4.parser.enabled defaults to false; they will stop compiling when the ANTLR4 parser becomes the default.

Measured directly against DRL10ParserWrapper from org.drools:drools-drl-parser:10.2.0, loaded in an isolated classloader over its own ANTLR 4.13.2 runtime, so no other parser could be in play. The same constructs parse cleanly in a rule consequence, which is handled as an island, and the legacy ANTLR3 parser accepts them in both positions.

Scope of the gap — everything else tried in a function body parses: diamond generics, explicit generics, var, enhanced for, try-with-resources, switch, casts, ternaries and anonymous inner classes. Only lambdas (expression-bodied, block-bodied and typed-parameter forms) and method references (obj::m, Type::m) fail, plus any stream chain containing one.

Likely causeDRL10Parser.g4 does carry the alternatives:

| lambdaExpression // Java8
| switchExpression // Java17
| drlExpression COLONCOLON typeArguments? drlIdentifier
| typeType COLONCOLON (typeArguments? drlIdentifier | NEW)
| classType COLONCOLON typeArguments? NEW

but they hang off drlExpression, and a function body is drlBlock → drlBlockStatement, whose expression statements do not route through drlExpression. So the support appears to be present-but-unreachable from a block statement rather than absent by design — which matches the constructs working in every other position.

Expected behavior

The ANTLR4 parser supports patterns supported by the ANTLR3 parser, including functions in DRL

Actual behavior

Error: Line X:Y missing ';' at ''

How to Reproduce?

any of these as a DRL function body:

package org.example;

function void f( java.util.List xs, java.util.List out )
{
  xs.forEach(e -> out.add(e));      // lambda
}
function void g( java.util.List xs, java.util.List out )
{
  xs.forEach(out::add);             // method reference
}

Output of uname -a or ver

No response

Output of java -version

No response

GraalVM version (if different from Java)

No response

Kogito version or git rev (or at least Quarkus version if you are using Kogito via Quarkus platform BOM)

10.2.0

Build tool (ie. output of mvnw --version or gradlew --version)

No response

Additional information

No response

Metadata

Metadata

Assignees

Type

No type

Projects

Status
📋 Backlog

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions