Skip to content

True suppression of errors or "Am I holding try_ wrong?" #117

Answered by foonathan
jevinskie asked this question in Q&A
Discussion options

You must be logged in to vote

So I think there is a bit of a misunderstanding with dsl::try_: it is only used for error recovery. If you have a situation where a token is required by the grammar, but parsing can continue if it's omitted, you can use dsl::try_ for that. The error will still be reported, but instead of canceling the production, parsing can continue to check the rest of the input.

Also, dsl::opt(dsl::else_ >> x) is never correct, as that is equivalent to x: dsl::else_ is a branch rule that is unconditionally taken and is meant in combination with |.

I didn't quite understand what you want, so here are possible interpretations:

  1. You want to parse hello world or hello::world, where either is correct. Use d…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@foonathan
Comment options

Answer selected by foonathan
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants