autoconf-patches
[Top][All Lists]
Advanced

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

Re: 15autotest-more-info-prettier.diff


From: Akim Demaille
Subject: Re: 15autotest-more-info-prettier.diff
Date: Mon, 18 Aug 2003 17:08:14 +0200
User-agent: Gnus/5.1002 (Gnus v5.10.2) Emacs/21.3 (gnu/linux)

 > This is the same problem you are having with patsubst and regex
 > right? I'm not sure that I understand the criterion for determining
 > whether a builtin is underquoting.

There are too different M4 worlds that could have existed: the strict
M4, and the lazy M4.  Today, we live in the strict m4 world, which,
IMNSHO, is broken.  Strict M4 does not quote the result of some of its
macros, so for instance, there is no means to write

        m4_format([%s_%s], [m4], [exit])

without triggering m4_exit.  To work around this mis-feature, we
developed a style where text-processing builtins are given an
overquoted argument so that the over quotation be transfered to the
result, being properly quoted.  In the present case, it means:

        m4_format([[%s_%s]],...)

When there are several text processing macros, you have to stack the
(over-) quotes:


# m4_flatten(STRING)
# ------------------
# If STRING contains end of lines, replace them with spaces.  If there
# are backslashed end of lines, remove them.  This macro is safe with
# active symbols.
#    m4_define(active, ACTIVE)
#    m4_flatten([active
#    act\
#    ive])end
#    => active activeend
m4_define([m4_flatten],
[m4_translit(m4_bpatsubst([[[$1]]], [\\
]), [
], [ ])])


The best example used to m4_strip, as the (obsolete) comment
demonstrates.  But m4sugar's m4_bpatsubsts hides a part of this
awfulness:

# m4_strip(STRING)
# ----------------
# Expands into STRING with tabs and spaces singled out into a single
# space, and removing leading and trailing spaces.
#
# This macro is robust to active symbols.
#    m4_define(active, ACTIVE)
#    m4_strip([  active                 active ])end
#    => active activeend
#
# This macro is fun!  Because we want to preserve active symbols, STRING
# must be quoted for each evaluation, which explains there are 4 levels
# of brackets around $1 (don't forget that the result must be quoted
# too, hence one more quoting than applications).
#
# Then notice the 2 last patterns: they are in charge of removing the
# leading/trailing spaces.  Why not just `[^ ]'?  Because they are
# applied to doubly quoted strings, i.e. more or less [[STRING]].  So
# if there is a leading space in STRING, then it is the *third*
# character, since there are two leading `['; equally for the last pattern.
m4_define([m4_strip],
[m4_bpatsubsts([[$1]],
               [[        ]+], [ ],
               [^\(..\) ],    [\1],
               [ \(..\)$],    [\1])])


This macro also fully demonstrates Paul's purpose about active
characters being really nasty sometimes.



The other world, lazy M4, the one we live in when we are not using
text-builtins, would have quoting m4_format, m4_patsubst, m4_regexp
etc. And to provide for the (very theoretical, since I never really
felt a need for it) loss of expression power, an m4_eval (which would
not perform some calculation, yet another unfortunate decision in
M4...).




reply via email to

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