any macro-like construct/technique/trick?

François Pinard pinard at iro.umontreal.ca
Sat Jun 4 08:24:08 EDT 2005


[Paddy]

> If you still must have something like the c preprocessor
> then unix has m4 (and it seems there is a windows version
> http://gnuwin32.sourceforge.net/packages/m4.htm).

The difficulty of `m4' for Python source is that macro expansions should
be accompanied with proper adjustment of indentation, for adapting to
the context where macros are getting expanded.

René Seindal's `m4' is surprisingly powerful, so maybe that with enough
trickery (I really mean: a _lot_ of trickery), adjustment of indentation
could be possible.  And maybe that a simpler `m4' approach to Python
macro-expansion could be made available through the later pluggin
features which René added to `m4'.  (Yet I do not know if the pluggin
features have been integrated in the `m4' distribution mainstream.)

It would be much easier using `m4' for Python, if there was a way
to invoke it after Python lexer and before further parsing, because
<indent> and <dedent> tokens would already been identified.  If this was
possible, `m4' would be a breeze to use as a pre-processor for Python.

Still in this dreaming mode, there would also be one necessary detail
missing for full comfort: that is, the recognition of `#line' like
directives as generated by `m4' so Python tracebacks, for example, would
correctly refer to the Python source lines before macro-expansion.

-- 
François Pinard   http://pinard.progiciels-bpi.ca



More information about the Python-list mailing list