|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectedu.iu.cnets.klatsch.parser.TokenStream
public class TokenStream
This class encapsulates a buffer and makes it possible to read a stream of tokens from it,
with one-token lookahead for the parser. The class is public, but only Parser
really
needs to interact with it.
Nested Class Summary | |
---|---|
private static class |
TokenStream.State
|
Field Summary | |
---|---|
(package private) java.lang.String |
buffer
the buffer we're converting |
(package private) int |
offset
the current offset within the buffer |
(package private) Token |
peek
a buffered token to peek at, for ease of parsing |
Constructor Summary | |
---|---|
TokenStream(java.lang.String buffer)
Creates a new token stream based on the given string data. |
Method Summary | |
---|---|
(package private) boolean |
atTerminator()
Determines if the stream is at an expression terminator (EOF) |
(package private) boolean |
eof()
Determines if the stream is at its end. |
(package private) Token |
get()
Returns the next token in the stream. |
(package private) Token |
peek()
Returns the next token in the stream without actually advancing the pointer within the buffer. |
private Token |
readToken()
Reads the next token from the buffer and returns it. |
(package private) Token |
require(Token.Type type)
Reads the next token in the stream, which must match the given type to avoid causing an error. |
(package private) Token |
requireKeyword(java.lang.String keyword)
Reads the next token in the stream, which must be a keyword of the given type to avoid causing an error. |
(package private) void |
reset()
Resets the internal state of the token stream so that subsequent reads will start over from the beginning. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
java.lang.String buffer
int offset
Token peek
Constructor Detail |
---|
public TokenStream(java.lang.String buffer)
buffer
- the string to tokenizeMethod Detail |
---|
boolean atTerminator() throws TokenException
TokenException
boolean eof() throws TokenException
TokenException
Token get() throws TokenException
peek
instead for a
read with no side-effects.
TokenException
- if an error was encounteredToken peek() throws TokenException
get()
instead for a read with
side-effects.
TokenException
- if an error was encounteredToken requireKeyword(java.lang.String keyword) throws TokenException
keyword
- the type of keyword required
TokenException
- if an error or incorrect type was encounteredToken require(Token.Type type) throws TokenException
type
- the type required
TokenException
- if an error or incorrect type was encounteredvoid reset()
private Token readToken() throws TokenException
TokenException
- if an error was encountered
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |