Package ec.util

# Class Lexer

java.lang.Object
ec.util.Lexer

public class Lexer extends 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

  Fields
  Modifier and Type
  Field
  Description
  `static final int`
  `FAILURE`
  An index which indicates that no further tokens were found.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `Lexer(CharSequence input, String[] regexps)`
  Builds a Lexer for the given input with the provided regular expressions.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `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.
  `String`
  `getMatchingRule()`
  Returns the regular expression which matched the most recent token.
  `String`
  `nextToken()`
  Returns the next token as a string.
  `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 Details

  - ### 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 Details

  - ### Lexer

    public Lexer(CharSequence input, 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 Details

  - ### nextToken

    public 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 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 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.