m4-discuss
[Top][All Lists]
Advanced

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

Fwd: Filter user macro invocation


From: mroberge
Subject: Fwd: Filter user macro invocation
Date: Fri, 02 May 2008 12:43:47 -0400




-----Original Message-----
From: address@hidden
To: address@hidden
Sent: Fri, 2 May 2008 12:40 pm
Subject: Re: Filter user macro invocation

Sorry I made a mistake... my syntax for mydefine below is just plain wrong.... Since it doesn't contain an actual call to the built-in "define" and as such it wasn't really making full substitutions. So I really need to figure out how to make the orig suggestion from Eric work... As I said in item#2 it works but fails to suppress substitution of free text without parens.

Eric's orig idea.... not working 100%....
  pushdef(`define', `builtin(`define', `$1', 
  ~ `ifelse(`$#', `0', ``$1'', `$2')')') 
Does the ifelse need to be double quoted?

THIS IS WRONG.....

As an extension to you idea I tried the following.....
define(`mydefine',`ifelse(`$#',`0',``$1'',`$2')')

Than when I "define" my user macros I use "mydefine" instead of "define" and it works as expected. In my solution you have to be willing to use a unique name such as mydefine instead of redefining built in "define" itself. What is also interesting is that in my solution the my userMacros are never actually getting formal "define" cmds in m4, it more of a conditional substitution on the fly.

In the end the idea of not having to place the ifelse structure into every userMacro define is great. And to that end I would love to see how to make both your and my solution work.



-----Original Message-----
From: address@hidden
To: address@hidden
Sent: Fri, 2 May 2008 11:06 am
Subject: Re: Filter user macro invocation

 
You can even go one step further: 
 
pushdef(`define', `builtin(`define', `$1', 
~ `ifelse(`$#', `0', ``$1'', `$2')')') 
 
to make define always treat new macros like this. Hmm, maybe I should 
mention that in the manual. 

Oh... that's very clever. And is exactly what I was wanting to do orig. However I can't seem to make your example work.
1) Is the tilda ~ really part of the syntax or is that a typo/email conversion problem?
2) Even when I remove the ~, text substitution seems to work but the instances without parens are also getting substituted. And thats the orig problem I was attempting to fix.
I would love to get your idea working !!

As an extension to you idea I tried the following.....
define(`mydefine',`ifelse(`$#',`0',``$1'',`$2')')

Than when I "define" my user macros I use "mydefine" instead of "define" and it works as expected. In my solution you have to be willing to use a unique name such as mydefine instead of redefining built in "define" itself. What is also interesting is that in my solution the my userMacros are never actually getting formal "define" cmds in m4, it more of a conditional substitution on the fly.

In the end the idea of not having to place the ifelse structure into every userMacro define is great. And to that end I would love to see how to make both your and my solution work.



-----Original Message-----
From: Eric Blake <address@hidden>
To: address@hidden; address@hidden
Sent: Wed, 30 Apr 2008 9:35 pm
Subject: Re: Filter user macro invocation

-----BEGIN PGP SIGNED MESSAGE----- 
Hash: SHA1 
 
[you should probably keep the list in the loop, as this is an interesting 
topic for other people to learn from] 
 
According to address@hidden on 4/30/2008 8:44 AM: 
| Thanks... 
| Using your clues I was able to find and comprehend the ifelse example. I 
| have now updated all my user-macro defines with the ifelse structure and 
| this now prevents general string text from causing a full substitution. 
 
You can even go one step further: 
 
pushdef(`define', `builtin(`define', `$1', 
~ `ifelse(`$#', `0', ``$1'', `$2')')') 
 
to make define always treat new macros like this. Hmm, maybe I should 
mention that in the manual. 
 

| Do you have time for another? 
| When the argument of a macro define spans multiple lines... is it 
| possible to to get the starting column for lines 2,3,... to line up with 
| the starting column of the 1st line. It appears that the 1st line starts 
| at the column at which the macroName was detected and that the 
| subsequent lines are added at newline col1. How do I force the later 
| lines to line up with the same starting col location as the 1st line in 
| the substituted output? I suspect this would require some sort 
| of location tracking tab/space function. 
 
According to wikipedia, m4 is Turing Complete, so yes this is possible. 
But determining how to do it, and whether it is possible to do 
efficiently, is another matter :) 
 

| resulting output is ... 
| // export real CeffAvgLH_ .... 
| export real CeffAvgPwr_ .... 

| I would like to some how get it to do... 
| // export real CeffAvgLH_ .... 
| export real CeffAvgPwr_ .... 
 
Autoconf tackles this with the m4_text_wrap macro, as part of the m4sugar 
wrapper around m4: 
http://git.sv.gnu.org/gitweb/?p=autoconf.git;a=blob;f=lib/m4sugar/m4sugar.m4 
 
Look around line 1953. This is a very involved macro, with lots of 
involved work and preliminary macro definitions earlier in the file to 
make this pull off nicely. For help in understanding it, recall that 
m4sugar uses changequote([,]), and prefixes all builtins with m4_; the 
basic idea behind this macro is that it splits the original string at all 
whitespace, then outputs one word at a time with wrapping taken care of 
along the way. 
 
To be honest, m4sugar cheats a bit - it relies on a post-processing pass 
to strip trailing blanks and convert quadrigraphs. This task becomes even 
harder if you must handle unbalanced quotes in the output without a 
post-processing pass. 
 
- -- 
Don't work too hard, make some time for fun as well! 
 
Eric Blake address@hidden 
-----BEGIN PGP SIGNATURE----- 
Version: GnuPG v1.4.9 (Cygwin) 
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg 
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org 
 
iEYEARECAAYFAkgZHlAACgkQ84KuGfSFAYCHbgCfexkoeCFCkJIycfJKJnLksyhO 
d40AoKmTfmZQY/96Lj5ikyLq1GClxeB+ 
=REwV 
-----END PGP SIGNATURE----- 

reply via email to

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