Closed kfsone closed 2 years ago
@kfsone, thank you for the feedback. One of the weaknesses of using PEG parser is poor error reporting. cpp-peglib supports the furthest failure error position report as described in the Bryan Ford original document. But unfortunately, it doesn't give us good error reports as you experienced in your grammar...
Please see the section Error report and recovery in README to implement better error messages and recovery with recovery
operator. You can also see some examples in test/test2.cc
. Hope it helps.
test2.cc is a treasure trove. +9000 for that.
My problem is that it says it's expecting Repetition or Name after repetition, when that's clearly not what the grammar says:
Rule:
Heading <- "[Block" Name Repetition "]"
Source:
# line1
[Block myname sometypo] # line2
2:15 syntax error, unexpected 'sometypo', expecting <Repetition>, <Name>.
which is the beginning of the 3rd token, which should be a Repetition
.
[Block myname sometypo] # line2
123456789|1234^ # col 15 = start of 'sometypo'
I reduced it even further, with manual whitespace control it works
but turn on whitespace skipping:
(same for " "
, [ ]
, [ \t]
, with either of ?
or *
)
@kfsone, thanks for more detailed information! I'll take a look at the default error reporting feature to see if I can make any improvements to make error messages more understandable.
@kfsone, I improve the default error reporting. I actually found some bugs in the code. I really appreciate your contribution. Please let me know if you find any problem. Thanks!
@kfsone, I discovered that this fix actually causes other serious problems. I'll revert back to the original default error recovery for now... Sorry for that...
I made additional changes to fix regressions.
@yhirose I would usually have done you the courtesy of a quick look at the changes and tested it locally, but I've been under crunch so I did not get chance to.
Thank you for your diligence!
Full grammar & example at the end. I'm seeing an unexpected claim that the parser is expecting an identifier where I think it should only be expecting a word from a named dictionary:
Sees
and complains:
Full grammar & example
example