pobs.parser
Class POr

java.lang.Object
  extended bypobs.PParser
      extended bypobs.parser.POr
All Implemented Interfaces:
PObject

public class POr
extends PParser

Tries a number of parsers specified until one of them matches. The order of the parsers determines the order of parsing. Only the parsers upto the first which matches the input are parsed so be sure to put the longest of two parses which share the same beginning before the other. To clarify, rule := "a" | "ab" will match "a" even when input is "abc" because the second parser is never evaluated if the first one matched. Uses alternatives directive. BNF: this := parser[0] | .. | parser[..] (any number of parsers can be specified).

Author:
Martijn W. van der Lee

Constructor Summary
POr(PObject[] parsers)
          Constructor taking an array of any number of parsers.
POr(PObject parser1, PObject parser2)
          Stub constructor taking two parsers.
POr(PObject parser1, PObject parser2, PObject parser3)
          Stub constructor taking three parsers.
POr(PObject parser1, PObject parser2, PObject parser3, PObject parser4)
          Stub constructor taking four parsers.
POr(PObject parser1, PObject parser2, PObject parser3, PObject parser4, PObject parser5)
          Stub constructor taking five parsers.
 
Method Summary
 PMatch parse(PScanner input, long begin, PContext context)
           
 
Methods inherited from class pobs.PParser
addControl, getErrorInfo, process, setErrorInfo, setMatchAction, setMismatchAction
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

POr

public POr(PObject[] parsers)
Constructor taking an array of any number of parsers.

Parameters:
parsers - array of parsers
Throws:
java.lang.IllegalArgumentException - if either no array is specified or array is empty.

POr

public POr(PObject parser1,
           PObject parser2)
Stub constructor taking two parsers.


POr

public POr(PObject parser1,
           PObject parser2,
           PObject parser3)
Stub constructor taking three parsers.


POr

public POr(PObject parser1,
           PObject parser2,
           PObject parser3,
           PObject parser4)
Stub constructor taking four parsers.


POr

public POr(PObject parser1,
           PObject parser2,
           PObject parser3,
           PObject parser4,
           PObject parser5)
Stub constructor taking five parsers.

Method Detail

parse

public PMatch parse(PScanner input,
                    long begin,
                    PContext context)
Parameters:
input - Input to be parsed.
begin - Index of first character of input to be parsed.
context - Parsing context.
Returns:
Parsing result.