Replies: 3 comments
-
Yes, but it requires work in your grammar, because there's no good way for peggy to know where your synchronization point is, and what "recovery" means. Let's say you want to parse a list of numbers: numbers
= number*
number
= n:[0-9]+ "\n" { return parseInt(n, 10) } When you feed it valid decimal numbers separated by newlines, it works. When you feed it letters, it errors. If you used this grammar instead: numbers
= nums:number* { return nums.filter(n => n != null) } // Remember 0 is falsy.
number
= n:[0-9]+ "\n" { return parseInt(n, 10) }
/ n:$[^\n]* "\n" {
console.error(`Invalid number: "${n}"`);
return null;
} This recovers from the error processing a number, skips to the next synchronization point (the "\n"), outputs an error, and returns a sentinel value (null) to denote the error. The |
Beta Was this translation helpful? Give feedback.
-
I'm going to move this issue to a discussion, so it will stick around for the future. |
Beta Was this translation helpful? Give feedback.
-
See #173 |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
It would be greate that the parser can continue to parse the next statement when encounter an error.
Beta Was this translation helpful? Give feedback.
All reactions