From: Akim Demaille Date: Mon, 4 Mar 2002 15:05:13 +0000 (+0000) Subject: * doc/autoconf.texi (Evaluation Macros): New. X-Git-Tag: AUTOCONF-2.52i~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a002bdb48757ebdcf1d37a2b24ccc36e0aae82c1;p=thirdparty%2Fautoconf.git * doc/autoconf.texi (Evaluation Macros): New. * lib/m4sugar/m4sugar.m4 (m4_lquote): Remove, it is totally useless. (_m4_foreach): Define the variant with immediate evaluation so that it contains exactly the items, not an expression which evaluation is the current item. (m4_re_string, m4_re_word): Don't over quote them. --- diff --git a/ChangeLog b/ChangeLog index e15467f17..868fe6584 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2002-03-04 Akim Demaille + + * doc/autoconf.texi (Evaluation Macros): New. + * lib/m4sugar/m4sugar.m4 (m4_lquote): Remove, it is totally + useless. + (_m4_foreach): Define the variant with immediate evaluation so + that it contains exactly the items, not an expression which + evaluation is the current item. + (m4_re_string, m4_re_word): Don't over quote them. + 2002-03-04 Akim Demaille Instead of having stacking `shift's evaluated at the end, let diff --git a/doc/autoconf.texi b/doc/autoconf.texi index b6d62de7d..d4c72dc2f 100644 --- a/doc/autoconf.texi +++ b/doc/autoconf.texi @@ -327,6 +327,7 @@ M4 Quotation Programming in M4sugar * Redefined M4 Macros:: M4 builtins changed in M4sugar +* Evaluation Macros:: More quotation and evaluation control * Forbidden Patterns:: Catching unexpanded macros Writing Autoconf Macros @@ -6877,6 +6878,7 @@ M4sugar''. @menu * Redefined M4 Macros:: M4 builtins changed in M4sugar +* Evaluation Macros:: More quotation and evaluation control * Forbidden Patterns:: Catching unexpanded macros @end menu @@ -6964,6 +6966,44 @@ m4_wrap([foo]) @end example @end defmac +@node Evaluation Macros +@subsection Evaluation Macros + +The following macros give some control over the order of the evaluation +by adding or removing levels of quotes. They are meant for hard core M4 +programmers. + +@defmac m4_dquote (@var{arg1}, ...) +@msindex dquote +Return the arguments as a quoted list of quoted arguments. +@end defmac + +@defmac m4_quote (@var{arg1}, ...) +@msindex quote +Return the arguments as a single entity, i.e., wrap them into a pair of +quotes. +@end defmac + +The following example aims at emphasing the difference between (i), not +using these macros, (ii), using @code{m4_quote}, and (iii), using +@code{m4_dquote}. + +@example +$ @kbd{cat example.m4} +# Over quote, so that quotes are visible. +m4_define([show], [$[]1 = [$1], $[]@@ = [$@@]]) +m4_divert(0)dnl +show(a, b) +show(m4_quote(a, b)) +show(m4_dquote(a, b)) +$ @kbd{autom4te -l m4sugar example.m4} +$1 = a, $@@ = [a],[b] +$1 = a,b, $@@ = [a,b] +$1 = [a],[b], $@@ = [[a],[b]] +@end example + + + @node Forbidden Patterns @subsection Forbidden Patterns diff --git a/lib/m4sugar/m4sugar.m4 b/lib/m4sugar/m4sugar.m4 index 8dac844ae..08317ccc7 100644 --- a/lib/m4sugar/m4sugar.m4 +++ b/lib/m4sugar/m4sugar.m4 @@ -523,17 +523,14 @@ m4_builtin([popdef], $@)]) # m4_quote(ARGS) # -------------- -# Return ARGS quoted. Note that a list of quoted arguments is returned, -# not a quoted list. +# Return ARGS as a single arguments. # # It is important to realize the difference between `m4_quote(exp)' and # `[exp]': in the first case you obtain the quoted *result* of the # expansion of EXP, while in the latter you just obtain the string # `exp'. m4_define([m4_quote], [[$*]]) -m4_define([m4_lquote], [$@]) -m4_define([m4_dquote], [[$@]]) - +m4_define([m4_dquote], [[$@]]) # m4_noquote(STRING) # ------------------ @@ -701,9 +698,9 @@ m4_define([m4_car], [[$1]]) m4_define([m4_cdr], [m4_dquote(m4_shift($@))]) m4_define([_m4_foreach], [m4_if([$2], [[]], [], - [m4_define([$1], [m4_car($2)])$3[]_m4_foreach([$1], - m4_cdr($2), - [$3])])]) + [m4_define([$1], m4_car($2))$3[]_m4_foreach([$1], + m4_cdr($2), + [$3])])]) @@ -1377,7 +1374,7 @@ m4_define([m4_re_escape], # ------------ # Regexp for `[a-zA-Z_0-9]*' m4_define([m4_re_string], -m4_quote(m4_defn([m4_cr_symbols2]))dnl +m4_defn([m4_cr_symbols2])dnl [*]dnl ) @@ -1386,7 +1383,7 @@ m4_quote(m4_defn([m4_cr_symbols2]))dnl # ---------- # Regexp for `[a-zA-Z_][a-zA-Z_0-9]*' m4_define([m4_re_word], -m4_quote(m4_defn([m4_cr_symbols1]))dnl +m4_defn([m4_cr_symbols1])dnl m4_defn([m4_re_string])dnl )