pobs.errorhandler
Class PDefaultErrorHandler

java.lang.Object
  extended bypobs.errorhandler.PDefaultErrorHandler
All Implemented Interfaces:
PErrorHandler

public class PDefaultErrorHandler
extends java.lang.Object
implements PErrorHandler

Default error handler. Creates pretty error messages.

Author:
Franz-Josef Elmer

Constructor Summary
PDefaultErrorHandler(boolean showStackTrace)
           
 
Method Summary
 java.lang.String createErrorMessage(PScanner input)
          Creates a human readable error message using the specified input to get reasonable error positions (like line number and column number).
 long getErrorPosition()
          Gets the actual error position.
 void notifySemanticError(long position, java.lang.RuntimeException exception)
          Notifies the error handler that a semantic error occured during execution of a PAction attached to the specified parser.
 void notifySyntaxError(long position, PParser parser)
          Notifies the error handler that a syntax error occured for the specified parser at the specified parsing position.
 boolean semanticErrorOccured()
          Returns true if at least one semantic error occured.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PDefaultErrorHandler

public PDefaultErrorHandler(boolean showStackTrace)
Method Detail

notifySyntaxError

public void notifySyntaxError(long position,
                              PParser parser)
Description copied from interface: PErrorHandler
Notifies the error handler that a syntax error occured for the specified parser at the specified parsing position. This method might be called several times even if complete parsing is successful.

From both types of notifiction events concrete implementations must find out where the actual error occured and what is its reason. For the later PParser.getErrorInfo() can be used.

Specified by:
notifySyntaxError in interface PErrorHandler
Parameters:
position - Parsing position.
parser - Parser who has detected a syntax error.

notifySemanticError

public void notifySemanticError(long position,
                                java.lang.RuntimeException exception)
Description copied from interface: PErrorHandler
Notifies the error handler that a semantic error occured during execution of a PAction attached to the specified parser. This method might be called several times even if complete parsing is successful.

From both types of notifiction events concrete implementations must find out where the actual error occured and what is its reason. For the later exception.getMessage() can be used.

Specified by:
notifySemanticError in interface PErrorHandler
Parameters:
position - Parsing position.
exception - Exception thrown by the PAction instance.

getErrorPosition

public long getErrorPosition()
Description copied from interface: PErrorHandler
Gets the actual error position.

Specified by:
getErrorPosition in interface PErrorHandler
Returns:
actual parsing position where the error occured.

semanticErrorOccured

public boolean semanticErrorOccured()
Description copied from interface: PErrorHandler
Returns true if at least one semantic error occured.

Specified by:
semanticErrorOccured in interface PErrorHandler

createErrorMessage

public java.lang.String createErrorMessage(PScanner input)
Description copied from interface: PErrorHandler
Creates a human readable error message using the specified input to get reasonable error positions (like line number and column number).

Specified by:
createErrorMessage in interface PErrorHandler
Parameters:
input - Input source of parsing.
Returns:
error message.