-
Hello I have implemented a parser, and i am getting the following error. (I have tried adding labels to everything in cond/expr parsers, but it doesn't seem to solve the "something else" to something more indicative.) Error: Unexpected token
╭─[./examples/factors.alan:15:20]
│
15 │ if ( (n % lcv) == 0) {
│ ─┬
│ ╰── found == expected something else
────╯
Error: Unexpected token
╭─[./examples/factors.alan:25:5]
│
25 │ }
│ ┬
│ ╰── found } expected end of input
────╯ |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
It's hard to know what's going to without knowing much about the parser's design. Are you treating parenthesised expressions as having the same precedence as atoms (i.e: literals, variable names, etc.)? |
Beta Was this translation helpful? Give feedback.
-
I think the problem lies in the fact that the second "(" is parsed as Printing the context in the error message seems to indicate that,
|
Beta Was this translation helpful? Give feedback.
It is intended behaviour, although admittedly not always desirable behaviour. Chumsky will prefer branches that result in fewer errors, but the exponential explosion of possible parse paths means that the parser may overly eagerly commit to a recovery pattern, missing an alternative valid parse. It's important to have error recovery occur as high up the stack as you reasonably can, and to not be overly general, so that the parser gets the opportunity to try all valid approaches to parsing the syntax before falling back to recovery.