public final class Macros
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
private java.util.Map<java.lang.String,RegExp> |
macros
Maps names of macros to their definition
|
private java.util.Map<java.lang.String,java.lang.Boolean> |
used
Maps names of macros to their "used" flag
|
| Constructor and Description |
|---|
Macros()
Creates a new macro expander.
|
| Modifier and Type | Method and Description |
|---|---|
void |
expand()
Expands all stored macros, so that getDefinition always returns
a defintion that doesn't contain any macro usages.
|
private RegExp |
expandMacro(java.lang.String name,
RegExp definition)
Expands the specified macro by replacing each macro usage
with the stored definition.
|
RegExp |
getDefinition(java.lang.String name)
Fetches the definition of the macro with the specified name,
|
boolean |
insert(java.lang.String name,
RegExp definition)
Stores a new macro and its definition.
|
boolean |
isUsed(java.lang.String name)
Tests if a macro has been used.
|
boolean |
markUsed(java.lang.String name)
Marks a makro as used.
|
java.util.List<java.lang.String> |
unused()
Returns all unused macros.
|
private java.util.Map<java.lang.String,RegExp> macros
private java.util.Map<java.lang.String,java.lang.Boolean> used
public boolean insert(java.lang.String name,
RegExp definition)
name - the name of the new macrodefinition - the definition of the new macrotrue, iff the macro name has not been
stored before.public boolean markUsed(java.lang.String name)
true, iff the macro name has been
stored before.public boolean isUsed(java.lang.String name)
true, iff the macro has been used in
a regular expression.public java.util.List<java.lang.String> unused()
public RegExp getDefinition(java.lang.String name)
The definition will either be the same as stored (expand() not called), or an equivalent one, that doesn't contain any macro usages (expand() called before).
name - the name of the macronull if
no macro with the specified name has been stored.expand()public void expand()
throws MacroException
MacroException - if there is a cycle in the macro usage graph.private RegExp expandMacro(java.lang.String name, RegExp definition) throws MacroException
name - the name of the macro to expand (for detecting cycles)definition - the definition of the macro to expandMacroException - when an error (such as a cyclic definition)
occurs during expansion