[exim-dev] [Bug 214] Macros with arguments, a la C

Top Page
Delete this message
Reply to this message
Author: bug214
Date:  
To: exim-dev
Subject: [exim-dev] [Bug 214] Macros with arguments, a la C
------- You are receiving this mail because: -------
You are the QA contact for the bug, or are watching the QA contact.

http://www.exim.org/bugzilla/show_bug.cgi?id=214





------- Comment #1 from anomie@??? 2007-02-15 22:54 -------
Created an attachment (id=71)
--> (http://www.exim.org/bugzilla/attachment.cgi?id=71&action=view)
A patch to implement function-like macros

This patch is a try at implementing function-like macros. Parsing the
definition is a bit of extra work, but performing the replacement is as cheap
as I could make it. A config using only "normal" macros should have minimal
parsing impact, just a few extra ifs and an extra 'int' in the struct
macro_item.

The syntax is fairly straightforward:

MACRO{ARG1,ARG2} = This is my macro. My args were "ARG1" and "ARG2".

Argument names can be anything matching [[:alpha:]_][[:alnum:]_]*, and no
argument name can be a substring of another. There is no provision for variable
numbers of arguments. Spaces are allowed around the braces and commas.

To use the macro:

Look! MACRO{The first arg}{The second arg} Isn't it nice?

expands to

Look! This is my macro. My args were "The first arg" and "The second arg".
Isn't it nice?

The entire macro including all args must be on one physical line, since the
comment removal and line continuation happens after macro expansion. Spaces are
allowed between the macro name and between each arg, but spaces within each arg
are significant.

The code properly counts nested braces, so something like
FOO{${uc:BAR{BAZ{${extract{key}{value}}}}}} will expand correctly. Braces can
also be backslashed if for some reason they don't balance in the argument body,
however the backslashes are passed into the output (e.g. FOO{a brace: \}} => "a
brace \}").

However, there has been no effort to change the order of macro expansion based
on nesting. So you can do stupid things and have the order of macro definition
matter. For example, this will work:
XX = a}{b
OR{A,B} = A or B?
OR{XX}
while defining XX after OR will give you an error instead.

--
Configure bugmail: http://www.exim.org/bugzilla/userprefs.cgi?tab=email