Package gavo :: Package base :: Module macros :: Class MacroExpander
[frames] | no frames]

Class MacroExpander

source code

object --+
         |
        MacroExpander
Known Subclasses:

is a generic "macro" expander for scripts of all kinds.

It is loosely inspired by TeX, but of course much simpler. See the syntax below.

The macros themselves come from a MacroPackage object. There are a few of these around, implementing different functionality depending on the script context (i.e., whether it belongs to an RD, a DD, or a Table.

All macros are just functions receiving and returning strings. The arguments are written as {arg1}{arg2}, where you can escape curly braces with a backslash. There must be no whitespace between a macro and its first argument.

If you need to glue together a macro expansion and text following, use the glue sequence \+

The main entry point to the class is the expand function below, taking a string possibly containing macro calls and returning a string.

The construction of such a macro expander is relatively expensive, so it pays to cache them. MacroPackage below has a getExpander method that does the caching for you.

Instance Methods
 
__init__(self, package)
x.__init__(...) initializes x; see help(type(x)) for signature
source code
 
expand(self, aString) source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Properties

Inherited from object: __class__

Method Details

__init__(self, package)
(Constructor)

source code 

x.__init__(...) initializes x; see help(type(x)) for signature

Overrides: object.__init__
(inherited documentation)