pobs
Class PDirective

java.lang.Object
  extended bypobs.PDirective

public class PDirective
extends java.lang.Object

Maintains all state information for the POBS framework such as parser policies. Directive also provides a number of support methods which helps parsers implement the directives, it is ultimately up to the implementor of a parser to handle the directives, this class cannot force parsers to abide by the directives. All parsers supplied with POBS obey these directives fully.

Author:
Martijn W. van der Lee

Field Summary
static byte FIRST
           
static byte LONGEST
           
static byte SHORTEST
           
 
Constructor Summary
PDirective()
          Empty constructor with all set to default.
PDirective(PObject skipper)
          Construct a new object with a specified skipper.
 
Method Summary
 PMatch alternative(PMatch a, PMatch b)
          Determines the match of two matches based upon the alternatives directive.
 char convert(char character)
          Converts a character based on whether the directive for case sensitivity is set.
 byte getAlternatives()
          gets the alternatives mode used in this directive.
 PObject getSkipper()
          gets the parser used in this directive for skipping.
 boolean isActions()
          Checks whether actions are enabled for this PContext.
 boolean isCaseSensitive()
          checks whether case sensitivity is enabled for this PContext.
 boolean isSkip()
          Checks whether skipping is enabled for this PContext.
 void setActions(boolean actions)
          Enables or disables actions for this PContext.
 void setAlternatives(byte alternatives)
          Sets the alternatives mode for this PContext.
 void setCaseSensitive(boolean caseSensitive)
          Enables or disables case sensitivity for this PContext.
 void setSkip(boolean skip)
          Enables or disables skipping for this PContext.
 void setSkipper(PObject skipper)
          Sets the parserto use for skipping.
 long skip(PScanner input, long begin)
          Support method for skipping.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FIRST

public static final byte FIRST
See Also:
Constant Field Values

LONGEST

public static final byte LONGEST
See Also:
Constant Field Values

SHORTEST

public static final byte SHORTEST
See Also:
Constant Field Values
Constructor Detail

PDirective

public PDirective()
Empty constructor with all set to default.


PDirective

public PDirective(PObject skipper)
Construct a new object with a specified skipper.

Method Detail

alternative

public PMatch alternative(PMatch a,
                          PMatch b)
Determines the match of two matches based upon the alternatives directive.

Parameters:
a - the first alternative (leftmost in parser)
b - the second alternative (rightmost in parser)

convert

public char convert(char character)
Converts a character based on whether the directive for case sensitivity is set. This method is ment for parser implementors only, to easy the support for the case sensitivity directive. An implementor just needs to pass every single character to this method and will hereby automatically gain support for this directive. If an implementor wishes to parse by any means other than character-by-character comparison, it is left to the implementor to handle case sensitivity. Note however that if you want to return the lengths of failed parses (which is highly recommended), a character-by-character comparison is likely the best way to do so.

Parameters:
character - the char to convert
Returns:
the converted character

getAlternatives

public byte getAlternatives()
gets the alternatives mode used in this directive.

Returns:
the alternatives mode of this directive.

getSkipper

public PObject getSkipper()
gets the parser used in this directive for skipping. Please note that this method may return a null value if no skipper is specified.

Returns:
the skipper parser of this directive.
See Also:
PObject

isActions

public boolean isActions()
Checks whether actions are enabled for this PContext.

Returns:
indication of actions

isCaseSensitive

public boolean isCaseSensitive()
checks whether case sensitivity is enabled for this PContext.

Returns:
indication of case sensitivity

isSkip

public boolean isSkip()
Checks whether skipping is enabled for this PContext.

Returns:
indication of skipping

setActions

public void setActions(boolean actions)
Enables or disables actions for this PContext.

Parameters:
actions - true to enable actions.

setAlternatives

public void setAlternatives(byte alternatives)
Sets the alternatives mode for this PContext.

Parameters:
alternatives - either FIRST, LONGEST or SHORTEST alternatives.

setCaseSensitive

public void setCaseSensitive(boolean caseSensitive)
Enables or disables case sensitivity for this PContext.

Parameters:
caseSensitive - true to enable case sensitivity

setSkip

public void setSkip(boolean skip)
Enables or disables skipping for this PContext.

Parameters:
skip - true to enable skipping

setSkipper

public void setSkipper(PObject skipper)
Sets the parserto use for skipping. This does not enable skipping but merely specifies which skipper to use when skipping is enabled.

Parameters:
skipper - a parser to use for skipping

skip

public long skip(PScanner input,
                 long begin)
Support method for skipping. This method is to be used by parser implementors to more easily use the skipping directive. The parser implementor must pass the input iteratorand begin position then add the returned length to it's own internal position variable, there is no need for the parser implementer to check any of the directives, this method will always return the expected result. Contrary to instinct, skipping is not commonly implemented in terminal parsers. Since skipping occurs between terminals, it needs only to be implemented in those parsers which can parse sequences of (possibly terminal) parsers such as and PRepeat.

Parameters:
input - iterator in which to skip
begin - location from which to start skipping
Returns:
length of the skipped input area