ec.util
Class Lexer

java.lang.Object
  extended by ec.util.Lexer

public class Lexer
extends java.lang.Object

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
static int FAILURE
          An index which indicates that no further tokens were found.
 
Constructor Summary
Lexer(java.lang.CharSequence input, java.lang.String[] regexps)
          Builds a Lexer for the given input with the provided regular expressions.
 
Method Summary
 int getMatchingIndex()
          Returns the index of the regular expression which matched the most recent token.
 int getMatchingPosition()
          Returns the position in the String just beyond the most recent token.
 java.lang.String getMatchingRule()
          Returns the regular expression which matched the most recent token.
 java.lang.String nextToken()
          Returns the next token as a string.
 java.lang.String nextToken(boolean trim)
          Returns the next token as a string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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.