public class

Alternative

extends Parser<T>
java.lang.Object
   ↳ com.google.gdata.util.parser.Parser<T>
     ↳ com.google.gdata.util.parser.Alternative<T>

Class Overview

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

Summary

[Expand]
Inherited Constants
From class com.google.gdata.util.parser.Parser
Fields
private Parser<? super T> left
private Parser<? super T> right
Public Constructors
Alternative(Parser<? super T> left, Parser<? super T> right)
Class constructor.
Public Methods
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.
[Expand]
Inherited Methods
From class com.google.gdata.util.parser.Parser
From class java.lang.Object

Fields

private Parser<? super T> left

private Parser<? super T> right

Public Constructors

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.

Public Methods

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.

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