tkobayas commented on code in PR #5855:
URL:
https://github.com/apache/incubator-kie-drools/pull/5855#discussion_r1574238317
##########
drools-drl/drools-drl-parser-tests/src/test/java/org/drools/drl/parser/antlr4/DRLExprParserTest.java:
##########
@@ -403,26 +418,48 @@ public void testExtraneousInput() {
assertThat(parser.hasErrors()).isTrue();
assertThat(parser.getErrors()).hasSize(1);
DroolsParserException exception = parser.getErrors().get(0);
- assertThat(exception.getErrorCode()).isEqualTo("ERR 109");
- assertThat(exception.getLineNumber()).isEqualTo(1);
- assertThat(exception.getColumn()).isEqualTo(3);
- assertThat(exception.getOffset()).isEqualTo(3);
- assertThat(exception.getMessage())
- .startsWithIgnoringCase("[ERR 109] Line 1:3 extraneous input
';' expecting ")
- .contains("TIME_INTERVAL", "DRL_STRING_LITERAL", "?/",
"boolean", "byte", "char", "double", "float", "int", "long", "new", "short",
"super", "DECIMAL_LITERAL", "HEX_LITERAL", "FLOAT_LITERAL", "BOOL_LITERAL",
"STRING_LITERAL", "null", "(", "[", ".", "<", "!", "~", "++", "--", "+", "-",
"*", "/", "IDENTIFIER");
+
+ // Backward Compatibility Notes:
+ // Antlr4 gives a different error code/message from antlr3 for this
case.
+ // Backward compatibility doesn't seem to be required in this case.
+ if (DrlParser.ANTLR4_PARSER_ENABLED) {
+ assertThat(exception.getErrorCode()).isEqualTo("ERR 109");
+ assertThat(exception.getLineNumber()).isEqualTo(1);
+ assertThat(exception.getColumn()).isEqualTo(3);
+ assertThat(exception.getOffset()).isEqualTo(3);
+ assertThat(exception.getMessage())
+ .startsWithIgnoringCase("[ERR 109] Line 1:3 extraneous
input ';' expecting ")
+ .contains("TIME_INTERVAL", "DRL_STRING_LITERAL", "?/",
"boolean", "byte", "char", "double", "float", "int", "long", "new", "short",
"super", "DECIMAL_LITERAL", "HEX_LITERAL", "FLOAT_LITERAL", "BOOL_LITERAL",
"STRING_LITERAL", "null", "(", "[", ".", "<", "!", "~", "++", "--", "+", "-",
"*", "/", "IDENTIFIER");
+ } else {
+ assertThat(exception.getErrorCode()).isEqualTo("ERR 101");
+ assertThat(exception.getLineNumber()).isEqualTo(1);
+ assertThat(exception.getColumn()).isEqualTo(3);
+ assertThat(exception.getOffset()).isEqualTo(3);
+ assertThat(exception.getMessage())
+ .isEqualToIgnoringCase("[ERR 101] Line 1:3 no viable
alternative at input ';'");
+ }
}
+
@Test
public void testNoViableAlt() {
String source = "x.int";
parser.parse(source);
- assertThat(parser.hasErrors()).isTrue();
- assertThat(parser.getErrors()).hasSize(1);
- DroolsParserException exception = parser.getErrors().get(0);
- assertThat(exception.getErrorCode()).isEqualTo("ERR 101");
- assertThat(exception.getLineNumber()).isEqualTo(1);
- assertThat(exception.getColumn()).isEqualTo(2);
- assertThat(exception.getOffset()).isEqualTo(2);
- assertThat(exception.getMessage())
- .isEqualToIgnoringCase("[ERR 101] Line 1:2 no viable
alternative at input '.int'");
+
+ // Backward Compatibility Notes:
+ // Old expr parser (DRL6Expressions) allows this expression because
it's too tolerant (fail at runtime anyway).
+ // Backward compatibility doesn't seem to be required in this case.
(But we may align with the old tolerant behavior.)
+ if (DrlParser.ANTLR4_PARSER_ENABLED) {
Review Comment:
`Backward Compatibility Notes` : B) Old parser seems to be wrong
Old parser allows `x.int`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]