Class OPScanner
java.lang.Object
com.tangosol.coherence.dsltools.precedence.OPScanner
OPScanner gives clients a streaming api that returns a next
OPToken by processing a java.lang.String using a TokenTable to convert
lower level BaseTokens into the high functionality OPTokens. Since
BaseTokens support a composite sequence token OPScanner supports nested
scanning.
- Author:
- djl 2009.03.02
-
Field Summary
Modifier and TypeFieldDescriptionprotected BaseToken
The current BaseTokens from dataprotected OPToken
The current OPToken translated from currentprotected BaseTokenStream
The source of BaseTokens to processprotected Set
<CharSequence> The set of valid operators used by this scannerprotected TokenTable
The TokenTable that defines the translation from BaseTokens to OPTokens -
Constructor Summary
ConstructorDescriptionOPScanner
(TokenTable tokenTable, Set<CharSequence> setOperators) Construct a new OPScanner using the given TokenTable. -
Method Summary
Modifier and TypeMethodDescriptionadvance()
Advance to the next token.Advance to the next token and expect it to match the given string.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.Answer the current OPToken.Answer the string representation of the current BaseToken.Answer the string representation of the current BaseToken and advance.Answer the current BaseToken.boolean
isEnd()
If the Scanner is at the end answer true otherwise answer false.boolean
If the scanner is at the end of a statement return true.boolean
Test to see if the current BaseToken's string matches the given string.boolean
Test to see if the current BaseToken's string matches the given string.next()
Move to the next token in the stream and return it.peekNext()
Answer the string representation of the next BaseToken.String[]
Answer the String[] representation of the next two BaseTokens.Answer the string representation of the next BaseToken.void
Restore the remembered BaseTokenStream as the source of streaming.void
Remember the current BaseTokenStream and stream over the given stream.void
reset()
Reset this scanner to process the current BaseTokenStreamvoid
Initialize a new OPScanner to process the given Reader and load first token into current.void
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.
-
Field Details
-
m_data
The source of BaseTokens to process -
m_current
The current BaseTokens from data -
m_currentToken
The current OPToken translated from current -
m_tokenTable
The TokenTable that defines the translation from BaseTokens to OPTokens -
m_setOperators
The set of valid operators used by this scanner
-
-
Constructor Details
-
OPScanner
Construct a new OPScanner using the given TokenTable.- Parameters:
tokenTable
- the TokenTable that defines the mapping from BaseTokenssetOperators
- the set of operators to use
-
-
Method Details
-
scan
Initialize a new OPScanner to process the given String and load first token into current.- Parameters:
s
- the String to convert to a stream of tokens
-
scan
Initialize a new OPScanner to process the given Reader and load first token into current.- Parameters:
r
- the Reader to use as source for a stream of tokens
-
reset
public void reset()Reset this scanner to process the current BaseTokenStream -
setStrictness
public 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. The default setting is false.- Parameters:
fStrict
- boolean to control the strictness
-
next
Move to the next token in the stream and return it.- Returns:
- the current token
-
isEnd
public boolean isEnd()If the Scanner is at the end answer true otherwise answer false.- Returns:
- the boolean that answers as to whether the stream is atEnd
-
isEndOfStatement
public boolean isEndOfStatement()If the scanner is at the end of a statement return true. A statement end is signified by either a semi-colon or the end of the token stream.- Returns:
- true if the scanner is at the end of a statement
-
getCurrent
Answer the current OPToken.- Returns:
- the current token
-
getCurrentBaseToken
Answer the current BaseToken.- Returns:
- the current BaseToken
-
getCurrentAsString
Answer the string representation of the current BaseToken.- Returns:
- the string representation of the current BaseToken
-
peekNextAsString
Answer the string representation of the next BaseToken.- Returns:
- the string representation of the next BaseToken
-
peekNext
Answer the string representation of the next BaseToken.- Returns:
- the string representation of the next BaseToken
-
peekNext2AsStrings
Answer the String[] representation of the next two BaseTokens.- Returns:
- the String[] representation of the next BaseToken
-
getCurrentAsStringWithAdvance
Answer the string representation of the current BaseToken and advance.- Returns:
- the string representation of the current BaseToken
-
matches
Test to see if the current BaseToken's string matches the given string. The token table's ignoringCase flag is consulted to see if case matters.- Parameters:
sWord
- the string to match with- Returns:
- a boolean indication of the success of the match
-
matches
Test to see if the current BaseToken's string matches the given string. The given flag controls whether case is interesting.- Parameters:
sWord
- the string to match withfIgnoreCase
- the flag that indicates if case is interesting- Returns:
- a boolean indication of the success of the match
-
advanceWhenMatching
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.- Parameters:
sWord
- the string to match with- Returns:
- a boolean indication of the success of the match
-
advance
Advance to the next token and expect it to match the given string. If expectations are not met then throw an Exception. The token table's ignoringCase flag is consulted to see if case matters.- Parameters:
s
- the string that should match the next token- Returns:
- the next OPToken
-
advance
Advance to the next token and expect it to match the given string. If expectations are not met then throw an Exception. The given flag controls whether case is interesting.- Parameters:
s
- the string that should match the next tokenfIgnoreCase
- the flag that indicates if case is interesting- Returns:
- the next OPToken
-
advance
Advance to the next token.- Returns:
- the next OPToken
-
pushStream
Remember the current BaseTokenStream and stream over the given stream.- Parameters:
ts
- the BaseTokenStream to now stream over
-
popStream
public void popStream()Restore the remembered BaseTokenStream as the source of streaming. -
enableTokenNamed
Enable the token named by the given string.- Parameters:
name
- the name of the OPToken to enable
-
disableTokenNamed
Disable the token named by the given string.- Parameters:
name
- the name of the OPToken to disable
-
classify
Figure out how to map the current BaseToken to a OPToken and return it.- Returns:
- the current OPToken
-