Package ec.util
Class Lexer
java.lang.Object
ec.util.Lexer
A simple line-by-line String tokenizer. You provide Lexer with a String or other
CharSequence as input, plus an array of regular expressions. Each time you call
nextToken(...), the Lexer matches the next token against the regular expressions
and returns it. The regular expressions are checked in order, and the first one
that matches is the winner.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
An index which indicates that no further tokens were found. -
Constructor Summary
ConstructorDescriptionLexer
(CharSequence input, String[] regexps) Builds a Lexer for the given input with the provided regular expressions. -
Method Summary
Modifier and TypeMethodDescriptionint
Returns the index of the regular expression which matched the most recent token.int
Returns the position in the String just beyond the most recent token.Returns the regular expression which matched the most recent token.Returns the next token as a string.nextToken
(boolean trim) Returns the next token as a string.
-
Field Details
-
FAILURE
public static final int FAILUREAn index which indicates that no further tokens were found. This could be due to the end of the string or due to a bad string. You'll need to check the index to determine for sure.- See Also:
-
-
Constructor Details
-
Lexer
Builds a Lexer for the given input with the provided regular expressions. The regular expressions will be checked in order against the input, and the first one which matches will be assumed to be the token.
-
-
Method Details
-
nextToken
Returns the next token as a string. If *trim* is true, then the string is first trimmed of whitespace. -
nextToken
Returns the next token as a string. The string is first trimmed of whitespace. -
getMatchingIndex
public int getMatchingIndex()Returns the index of the regular expression which matched the most recent token. -
getMatchingRule
Returns the regular expression which matched the most recent token. -
getMatchingPosition
public int getMatchingPosition()Returns the position in the String just beyond the most recent token.
-