| java.lang.Object | ||
| ↳ | com.google.gdata.util.parser.Parser<T> | |
| ↳ | com.google.gdata.util.parser.Rule<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
|
[Expand]
Inherited Constants | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
From class
com.google.gdata.util.parser.Parser
| |||||||||||
| Fields | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| subject | |||||||||||
| Public Constructors | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
Class constructor for a
null subject. | |||||||||||
Class constructor.
| |||||||||||
| Public Methods | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
Delegates parsing responsibilties to
subject if it is
non-null, and returns NO_MATCH otherwise. | |||||||||||
Sets the
subject member. | |||||||||||
|
[Expand]
Inherited Methods | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
From class
com.google.gdata.util.parser.Parser
| |||||||||||
From class
java.lang.Object
| |||||||||||
Class constructor for a null subject.
Class constructor.
| subject | The Parser that this parser delegates parsing
responsibilities to.
|
|---|
Delegates parsing responsibilties to subject if it is
non-null, and returns NO_MATCH otherwise.
| 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.
|
Sets the subject member.
| subject | TheParser that this parser delegates
parsing responsibilities to.
|
|---|