public class OPScanner extends Object
Modifier and Type | Field and Description |
---|---|
protected BaseToken |
m_current
The current BaseTokens from data
|
protected OPToken |
m_currentToken
The current OPToken translated from current
|
protected BaseTokenStream |
m_data
The source of BaseTokens to process
|
protected Set<CharSequence> |
m_setOperators
The set of valid operators used by this scanner
|
protected TokenTable |
m_tokenTable
The TokenTable that defines the translation from BaseTokens to OPTokens
|
Constructor and Description |
---|
OPScanner(TokenTable tokenTable,
Set<CharSequence> setOperators)
Construct a new OPScanner using the given TokenTable.
|
Modifier and Type | Method and Description |
---|---|
OPToken |
advance()
Advance to the next token.
|
OPToken |
advance(String s)
Advance to the next token and expect it to match the given string.
|
OPToken |
advance(String s,
boolean fIgnoreCase)
Advance to the next token and expect it to match the given string.
|
boolean |
advanceWhenMatching(String sWord)
Test to see if the current BaseToken's string matches the given string
and advance if true. * The token table's ignoringCase flag is consulted
to see if case matters.
|
protected OPToken |
classify()
Figure out how to map the current BaseToken to a OPToken and return it.
|
void |
disableTokenNamed(String name)
Disable the token named by the given string.
|
void |
enableTokenNamed(String name)
Enable the token named by the given string.
|
OPToken |
getCurrent()
Answer the current OPToken.
|
String |
getCurrentAsString()
Answer the string representation of the current BaseToken.
|
String |
getCurrentAsStringWithAdvance()
Answer the string representation of the current BaseToken and advance.
|
BaseToken |
getCurrentBaseToken()
Answer the current BaseToken.
|
boolean |
isEnd()
If the Scanner is at the end answer true otherwise answer false.
|
boolean |
isEndOfStatement()
If the scanner is at the end of a statement return true.
|
boolean |
matches(String sWord)
Test to see if the current BaseToken's string matches the given string.
|
boolean |
matches(String sWord,
boolean fIgnoreCase)
Test to see if the current BaseToken's string matches the given string.
|
OPToken |
next()
Move to the next token in the stream and return it.
|
BaseToken |
peekNext()
Answer the string representation of the next BaseToken.
|
String[] |
peekNext2AsStrings()
Answer the String[] representation of the next two BaseTokens.
|
String |
peekNextAsString()
Answer the string representation of the next BaseToken.
|
void |
popStream()
Restore the remembered BaseTokenStream as the source of streaming.
|
void |
pushStream(BaseTokenStream ts)
Remember the current BaseTokenStream and stream over the given stream.
|
void |
reset()
Reset this scanner to process the current BaseTokenStream
|
void |
scan(Reader r)
Initialize a new OPScanner to process the given Reader and load first
token into current.
|
void |
scan(String s)
Initialize a new OPScanner to process the given String and load first
token into current.
|
void |
setStrictness(boolean fStrict)
The given flag determines the strictness in that an unknown token
throws an exception otherwise they are turned into an identifier.
|
protected BaseTokenStream m_data
protected BaseToken m_current
protected OPToken m_currentToken
protected TokenTable m_tokenTable
protected Set<CharSequence> m_setOperators
public OPScanner(TokenTable tokenTable, Set<CharSequence> setOperators)
tokenTable
- the TokenTable that defines the mapping
from BaseTokenssetOperators
- the set of operators to usepublic void scan(String s)
s
- the String to convert to a stream of tokenspublic void scan(Reader r)
r
- the Reader to use as source for a stream of tokenspublic void reset()
public void setStrictness(boolean fStrict)
fStrict
- boolean to control the strictnesspublic OPToken next()
public boolean isEnd()
public boolean isEndOfStatement()
public OPToken getCurrent()
public BaseToken getCurrentBaseToken()
public String getCurrentAsString()
public String peekNextAsString()
public BaseToken peekNext()
public String[] peekNext2AsStrings()
public String getCurrentAsStringWithAdvance()
public boolean matches(String sWord)
sWord
- the string to match withpublic boolean matches(String sWord, boolean fIgnoreCase)
sWord
- the string to match withfIgnoreCase
- the flag that indicates if case is interestingpublic boolean advanceWhenMatching(String sWord)
sWord
- the string to match withpublic OPToken advance(String s)
s
- the string that should match the next tokenpublic OPToken advance(String s, boolean fIgnoreCase)
s
- the string that should match the next tokenfIgnoreCase
- the flag that indicates if case is interestingpublic OPToken advance()
public void pushStream(BaseTokenStream ts)
ts
- the BaseTokenStream to now stream overpublic void popStream()
public void enableTokenNamed(String name)
name
- the name of the OPToken to enablepublic void disableTokenNamed(String name)
name
- the name of the OPToken to disableprotected OPToken classify()