Class TokenSymbol

java.lang.Object
quickparse.grammar.symbol.Symbol
quickparse.grammar.symbol.TokenSymbol

public class TokenSymbol
extends Symbol
Defines the symbol used in grammars to represent a token.
A token is matched against a given pattern, that is expressed as a standard Java Regular Expression.
  • Method Details

    • get

      public static TokenSymbol get​(java.lang.String name, java.lang.String pattern)
      Gets a new TokenSymbol instance for the given name and pattern.
      This method uses the Flyweight design pattern by GoF to cache already created instances.
      Parameters:
      name - the name of the token
      pattern - the Java Regular Expression to match the token against.
      Returns:
      a TokenSymbol instance
    • getName

      public java.lang.String getName()
      Description copied from class: Symbol
      The name of the symbol
      Specified by:
      getName in class Symbol
      Returns:
      the name of this symbol as a String
    • getPattern

      public java.util.regex.Pattern getPattern()
      Gets the pattern that matches this TokenSymbol
      Returns:
      a compiled Pattern
    • accept

      public <R,​ C> R accept​(C context, Symbol.Function<R,​C> symbolFunction)
      Description copied from class: Symbol
      Solves the subclass of this symbol (ConstructSymbol or TokenSymbol and computes the given Symbol.Function
      Specified by:
      accept in class Symbol
      Type Parameters:
      R - the return type of the function
      C - the context type for the function
      Parameters:
      context - the context used for computation
      symbolFunction - the function that must be computed on this symbol
      Returns:
      the return value returned by computing the Symbol.Function
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class java.lang.Object
    • equals

      public boolean equals​(java.lang.Object obj)
      Overrides:
      equals in class java.lang.Object
    • toString

      public java.lang.String toString()
      Overrides:
      toString in class java.lang.Object