usethesource / rascal

The implementation of the Rascal meta-programming language (including interpreter, type checker, parser generator, compiler and JVM based run-time system)
http://www.rascal-mpl.org
Other
408 stars 77 forks source link

Trigger recovery when only recovery stacks are left #2057

Closed PieterOlivier closed 1 month ago

PieterOlivier commented 1 month ago

Previously, error recovery was only triggered when no more active stacks where left. This PR improves on this by also triggering recovery when only recovery stacks are left.

This change increases recovery quality tremendously, but it also decreased performance significantly. To combat this, filtering of "duplicate" skip nodes has been added. Only one skip node with for a specific starting position, result type, and skip length is added. This does not impact recovery quality but it does improve performance dramatically.

The end result of these changes is improved recovery quality and improved performance.

Note that the downside is that the resulting parse forest does not include some nodes. For instance, if we have a language that allows expressions with multiple productions like <expr> + <expr> and <expr> - <expr> and an error occurs before the operator, only one of these expression productions will be included as an error node in the parse tree. Note that this information can be reconstructed by combining the error nodes with the grammar so it does not really limit the future use cases.

This PR also adds support for limiting the match length. This feature has only been used in experiments but might be actively used in the future so I decided to leave it in.

codecov[bot] commented 1 month ago

Codecov Report

Attention: Patch coverage is 88.88889% with 3 lines in your changes missing coverage. Please review.

Project coverage is 49%. Comparing base (2683d8c) to head (4d94b28). Report is 14 commits behind head on feat/error-recovery.

Files with missing lines Patch % Lines
src/org/rascalmpl/parser/gtd/SGTDBF.java 80% 1 Missing and 2 partials :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## feat/error-recovery #2057 +/- ## ===================================================== Coverage 49% 49% - Complexity 6580 6593 +13 ===================================================== Files 685 685 Lines 61127 61147 +20 Branches 8841 8849 +8 ===================================================== + Hits 30189 30215 +26 Misses 28725 28725 + Partials 2213 2207 -6 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.