Skip to content

Commit 9da9b0e

Browse files
tkobayasmariofuscogitgabriolbenc135livio
committed
[DROOLS-7591] Experiment branch : migrate a new drools-lsp parser int… (#5682)
* add antlr4 based drl parser * bump to drools 8.16.0.Beta * improve node position discovery * first c3 integration * Module reorganization (#2) * WIP * Ignore directories * Add debug. Minor modifications * WIP * Fix tests - add comments * manage null ast nodes and fix failing test * improve drl parser * Fix basic completion (#4) * Add Java grammar, fix DRL grammar, simplify token index calculation, remove template code * Add ignored tokens to completion Co-authored-by: livio <[email protected]> * add constraints parsing * - Added DRLParserWrapper to store errors using DRLErrorListener (#5) - Added MiscDRLParserTest which is being ported from RuleParserTest to enhance coverage. * Enhance test/grammar coverage. function import, global, exists, not (#6) * Enhance test/grammar coverage. and, or, listExpression (#7) * Enhance test/grammar coverage. matches, single quoted string, escape (#9) - Introduced drlExpression, drlPrimary, drlLiteral, DRL_STRING_LITERAL * Enhance test/grammar coverage. dialect, invalid lhs (#10) * Enhance test/grammar coverage. keyword collision (#11) - Add "DRL_" prefix for DRL keywords for clarification * Enhance test/grammar coverage. function, attributes, consequence (#12) * Enhance test/grammar coverage. function, attributes, consequence - better getText preserving whitespaces - resolving WARNs because of overlapping keywords * - No need to declare duplicate keywords * Enhance test/grammar coverage. OR, inline map (#13) * OpenRewrite applied for junit5 and assertj (#14) * Enhance test/grammar coverage. label, consequenceLocation, test refac… (#15) * Enhance test/grammar coverage. label, consequenceLocation, test refactoring, assertj best practice * - better test method names * [DROOLS-7253] Review and improve drools-lsp parser Visitor design (#16) * [DROOLS-7253] Review and improve drools-lsp parser Visitor design - Remove currentConstructStack. Utilize return object instead. * - Remove instance fields. Utilize return objects instead. * [DROOLS-7270] Enhance test/grammar coverage : andRestriction, orRestriction (#4) - Removed some unused cast * [DROOLS-7271] Fully port RuleParserTest as MiscDRLParserTest with @disabled and priority comment (#10) * [DROOLS-7285] Failed to parse and/or with parentheses in LHS (#15) * [DROOLS-7286] Failed to parse binding with || (#21) * [DROOLS-7287] Failed to parse comments in RHS (#23) * [DROOLS-7287] Failed to parse comments in RHS * - add rhs string check * [DROOLS-7515] Parser : Accept plain text in RHS (#26) * [DROOLS-7515] Parser : Accept plain text in RHS * - Handle keyword token in RHS * - Removed sysout * - Revert statementKeywords. Instead, define DRL_END with newline or EOF * - fix method name * [DROOLS-7288] Failed to parse complex parentheses (#27) * [DROOLS-7288] Failed to parse complex parentheses - bump to 8.43.0.Final * additional tests * [DROOLS-7289] Implement accumulate (#28) * [DROOLS-7296] Implement from entry-point (#30) * [DROOLS-7297] Implement import accumulate (#29) * [DROOLS-7290] Implement BigInteger literal, BigDecimal literal (#31) * [DROOLS-7292] Implement eval (#32) * [DROOLS-7293] Implement extends (#33) * [DROOLS-7294] Implement forall (#34) * [DROOLS-7298] Implement memberOf (#35) * [DROOLS-7300] Implement positional constraint (#36) * [DROOLS-7304] Implement temporal operators (#38) - Also covers [DROOLS-7303] Implement sliding window * [DROOLS-7301] Implement query (#37) - Also partially fixes [DROOLS-7302] Implement semicolon delimiter * [DROOLS-7295] Implement from collect (#39) * [DROOLS-7305] Implement type declaration (#40) - also covers [DROOLS-7291] Implement entry-point declaration - also covers window declaration * [DROOLS-7306] Implement unification (#41) * [DROOLS-7306] Implement unification - Also [DROOLS-7307] Parse attribute agenda-group * [DROOLS-7308] Parse attribute without value - Also [DROOLS-7309] Parse attribute with parentheses * [DROOLS-7310] parse nested parentheses (#42) * [DROOLS-7310] parse nested parentheses * - Adding code commentes and explanations - Adding more nested level tests * [DROOLS-7577] drools-lsp : Add comments and explanations for drools-p… (#43) * [DROOLS-7577] drools-lsp : Add comments and explanations for drools-parser * removed syntax examples * [DROOLS-7591] Experiment branch : migrate a new drools-lsp parser into drools (#44) - Add some methods to call from drools code base * Move necessary files without any additional modifications * Update DRL6Expressions.g4 to ANTLR 4 (#47) * Add DescrDumperTest and fix the expression parser grammar (#48) * Add DescrDumperTest * Fix it * [DROOLS-7591] Experiment branch : migrate a new drools-lsp parser into drools - New parser is migrated in drools-drl/drools-drl-parser with org.drools.drl10.parser package - To enable the new parser, run `mvn test -PDRL10` - At the moment, we get lots of test failures especially in drools-model/drools-model-codegen and drools-test-coverage/test-compiler-integration * - License header - Revert an inappropriate test edit - Removed unnecessary profile - Clarify unsupported methods - Removed unnecessary bom dependency --------- Co-authored-by: mariofusco <[email protected]> Co-authored-by: Gabriele Cardosi <[email protected]> Co-authored-by: Livio Benčik <[email protected]> Co-authored-by: livio <[email protected]> Co-authored-by: Jiří Locker <[email protected]>
1 parent 23fa0a3 commit 9da9b0e

File tree

131 files changed

+11957
-63
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

131 files changed

+11957
-63
lines changed

drools-compiler/src/main/java/org/drools/compiler/builder/impl/KnowledgeBuilderRulesConfigurationImpl.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ public KnowledgeBuilderRulesConfigurationImpl(CompositeConfiguration<KnowledgeBu
127127
}
128128

129129
private void init() {
130-
131130
setProperty( TrimCellsInDTableOption.PROPERTY_NAME,
132131
getPropertyValue(TrimCellsInDTableOption.PROPERTY_NAME,
133132
"true"));

drools-compiler/src/main/java/org/drools/compiler/lang/DescrDumper.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import org.drools.drl.ast.descr.OperatorDescr;
3535
import org.drools.drl.ast.descr.RelationalExprDescr;
3636
import org.drools.drl.parser.DrlExprParser;
37+
import org.drools.drl.parser.DrlExprParserFactory;
3738
import org.drools.drl.parser.impl.Operator;
3839
import org.kie.internal.builder.conf.LanguageLevelOption;
3940

@@ -137,7 +138,7 @@ public StringBuilder dump( StringBuilder sbuilder,
137138
}
138139

139140
private void processConstraint(StringBuilder sbuilder, ExprConstraintDescr base, boolean isInsideRelCons, DumperContext context) {
140-
DrlExprParser expr = new DrlExprParser( context.getRuleContext().getConfiguration().getOption(LanguageLevelOption.KEY));
141+
DrlExprParser expr = DrlExprParserFactory.getDrlExrParser(context.getRuleContext().getConfiguration().getOption(LanguageLevelOption.KEY));
141142
ConstraintConnectiveDescr result = expr.parse( base.getExpression() );
142143
if ( result.getDescrs().size() == 1 ) {
143144
dump( sbuilder,

drools-compiler/src/main/java/org/drools/compiler/rule/builder/PatternBuilder.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@
9999
import org.drools.drl.ast.descr.ReturnValueRestrictionDescr;
100100
import org.drools.drl.ast.descr.RuleDescr;
101101
import org.drools.drl.parser.DrlExprParser;
102+
import org.drools.drl.parser.DrlExprParserFactory;
102103
import org.drools.drl.parser.DroolsParserException;
103104
import org.drools.util.ClassUtils;
104105
import org.drools.util.StringUtils;
@@ -1803,7 +1804,7 @@ protected ConstraintConnectiveDescr parseExpression(final RuleBuildContext conte
18031804
final PatternDescr patternDescr,
18041805
final BaseDescr original,
18051806
final String expression) {
1806-
DrlExprParser parser = new DrlExprParser(context.getConfiguration().getOption(LanguageLevelOption.KEY));
1807+
DrlExprParser parser = DrlExprParserFactory.getDrlExrParser(context.getConfiguration().getOption(LanguageLevelOption.KEY));
18071808
ConstraintConnectiveDescr result = parser.parse(normalizeEval(expression));
18081809
result.setResource(patternDescr.getResource());
18091810
result.copyLocation(original);

drools-compiler/src/main/java/org/drools/compiler/rule/builder/QueryElementBuilder.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import org.drools.drl.ast.descr.ExprConstraintDescr;
4747
import org.drools.drl.ast.descr.PatternDescr;
4848
import org.drools.drl.parser.DrlExprParser;
49+
import org.drools.drl.parser.DrlExprParserFactory;
4950
import org.drools.drl.parser.DroolsParserException;
5051
import org.drools.util.ClassUtils;
5152
import org.drools.util.StringUtils;
@@ -264,7 +265,7 @@ private void processBinding( RuleBuildContext context,
264265
} else {
265266
// it must be a literal/expression
266267
// it's an expression and thus an input
267-
DrlExprParser parser = new DrlExprParser( context.getConfiguration().getOption(LanguageLevelOption.KEY));
268+
DrlExprParser parser = DrlExprParserFactory.getDrlExrParser(context.getConfiguration().getOption(LanguageLevelOption.KEY));
268269
ConstraintConnectiveDescr bresult = parser.parse( bind.getExpression() );
269270
if ( parser.hasErrors() ) {
270271
for ( DroolsParserException error : parser.getErrors() ) {
@@ -395,7 +396,7 @@ private static int getPos( String identifier,
395396
private ConstraintConnectiveDescr parseExpression( final RuleBuildContext context,
396397
final PatternDescr patternDescr,
397398
final String expression ) {
398-
DrlExprParser parser = new DrlExprParser( context.getConfiguration().getOption(LanguageLevelOption.KEY));
399+
DrlExprParser parser = DrlExprParserFactory.getDrlExrParser( context.getConfiguration().getOption(LanguageLevelOption.KEY));
399400
ConstraintConnectiveDescr result = parser.parse( expression );
400401
if ( result == null || parser.hasErrors() ) {
401402
for ( DroolsParserException error : parser.getErrors() ) {
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
4+
Licensed to the Apache Software Foundation (ASF) under one
5+
or more contributor license agreements. See the NOTICE file
6+
distributed with this work for additional information
7+
regarding copyright ownership. The ASF licenses this file
8+
to you under the Apache License, Version 2.0 (the
9+
"License"); you may not use this file except in compliance
10+
with the License. You may obtain a copy of the License at
11+
12+
http://www.apache.org/licenses/LICENSE-2.0
13+
14+
Unless required by applicable law or agreed to in writing,
15+
software distributed under the License is distributed on an
16+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17+
KIND, either express or implied. See the License for the
18+
specific language governing permissions and limitations
19+
under the License.
20+
21+
-->
22+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
23+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
24+
25+
<modelVersion>4.0.0</modelVersion>
26+
<parent>
27+
<groupId>org.drools</groupId>
28+
<artifactId>drools-drl</artifactId>
29+
<version>999-SNAPSHOT</version>
30+
</parent>
31+
32+
<groupId>org.drools</groupId>
33+
<artifactId>drools-drl-parser-tests</artifactId>
34+
35+
<name>Drools :: DRL :: Parser :: Tests</name>
36+
37+
<properties>
38+
<java.module.name>org.drools.drl.parser.tests</java.module.name>
39+
</properties>
40+
41+
<dependencies>
42+
<!-- Tests -->
43+
<dependency>
44+
<groupId>org.assertj</groupId>
45+
<artifactId>assertj-core</artifactId>
46+
<scope>test</scope>
47+
</dependency>
48+
<dependency>
49+
<groupId>org.junit.jupiter</groupId>
50+
<artifactId>junit-jupiter-api</artifactId>
51+
<scope>test</scope>
52+
</dependency>
53+
<dependency>
54+
<groupId>org.junit.jupiter</groupId>
55+
<artifactId>junit-jupiter-engine</artifactId>
56+
<scope>test</scope>
57+
</dependency>
58+
<dependency>
59+
<groupId>ch.qos.logback</groupId>
60+
<artifactId>logback-classic</artifactId>
61+
<scope>test</scope>
62+
</dependency>
63+
64+
<dependency>
65+
<groupId>org.drools</groupId>
66+
<artifactId>drools-drl-parser</artifactId>
67+
<scope>test</scope>
68+
</dependency>
69+
<dependency>
70+
<groupId>org.drools</groupId>
71+
<artifactId>drools-compiler</artifactId>
72+
<scope>test</scope>
73+
</dependency>
74+
<dependency>
75+
<groupId>org.drools</groupId>
76+
<artifactId>drools-mvel</artifactId>
77+
<scope>test</scope>
78+
</dependency>
79+
</dependencies>
80+
81+
</project>

0 commit comments

Comments
 (0)