[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Macro + diversion issue

From: Eric Blake
Subject: Re: Macro + diversion issue
Date: Sat, 19 May 2007 21:21:31 -0600
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv: Gecko/20070221 Thunderbird/ Mnenhy/

Hash: SHA1

According to Daniel Richard G. on 5/19/2007 7:00 PM:
> Hello,
> I've been messing around with diversions inside macros, and have come upon 
> an odd scenario. I'd like to call it a bug, but I get the same behavior 
> from m4 1.4 as from 1.9a.

Not a bug in m4, but a lack of understanding on your part.  You may find
using the debug and tracing abilities of m4 useful here.

> So, what's going on here, and is there any way to make div10() work as 
> expected without needing to quote the argument to foo()?
> define(`div10', `divert(10)$1`'divert(0)')dnl
> define(`foo', `<FOO>$1</FOO>
> ')dnl
> dnl
> div10(`This is text in div 10.
> ')dnl
> foo(`This goes inside FOO tags.div10(`This is some more text in div 10.
> ')')dnl
> foo(This also goes inside FOO tags.div10(`This is even more text in div 10.
> '))dnl

Or more simply:

When m4 gets to the point marked by ^, it notices a macro, and expands it
to text as it continues to collect the arguments of foo, resulting in:


but there are still unexpanded macros, so it continues to expand text,
further resulting in:


that is, you both swapped to and back from diversion 10, all while
collecting the argument for foo.  Finally, with the argument now in place,
foo is invoked, as though it had been called with `text1.text2' as its
properly quoted argument.

As for how to do this, I recommend that you stick with consistent quoting,
as you already surmised.  The autoconf manual, and my recent revisions to
the m4 manual, are serious when they say that the policy of a consistent
interface of one level of quoting per level of parentheses is the easiest
way to have predictable results.

- --
Don't work too hard, make some time for fun as well!

Eric Blake             address@hidden
Version: GnuPG v1.4.5 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org


reply via email to

[Prev in Thread] Current Thread [Next in Thread]