mmp.engine
Class Engine

java.lang.Object
  extended by mmp.engine.Engine
All Implemented Interfaces:
EngineContext

public class Engine
extends java.lang.Object
implements EngineContext

The MNI macro processor engine.

Author:
Burkhardt Renz

Constructor Summary
Engine(java.io.Reader reader, java.io.Writer writer)
          Constructs the MMP engine with default compatibility level.
Engine(java.io.Reader reader, java.io.Writer writer, Settings.CompatibilityLevel compLevel)
          Constructs the MMP engine.
 
Method Summary
 void define(java.lang.String macroName, java.lang.String expansion)
          Defined macro 'macroName' to expand to 'expansion'.
 Input getInput()
          Get input of macro processor.
 MacroRegistry getMacroRegistry()
          Get macro registry of macro processor.
 Output getOutput()
          Get output of macro processor.
 int getRecursionLevel()
          Get current recursion level of expansion of macro.
 Settings getSettings()
          Get settings of macro processor.
 void register(java.lang.String macroName, Macro macro)
          Registers the macro object 'macro' under the name 'macroName'.
 int run()
          Runs the MMP engine.
 void setTraceHandler(java.util.logging.Handler traceHandler)
          mmp uses the Java logging mechanism for tracing.
 void setTraceOn(java.lang.String macroName)
          Turn tracing of macro 'macroName' on.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Engine

public Engine(java.io.Reader reader,
              java.io.Writer writer)
Constructs the MMP engine with default compatibility level.

Parameters:
reader - where to read the input.
writer - where to write the output.

Engine

public Engine(java.io.Reader reader,
              java.io.Writer writer,
              Settings.CompatibilityLevel compLevel)
Constructs the MMP engine.

Parameters:
reader - where to read the input.
writer - where to write the output.
compLevel - compatibility level for the engine, the levels are Settings.CompatibilityLevel.
Method Detail

define

public final void define(java.lang.String macroName,
                         java.lang.String expansion)
Defined macro 'macroName' to expand to 'expansion'.

Parameters:
macroName - name of macro
expansion - expansion of macro

getInput

public final Input getInput()
Description copied from interface: EngineContext
Get input of macro processor.

Specified by:
getInput in interface EngineContext
Returns:
Input
See Also:
Input

getMacroRegistry

public final MacroRegistry getMacroRegistry()
Description copied from interface: EngineContext
Get macro registry of macro processor.

Specified by:
getMacroRegistry in interface EngineContext
Returns:
MacroRegistry
See Also:
MacroRegistry

getOutput

public final Output getOutput()
Description copied from interface: EngineContext
Get output of macro processor.

Specified by:
getOutput in interface EngineContext
Returns:
Output
See Also:
Output

getRecursionLevel

public final int getRecursionLevel()
Description copied from interface: EngineContext
Get current recursion level of expansion of macro.

Specified by:
getRecursionLevel in interface EngineContext
Returns:
recursion level

getSettings

public final Settings getSettings()
Description copied from interface: EngineContext
Get settings of macro processor.

Specified by:
getSettings in interface EngineContext
Returns:
Settings
See Also:
Settings

register

public final void register(java.lang.String macroName,
                           Macro macro)
Registers the macro object 'macro' under the name 'macroName'.

Parameters:
macroName - the macro name
macro - the macro object
See Also:
Macro
Pre:
macroName != null && macro != null

run

public final int run()
              throws java.io.IOException,
                     SyntaxErrorException,
                     RuntimeErrorException
Runs the MMP engine.

Returns:
0
If the engine is stopped by 'm4exit', it returns the error code given as parameter to 'm4exit'.
Throws:
java.io.IOException - if io error
SyntaxErrorException - if syntax error
RuntimeErrorException - if runtime error

setTraceHandler

public final void setTraceHandler(java.util.logging.Handler traceHandler)
mmp uses the Java logging mechanism for tracing. This method sets the trace handler for the Java logging to 'traceHandler'.

Parameters:
traceHandler - the trace handler

setTraceOn

public final void setTraceOn(java.lang.String macroName)
Turn tracing of macro 'macroName' on.
It switches to tracing of all the macros that share the logger of 'macroName', i.e. of all the macros that are implemented by the same Java class. E.g. used with a user defined macro, tracing of all user defined macros is on, because they all are implemented by the same class.
The tracing is automatically set off after run of the engine.

Parameters:
macroName - the name of the macro