Google Data APIs Client Library (1.41.1)



com.google.gdata.util.parser
Class Alternative<T>

java.lang.Object
  extended by com.google.gdata.util.parser.Parser<T>
      extended by com.google.gdata.util.parser.Alternative<T>
Type Parameters:
T -

public class Alternative<T>
extends Parser<T>

The Alternative parser parses either the left or right sub-parsers. If the left parser matches, the right parser is not invoked. This short-circuiting is similar to the way the evaluation of the logical-or (||) operator is short-circuited in C++ and Java. It is important to be aware of the short-circuiting in cases where the right parser contains a Action. The following is a complicated way of constructing a parser which matches letters: Parser p = Parser.alternative(Chset.LOWER, Chset.UPPER); p.parse("a") -> matches "a" p.parse("A") -> matches "A"

See Also:
Parser

Field Summary
 
Fields inherited from class com.google.gdata.util.parser.Parser
NO_MATCH
 
Constructor Summary
Alternative(Parser<? super T> left, Parser<? super T> right)
          Class constructor.
 
Method Summary
 int parse(char[] buf, int start, int end, T data)
          Matches the current prefix of the buffer being parsed buf[start,end] against left or right sub-parsers.
 
Methods inherited from class com.google.gdata.util.parser.Parser
action, alternative, difference, intersection, list, optional, parse, parse, parse, plus, repeat, repeat, sequence, sequence, sequence, sequence, star
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Alternative

public Alternative(Parser<? super T> left,
                   Parser<? super T> right)
Class constructor.

Parameters:
left - The Parser that is matched against the parse buffer first.
right - The Parser that is matched against the parse buffer if the left parser does not match.
Method Detail

parse

public int parse(char[] buf,
                 int start,
                 int end,
                 T data)
Matches the current prefix of the buffer being parsed buf[start,end] against left or right sub-parsers.

Specified by:
parse in class Parser<T>
Parameters:
buf - The character array to match against.
start - The start offset of data within the character array to match against.
end - The end offset of data within the character array to match against.
data - User defined object that is passed to Callback.handle when an Action fires.
See Also:
Parser.parse(char[], int, int, T)