Skip to content

Why do I need a peek if I have a LEXY_LIT in a branch condition? #160

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

You must be logged in to vote

Maybe I am getting confused with the Parsec library for Haskell where errors are propagated as far as needed up the call chain until something succeeds.

Yes, that is not how lexy works. In lexy backtracking is explicit, it will not just try a rule and hope for the best. You need to tell lexy how it should decide which rule to take. That is accomplished with the >> operator. In the case of StaticQualifiedPoint, you want that rule to be taken when Static is encountered, so change the rule to dsl::p<Static> >> dsl::p<Identifier>. Further reading: https://lexy.foonathan.net/learn/branching/

As an aside, if you have a new whitespace rule, you shouldn't need to use lexy::token_production.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by EmmanuelMess
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