Skip to content

dsl::try_ still seems to fail on errors #40

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

You must be logged in to vote

Yes, this is the expected behavior.

dsl::try_() is used to do error recovery: if an error happens, it is still reported, but parsing continues after doing the optional recovery part: https://lexy.foonathan.net/playground/?id=7zf1WG4oG

If you want to make something optional, use either dsl::if_(branch), which parses the branch if the condition matches, and does nothing otherwise, or dsl::opt_(branch), which produces a special lexy::nullopt value if the branch was not taken: https://lexy.foonathan.net/playground/?id=G1ndY9jrb

(Maybe the name dsl::try_() isn't ideal)

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
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
Converted from issue

This discussion was converted from issue #23 on December 10, 2021 07:50.