Package snap.parse
Class Tokenizer
java.lang.Object
snap.parse.Tokenizer
- Direct Known Subclasses:
CodeTokenizer
,XMLParser.XMLTokenizer
A class to extract tokens from a char sequence.
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addPattern
(String aName, String aPattern) Adds a pattern.void
addPatternsForRule
(ParseRule aRule) Adds patterns to this tokenizer for given rule.final char
charAt
(int anIndex) CharSequence method.protected ParseToken
createToken
(String aName, String aPattern, int aStart, int anEnd, ParseToken aSpecialToken) Creates a new token.final char
eatChar()
Returns the char at the current index plus offset.final char
getChar()
Returns the current parse char.final char
getChar
(int anOffset) Returns the char at the current index plus offset.final int
Returns the current parse char location.final String
getChars
(int aValue) Returns the next given number of chars as a string.final int
Returns the current column index in the current line.getInput()
Returns the current tokenizer input.getInput
(int aStart, int anEnd) Returns the input subsequence for the given range of characters in input.final int
Returns the current line index.final int
Returns the current line start index.Processes and returns a special token if found.Returns the next token.protected Regex[]
Returns the array of regexes (creating it if missing).Regex[]
getRegexesForStartChar
(char aChar) Returns list of Regex for a starting char.final boolean
hasChar()
Returns whether another char is available.final boolean
hasChars
(int aVal) Returns whether another given number of chars is available.final int
length()
CharSequence method.void
setCharIndex
(int aValue) Sets the current parse char location.void
setInput
(CharSequence anInput) Sets the current tokenizer input.final void
setLineIndex
(int aValue) Returns the current line index.protected void
Gobble input characters until next non-whitespace or input end.protected ParseToken
tokenizerFailed
(String nextChars) Called when next chars don't conform to any known token pattern.
-
Field Details
-
_charIndex
protected int _charIndex -
_lineIndex
protected int _lineIndex -
_lineStart
protected int _lineStart -
SINGLE_LINE_COMMENT
- See Also:
-
MULTI_LINE_COMMENT
- See Also:
-
-
Constructor Details
-
Tokenizer
public Tokenizer()Constructor.
-
-
Method Details
-
getInput
Returns the current tokenizer input. -
setInput
Sets the current tokenizer input. -
getInput
Returns the input subsequence for the given range of characters in input. -
length
public final int length()CharSequence method. -
charAt
public final char charAt(int anIndex) CharSequence method. -
hasChar
public final boolean hasChar()Returns whether another char is available. -
hasChars
public final boolean hasChars(int aVal) Returns whether another given number of chars is available. -
getChar
public final char getChar()Returns the current parse char. -
getChar
public final char getChar(int anOffset) Returns the char at the current index plus offset. -
eatChar
public final char eatChar()Returns the char at the current index plus offset. -
getChars
Returns the next given number of chars as a string. -
getCharIndex
public final int getCharIndex()Returns the current parse char location. -
setCharIndex
public void setCharIndex(int aValue) Sets the current parse char location. -
addPattern
Adds a pattern. -
addPatternsForRule
Adds patterns to this tokenizer for given rule. -
getRegexes
Returns the array of regexes (creating it if missing). -
getLineIndex
public final int getLineIndex()Returns the current line index. -
setLineIndex
public final void setLineIndex(int aValue) Returns the current line index. -
getLineStart
public final int getLineStart()Returns the current line start index. -
getColumnIndex
public final int getColumnIndex()Returns the current column index in the current line. -
getNextToken
Returns the next token. -
getRegexesForStartChar
Returns list of Regex for a starting char. -
createToken
protected ParseToken createToken(String aName, String aPattern, int aStart, int anEnd, ParseToken aSpecialToken) Creates a new token. -
getNextSpecialToken
Processes and returns a special token if found. This version just skips whitespace. -
skipWhiteSpace
protected void skipWhiteSpace()Gobble input characters until next non-whitespace or input end. -
tokenizerFailed
Called when next chars don't conform to any known token pattern. Default implementation just throws ParseExcpetion.
-