Package com.singularsys.jep.configurableparser.matchers

# Class RegExpTokenMatcher

java.lang.Object
com.singularsys.jep.configurableparser.matchers.RegExpTokenMatcher

All Implemented Interfaces:
  `TokenBuilder`, `TokenMatcher`, `Serializable`

Direct Known Subclasses:
  `BugsTest.NumberWithUnitTokenMatcher`, `CommentTokenMatcher`, `IdentifierTokenMatcher`, `NumberTokenMatcher`, `StringTokenMatcher`, `TerminatorTokenMatcher`, `WhiteSpaceTokenMatcher`

public abstract class RegExpTokenMatcher extends Object implements TokenBuilder
An abstract TokenMatcher which uses RegExp patterns to match patterns. Subclasses should overload the buildToken method which builds a token after a successful match.

Author:
  Richard Morris
See Also:
  - `Pattern`
  - Serialized Form

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `RegExpTokenMatcher(String regex)`
  A token matcher which matches a regular expression of pattern.
  `RegExpTokenMatcher(Pattern pattern)`
  A token matcher which matches a specified of pattern.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `abstract Token`
  `buildToken(String s)`
  Builds a token following a successful match.
  `Token`
  `match(String s)`
  Attempts to match the start of the string.
  `String`
  `toString()`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

  ### Methods inherited from interface com.singularsys.jep.configurableparser.matchers.TokenMatcher

  `init`

- ## Constructor Details

  - ### RegExpTokenMatcher

    public RegExpTokenMatcher(Pattern pattern)
    A token matcher which matches a specified of pattern.
    Parameters:
      `pattern` - Pattern to match

  - ### RegExpTokenMatcher

    public RegExpTokenMatcher(String regex)
    A token matcher which matches a regular expression of pattern.
    Parameters:
      `regex` - the expression to match

- ## Method Details

  - ### match

    public Token match(String s) throws ParseException
    Attempts to match the start of the string.
    Specified by:
      `match` in interface `TokenMatcher`
    Parameters:
      `s` - the string to match against
    Returns:
      if successful returns the corresponding token, return null if failed to match
    Throws:
      `ParseException` - on syntax error

  - ### buildToken

    public abstract Token buildToken(String s) throws ParseException
    Builds a token following a successful match. Note new objects should be created each time as error reporting information is later attached to tokens.
    Specified by:
      `buildToken` in interface `TokenBuilder`
    Parameters:
      `s` - String representing the completed matched token
    Returns:
      the appropriate type of token.
    Throws:
      `ParseException`

  - ### toString

    public String toString()
    Overrides:
      `toString` in class `Object`