|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
public interface Interpreter
This interface should be implemented by all macro processors.
All interpreters from this package are expected to read text
from a Input source and write the results of the text
processing to a Output.
To see a example of how this works in a final "macro processor",
take a look at the AtMacros and At
classes.
At| Method Summary | |
|---|---|
void |
interpret(Input in,
Output out)
The fundamental method which ALL interpreters must implement. |
| Method Detail |
|---|
void interpret(Input in,
Output out)
throws IOException,
InterpretException
interpreters must implement.
This is the fundamental method which ALL implementations of a
Interpreter object must implement. This method is
designed to read information from a generic input
source, interpret any macros or special values from the input
and write the resulting output to the output
destination.
You can refer to the AtMacros class as a fully working
interpreter which does this. However, a quick example of how one
might use a interpreter to evaluate a simple string has been
included below. It assumes a macro "@name()" has been defined
which will insert the user's name during interpretation. If a
error results during interpretation, a simple string of "Hello:"
is returned.
String getGreeting(Interpreter i) {
try {
OutputStringBuffer osb = new OutputStringBuffer(200);
i.interpret(new Input("Hello @name():"),osb);
return osb.toString();
}
catch (IOException ioEx) {
}
catch (InterpretException inEx) {
}
return "Hello:";
}
in - The input source to read the text information
from. See the Input class to pass a String or
set of characters. See the InputReader class to pass a
file.out - The output destination to write the results of
the interpretation to. See the OutputStringBuffer
class to get your results as a string, and the OutputWriter class to get your results to a file.
IOException - If a I/O error is encountered when reading from a input
source, or writing to a output destination.
InterpretException - If the contents of the source being interpretted violates the
rules of the interpreter. Note, each interpretter is able to
define its own set of rules as to what is allowed or not.AtMacros
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||