DefaultErrorStrategy.recoverInline

{@inheritDoc}

<p>The default implementation attempts to recover from the mismatched input by using single token insertion and deletion as described below. If the recovery attempt fails, this method throws an {@link InputMismatchException}.</p>

<p><strong>EXTRA TOKEN</strong> (single token deletion)</p>

<p>{@code LA(1)} is not what we are looking for. If {@code LA(2)} has the right token, however, then assume {@code LA(1)} is some extra spurious token and delete it. Then consume and return the next token (which was the {@code LA(2)} token) as the successful result of the match operation.</p>

<p>This recovery strategy is implemented by {@link #singleTokenDeletion}.</p>

<p><strong>MISSING TOKEN</strong> (single token insertion)</p>

<p>If current token (at {@code LA(1)}) is consistent with what could come after the expected {@code LA(1)} token, then assume the token is missing and use the parser's {@link TokenFactory} to create it on the fly. The "insertion" is performed by returning the created token as the successful result of the match operation.</p>

<p>This recovery strategy is implemented by {@link #singleTokenInsertion}.</p>

<p><strong>EXAMPLE</strong></p>

<p>For example, Input {@code i=(3;} is clearly missing the {@code ')'}. When the parser returns from the nested call to {@code expr}, it will have call chain:</p>

<pre> stat &rarr; expr &rarr; atom </pre>

and it will be trying to match the {@code ')'} at this point in the derivation:

<pre> =&gt; ID '=' '(' INT ')' ('+' atom)* ';' ^ </pre>

The attempt to match {@code ')'} will fail when it sees {@code ';'} and call {@link #recoverInline}. To recover, it sees that {@code LA(1)==';'} is in the set of tokens that can follow the {@code ')'} token reference in rule {@code atom}. It can assume that you forgot the {@code ')'}.

class DefaultErrorStrategy
recoverInline

Meta