Google Data APIs Client Library (1.41.1)



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

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

public class Rule<T>
extends Parser<T>

The Rule parser has a very simple reason for existence: in order to construct recursive grammars, a parser needs to reference itself. But the normal parser construction routines don't allow that to be done. An alternative to this design would be to allow the modification of the sub-parsers of Alternative, Sequence, etc. after the objects have been constructed. The following matches a sequence of letters and digits that end in a digit. This could be more easily accomplished, but it demonstrates how a recursive parser can be constructed: Rule r = new Rule(); r.set(Parser.alternative(Chset.DIGIT, Parser.sequence(Chset.ALPHA, r))); r.parse("a0") -> matches "a0" r.parse("a0b1") -> matches "a0b1" r.parse("a") -> no match

See Also:
Parser

Field Summary
 
Fields inherited from class com.google.gdata.util.parser.Parser
NO_MATCH
 
Constructor Summary
Rule()
          Class constructor for a null subject.
Rule(Parser<T> subject)
          Class constructor.
 
Method Summary
 int parse(char[] buf, int start, int end, T data)
          Delegates parsing responsibilties to subject if it is non-null, and returns NO_MATCH otherwise.
 void set(Parser<T> subject)
          Sets the subject member.
 
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

Rule

public Rule()
Class constructor for a null subject.


Rule

public Rule(Parser<T> subject)
Class constructor.

Parameters:
subject - The Parser that this parser delegates parsing responsibilities to.
Method Detail

parse

public int parse(char[] buf,
                 int start,
                 int end,
                 T data)
Delegates parsing responsibilties to subject if it is non-null, and returns NO_MATCH otherwise.

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)

set

public void set(Parser<T> subject)
Sets the subject member.

Parameters:
subject - TheParser that this parser delegates parsing responsibilities to.