AST for code with errors
dkundel opened this issue · 4 comments
Hi everyone,
is there a way to get the AST even though the code passed to the parser has errors?
Cheers!
If the parser can't parse the code, how can it gives you what it parsed ?
Agree with that part :) I was just hoping there might be a way I can achieve something such as the acorn_loose parser and it's parse_dammit function :) https://github.com/marijnh/acorn#acorn_loosejs
I believe I saw a pegjs thread on returning partial trees on failure (though it could be done manually in each parse rule without support from pegjs), but I can't find it right now. This would be a lot of work, whichever strategy was chosen, but I'd be open to a PR if someone wants to take it on.
My main issue with that is : it usually doesn't help (although you're maybe not trying to do something like acorn_loosejs). Compilers that don't skip on the first error and try to get as many as possible are usually really bad at that -- You get tons of error and you usually get to the first one anyway (that's what I do when I use gcc, for example) ...
If that's not your use-case, it might be fine, tho.