public class

Rule

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

Class Overview

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

Summary

[Expand]
Inherited Constants
From class com.google.gdata.util.parser.Parser
Fields
private Parser<T> subject
Public Constructors
Rule()
Class constructor for a null subject.
Rule(Parser<T> subject)
Class constructor.
Public Methods
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.
[Expand]
Inherited Methods
From class com.google.gdata.util.parser.Parser
From class java.lang.Object

Fields

private Parser<T> subject

Public Constructors

public Rule ()

Class constructor for a null subject.

public Rule (Parser<T> subject)

Class constructor.

Parameters
subject The Parser that this parser delegates parsing responsibilities to.

Public Methods

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.

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

public void set (Parser<T> subject)

Sets the subject member.

Parameters
subject TheParser that this parser delegates parsing responsibilities to.