class DefaultScanner extends Object implements Scanner
The scanner tokenizes:
| Modifier and Type | Field and Description |
|---|---|
private LiteralCommandMap |
commandMap
Maps command literal strings to command types.
|
| Constructor and Description |
|---|
DefaultScanner(LiteralCommandMap commandMap)
Dedicated constructor.
|
| Modifier and Type | Method and Description |
|---|---|
private boolean |
isAllowedInFloat(char c)
Whether an character is allowed in float literals.
|
private boolean |
isKeyword(String token)
Determines if a token string is a keyword.
|
private void |
scan(List<Token> tokens,
CharacterStream characterStream)
Loops over all characters of stream.
|
List<Token> |
scan(String line)
Scans give line and returns list of recognized tokens.
|
private Token |
scanFloat(CharacterStream characterStream,
StringBuilder value)
Recognize float tokens until next white space character.
|
private Token |
scanLiteral(CharacterStream characterStream)
Recognize alpha numeric string tokens until next white space character.
|
private Token |
scanLiteralOrKeyword(CharacterStream characterStream,
StringBuilder value)
Recognize alpha numeric string tokens until next white space character.
|
private Token |
scanNumber(CharacterStream characterStream)
Recognize numeric tokens until next white space character.
|
private Token |
scanString(CharacterStream characterStream)
Scan string tokens.
|
private final LiteralCommandMap commandMap
public DefaultScanner(LiteralCommandMap commandMap)
commandMap - map key word literals to command typespublic List<Token> scan(String line) throws SyntaxException
scan in interface Scannerline - must not be nullnull, maybe emptySyntaxException - if syntax error occurredprivate void scan(List<Token> tokens, CharacterStream characterStream) throws SyntaxException
tokens - list to which recognized tokens will be addcharacterStream - input line to scanSyntaxException - if string is not correct encapsulated by quotesprivate Token scanLiteral(CharacterStream characterStream)
characterStream - input line to scanprivate Token scanLiteralOrKeyword(CharacterStream characterStream, StringBuilder value)
characterStream - input line to scanvalue - collects the token string, must not be nullprivate Token scanNumber(CharacterStream characterStream)
If this method recognizes a dot it will try to scan a float. If any not number character is detected it will treat the token as a literal/keyword.
characterStream - input line to scanprivate Token scanFloat(CharacterStream characterStream, StringBuilder value)
If any not number character is detected it will treat the token as a literal/keyword.
characterStream - input line to scanvalue - accumulates the token literal stringprivate Token scanString(CharacterStream characterStream) throws SyntaxException
characterStream - input line to scanSyntaxException - if string is not correct encapsulated by quotesprivate boolean isKeyword(String token)
LiteralCommandMap.isCommand(java.lang.String) and
LiteralCommandMap.isSubCommand(java.lang.String).token - string to checkprivate boolean isAllowedInFloat(char c)
Allowed are signs (+|-) and the exponential characters (E|e).
c - any charactertrue if c is allowed, else falseCopyright © 2014 Sven Strittmatter. All Rights Reserved.