Can we relax the EOF and don't insist on a Semicolon
manticore-projects opened this issue · 3 comments
Currently every statement MUST end with a Semicolon, or else there will be an unexpected EOF
exception.
In the real world, for single statements this Semicolon is optional. Oracle JDBC even refuses to work with a trailing Semicolon.
Would it be possible to terminate a statement by ";" | <EOF> | "\n\n"
for practical reasons? (Then there is GO
and /
...)
Alternatively we could keep a Pure Grammar and put a Tainted Grammar beside. I love pure after all but still wait to experience it in real life.
The spec is clear that we need a semicolon. Add an flag to not need it. So the purity of the grammar is a must and any short-cut we take should be controlled by a flag.
Format
<direct SQL statement> ::=
<directly executable statement> <semicolon>
<directly executable statement> ::=
<direct SQL data statement>
| <SQL schema statement>
| <SQL transaction statement>
| <SQL connection statement>
| <SQL session statement>
| <direct implementation-defined statement>
<direct SQL data statement> ::=
<delete statement: searched>
| <direct select statement: multiple rows>
| <insert statement>
| <update statement: searched>
| <truncate table statement>
| <merge statement>
| <temporary table declaration>
<direct implementation-defined
In case you are not familiar - JavaCC has a semantic look ahead concept. So you can add something like:
LOOKAHEAD(0, { isSemicolonNeeded() }) ";"
Actually, just add a separate rule (preferably in a separate fragment file) that simply does not have the semicolon - instead use EOF. In JavaCC, you can call any production directly so you can just call this new one