|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--kmy.regex.compiler.RMachine
This class represents "regex matching machine" that can be loaded with "RMachine instructions" and used later for regex matching. Subclasses of this class are used together with RCompiler (which compiles regex parsing tree into RMachine instructions). This class is used in the following fashion:
RMachine can have a number of variables, and several character buffers (which a "pre-set" at runtime by a method external to RMachine (see Regex class documentation)). One of this buffers (main buffer) holds the string which this regex is being matched against. It also has an implicit character position that points into main buffer, as well as implicit instruction pointer that points to the RMachine instruction about to be executed. There is also a backtracing mechanism. When fork instruction is executed by the machine, it stores the value of the current character position and instruction pointer (that corresponds to the label given to the fork instruction) into special internal backtracing stack as a fork record. Also, for most modifications of RMachine variables (except for the hardAssign instruction), the original value (before assignment) is stored into backtracing stack. When fail instruction is executed, backtracing is performed. Information in backtracing stack is used to reverse assignments, reset character position and jump to the label given to the last fork instruction. Backtracing stack is cleared up to (and including) the last fork record. If not fork record is found in the stack, regex matching fails.
Field Summary | |
static int |
EXT_CONDJUMP
|
static int |
EXT_HINT
|
static int |
EXT_MULTIFORK
|
static int |
EXT_SHIFTTBL
|
private int |
extensions
|
static int |
FLAG_DOT_IS_ANY
|
static int |
HINT_CHAR_STAR_HEAD
|
static int |
HINT_END_ANCHORED
|
static int |
HINT_START_ANCHORED
|
Constructor Summary | |
RMachine()
|
Method Summary | |
abstract void |
assert(char[] constStr)
|
abstract void |
assert(int charClass,
char[] ranges)
Make sure that current character belongs to the given character class. |
abstract void |
assert(java.lang.String varName,
boolean picked)
|
abstract void |
boundary(int boundaryClass)
Check if current position is on the certain type of boundary given by. |
void |
condJump(char[] ranges,
RLabel label)
Jump if char is NOT in range |
void |
condJump(char c,
RLabel label)
Jump if char is NOT one that is given. |
void |
condJump(int atLeastCharLeft,
int atMostCharLeft,
RLabel label)
Jump if less then atLeast or more then atMost chars left. |
abstract void |
decfail(RVariable var)
|
abstract void |
decjump(RVariable var,
RLabel label)
|
abstract void |
fail()
|
void |
finish()
|
abstract void |
forget(RVariable var)
|
abstract void |
fork(RLabel forkLabel)
Add a fork record to backtracing stack. |
int |
getExtensions()
|
int |
getNVars()
|
abstract void |
hardAssign(RVariable v,
int value)
|
void |
hint(int flags,
int minLength,
int maxLength)
|
void |
init()
|
abstract void |
jump(RLabel label)
|
Regex |
makeRegex()
|
abstract void |
mark(RLabel label)
Makes the given label to refer to the next RMachine instruction. |
void |
mfEnd(int maxCount)
maxCount got minCount subtracted from it! |
void |
mfStart(int headDecrement,
int minCount)
|
abstract RLabel |
newLabel()
Creates a new RMachine label. |
abstract RVariable |
newTmpVar(int init)
Creates a new RMachine temporary variable. |
abstract RVariable |
newVar(java.lang.String name,
boolean begin)
Creates a new RMachine named variable. |
abstract void |
pick(RVariable v)
Store current character position (in the main buffer) into a given variable. |
void |
setExtensions(int ext)
|
void |
setNoRefiller(boolean norefiller)
|
void |
shiftTable(boolean beginning,
int charsAhead,
char[] chars,
int[] shifts)
|
abstract void |
skip()
Increment current position by 1 (skip a character). |
void |
tellName(java.lang.String name)
Provides string representation of this regular expression. |
void |
tellPosition(int pos)
Informs RMachine about current character position in the regex. |
Methods inherited from class java.lang.Object |
|
Field Detail |
private int extensions
public static final int HINT_START_ANCHORED
public static final int HINT_END_ANCHORED
public static final int HINT_CHAR_STAR_HEAD
public static final int FLAG_DOT_IS_ANY
public static final int EXT_HINT
public static final int EXT_MULTIFORK
public static final int EXT_CONDJUMP
public static final int EXT_SHIFTTBL
Constructor Detail |
public RMachine()
Method Detail |
public Regex makeRegex()
public int getNVars()
public void init()
public void finish()
public void setNoRefiller(boolean norefiller)
public void tellName(java.lang.String name)
public void tellPosition(int pos)
public abstract RVariable newVar(java.lang.String name, boolean begin)
public abstract RLabel newLabel()
public abstract RVariable newTmpVar(int init)
init
- initial value for the variablepublic abstract void mark(RLabel label)
public abstract void pick(RVariable v)
public abstract void fork(RLabel forkLabel)
public abstract void skip()
public abstract void boundary(int boundaryClass)
public abstract void assert(int charClass, char[] ranges)
public abstract void assert(char[] constStr)
public abstract void assert(java.lang.String varName, boolean picked)
public abstract void hardAssign(RVariable v, int value)
public abstract void decjump(RVariable var, RLabel label)
public abstract void decfail(RVariable var)
public abstract void forget(RVariable var)
public abstract void jump(RLabel label)
public abstract void fail()
public int getExtensions()
public void setExtensions(int ext)
public void hint(int flags, int minLength, int maxLength)
public void mfStart(int headDecrement, int minCount)
public void mfEnd(int maxCount)
public void condJump(char[] ranges, RLabel label)
public void condJump(int atLeastCharLeft, int atMostCharLeft, RLabel label)
public void condJump(char c, RLabel label)
public void shiftTable(boolean beginning, int charsAhead, char[] chars, int[] shifts)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |