jatha
Class Macro

java.lang.Object
  |
  +--jatha.Macro
Direct Known Subclasses:
CLASS, CTOR, ENUM_BITS, ENUM_INT, ENUM_OBJ, INCLUDE, PROP, STRINGIFY

public class Macro
extends java.lang.Object

This is the base class for all macros.


Field Summary
protected static MacroUtil util
          Contains helper functions for macros.
 
Constructor Summary
Macro()
           
 
Method Summary
 void expand(java.lang.String[] args, java.io.Writer out, Expander expander)
          This is the more convenient version of expand.
 void expand(java.lang.String arg, java.io.Writer out, Expander expander)
          Most macros use the other version of expand.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

util

protected static MacroUtil util
Contains helper functions for macros.
Constructor Detail

Macro

public Macro()
Method Detail

expand

public void expand(java.lang.String arg,
                   java.io.Writer out,
                   Expander expander)
            throws java.io.IOException
Most macros use the other version of expand. When a file contains a call to a macro, the Expander passes the macro arguments to the appropriate Macro object, via this function.

This version of expand needs to do its own argument processing. For example, if your macro takes two arguments separated by a comma like @foo(a, b), this version of expand will be passed "a, b". The other version of expand would get {"a", "b"}. If your Macro is like most macros, you should override the other version and pretend this one doesn't exist.

The default implementation of this method calls MacroUtil.splitString(arg, ',', true, true, true, true) and passes the result to the other version of expand. In English, that means that it breaks the raw argument string into a bunch of separate arguments, separated by commas. Each argument has any leading or trailing whitespace removed, and commas that are inside parenthesis or double-quotes are not split into separate arguments.

Parameters:
arg - The raw, unsplit argument to the macro.

expand

public void expand(java.lang.String[] args,
                   java.io.Writer out,
                   Expander expander)
            throws java.io.IOException
This is the more convenient version of expand. The arguments have already been split and trimmed. For example, if your macro takes two arguments separated by a comma like @foo(a, b), this version of expand will get {"a", "b"} instead of "a, b". Nested parentheses and strings are preserved whole; for example, @foo(a(b,c), x"y,z") becomes {"a(b,c)", "x\"y,z\""}. Note that in that example, there are only two arguments, not four.

If you want to parse the arguments yourself, you should use the other version of expand.

The default implementation throws an error, complaining that expand() hasn't been implemented.