ec.util
Class Lexer
- java.lang.Object
-
- ec.util.Lexer
-
public class Lexer extends java.lang.ObjectA 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
Fields Modifier and Type Field and Description static intFAILUREAn index which indicates that no further tokens were found.
-
Constructor Summary
Constructors Constructor and Description Lexer(java.lang.CharSequence input, java.lang.String[] regexps)Builds a Lexer for the given input with the provided regular expressions.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description intgetMatchingIndex()Returns the index of the regular expression which matched the most recent token.intgetMatchingPosition()Returns the position in the String just beyond the most recent token.java.lang.StringgetMatchingRule()Returns the regular expression which matched the most recent token.java.lang.StringnextToken()Returns the next token as a string.java.lang.StringnextToken(boolean trim)Returns the next token as a string.
-
-
-
Field Detail
-
FAILURE
public static final int FAILURE
An 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:
- Constant Field Values
-
-
Constructor Detail
-
Lexer
public Lexer(java.lang.CharSequence input, java.lang.String[] regexps)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 Detail
-
nextToken
public java.lang.String nextToken(boolean trim)
Returns the next token as a string. If *trim* is true, then the string is first trimmed of whitespace.
-
nextToken
public java.lang.String 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
public java.lang.String 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.
-
-
DMelt 3.0 © DataMelt by jWork.ORG