Skip to content

Need some help writing the parser #293

Discussion options

You must be logged in to vote

The issue is extremely subtle: The lexer names the enum variant SemiColon but in the grammar you use [Semicolon]. The PEG [...] compiles into a Rust match expr like match t { Semicolon => ... }, which has the pitfall where unknown names are interpreted as a fresh variable that matches any value. Therefore the e:expr()? [Semicolon] in rule expression_statement() skips the optional expr() and matches the } with the [Semicolon] because of this. Then you're out of tokens and fail to match the [BracketCurlyRight] in block_statement where it's supposed to be.

Try cargo test parser::tests::test_block_statement --features peg/trace if you haven't seen the tracing feature.

We set allow(non_snake_c…

Replies: 3 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by stevefan1999-personal
Comment options

You must be logged in to vote
0 replies
Comment options

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

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