Re: How to not expand in strings

Eric Blake <[email protected]>
Newsgroups gmane.comp.gnu.m4.general
Organization Red Hat
Message-ID <[email protected]>
On 09/30/2010 10:00 PM, Mike Gran wrote:
> Hi-
>
> I have a newbie question.  I'm using m4 to preprocess files in
> the Scheme language.  I've changed the quotes to
> U+007B LEFT CURLY BRACKET and U+007D RIGHT CURLY BRACKET which
> works great with Scheme.  But now I need to avoid processing
> a curly bracket that appears inside a string, as in the
> following
>
> (set! str
>        m4_ifdef({USE_REGEX},
>                 {" } "},
>                 {">  "}))

The ONLY way to represent an m4 close-quote sequence within an m4 string 
is to temporarily change quotes to some other string for the duration of 
quoting the problem character.

> I guess I could just temporarily change the quote characters
> again, but, is there some more compact way to not expand just that
> one string that contains the curly bracket?

Sorry, there isn't.  There have been some proposals for adding some 
additional syntax abilities in m4 2.0 to make it possible, but no code 
has materialized for it yet.

You may also want to consider how both autoconf and bison do things - 
they have a post-processing step and a specific character sequence that 
maps to a few specific characters that are otherwise difficult to 
represent directly in m4; in autoconf, they are quadrigraphs (quoting 
characters [ and ], so @:>@ maps to ] and @<:@ maps to ]); in bison, 
they are digraphs (quoting characters [ and ], so @{ maps to [ and @} 
maps to ]).  Again, making a post-processing step a built-in part of m4 
would be nice, but no one has contributed code.

-- 
Eric Blake   [email protected]    +1-801-349-2682
Libvirt virtualization library http://libvirt.org
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.