| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||||
| Interpreter |
|
| 1.0;1 |
| 1 | /*---------------------------------------------------------------- |
|
| 2 | * $Id: Interpreter.java,v 1.1.1.1 2004/01/26 20:46:18 pkb Exp $ |
|
| 3 | * |
|
| 4 | * (c)2000 - Paul Blankenbaker |
|
| 5 | * |
|
| 6 | * Revision Log |
|
| 7 | * |
|
| 8 | * 2000-11-14 13:08:22 Paul Blankenbaker |
|
| 9 | * |
|
| 10 | * Created initial version |
|
| 11 | */ |
|
| 12 | //---------------------------------------------------------------- |
|
| 13 | ||
| 14 | package com.ccg.macros; |
|
| 15 | ||
| 16 | import java.io.*; // needed for I/O operations |
|
| 17 | ||
| 18 | ||
| 19 | //---------------------------------------------------------------- |
|
| 20 | /** This interface should be implemented by all macro processors. |
|
| 21 | * |
|
| 22 | * <p>All interpreters from this package are expected to read text |
|
| 23 | * from a {@link Input Input} source and write the results of the text |
|
| 24 | * processing to a {@link Output Output}. |
|
| 25 | * |
|
| 26 | * <p>To see a example of how this works in a final "macro processor", |
|
| 27 | * take a look at the {@link AtMacros AtMacros} and {@link At At} |
|
| 28 | * classes. |
|
| 29 | * |
|
| 30 | * @version $Revision: 1.1.1.1 $ |
|
| 31 | * |
|
| 32 | * @since 1.0 |
|
| 33 | * |
|
| 34 | * @author $Author: pkb $ |
|
| 35 | * |
|
| 36 | * @see At */ |
|
| 37 | //---------------------------------------------------------------- |
|
| 38 | ||
| 39 | public interface Interpreter { |
|
| 40 | ||
| 41 | //---------------------------------------------------------------- |
|
| 42 | /** The fundamental method which ALL {@link Interpreter interpreters} must implement. |
|
| 43 | * |
|
| 44 | * This is the fundamental method which ALL implementations of a |
|
| 45 | * {@link Interpreter} object must implement. This method is |
|
| 46 | * designed to read information from a generic {@link Input input |
|
| 47 | * source}, interpret any macros or special values from the input |
|
| 48 | * and write the resulting output to the {@link Output output |
|
| 49 | * destination}. |
|
| 50 | * |
|
| 51 | * <p>You can refer to the {@link AtMacros} class as a fully working |
|
| 52 | * interpreter which does this. However, a quick example of how one |
|
| 53 | * might use a interpreter to evaluate a simple string has been |
|
| 54 | * included below. It assumes a macro "@name()" has been defined |
|
| 55 | * which will insert the user's name during interpretation. If a |
|
| 56 | * error results during interpretation, a simple string of "Hello:" |
|
| 57 | * is returned. |
|
| 58 | * |
|
| 59 | * <pre><code> |
|
| 60 | * {@link String String} getGreeting({@link Interpreter Interpreter} i) { |
|
| 61 | * try { |
|
| 62 | * {@link OutputStringBuffer OutputStringBuffer} osb = new OutputStringBuffer(200); |
|
| 63 | * i.interpret(new {@link Input Input}("Hello @name():"),osb); |
|
| 64 | * return osb.toString(); |
|
| 65 | * } |
|
| 66 | * catch ({@link IOException IOException} ioEx) { |
|
| 67 | * } |
|
| 68 | * catch ({@link InterpretException InterpretException} inEx) { |
|
| 69 | * } |
|
| 70 | * return "Hello:"; |
|
| 71 | * } |
|
| 72 | * </code></pre> |
|
| 73 | * |
|
| 74 | * @param in |
|
| 75 | * |
|
| 76 | * The {@link Input input} source to read the text information |
|
| 77 | * from. See the {@link Input} class to pass a {@link String} or |
|
| 78 | * set of characters. See the {@link InputReader} class to pass a |
|
| 79 | * file. |
|
| 80 | * |
|
| 81 | * @param out |
|
| 82 | * |
|
| 83 | * The {@link Output output} destination to write the results of |
|
| 84 | * the interpretation to. See the {@link OutputStringBuffer} |
|
| 85 | * class to get your results as a string, and the {@link |
|
| 86 | * OutputWriter} class to get your results to a file. |
|
| 87 | * |
|
| 88 | * @throws IOException |
|
| 89 | * |
|
| 90 | * If a I/O error is encountered when reading from a input |
|
| 91 | * source, or writing to a output destination. |
|
| 92 | * |
|
| 93 | * @throws InterpretException |
|
| 94 | * |
|
| 95 | * If the contents of the source being interpretted violates the |
|
| 96 | * rules of the interpreter. Note, each interpretter is able to |
|
| 97 | * define its own set of rules as to what is allowed or not. |
|
| 98 | * |
|
| 99 | * @since 1.0 |
|
| 100 | * |
|
| 101 | * @see AtMacros */ |
|
| 102 | //---------------------------------------------------------------- |
|
| 103 | ||
| 104 | public void interpret(Input in, Output out) |
|
| 105 | throws IOException, InterpretException; |
|
| 106 | ||
| 107 | } |
|
| 108 | ||
| 109 |