From a previous question I'm wondering what the correct way to deal with the following race condition between whether an expression is a subselect or a parenthesized expression:
grammar Subselect;
statement: query EOF;
query
: select
| query 'UNION' query
;
select: 'SELECT' expr (',' expr)*;
expr
: '1' # identifier
| '(' expr ')' # parenExpr
| '(' query ')' # subSelect
;
WHITESPACE: [ \t\r\n] -> skip;
And from running SELECT ((SELECT 1))
I get:
What would be a suggested way to deal with this? (Note: the grammar above is a tremendous simplification and the select clause has many more components of it, but this is the simplest example I could use to show the issue that seems a bit insoluble to me with antlr4 -- hopefully an expert can help me solve it though!)