NAME ^

src/macro.pir - does macro substitution

DESCRIPTION ^

Copyright: 2004-2005 Bernhard Schmalhofer. All Rights Reserved. SVN Info: $Id$ History: Ported from GNU m4 1.4 References: http://www.gnu.org/software/m4/m4.html

SUBROUTINES ^

void expand_input( Hash state ) ^

Loop through some input files. TODO: read files in next_token()

void expand_token( Hash state, string token_type, string token_data ) ^

Expand one token, according to its type. Potential macro names (TOKEN_WORD) are looked up in the symbol table, to see if they have a macro definition. If they have, they are expanded as macros, otherwise the text are just copied to the output.

string processed_token expand_macro( Hash state, Hash symbol ) ^

The macro expansion is handled by expand_macro(). It parses the arguments in collect_arguments() and builds a ResizablePMCArray containing the arguments. The arguments themselves are stored on a local obstack. expand_macro() uses call_macro() to do the call of the macro.

expand_macro() is potentially recursive, since it calls expand_argument(), which might call expand_token (), which might call expand_macro().

string processed_token call_macro( ResizablePMCArray macro, string token ) ^

Apply macro to a token.

TODO: distinguish between TOKEN_FUNC and TOKEN_WORD

void collect_arguments ^

Collect all the arguments to a call of a macro.


parrot