Skip to content

Small parser, weird failure, faulty understanding? #470

Answered by Zij-IT
dovreshef asked this question in Q&A
Discussion options

You must be logged in to vote

You are close, but are missing a key point of or parsers. In an or chain, the first parser that is able to successfully parse some of the input will "win" the chain, and stop the chain from parsing further. This means that because your inner_expr is written first, it will successfully parse the "1 = 1" and what remains of the input is " or 2 = 2". Parsing fails here, because there is no repeat, and even if there was, nothing could parse the remaining input successfully.

A simplified example of this problem is:

let result = just("fun").or(just("function")).then_ignore(end()).parse("function");
assert!(result.is_err());

This will error because just("fun") will successfully eat the first thr…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@dovreshef
Comment options

@Zij-IT
Comment options

Answer selected by dovreshef
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