Macro preprocessor.

Kaz Kylheku kaz at
Wed Aug 11 09:20:12 CEST 1999

Hi folks. I wrote a macro preprocessor that can be used with a language that
uses indendation for statement or declaration grouping, because it is
intelligent about dealing with leading whitespace.

I haven't done work on it in a long while and I need some motivation to to add
features to it to make it more useful. (It needs conditionals, numeric
variables and operations, iteration constructs). It would help, like, to
have some users. :)

I know jack about Python, but I was partially thinking of you guys when I added
whitespace intelligence to the list of requirements.  (That and the desire to
have a preprocessor tool that doesn't leave obvious artifacts usually caused by
preprocessing, such as broken formatting, and gives you great control over

In this macro preprocessor you can do something like this:

    #def snippet1 {

    #def snippet2 {

    def func(x)

and the output will be:

    def func(x)

as you would intuitively expect, rather than coming out in some horrible mess
as would happen with a traditional C preprocessor utility, or something like
m4, either of which would make dog's breakfast out of, say, a Python program. 

There are other features im MPP. One noteworthy feature is that it supports C++
style nested namespaces:

    #namespace html {
	#def url(link, text) {<a href="http://#link">#text</a>}

    #using html.url
    #url(, slashdot)

    #comment { or full scope resolution }
    #html.url(, freshmeat)

    #comment { create alternate name for something }
    #alias web_stuff html
    #web_stuff.url(, kernel)

    #comment { and other cheap symbol-table tricks. :) }

With namespaces you can create macro libraries that don't clash.  Speaking of
which, there is a fully blown #include directive, with "..." and <...> header
searching logic that can be influenced with command-line options.  There is a
#once directive to suppress multiple inclusions of same header.  Great
diagnostics that pinpoint the line number and file where an error was caused,
accompanied by a dump of the whole #include chain that led up to the error, if
it was in a header. Oh, and did I mention that you can dynamically modify the
lexical character mapping, similar to the way codes can be redefined in TeX? If
you don't want the # character to introduce directives, you can change it to
something else on the fly. (If you change it within a header, the change won't
automatically be propagated to the host file that included it.)

    #code leftbrace [
    #code rightbrace ]
    #code escape %

    %def foo [ bar ]	

Okay, enough. :) I'll probably get hate mail now about being off topic.

More information about the Python-list mailing list