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

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

public class DefaultParserErrorRecoveryPolicy<T,N,P,V>
extends ParserErrorRecoveryPolicy<T,N,P,V>

Error recover policy that try to recover ... An instance of this policy must be associated to only one parser because it owns an error state specific to a parser. It use an error recovery listener to inform that during recover phase some terminal or non terminal must be discarded in order to recover.

Author:
Remi Forax, Julien Cervelle

Constructor Summary
DefaultParserErrorRecoveryPolicy(ErrorRecoveryListener<? super T,? super N> errorRecoveryListener)
          Creates the recover policy with a listener to signal when pop terminal and non terminal during a recover phase.
 
Method Summary
 boolean closeParser(Parser<T,N,P,V> parser)
          Notifies that the parser is closing and an error was notified by ParserErrorRecoveryPolicy.continueRecoverOnError(fr.umlv.tatoo.runtime.parser.Parser, fr.umlv.tatoo.runtime.util.IntArrayList, T) returning ActionReturn.NEXT_ERROR.
 ActionReturn continueRecoverOnError(Parser<T,N,P,V> parser, IntArrayList states, T terminal)
          Called when error recovery was initiated by recover on error, and method ParserErrorRecoveryPolicy.errorRecoveryNeedsContinuation() returns true
 boolean errorRecoveryNeedsContinuation()
          Indicate if ParserErrorRecoveryPolicy.continueRecoverOnError(fr.umlv.tatoo.runtime.parser.Parser, fr.umlv.tatoo.runtime.util.IntArrayList, T) needs to be called by processor
 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().
 ActionReturn recoverOnError(Parser<T,N,P,V> parser, IntArrayList states, T terminal, String message)
          Tries to recover on an error.
 void reset()
          Reset the error recovery policy.
 
Methods inherited from class fr.umlv.tatoo.runtime.parser.ParserErrorRecoveryPolicy
getNoErrorRecoveryPolicy
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultParserErrorRecoveryPolicy

public DefaultParserErrorRecoveryPolicy(ErrorRecoveryListener<? super T,? super N> errorRecoveryListener)
Creates the recover policy with a listener to signal when pop terminal and non terminal during a recover phase.

Parameters:
errorRecoveryListener - the listener.
Method Detail

recoverOnError

public ActionReturn recoverOnError(Parser<T,N,P,V> parser,
                                   IntArrayList states,
                                   T terminal,
                                   String message)
Description copied from class: ParserErrorRecoveryPolicy
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.

Specified by:
recoverOnError in class ParserErrorRecoveryPolicy<T,N,P,V>
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 ActionReturn continueRecoverOnError(Parser<T,N,P,V> parser,
                                           IntArrayList states,
                                           T terminal)
Description copied from class: ParserErrorRecoveryPolicy
Called when error recovery was initiated by recover on error, and method ParserErrorRecoveryPolicy.errorRecoveryNeedsContinuation() returns true

Specified by:
continueRecoverOnError in class ParserErrorRecoveryPolicy<T,N,P,V>
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 boolean closeParser(Parser<T,N,P,V> parser)
Description copied from class: ParserErrorRecoveryPolicy
Notifies that the parser is closing and an error was notified by ParserErrorRecoveryPolicy.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().

Specified by:
closeParser in class ParserErrorRecoveryPolicy<T,N,P,V>
Parameters:
parser - the parser.
Returns:
true if
See Also:
Parser.close()

getLookahead

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

Specified by:
getLookahead in class ParserErrorRecoveryPolicy<T,N,P,V>
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 void reset()
Description copied from class: ParserErrorRecoveryPolicy
Reset the error recovery policy. If the policy maintains some states because it try to recover, they must be reseted.

Specified by:
reset in class ParserErrorRecoveryPolicy<T,N,P,V>
See Also:
Parser.reset(Object)

errorRecoveryNeedsContinuation

public boolean errorRecoveryNeedsContinuation()
Description copied from class: ParserErrorRecoveryPolicy
Indicate if ParserErrorRecoveryPolicy.continueRecoverOnError(fr.umlv.tatoo.runtime.parser.Parser, fr.umlv.tatoo.runtime.util.IntArrayList, T) needs to be called by processor

Specified by:
errorRecoveryNeedsContinuation in class ParserErrorRecoveryPolicy<T,N,P,V>
Returns:
true if ParserErrorRecoveryPolicy.continueRecoverOnError(fr.umlv.tatoo.runtime.parser.Parser, fr.umlv.tatoo.runtime.util.IntArrayList, T) needs to be called by processor