antlr / antlr/antlr4

Order of recovery strategies in `recoverInline`?

Open
#798 7 comments 0 reactions 0 assignees View on GitHub
comp:runtime error-handling parsers type:improvement
Dominant language
Java
Stars
19k
Forks
3.5k
PR merge metrics
No merged PRs in 30d

Description

Empirically speaking, I've found that the order in which the recovery strategies are tried in `DefaultErrorStrategy.recoverInline` is less useful than the reverse order. Single token insertion is less likely to apply, and hence usually gives a better recovery when it does apply. Plus, since it's fairly rare, you still end up using deletion in most of the contexts where it is helpful.

For example, I have a language where lower-cased identifiers are quite common, but separating keywords are fairly rare. Then given a sequence like
`... keyword lowerid ...`
both token insertion and deletion are possible, but token insertion is a lot more helpful! It's possible that I just hit this kind of case more often, as I find my users are more likely to enter input that is missing a token than input that has an truly extraneous token (i.e. where we will get a sensical parse without it).

I don't have an argument for this in generality, but I was wondering whether this was something you'd tried?

(Of course, you can just override `recoverInline`, which is what I've done.)

Contributor guide

Open the contributing guide

Research direction

Start by reading DefaultErrorStrategy.recoverInline and compare the current recovery-strategy ordering with the proposed reverse ordering. Review the issue's examples and existing discussion, then determine whether a behavior change is agreed upon and how it should be validated before attempting an implementation.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.