yhirose / cpp-peglib

A single file C++ header-only PEG (Parsing Expression Grammars) library
MIT License
880 stars 112 forks source link

Custom error messages without recovery #240

Closed rwtolbert closed 2 years ago

rwtolbert commented 2 years ago

I've been playing with the recovery options, in order to get more specific error messages, but now I realize that I don't really want "recovery" and continued parsing.

I'm not parsing an entire document, so I want the parser to fail and return false but with my custom error messages in place of the default.

Is this even possible?

yhirose commented 2 years ago

@rwtolbert, in the error recovery example in README, semia doesn't really recover since it takes an empty expression ''. I think you can try the same. Hope it helps.

# Recovery operator labels
semia       ← '' { message "missing semicolon in assignment." }
stmtb       ← (!(Stmt / 'else' / '}') .)* { message "invalid statement" }
condw       ← &'==' ('==' RelExp)* / &'<' ('<' AddExp)* / (!')' .)*