apache / incubator-kie-drools

Drools is a rule engine, DMN engine and complex event processing (CEP) engine for Java.
http://www.drools.org
Apache License 2.0
5.88k stars 2.5k forks source link

[new-parser] No whitespace between rule keyword and rule name causes problems #5895

Closed yurloc closed 6 months ago

yurloc commented 6 months ago

Parent issue

Failing tests

Rule code snippet

rule "5" when str :String() then end

rule"6" when then end rule"7" when then end

LexerHelper does not recognize rule in rule"6" as a valid end of the previous rule's RHS and so rule"6" is tokenized as RHS_CHUNK.

Error output

### parse : ANTLR4_PARSER_ENABLED = true
00:26:32.836 [main] ERROR o.d.c.k.b.impl.AbstractKieProject.buildKnowledgePackages:280 - Unable to build KieBaseModel:KieBaseModelName
InvalidExpressionErrorResult: Unable to parse consequence caused by: (line 4,col 1) Parse error. Found  "\"6\"" <STRING_LITERAL>, expected one of  "," ";" "=" "@" "["
Problem stacktrace : 
  com.github.javaparser.GeneratedJavaParser.generateParseException(GeneratedJavaParser.java:13933)
  com.github.javaparser.GeneratedJavaParser.jj_consume_token(GeneratedJavaParser.java:13778)
  com.github.javaparser.GeneratedJavaParser.BlockStatement(GeneratedJavaParser.java:5807)
  com.github.javaparser.GeneratedJavaParser.Statements(GeneratedJavaParser.java:2773)
  com.github.javaparser.GeneratedJavaParser.Block(GeneratedJavaParser.java:5744)
  com.github.javaparser.GeneratedJavaParser.BlockParseStart(GeneratedJavaParser.java:8238)
  com.github.javaparser.JavaParser.parse(JavaParser.java:125)
  com.github.javaparser.JavaParser.parseBlock(JavaParser.java:317)
  org.drools.model.codegen.execmodel.generator.DrlxParseUtil.parseBlock(DrlxParseUtil.java:500)
  org.drools.model.codegen.execmodel.generator.Consequence.rewriteConsequence(Consequence.java:229)
  org.drools.model.codegen.execmodel.generator.Consequence.createCall(Consequence.java:143)
  org.drools.model.codegen.execmodel.generator.ModelGenerator.processRule(ModelGenerator.java:242)
  org.drools.model.codegen.execmodel.generator.ModelGenerator.processRuleDescr(ModelGenerator.java:185)
  org.drools.model.codegen.execmodel.generator.ModelGenerator.processRules(ModelGenerator.java:164)
  org.drools.model.codegen.execmodel.generator.ModelGenerator.generateModel(ModelGenerator.java:130)
  org.drools.model.codegen.execmodel.processors.ModelGeneratorPhase.process(ModelGeneratorPhase.java:48)
  org.drools.compiler.builder.impl.processors.IteratingPhase.process(IteratingPhase.java:53)
  org.drools.model.codegen.execmodel.processors.ModelMainCompilationPhase.process(ModelMainCompilationPhase.java:104)
  org.drools.model.codegen.execmodel.ModelBuilderImpl.doSecondBuildStep(ModelBuilderImpl.java:114)
  org.drools.compiler.builder.impl.CompositeKnowledgeBuilderImpl.build(CompositeKnowledgeBuilderImpl.java:125)
  org.drools.compiler.builder.impl.CompositeKnowledgeBuilderImpl.build(CompositeKnowledgeBuilderImpl.java:109)
  org.drools.compiler.kie.builder.impl.AbstractKieProject.buildKnowledgePackages(AbstractKieProject.java:274)
  org.drools.compiler.kie.builder.impl.AbstractKieProject.buildKnowledgePackages(AbstractKieProject.java:220)
  org.drools.compiler.kie.builder.impl.AbstractKieProject.verify(AbstractKieProject.java:84)
  org.drools.compiler.kie.builder.impl.KieBuilderImpl.buildKieProject(KieBuilderImpl.java:285)
  org.drools.compiler.kie.builder.impl.KieBuilderImpl.buildAll(KieBuilderImpl.java:251)
  org.drools.compiler.kie.builder.impl.KieBuilderImpl.buildAll(KieBuilderImpl.java:208)
  org.drools.testcoverage.common.util.KieUtil.getKieBuilderFromKieFileSystem(KieUtil.java:147)
  org.drools.testcoverage.common.util.KieUtil.getKieBuilderFromKieFileSystem(KieUtil.java:134)
  org.drools.testcoverage.common.util.KieUtil.getKieBuilderFromResources(KieUtil.java:121)
  org.drools.testcoverage.functional.parser.DrlParserTest.testParserSmoke(DrlParserTest.java:45)

00:26:32.842 [main] ERROR o.d.testcoverage.common.util.KieUtil.getKieBuilderFromKieFileSystem:165 - KieBuilder errors: [Message [id=1, kieBase=KieBaseModelName, level=ERROR, path=/var/home/jlocker/src/github.com/kiegroup/drools/drools-test-coverage/test-suite/src/test/resources/org/drools/testcoverage/functional/parser/drl/whitespaces.drl, line=35, column=0
   text=Unable to parse consequence caused by: (line 4,col 1) Parse error. Found  "\"6\"" <STRING_LITERAL>, expected one of  "," ";" "=" "@" "["
Problem stacktrace : 
  com.github.javaparser.GeneratedJavaParser.generateParseException(GeneratedJavaParser.java:13933)
  com.github.javaparser.GeneratedJavaParser.jj_consume_token(GeneratedJavaParser.java:13778)
  com.github.javaparser.GeneratedJavaParser.BlockStatement(GeneratedJavaParser.java:5807)
  com.github.javaparser.GeneratedJavaParser.Statements(GeneratedJavaParser.java:2773)
  com.github.javaparser.GeneratedJavaParser.Block(GeneratedJavaParser.java:5744)
  com.github.javaparser.GeneratedJavaParser.BlockParseStart(GeneratedJavaParser.java:8238)
  com.github.javaparser.JavaParser.parse(JavaParser.java:125)
  com.github.javaparser.JavaParser.parseBlock(JavaParser.java:317)
  org.drools.model.codegen.execmodel.generator.DrlxParseUtil.parseBlock(DrlxParseUtil.java:500)
  org.drools.model.codegen.execmodel.generator.Consequence.rewriteConsequence(Consequence.java:229)
  org.drools.model.codegen.execmodel.generator.Consequence.createCall(Consequence.java:143)
  org.drools.model.codegen.execmodel.generator.ModelGenerator.processRule(ModelGenerator.java:242)
  org.drools.model.codegen.execmodel.generator.ModelGenerator.processRuleDescr(ModelGenerator.java:185)
  org.drools.model.codegen.execmodel.generator.ModelGenerator.processRules(ModelGenerator.java:164)
  org.drools.model.codegen.execmodel.generator.ModelGenerator.generateModel(ModelGenerator.java:130)
  org.drools.model.codegen.execmodel.processors.ModelGeneratorPhase.process(ModelGeneratorPhase.java:48)
  org.drools.compiler.builder.impl.processors.IteratingPhase.process(IteratingPhase.java:53)
  org.drools.model.codegen.execmodel.processors.ModelMainCompilationPhase.process(ModelMainCompilationPhase.java:104)
  org.drools.model.codegen.execmodel.ModelBuilderImpl.doSecondBuildStep(ModelBuilderImpl.java:114)
  org.drools.compiler.builder.impl.CompositeKnowledgeBuilderImpl.build(CompositeKnowledgeBuilderImpl.java:125)
  org.drools.compiler.builder.impl.CompositeKnowledgeBuilderImpl.build(CompositeKnowledgeBuilderImpl.java:109)
  org.drools.compiler.kie.builder.impl.AbstractKieProject.buildKnowledgePackages(AbstractKieProject.java:274)
  org.drools.compiler.kie.builder.impl.AbstractKieProject.buildKnowledgePackages(AbstractKieProject.java:220)
  org.drools.compiler.kie.builder.impl.AbstractKieProject.verify(AbstractKieProject.java:84)
  org.drools.compiler.kie.builder.impl.KieBuilderImpl.buildKieProject(KieBuilderImpl.java:285)
  org.drools.compiler.kie.builder.impl.KieBuilderImpl.buildAll(KieBuilderImpl.java:251)
  org.drools.compiler.kie.builder.impl.KieBuilderImpl.buildAll(KieBuilderImpl.java:208)
  org.drools.testcoverage.common.util.KieUtil.getKieBuilderFromKieFileSystem(KieUtil.java:147)
  org.drools.testcoverage.common.util.KieUtil.getKieBuilderFromKieFileSystem(KieUtil.java:134)
  org.drools.testcoverage.common.util.KieUtil.getKieBuilderFromResources(KieUtil.java:121)
  org.drools.testcoverage.functional.parser.DrlParserTest.testParserSmoke(DrlParserTest.java:45)
]]

java.lang.AssertionError: [[Message [id=1, kieBase=KieBaseModelName, level=ERROR, path=/var/home/jlocker/src/github.com/kiegroup/drools/drools-test-coverage/test-suite/src/test/resources/org/drools/testcoverage/functional/parser/drl/whitespaces.drl, line=35, column=0
   text=Unable to parse consequence caused by: (line 4,col 1) Parse error. Found  "\"6\"" <STRING_LITERAL>, expected one of  "," ";" "=" "@" "["
Problem stacktrace : 
  com.github.javaparser.GeneratedJavaParser.generateParseException(GeneratedJavaParser.java:13933)
  com.github.javaparser.GeneratedJavaParser.jj_consume_token(GeneratedJavaParser.java:13778)
  com.github.javaparser.GeneratedJavaParser.BlockStatement(GeneratedJavaParser.java:5807)
  com.github.javaparser.GeneratedJavaParser.Statements(GeneratedJavaParser.java:2773)
  com.github.javaparser.GeneratedJavaParser.Block(GeneratedJavaParser.java:5744)
  com.github.javaparser.GeneratedJavaParser.BlockParseStart(GeneratedJavaParser.java:8238)
  com.github.javaparser.JavaParser.parse(JavaParser.java:125)
  com.github.javaparser.JavaParser.parseBlock(JavaParser.java:317)
  org.drools.model.codegen.execmodel.generator.DrlxParseUtil.parseBlock(DrlxParseUtil.java:500)
  org.drools.model.codegen.execmodel.generator.Consequence.rewriteConsequence(Consequence.java:229)
  org.drools.model.codegen.execmodel.generator.Consequence.createCall(Consequence.java:143)
  org.drools.model.codegen.execmodel.generator.ModelGenerator.processRule(ModelGenerator.java:242)
  org.drools.model.codegen.execmodel.generator.ModelGenerator.processRuleDescr(ModelGenerator.java:185)
  org.drools.model.codegen.execmodel.generator.ModelGenerator.processRules(ModelGenerator.java:164)
  org.drools.model.codegen.execmodel.generator.ModelGenerator.generateModel(ModelGenerator.java:130)
  org.drools.model.codegen.execmodel.processors.ModelGeneratorPhase.process(ModelGeneratorPhase.java:48)
  org.drools.compiler.builder.impl.processors.IteratingPhase.process(IteratingPhase.java:53)
  org.drools.model.codegen.execmodel.processors.ModelMainCompilationPhase.process(ModelMainCompilationPhase.java:104)
  org.drools.model.codegen.execmodel.ModelBuilderImpl.doSecondBuildStep(ModelBuilderImpl.java:114)
  org.drools.compiler.builder.impl.CompositeKnowledgeBuilderImpl.build(CompositeKnowledgeBuilderImpl.java:125)
  org.drools.compiler.builder.impl.CompositeKnowledgeBuilderImpl.build(CompositeKnowledgeBuilderImpl.java:109)
  org.drools.compiler.kie.builder.impl.AbstractKieProject.buildKnowledgePackages(AbstractKieProject.java:274)
  org.drools.compiler.kie.builder.impl.AbstractKieProject.buildKnowledgePackages(AbstractKieProject.java:220)
  org.drools.compiler.kie.builder.impl.AbstractKieProject.verify(AbstractKieProject.java:84)
  org.drools.compiler.kie.builder.impl.KieBuilderImpl.buildKieProject(KieBuilderImpl.java:285)
  org.drools.compiler.kie.builder.impl.KieBuilderImpl.buildAll(KieBuilderImpl.java:251)
  org.drools.compiler.kie.builder.impl.KieBuilderImpl.buildAll(KieBuilderImpl.java:208)
  org.drools.testcoverage.common.util.KieUtil.getKieBuilderFromKieFileSystem(KieUtil.java:147)
  org.drools.testcoverage.common.util.KieUtil.getKieBuilderFromKieFileSystem(KieUtil.java:134)
  org.drools.testcoverage.common.util.KieUtil.getKieBuilderFromResources(KieUtil.java:121)
  org.drools.testcoverage.functional.parser.DrlParserTest.testParserSmoke(DrlParserTest.java:45)
]]] 
Expecting empty but was: [Message [id=1, kieBase=KieBaseModelName, level=ERROR, path=/var/home/jlocker/src/github.com/kiegroup/drools/drools-test-coverage/test-suite/src/test/resources/org/drools/testcoverage/functional/parser/drl/whitespaces.drl, line=35, column=0
   text=Unable to parse consequence caused by: (line 4,col 1) Parse error. Found  "\"6\"" <STRING_LITERAL>, expected one of  "," ";" "=" "@" "["
Problem stacktrace : 
  com.github.javaparser.GeneratedJavaParser.generateParseException(GeneratedJavaParser.java:13933)
  com.github.javaparser.GeneratedJavaParser.jj_consume_token(GeneratedJavaParser.java:13778)
  com.github.javaparser.GeneratedJavaParser.BlockStatement(GeneratedJavaParser.java:5807)
  com.github.javaparser.GeneratedJavaParser.Statements(GeneratedJavaParser.java:2773)
  com.github.javaparser.GeneratedJavaParser.Block(GeneratedJavaParser.java:5744)
  com.github.javaparser.GeneratedJavaParser.BlockParseStart(GeneratedJavaParser.java:8238)
  com.github.javaparser.JavaParser.parse(JavaParser.java:125)
  com.github.javaparser.JavaParser.parseBlock(JavaParser.java:317)
  org.drools.model.codegen.execmodel.generator.DrlxParseUtil.parseBlock(DrlxParseUtil.java:500)
  org.drools.model.codegen.execmodel.generator.Consequence.rewriteConsequence(Consequence.java:229)
  org.drools.model.codegen.execmodel.generator.Consequence.createCall(Consequence.java:143)
  org.drools.model.codegen.execmodel.generator.ModelGenerator.processRule(ModelGenerator.java:242)
  org.drools.model.codegen.execmodel.generator.ModelGenerator.processRuleDescr(ModelGenerator.java:185)
  org.drools.model.codegen.execmodel.generator.ModelGenerator.processRules(ModelGenerator.java:164)
  org.drools.model.codegen.execmodel.generator.ModelGenerator.generateModel(ModelGenerator.java:130)
  org.drools.model.codegen.execmodel.processors.ModelGeneratorPhase.process(ModelGeneratorPhase.java:48)
  org.drools.compiler.builder.impl.processors.IteratingPhase.process(IteratingPhase.java:53)
  org.drools.model.codegen.execmodel.processors.ModelMainCompilationPhase.process(ModelMainCompilationPhase.java:104)
  org.drools.model.codegen.execmodel.ModelBuilderImpl.doSecondBuildStep(ModelBuilderImpl.java:114)
  org.drools.compiler.builder.impl.CompositeKnowledgeBuilderImpl.build(CompositeKnowledgeBuilderImpl.java:125)
  org.drools.compiler.builder.impl.CompositeKnowledgeBuilderImpl.build(CompositeKnowledgeBuilderImpl.java:109)
  org.drools.compiler.kie.builder.impl.AbstractKieProject.buildKnowledgePackages(AbstractKieProject.java:274)
  org.drools.compiler.kie.builder.impl.AbstractKieProject.buildKnowledgePackages(AbstractKieProject.java:220)
  org.drools.compiler.kie.builder.impl.AbstractKieProject.verify(AbstractKieProject.java:84)
  org.drools.compiler.kie.builder.impl.KieBuilderImpl.buildKieProject(KieBuilderImpl.java:285)
  org.drools.compiler.kie.builder.impl.KieBuilderImpl.buildAll(KieBuilderImpl.java:251)
  org.drools.compiler.kie.builder.impl.KieBuilderImpl.buildAll(KieBuilderImpl.java:208)
  org.drools.testcoverage.common.util.KieUtil.getKieBuilderFromKieFileSystem(KieUtil.java:147)
  org.drools.testcoverage.common.util.KieUtil.getKieBuilderFromKieFileSystem(KieUtil.java:134)
  org.drools.testcoverage.common.util.KieUtil.getKieBuilderFromResources(KieUtil.java:121)
  org.drools.testcoverage.functional.parser.DrlParserTest.testParserSmoke(DrlParserTest.java:45)
]]

    at org.drools.testcoverage.common.util.KieUtil.getKieBuilderFromKieFileSystem(KieUtil.java:169)
    at org.drools.testcoverage.common.util.KieUtil.getKieBuilderFromKieFileSystem(KieUtil.java:134)
    at org.drools.testcoverage.common.util.KieUtil.getKieBuilderFromResources(KieUtil.java:121)
    at org.drools.testcoverage.functional.parser.DrlParserTest.testParserSmoke(DrlParserTest.java:45)
yurloc commented 6 months ago

/take