Package jflex.core
Class Macros
- java.lang.Object
-
- jflex.core.Macros
-
public final class Macros extends java.lang.Object
Symbol table and expander for macros.Maps macros to their (expanded) definitions, detects cycles and unused macros.
- Version:
- JFlex 1.8.2
-
-
Constructor Summary
Constructors Constructor Description Macros()
Creates a new macro expander.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
expand()
Expands all stored macros, so that getDefinition always returns a definition 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 macro as used.java.util.List<java.lang.String>
unused()
Returns all unused macros.
-
-
-
Field Detail
-
macros
private final java.util.Map<java.lang.String,RegExp> macros
Maps names of macros to their definition
-
used
private final java.util.Map<java.lang.String,java.lang.Boolean> used
Maps names of macros to their "used" flag
-
-
Method Detail
-
insert
public boolean insert(java.lang.String name, RegExp definition)
Stores a new macro and its definition.- Parameters:
name
- the name of the new macrodefinition
- the definition of the new macro- Returns:
true
, iff the macro name has not been stored before.
-
markUsed
public boolean markUsed(java.lang.String name)
Marks a macro as used.- Parameters:
name
- aString
object.- Returns:
true
, iff the macro name has been stored before.
-
isUsed
public boolean isUsed(java.lang.String name)
Tests if a macro has been used.- Parameters:
name
- aString
object.- Returns:
true
, iff the macro has been used in a regular expression.
-
unused
public java.util.List<java.lang.String> unused()
Returns all unused macros.- Returns:
- the macro names that have not been used.
-
getDefinition
public RegExp getDefinition(java.lang.String name)
Fetches the definition of the macro with the specified 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).
- Parameters:
name
- the name of the macro- Returns:
- the definition of the macro,
null
if no macro with the specified name has been stored. - See Also:
expand()
-
expand
public void expand() throws MacroException
Expands all stored macros, so that getDefinition always returns a definition that doesn't contain any macro usages.- Throws:
MacroException
- if there is a cycle in the macro usage graph.
-
expandMacro
private RegExp expandMacro(java.lang.String name, RegExp definition) throws MacroException
Expands the specified macro by replacing each macro usage with the stored definition.- Parameters:
name
- the name of the macro to expand (for detecting cycles)definition
- the definition of the macro to expand- Returns:
- the expanded definition of the macro.
- Throws:
MacroException
- when an error (such as a cyclic definition) occurs during expansion
-
-