Package jflex.core
Class RegExp
- java.lang.Object
-
- jflex.core.RegExp
-
-
Field Summary
Fields Modifier and Type Field Description (package private) int
type
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
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static RegExp
anyChar()
Returns a regexp that matches any character:[^]
private static boolean
checkJPartStart(int type, int c)
Check whether a character is a member of the give char class type.static RegExp1
checkPrimClass(RegExp r)
Confirms that the parameter is a RegExp1 of type sym.PRIMCLASS.RegExp
expandPreClasses(java.util.Map<java.lang.Integer,IntCharSet> cache, CharClasses cl, boolean caseless)
Expand pre-defined character classes into primitive IntCharSet classes.private static IntCharSet
getPreClass(java.util.Map<java.lang.Integer,IntCharSet> preclassCache, CharClasses charClasses, int type)
Compute and memoize a pre-defined character class.boolean
isCharClass()
Find out if this regexp is a char class or equivalent to one.void
makeCCLs(CharClasses c, boolean caseless)
Make character class partitions based on the classes mentioned in this regexp.RegExp
normaliseCCLs(java.io.File f, int line)
Normalise the regular expression to eliminate compound character class expression (compute their content).RegExp
normaliseMacros(Macros m)
Normalise the regular expression to eliminate macro use (expand them).static IntCharSet
performClassOp(int op, IntCharSet l, IntCharSet r, RegExp ctxt)
Performs the given set operation on the twoIntCharSet
parameters.java.lang.String
print(java.lang.String tab)
Returns a String-representation of this regular expression with the specified indentation.RegExp
resolveTilde()
Recursively convert tilde (upto) expressions into negation and star.RegExp
rev()
Creates a new regexp that matches the reverse text of this one.(package private) static java.lang.String
revString(java.lang.String s)
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)java.lang.String
toString()
java.lang.String
typeName()
String representation of the type of this regular expression.
-
-
-
Method Detail
-
print
public java.lang.String print(java.lang.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 java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
typeName
public java.lang.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 java.lang.String revString(java.lang.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 twoIntCharSet
parameters.- Parameters:
op
- the operation to perform (as @{link sym} constant)l
- the left operator of the expressionr
- the right operator of the expressionctxt
- the regular expression containing the provided operator- Returns:
- a new
IntCharSet
- Throws:
RegExpException
- forctxt
if the operator is not supported
-
normaliseMacros
public final RegExp normaliseMacros(Macros m)
Normalise the regular expression to eliminate macro use (expand them).- Returns:
- a regexp that contains no
sym.MACROUSE
.
-
normaliseCCLs
public final RegExp normaliseCCLs(java.io.File f, int line)
Normalise the regular expression to eliminate compound character class expression (compute their content).- Parameters:
f
- the spec file containing the regular expression (for error reporting)line
- the line number of the regular expression (for error reporting)- Returns:
- a regexp where all char classes are primitive
IntCharSet
classes.
-
expandPreClasses
public RegExp expandPreClasses(java.util.Map<java.lang.Integer,IntCharSet> cache, CharClasses cl, boolean caseless)
Expand pre-defined character classes into primitive IntCharSet classes.- Parameters:
cache
- memoized pre-defined character class expansionscl
- character class partitions- Returns:
- the expanded regular expression
-
checkJPartStart
private static boolean checkJPartStart(int type, int c)
Check whether a character is a member of the give char class type.- Parameters:
type
- the type of the character class (sym.JLETTERCLASS
orsym.JLETTERDIGITCLASS
)c
- the character to check- Returns:
- true if the character is a member of the class
-
getPreClass
private static IntCharSet getPreClass(java.util.Map<java.lang.Integer,IntCharSet> preclassCache, CharClasses charClasses, int type)
Compute and memoize a pre-defined character class.- Parameters:
preclassCache
- memoized pre-defined character class expansionscharClasses
- character class partitionstype
- the type of the predefined character class- Returns:
- the expanded IntCharSet for the class
-
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
-
-