Package jflex.core

Class RegExp

java.lang.Object
jflex.core.RegExp
Direct Known Subclasses:
RegExp1, RegExp2

public class RegExp extends Object
Stores a regular expression of rules section in a JFlex-specification.

This base class has no content other than its type.

Version:
JFlex 1.8.2
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    (package private) int
    The type of the regular expression.
  • Constructor Summary

    Constructors
    Constructor
    Description
    RegExp(int type)
    Create a new regular expression of the specified type.
  • Method Summary

    Modifier and Type
    Method
    Description
    static RegExp
    Returns a regexp that matches any character: [^]
    static RegExp1
    Confirms that the parameter is a RegExp1 of type sym.PRIMCLASS.
    boolean
    Find out if this regexp is a char class or equivalent to one.
    final void
    makeCCLs(CharClasses c, boolean caseless)
    Make character class partitions based on the classes mentioned in this regexp.
    final RegExp
    Normalise the regular expression to eliminate macro use (expand them), and compound character class expression (compute their content).
    static IntCharSet
    performClassOp(int op, IntCharSet l, IntCharSet r, RegExp ctxt)
    Performs the given set operation on the two IntCharSet parameters.
    Returns a String-representation of this regular expression with the specified indentation.
    final RegExp
    Recursively convert tilde (upto) expressions into negation and star.
    final RegExp
    rev()
    Creates a new regexp that matches the reverse text of this one.
    (package private) static String
    Reverses a string.
    int
    size(Macros macros)
    The approximate number of NFA states this expression will need (only works correctly after macro expansion and without negation)
     
    String representation of the type of this regular expression.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • type

      int type
      The type of the regular expression. This field will be filled with values from class sym.java (generated by cup)
  • Constructor Details

    • RegExp

      public RegExp(int type)
      Create a new regular expression of the specified type.
      Parameters:
      type - a value from the cup generated class sym.
  • Method Details

    • print

      public String print(String tab)
      Returns a String-representation of this regular expression with the specified indentation.
      Parameters:
      tab - a String that should contain only space characters and that is inserted in front of standard String-representation pf this object.
      Returns:
      a String object.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • typeName

      public String typeName()
      String representation of the type of this regular expression.
    • isCharClass

      public boolean isCharClass()
      Find out if this regexp is a char class or equivalent to one.
      Returns:
      true if the regexp is equivalent to a char class.
    • size

      public int size(Macros macros)
      The approximate number of NFA states this expression will need (only works correctly after macro expansion and without negation)
      Parameters:
      macros - macro table for expansion
      Returns:
      a int.
    • revString

      static String revString(String s)
      Reverses a string.
    • resolveTilde

      public final RegExp resolveTilde()
      Recursively convert tilde (upto) expressions into negation and star.
      Returns:
      new RegExp equivalent to the current one, but without upto expressions.
    • anyChar

      public static RegExp anyChar()
      Returns a regexp that matches any character: [^]
      Returns:
      the regexp for [^]
    • checkPrimClass

      public static RegExp1 checkPrimClass(RegExp r)
      Confirms that the parameter is a RegExp1 of type sym.PRIMCLASS.
      Parameters:
      r - the RegExp to check
      Returns:
      r cast to RegExp1
      Throws:
      CharClassException - if r is not a RegExp1 or of type sym.PRIMCLASS.
    • performClassOp

      public static IntCharSet performClassOp(int op, IntCharSet l, IntCharSet r, RegExp ctxt)
      Performs the given set operation on the two IntCharSet parameters.
      Parameters:
      op - the operation to perform (as @{link sym} constant)
      l - the left operator of the expression
      r - the right operator of the expression
      ctxt - the regular expression containing the provided operator
      Returns:
      a new IntCharSet
      Throws:
      RegExpException - for ctxt if the operator is not supported
    • normalise

      public final RegExp normalise(Macros m)
      Normalise the regular expression to eliminate macro use (expand them), and compound character class expression (compute their content).
      Returns:
      a regexp that contains only IntCharSet char classes and no sym.MACROUSE.
    • makeCCLs

      public final void makeCCLs(CharClasses c, boolean caseless)
      Make character class partitions based on the classes mentioned in this regexp.

      Assumption: regexp is normalised.

    • rev

      public final RegExp rev()
      Creates a new regexp that matches the reverse text of this one.
      Returns:
      the reverse regexp