com.ccg.macros
Interface Interpreter

All Known Implementing Classes:
AtMacros

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.

Since:
1.0
Version:
$Revision: 1.1.1.1 $
Author:
$Author: pkb $
See Also:
At

Method Summary
 void interpret(Input in, Output out)
          The fundamental method which ALL interpreters must implement.
 

Method Detail

interpret

void interpret(Input in,
               Output out)
               throws IOException,
                      InterpretException
The fundamental method which ALL 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:";
 }
 

Parameters:
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.
Throws:
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.
Since:
1.0
See Also:
AtMacros


Copyright 1998-1998-2006 null. All Rights Reserved.