Package edu.odu.cs.cowem.macroproc
Class MacroProcessor
- java.lang.Object
-
- edu.odu.cs.cowem.macroproc.MacroProcessor
-
public class MacroProcessor extends java.lang.ObjectTransforms a text file via application of macros. Supported commands are #ifdef macroName or #if macroName or %ifnot macroname #else #endif #include (filename) The above are all analogous to the familiar C/C++ pre-processor #define (macroName) (argslist) (macrobody) defines a macro with the given name, a possibly empty, comma-separated arguments list, and a body. In this command (and in the #include, above), the ( ) may be any matching pair of: (), [], {}, or <>. The macro body may span multiple lines and the line feeds are considered part of the body. Examples of macro definitions: #define (authorName) () (Steven Zeil) #define (slide) (title) { \begin{slide}{title} } #define (picture)(file,sizepct) {<img src="file" style="max-width: sizepct%"/>}
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classMacroProcessor.ParseResultA description of an attempted command parse.
-
Constructor Summary
Constructors Constructor Description MacroProcessor()Defines a new macro processor with no currently defined macros, using # as the command prefix.MacroProcessor(java.lang.String commandPrefix0)Defines a new macro processor with no currently defined macros.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddefineMacro(Macro macro)Add a new macro to the processor state.static voidmain(java.lang.String[] args)Driver for macro processor.java.lang.Stringprocess(java.io.BufferedReader input)Process a block of text obtained from a reader.java.lang.Stringprocess(java.io.File inputFile)Process a block of text obtained from a file.java.lang.Stringprocess(java.lang.String inputString)Process a block of text.
-
-
-
Constructor Detail
-
MacroProcessor
public MacroProcessor()
Defines a new macro processor with no currently defined macros, using # as the command prefix.
-
MacroProcessor
public MacroProcessor(java.lang.String commandPrefix0)
Defines a new macro processor with no currently defined macros.- Parameters:
commandPrefix0- character to use as the command prefix
-
-
Method Detail
-
defineMacro
public final void defineMacro(Macro macro)
Add a new macro to the processor state.- Parameters:
macro- macro
-
process
public final java.lang.String process(java.io.BufferedReader input) throws java.io.IOExceptionProcess a block of text obtained from a reader. Processing can both alter the text (macro substitution) and affect the state of the processor by defining new macros.- Parameters:
input- source of text to be processed- Returns:
- processed text
- Throws:
java.io.IOException- on failure of reader
-
process
public final java.lang.String process(java.lang.String inputString)
Process a block of text. Processing can both alter the text (macro substitution) and affect the state of the processor by defining new macros.- Parameters:
inputString- text to process- Returns:
- processed text
-
process
public final java.lang.String process(java.io.File inputFile)
Process a block of text obtained from a file. Processing can both alter the text (macro substitution) and affect the state of the processor by defining new macros.- Parameters:
inputFile- text to process- Returns:
- processed text
-
main
public static void main(java.lang.String[] args) throws java.io.IOExceptionDriver for macro processor. Accepts args: -c? changes the macro prefix string (default is '#') -Dmacro defines a macro name -iFile processes File, ignoring output but keeping any macro definitions -oFile directs output to the indicated file fileName input file name- Parameters:
args- Command line parameters as described above- Throws:
java.io.IOException- on input failure
-
-