Closed kindaro closed 3 years ago
Thanks for the report. I think there must be a way to support 'empty statements' with a semi colon on its own as well as making it optional at the end of non empty statements.
But how?
We use an expression like sepEndBy statement semi
to parse multiple statements.
If the parser for the empty statement consumes the semicolon, then statement
also may consume a semicolon. The separating semi
in the expression above does not have a semicolon to consume and there is a failure.
If the parser for the empty statement consumes nothing, then an expression like the one above may enter infinite loop.
We may allow statements like /* */;
to be parsed without consuming the semicolon: as white space and commentary is consumed, the loop is avoided. That would be sufficient to parse the actual output of mysqldump
above. I think it is better to drop the support for statements without a semicolon and have consistency. But I am on board with whatever solution you choose.
What matters for me is that we decide something and proceed to other fascinating parse failures that await in the remaining code of my example. Since I already put a temporary fix for the semicolon problem into my fork, I have seen — there are many.
Maybe we can use a more complicated parser for statements
, along the lines of many statementWithSemicolon >> optional statementWithoutSemicolon
, where statementWithSemicolon
may parse an empty statement, but statementWithoutSemicolon
cannot. I shall try this.
What if you make the optional semicolon part of the statement, and parse a semicolon on its own as the empty statement, something like statement = (nonemptystatement >> optional semicolon) | semicolononly statements = many statement
Thanks for the contributions!
Thank you Jake.
There is an inherent contradiction in making the
statement
parser work on strings that are not terminated bysemi
(semicolon parser). Consider this example:See the error:
Consider a simpler case:
Same error. The reason is clear: empty statements are not supported. The support is desirable — the example is taken straight out of
mysqldump
!But how can we parse an empty statement? Without a
semi
, it is a parser that succeeds consuming nothing. Nowstatements
may loop forever, parsing infinite number of empty statements!I propose that statements without a terminating
semi
should not be supported, and that empty statements should be parsed with a solesemi
into their own nullary data constructor.