|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectedu.cornell.cs.sam.io.SamTokenizer
public class SamTokenizer
This is a SamTokenizer implementation that has full backwards/forwards mobility and loads everything into memory as soon as it is created. By default, quote processing is disabled and comment ignoring is enabled. You may use one of the constructors with options to enabled/disable this options
Nested Class Summary | |
---|---|
static class |
SamTokenizer.TokenizerOptions
|
Nested classes/interfaces inherited from interface edu.cornell.cs.sam.io.Tokenizer |
---|
Tokenizer.TokenType |
Constructor Summary | |
---|---|
SamTokenizer(java.io.Reader r,
SamTokenizer.TokenizerOptions... opt)
Creates a new SamTokenizer with a Reader as a source |
|
SamTokenizer(SamTokenizer.TokenizerOptions... opt)
Creates a new SamTokenizer with System.in as a source |
|
SamTokenizer(java.lang.String FileName,
SamTokenizer.TokenizerOptions... opt)
Creates a new SamTokenizer with a file for a source |
Method Summary | |
---|---|
boolean |
canPushBack()
Checks if the stream can be pushed back |
boolean |
check(char c)
Removes the next token if it is an operator, and matches the character c. |
boolean |
check(java.lang.String s)
Removes the next token if it is a word, and matches the string s. |
void |
close()
Closes the input stream |
char |
getCharacter()
Returns the next token (unless it is not a character) |
java.lang.String |
getComment()
Returns the next token (unless it is not a comment) |
float |
getFloat()
Returns the next token (unless it is not a float) |
int |
getInt()
Returns the next token (unless it is not an integer) |
char |
getOp()
Returns the next token (unless it is not an operator) |
java.lang.String |
getString()
Returns the next token (unless it is not a string) |
java.lang.String |
getWhitespaceBeforeToken()
Returns the whitespace in the file before the current token. |
java.lang.String |
getWord()
Returns the next token (unless it is not a word) |
int |
lineNo()
Returns the line number of the last token requested |
void |
match(char c)
Removes the next token if it is an operator, and matches the given character. |
void |
match(java.lang.String s)
Removes the next token if it is a word, and matches the given string. |
int |
nextLineNo()
Returns the line number of the next token to be read |
Tokenizer.TokenType |
peekAtKind()
Returns the type of the next token |
void |
pushBack()
Pushes the last token requested back. |
void |
skipToken()
Skips the next token |
boolean |
test(char c)
Checks if the next token is an operator and matches the character c. |
boolean |
test(java.lang.String s)
Checks if the next token is a word and matches the string s. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public SamTokenizer(java.lang.String FileName, SamTokenizer.TokenizerOptions... opt) throws java.io.IOException, java.io.FileNotFoundException, TokenParseException
FileName
- The file name of the file to readopt
- Options for parsing
java.io.IOException
- If there is a file error
java.io.FileNotFoundException
- If the file could not be found
TokenParseException
public SamTokenizer(java.io.Reader r, SamTokenizer.TokenizerOptions... opt) throws java.io.IOException, TokenParseException
r
- The sourceopt
- Options for parsing
java.io.IOException
- if there is a stream error
TokenParseException
public SamTokenizer(SamTokenizer.TokenizerOptions... opt) throws java.io.IOException, TokenParseException
opt
- Options for parsing
java.io.IOException
- if there is a stream error
TokenParseException
Method Detail |
---|
public Tokenizer.TokenType peekAtKind()
Tokenizer
peekAtKind
in interface Tokenizer
public int getInt() throws TokenizerException
Tokenizer
getInt
in interface Tokenizer
TokenizerException
- if the next token is not an integerpublic float getFloat() throws TokenizerException
Tokenizer
getFloat
in interface Tokenizer
TokenizerException
- if the next token is not a floatpublic java.lang.String getWord() throws TokenizerException
Tokenizer
getWord
in interface Tokenizer
TokenizerException
- if the next token is not a wordpublic java.lang.String getString() throws TokenizerException
Tokenizer
getString
in interface Tokenizer
TokenizerException
- if the next token is not a stringpublic char getCharacter() throws TokenizerException
Tokenizer
getCharacter
in interface Tokenizer
TokenizerException
- if the next token is not a characterpublic char getOp() throws TokenizerException
Tokenizer
getOp
in interface Tokenizer
TokenizerException
- if the next token is not an operatorpublic java.lang.String getComment() throws TokenizerException
Tokenizer
getComment
in interface Tokenizer
TokenizerException
- if the next token is not a commentpublic void match(char c) throws TokenizerException
Tokenizer
match
in interface Tokenizer
c
- the character to match
TokenizerException
- if the next token is not c, or is not an operator token.public void match(java.lang.String s) throws TokenizerException
Tokenizer
match
in interface Tokenizer
s
- the string to match
TokenizerException
- if the next token is not s, or is not a word tokenpublic boolean check(char c)
Tokenizer
check
in interface Tokenizer
c
- the character to match
public boolean check(java.lang.String s)
Tokenizer
check
in interface Tokenizer
s
- the string to match
public boolean test(char c)
Tokenizer
test
in interface Tokenizer
c
- the character to match
public boolean test(java.lang.String s)
Tokenizer
test
in interface Tokenizer
s
- the string to match
public void pushBack()
Tokenizer
pushBack
in interface Tokenizer
public boolean canPushBack()
Tokenizer
canPushBack
in interface Tokenizer
public java.lang.String getWhitespaceBeforeToken()
Tokenizer
getWhitespaceBeforeToken
in interface Tokenizer
public int lineNo()
Tokenizer
lineNo
in interface Tokenizer
public int nextLineNo()
Tokenizer
nextLineNo
in interface Tokenizer
public void close()
Tokenizer
close
in interface Tokenizer
public void skipToken()
Tokenizer
skipToken
in interface Tokenizer
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |