fr.umlv.tatoo.runtime.parser
Class ParserErrorRecoveryPolicy<T,N,P,V>

java.lang.Object
  extended by fr.umlv.tatoo.runtime.parser.ParserErrorRecoveryPolicy<T,N,P,V>
Type Parameters:
T - type of terminals.
N - type of non-terminal.
P - type of productions.
V - type of versions.
Direct Known Subclasses:
DefaultParserErrorRecoveryPolicy

public abstract class ParserErrorRecoveryPolicy<T,N,P,V>
extends Object

Error recovery policy of the parser.

Author:
Remi Forax
See Also:
Parser.createParser(ParserTable,ParserListener,ParserErrorRecoveryPolicy,Object,Object,LookaheadMap)

Constructor Summary
ParserErrorRecoveryPolicy()
           
 
Method Summary
abstract  boolean closeParser(Parser<T,N,P,V> parser)
          Notifies that the parser is closing and an error was notified by continueRecoverOnError(fr.umlv.tatoo.runtime.parser.Parser, fr.umlv.tatoo.runtime.util.IntArrayList, T) returning ActionReturn.NEXT_ERROR.
abstract  ActionReturn continueRecoverOnError(Parser<T,N,P,V> parser, IntArrayList states, T terminal)
          Called when error recovery was initiated by recover on error, and method errorRecoveryNeedsContinuation() returns true
abstract  boolean errorRecoveryNeedsContinuation()
          Indicate if continueRecoverOnError(fr.umlv.tatoo.runtime.parser.Parser, fr.umlv.tatoo.runtime.util.IntArrayList, T) needs to be called by processor
abstract  Set<? extends T> getLookahead(Parser<T,N,P,V> parser, Set<? extends T> proposedLookaheads)
          Returns the lookahead set of terminals that the parser should accept as input of next Parser.step().
static
<T,N,P,V> ParserErrorRecoveryPolicy<T,N,P,V>
getNoErrorRecoveryPolicy(ParserWarningReporter<T,N,P,V> warningReporter)
          Returns an error recover policy that doesn't recover errors.
abstract  ActionReturn recoverOnError(Parser<T,N,P,V> parser, IntArrayList states, T terminal, String message)
          Tries to recover on an error.
abstract  void reset()
          Reset the error recovery policy.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ParserErrorRecoveryPolicy

public ParserErrorRecoveryPolicy()
Method Detail

errorRecoveryNeedsContinuation

public abstract boolean errorRecoveryNeedsContinuation()
Indicate if continueRecoverOnError(fr.umlv.tatoo.runtime.parser.Parser, fr.umlv.tatoo.runtime.util.IntArrayList, T) needs to be called by processor

Returns:
true if continueRecoverOnError(fr.umlv.tatoo.runtime.parser.Parser, fr.umlv.tatoo.runtime.util.IntArrayList, T) needs to be called by processor

recoverOnError

public abstract ActionReturn recoverOnError(Parser<T,N,P,V> parser,
                                            IntArrayList states,
                                            T terminal,
                                            String message)
Tries to recover on an error. The method returns true if error recovery started and/or succeeded, false if lexer must skip some input. This method may throw a ParseException to signify a fatal error.

Parameters:
parser - the parser.
states - the state stack of the parser.
terminal - the terminal that caused the error or null if no terminal is available.
Returns:
NEXT if lexer must skip some input.

continueRecoverOnError

public abstract ActionReturn continueRecoverOnError(Parser<T,N,P,V> parser,
                                                    IntArrayList states,
                                                    T terminal)
Called when error recovery was initiated by recover on error, and method errorRecoveryNeedsContinuation() returns true

Parameters:
parser - the parser.
states - the state stack of the parser.
terminal - current terminal, argument of Parser.step(terminal) or null.
Returns:
NEXT if the terminal must be skipped by the parser, KEEP otherwise.

closeParser

public abstract boolean closeParser(Parser<T,N,P,V> parser)
Notifies that the parser is closing and an error was notified by continueRecoverOnError(fr.umlv.tatoo.runtime.parser.Parser, fr.umlv.tatoo.runtime.util.IntArrayList, T) returning ActionReturn.NEXT_ERROR. This method is called in Parser.close().

Parameters:
parser - the parser.
Returns:
true if
See Also:
Parser.close()

getLookahead

public abstract Set<? extends T> getLookahead(Parser<T,N,P,V> parser,
                                              Set<? extends T> proposedLookaheads)
Returns the lookahead set of terminals that the parser should accept as input of next Parser.step().

Parameters:
parser - the parser.
proposedLookaheads - the lookahead set of terminal of current parser state when there is no error.
Returns:
the set of terminals or null for all terminals.

reset

public abstract void reset()
Reset the error recovery policy. If the policy maintains some states because it try to recover, they must be reseted.

See Also:
Parser.reset(Object)

getNoErrorRecoveryPolicy

public static <T,N,P,V> ParserErrorRecoveryPolicy<T,N,P,V> getNoErrorRecoveryPolicy(ParserWarningReporter<T,N,P,V> warningReporter)
Returns an error recover policy that doesn't recover errors.

Type Parameters:
T - type of terminals.
N - type of non-terminals.
P - type of productions.
V - type of versions.
Parameters:
warningReporter - a reporter that will display a warning or null.
Returns:
the singleton instance of a policy that doesn't recover errors.