Skip to content

Regression in parsing expressions between ANTLR 4.6 and 4.7.2+ #4890

@prbisht

Description

@prbisht

Description:

We are seeing different parsing behavior between ANTLR 4.6 and 4.7.2 (and later).
Certain expressions that fail in 4.6 fail are parsing successfully in 4.7.2+, even though our grammar files are unchanged.

This makes us suspect a possible regression or behaviour change in the ANTLR runtime.

Details

  • Grammar in use: Custom grammar files (Expression.g4, OrderBy.g4)
  • Observed differences:
    • STRING rule escape-sequence :

      STRING: '\'' (( ~('\\'|'\'') | ('\\' '\'')))* '\'' |
              '"'  (( ~('\\'|'"') | ('\\' '"')))* '"';
      

      Error:

      error(156): Expression.g4:39:9: invalid escape sequence \"
      error(156): Expression.g4:39:24: invalid escape sequence \"
      error(156): Expression.g4:39:38: invalid escape sequence \"
      error(156): Expression.g4:39:47: invalid escape sequence \"
      error(144): Expression.g4:39:23: multi-character literals are not allowed in lexer sets: '\"'
      

      This error now occurs even in ANTLR 4.6, though previously the same grammar file allowed ANTLR to generate listeners, visitors, and parsers successfully.

    • OrderBy parsing

      Grammar excerpt:

      orderBy: orderByClause | orderByClause (',' orderBy)* ;
      orderByClause: path DIRECTION ;
      direction: DIRECTION ;
      path: expr;
      expr: atom (('+' | '-') atom)*;
      atom: KEY ('.' KEY)* | LPAREN expr RPAREN ;
      DIRECTION: 'ASC' | 'DESC' ;
      

      In ANTLR 4.7.2+, a couple of expressions that were failing in 4.6 are now being accepted, for example:

      • agent.skill ASC, (agent.chat.tasks + agent.email.tasks) ASC - agent.voice.tasks
      • agent.skill ASC DESC

Expected behaviour: Behaviour should be consistent between versions. Both versions should reject the invalid expressions.

Java version: 21

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions