pobs
Class PParser

java.lang.Object
  extended bypobs.PParser
All Implemented Interfaces:
PObject
Direct Known Subclasses:
PAny, PChar, PDigit, PEnd, PEOL, PExcept, PLetter, PLimit, PList, POptional, POr, PRepeat, PSequence, PSet, PToken, PTokens, PUnicode, PUnicodeBlock, PWhitespace, PWrapper

public abstract class PParser
extends java.lang.Object
implements PObject

Abstract base class of all parsers. It handles directives and optional actions. Concrete subclasses must implement #parse(PScanner, long, PContext).

In order to make parsers thread safe the following points must be fulfilled:

Author:
Martijn W. van der Lee, Franz-Josef Elmer

Constructor Summary
PParser()
           
 
Method Summary
 PParser addControl(PControl control)
          Adds a control.
 java.lang.String getErrorInfo()
          Returns the error information.
 PMatch process(PScanner input, long begin, PContext context)
          Parses specified input and invokes actions if defined.
 PParser setErrorInfo(java.lang.String errorInfo)
          Sets an error info.
 PParser setMatchAction(PAction matchAction)
          Defines the action used in the case of matching.
 PParser setMismatchAction(PAction mismatchAction)
          Defines the action used in the case of missmatching.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PParser

public PParser()
Method Detail

addControl

public final PParser addControl(PControl control)
Adds a control. Controls are executed in inverse order. That is, the last added control will be executed first.

Returns:
this instance.

getErrorInfo

public java.lang.String getErrorInfo()
Returns the error information.


process

public PMatch process(PScanner input,
                      long begin,
                      PContext context)
Parses specified input and invokes actions if defined. First, #parse(PScanner, long, PContext)is invoked. Depending on the result the matching or missmatching action is invoked with the PTargetof context.

Specified by:
process in interface PObject
Parameters:
input - a PScanner which contains the entire input sequence
begin - the index location into the input from where to start processing
context - the current processing context
Returns:
the processing result
See Also:
PMatch

setErrorInfo

public PParser setErrorInfo(java.lang.String errorInfo)
Sets an error info.

Parameters:
errorInfo - Error info which will be used by PErrorHandler. Can be null.
Returns:
this instance.

setMatchAction

public final PParser setMatchAction(PAction matchAction)
Defines the action used in the case of matching.

Parameters:
matchAction - Action invoked in case of a successful match. Can be null.
Returns:
this instance.

setMismatchAction

public final PParser setMismatchAction(PAction mismatchAction)
Defines the action used in the case of missmatching.

Parameters:
mismatchAction - Action invoked in case of a unsuccessful match. Can be null.
Returns:
this instance.