Need some help writing the parser #293
-
|
I know it's kinda shameless to ask but I can't really figure out why this couldn't parse. You can inspect the program here: https://replit.com/@stevefan1999_pe/TinyLanguage. Do I had a feeling there is an indirect left recursion in |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
|
The issue is extremely subtle: The lexer names the enum variant Try We set |
Beta Was this translation helpful? Give feedback.
-
|
By the way, I don't see any actual left recursion here and I think the |
Beta Was this translation helpful? Give feedback.
-
|
@kevinmehall Great. This is a really big unsight... Rather than this: Or maybe let tokens to be self-descriptable, also though the use of another proc macro (that's why I love Rust so much). Right now I don't see any remap function for &[T] so you basically have to guess what the pattern match is, which is not hard for devs but hard for users |
Beta Was this translation helpful? Give feedback.
The issue is extremely subtle: The lexer names the enum variant
SemiColonbut in the grammar you use[Semicolon]. The PEG[...]compiles into a Rustmatchexpr likematch t { Semicolon => ... }, which has the pitfall where unknown names are interpreted as a fresh variable that matches any value. Therefore thee:expr()? [Semicolon]inrule expression_statement()skips the optionalexpr()and matches the}with the[Semicolon]because of this. Then you're out of tokens and fail to match the[BracketCurlyRight]inblock_statementwhere it's supposed to be.Try
cargo test parser::tests::test_block_statement --features peg/traceif you haven't seen the tracing feature.We set
allow(non_snake_c…