antlr / grammars-v4

Grammars written for ANTLR v4; expectation that the grammars are free of actions.
MIT License
10.15k stars 3.7k forks source link

bug of PlSqlParser.g4: statement split error #1812

Open anhzhi opened 4 years ago

anhzhi commented 4 years ago

Input sql: from https://github.com/antlr/grammars-v4/blob/master/sql/plsql/examples/views.sql#L52

CREATE VIEW TEST (A, B, C)
      AS 
      WITH TESTCTE AS (
        SELECT 1 ONE FROM DUAL
      )
      SELECT 'A', 'B', 'C'
      FROM DUAL
      JOIN TESTCTE;

when parsing it with the rule of sql_script: https://github.com/antlr/grammars-v4/blob/master/sql/plsql/PlSqlParser.g4#L32

sql_script
    : ((unit_statement | sql_plus_command) SEMICOLON?)* EOF
    ;

the result is not as expected:

grun PlSql sql_script -gui

antlr4_parse_tree

The given sql is splitted into 2 clauses:

CREATE TABLE TEST
      AS 
      WITH TESTCTE AS (
        SELECT 1 ONE FROM DUAL
      )
      SELECT 'A', 'B', 'C'
      FROM DUAL

and

      JOIN TESTCTE;

While parsing it withrule of unit_statement: it works just as expected.

antlr4_parse_tree(unit_statement)

Marti2203 commented 4 years ago

Hi! I am gonna see if I can work this weekend on checking whether this grammar fully conforms to the standard as I recently played around with the SQLite grammar and there were things missing there.