cadence
cadence copied to clipboard
Make the parser resilient
Issue To Be Solved
Currently the parser terminates upon certain syntax errors with a panic. Once this happens, syntax analyzing stops for the remainder of the program, and the user would not get any further syntax errors, even if there's any.
Suggest A Solution
Solution is to replace the places where the parser panics, with a non-greedy/non-exhaustive recovery approach, and continue the parsing. Parser should be able to produce a valid syntax-tree/AST even when there are syntax errors.
In order to support this feature, following items needs to be completed:
- [ ] Add a way to switch modes for the compiler (e.g: a 'dev' mode that supports extensive error recovering, and a 'on-chain' mode that terminates upon the first error)
- [x] Support buffering tokens multiple times in the lexer.
- [ ] Introduce an error recovery algorithm that is capable of deciding whether to add or remove a token upon a syntax error.
- [ ] Skip the recovered nodes at the semantic analyzer phase. Because such recovered nodes at parser may leave to regression errors at the semantic analyzer.