X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/0d8bed5636c07f932fdcb6ef04df749ab1c162d7..fe22d5d20ff5a88a3a0dba28a11623b235a422ab:/data/m4sugar/m4sugar.m4?ds=sidebyside diff --git a/data/m4sugar/m4sugar.m4 b/data/m4sugar/m4sugar.m4 index bc965229..e2eced27 100644 --- a/data/m4sugar/m4sugar.m4 +++ b/data/m4sugar/m4sugar.m4 @@ -422,8 +422,8 @@ m4_define([m4_bmatch], [m4_if([$#], 0, [], [$#], 1, [], [$#], 2, [$2], - m4_bregexp([$1], [$2]), -1, [$0([$1], m4_shiftn(3, $@))], - [$3])]) + [m4_if(m4_bregexp([$1], [$2]), -1, [$0([$1], m4_shiftn(3, $@))], + [$3])])]) # m4_map(MACRO, LIST) @@ -432,11 +432,26 @@ m4_define([m4_bmatch], # of LIST (which can be lists themselves, for multiple arguments MACROs). m4_define([m4_fst], [$1]) m4_define([m4_map], -[m4_if([$2], [[]], [], +[m4_if([$2], [], [], + [$2], [[]], [], [$1(m4_fst($2))[]dnl m4_map([$1], m4_cdr($2))])]) +# m4_map_sep(MACRO, SEPARATOR, LIST) +# ---------------------------------- +# Invoke MACRO($1), SEPARATOR, MACRO($2), ..., MACRO($N) where $1, $2... $N +# are the elements of LIST (which can be lists themselves, for multiple +# arguments MACROs). +m4_define([m4_map_sep], +[m4_if([$3], [[]], [], + [$1(m4_fst($3))[]dnl +m4_if(m4_cdr($3), + [[]], [], + [$2])[]dnl +m4_map_sep([$1], [$2], m4_cdr($3))])]) + + ## ---------------------------------------- ## ## 6. Enhanced version of some primitives. ## ## ---------------------------------------- ## @@ -469,7 +484,7 @@ m4_define([m4_bpatsubsts], # ------------------ # This macro invokes all its arguments (in sequence, of course). It is # useful for making your macros more structured and readable by dropping -# unecessary dnl's and have the macros indented properly. +# unnecessary dnl's and have the macros indented properly. m4_define([m4_do], [m4_if($#, 0, [], $#, 1, [$1], @@ -615,7 +630,7 @@ m4_if($1, [$2], [], # Implementing `foreach' loops in m4 is much more tricky than it may # seem. Actually, the example of a `foreach' loop in the m4 # documentation is wrong: it does not quote the arguments properly, -# which leads to undesired expansions. +# which leads to undesirable expansions. # # The example in the documentation is: # @@ -1484,7 +1499,7 @@ m4_define([m4_flatten], # 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 pattens: they are in charge of removing the +# 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*