|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
public interface Parser<S,T extends Enum<T> & HasPattern>
| Method Summary | |
|---|---|
Token<T> |
consume()
Remove and return the next token from the token stream. |
Token<T> |
consume(EnumSet<T> expectedClass)
Expect a token matching any one of a number of possible types, and consume/return it. |
Token<T> |
consume(T expected)
Expect a particular token type and consume/return it. |
Token<T> |
consume(T expected,
Matcher ePat)
Expect a token by both type and string pattern, and consume/return it. |
void |
consumeUntil(T until)
Consume and discard every token until a token matching the type specification is found. |
void |
consumeUntil(T until,
Matcher untilPat)
Consume and discard every token until a token matching the type and content (regex) specification is found. |
boolean |
expect(EnumSet<T> expected)
Check whether the next token on the token stream matches any one of a number of token types. |
boolean |
expect(T expected)
Check whether the next token on the token stream matches an expected token type. |
boolean |
expect(T expected,
Matcher ePat)
Check whether the next token on the token stream matches both an expected token type and an expected regular expression pattern. |
void |
parse(S db)
Parse the data sequence, writing results into the state object db
as it goes. |
void |
shutDown()
Carry out any housekeeping to clean up after the parse is completed. |
| Method Detail |
|---|
void parse(S db)
throws ParseException
db
as it goes. This is the entry point to the parse, and it should correspond
to the top-most non-terminal of the target grammar. This method, in turn,
should invoke the various sub-rules via calls to other non-terminal
methods.
db - State object for recording information generated during the parse.
ParseException - If a lexical or syntactic error is encountered
during the parse.
void shutDown()
throws IOException
IOException - If there is an error shutting down any file resources.boolean expect(T expected)
Token.getType()) of the next Token from the token stream
without removing it from the stream or discarding it and
compares it to an "expected" token type. This returns true
iff the two match. That is, it checks that nextToken.getType()==expected
The intended use of this method is something like:
// inside some non-terminal rule
if (expect(QUOTED_STRING)) {
Token t=consume(QUOTED_STRING);
// do something with t or t.getContent()
}
- Parameters:
expected - The type of token to query.
- Returns:
true iff the next token on the stream matches
the specified token type.
boolean expect(T expected,
Matcher ePat)
nextToken.getType()==expected) and that
the token's string content matches the expected pattern (that is,
ePat matches nextToken.getContent()). Like
expect(Enum), it does not remove the token from the stream.
expected - Expected type of the next tokenePat - Regex pattern expected of the next token on the stream
boolean expect(EnumSet<T> expected)
T nType=nextTok.getType(); return ((nType == expected0) || (nType == expected1) || ... )It is helpful when you want to test whether the next token is any one of a variety of "acceptable" types.Like
expect(Enum), this does not remove the next token from the token stream -- it only tests it, without changing the stream's state.
expected - The set of possible types that the next token could match.
true iff the next token matches any of the
token types.
Token<T> consume()
throws ParseException
expect(Enum),
consume(), etc.).
ParseException - If no such token is available (e.g., because
EOF has been passed.)
Token<T> consume(T expected)
throws ParseException
consume()s the token
(i.e., removes it from the token stream and returns it). If it does
not match, this generates a ParseException, indicating
an attempt to consume an unexpected token.
expected - Type predicted for the next token on the token stream
expected
ParseException - Iff next token does not match expected
Token<T> consume(T expected,
Matcher ePat)
throws ParseException
Token.getType()) and string content
(Token.getContent()) of the next token available on the token
stream. If both match the expected values (literal type and regexp match),
then the token is removed from the stream and returned. Otherwise,
this generates a ParseException, indicating an attempt to consume an
unexpected token.
expected - Type predicted for the next token on the token streamePat - Regex pattern expected of the next token on the stream
expected and ePat
ParseException - Iff next token does not match one of expected
or ePat
Token<T> consume(EnumSet<T> expectedClass)
throws ParseException
Token.getType()) of the next token
on the token stream against a set of acceptable types. If it matches
any of them, it is removed from the token stream and returned. Otherwise,
this generates a ParseException, indicating an attempt to consume an
unexpected token.
expectedClass - Set of allowable types for the next token
expectedClass
ParseException - Iff next token does not match any of the
expectedClass
void consumeUntil(T until)
throws ParseException
until - Specification for token to stop on.
ParseException - If EOF is encountered before the specified token type.
void consumeUntil(T until,
Matcher untilPat)
throws ParseException
until - Token type specification to stop on.untilPat - Regular expression pattern to match against.
ParseException - If EOF is encountered before the specified token.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||