| java.lang.Object | |
| ↳ | com.google.gdata.util.parser.Parser<T> |
Known Direct Subclasses
Action<T, U extends T>,
Alternative<T>,
Chset,
Difference<T>,
Intersection<T>,
Repeat<T>,
Rule<T>,
Sequence<T>,
Strcaselit,
Strlit
|
The com.google.gdata.util.parser package provides a framework for creating recursive descent parsers. A fairly straightforward transformation exists between EBNF (extended Backus-Naur form) grammars and code used to construct a parser using this framework that will match the grammar. The intention of this package is to obviate the need to create small mini-parsers for tasks that don't feel large enough for a standard compiler-compiler (like JavaCC) but still need more formalism than simple string tokenization. The basic approach this framework takes to parsing is to define several types of leaf parsers which know how to parse a particular type of object (character set, string literal, etc.) and to then combine them together in interesting ways. For example, a parser for a comma separated list of integers would look like: Parser Chset.DIGIT.plus().list(new Chset(',')); The EBNF this represents is: sent: [0-9]+ ("," [0-9]+)* The Parser.list() functionality is sometimes represented as the '%' operator in EBNF extensions. It performs the transformation: a % b --> a (b a)* The leaf parsers that are currently defined are:
ChsetStrlitThe operators which combine 1 or 2 parsers together are:ActionAlternativeDifferenceIntersectionRepeatRuleIn general, it isn't necessary to create an operator-type parser directly as
an appropriate member function usually exists in Parser for creating
them. Note that these are purely convenience routines.
In general, the parsers are greedy. For example, the Sequence parser will
match as much as possible with the left sub-parser before trying the right
sub-parser. This behavior can normally be avoided by using a recursive
grammar. Consider the following grammar:
token: foo* bar
foo: [a-z]+
bar: foo [0-9]+
This grammar will fail to parse the string "aa0" because the 'foo*' rule
will consume all of the letters and not leave one left for the 'bar'
rule. An alternate definition of 'token' can prevent this behavior:
token: (foo token) | bar
The parsers created by this parser framework use infinite lookahead. In
extreme cases, a parser can be constructed which scans over the parse buffer
many times trying to find a match. In practice, this doesn't happen very
often.| Constants | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| int | NO_MATCH | ||||||||||
| Public Constructors | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| Public Methods | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
Creates a
Action that will fire and call
Callback.handle whenever this matches. | |||||||||||
Creates an
Alternative parser from the left and
right sub-parsers. | |||||||||||
Creates a
Difference parser from the left and
right sub-parsers. | |||||||||||
Creates an
Intersection parser from the left and
right sub-parsers. | |||||||||||
Creates a
Parser that matches a sequence of this
parsers separated by sep parsers. | |||||||||||
Creates a
Repeat parser that matches this either
0 or 1 times. | |||||||||||
Convenience routine to parse a string.
| |||||||||||
The parse interface that subclasses must implement.
| |||||||||||
Convenience routine to parse a
java.io.Reader. | |||||||||||
Convenience routine to parse a character array.
| |||||||||||
Creates a
Repeat parser that matches this 1 or
more times. | |||||||||||
Creates a
Repeat parser that matches this at
least min times and not mroe than max times. | |||||||||||
Creates a
Repeat parser that matches this
exactly count times. | |||||||||||
Creates a sequence of four parsers.
| |||||||||||
Creates a sequence of five parsers.
| |||||||||||
Creates a
Sequence parser from parsers one,
two and three sub-parsers. | |||||||||||
Creates a
Sequence parser from the left and
right sub-parsers. | |||||||||||
Creates a
Repeat parser that matches this 0 or
more times. | |||||||||||
|
[Expand]
Inherited Methods | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
| |||||||||||
Creates a Action that will fire and call
Callback.handle whenever this matches.
| callback | The Callback to call when
this matches.
|
|---|
Creates an Alternative parser from the left and
right sub-parsers.
left | right
| left | |
|---|---|
| right |
Creates a Difference parser from the left and
right sub-parsers.
left - right
| left | |
|---|---|
| right |
Creates an Intersection parser from the left and
right sub-parsers.
left & right
| left | |
|---|---|
| right |
Creates a Parser that matches a sequence of this
parsers separated by sep parsers. These sequences occur
often: space separated words, comma separated words, etc.
| sep | The parser which separates instances of this.
|
|---|
Creates a Repeat parser that matches this either
0 or 1 times.
this?
Convenience routine to parse a string.
| str | |
|---|---|
| udata |
The parse interface that subclasses must implement.
| 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. |
| udata | User defined object that is passed to
Callback.handle when an Action fires.
|
Convenience routine to parse a java.io.Reader.
| reader | |
|---|---|
| udata |
Convenience routine to parse a character array.
| buf | |
|---|---|
| udata |
Creates a Repeat parser that matches this at
least min times and not mroe than max times.
this{min,max}
| min | The minimum number of times this must match in
sequence. |
|---|---|
| max | The maximum number of times this is allowed to
match in sequence.
|
Creates a Repeat parser that matches this
exactly count times.
this{count}
| count | The number of times this must match in sequence.
|
|---|
Creates a sequence of four parsers.
| one | |
|---|---|
| two | |
| three | |
| four |
Creates a sequence of five parsers.
| one | |
|---|---|
| two | |
| three | |
| four | |
| five |
Creates a Sequence parser from parsers one,
two and three sub-parsers. Equivalent to calling
Parser.sequence(one, Parser.sequence(two, three)).
| one | |
|---|---|
| two | |
| three |
Creates a Sequence parser from the left and
right sub-parsers.
left right
| left | |
|---|---|
| right |