JFlex

Class Macros

public final class Macros extends Object

Symbol table and expander for macros. Maps macros to their (expanded) definitions, detects cycles and unused macros.
Constructor Summary
Macros()
Creates a new macro expander.
Method Summary
voidexpand()
Expands all stored macros, so that getDefinition always returns a defintion that doesn't contain any macro usages.
RegExpgetDefinition(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).

booleaninsert(String name, RegExp definition)
Stores a new macro and its definition.
booleanisUsed(String name)
Tests if a macro has been used.
booleanmarkUsed(String name)
Marks a makro as used.
Enumerationunused()
Returns all unused macros.

Constructor Detail

Macros

public Macros()
Creates a new macro expander.

Method Detail

expand

public void expand()
Expands all stored macros, so that getDefinition always returns a defintion that doesn't contain any macro usages.

Throws: MacroException if there is a cycle in the macro usage graph.

getDefinition

public RegExp getDefinition(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: Macros

insert

public boolean insert(String name, RegExp definition)
Stores a new macro and its definition.

Parameters: name the name of the new macro definition the definition of the new macro

Returns: true, iff the macro name has not been stored before.

isUsed

public boolean isUsed(String name)
Tests if a macro has been used.

Returns: true, iff the macro has been used in a regular expression.

markUsed

public boolean markUsed(String name)
Marks a makro as used.

Returns: true, iff the macro name has been stored before.

unused

public Enumeration unused()
Returns all unused macros.

Returns: the enumeration of macro-names that have not been used.