In Bison 3.6.2, the comments with brackets lose their brackets, for improper m4 quotation.
* data/skeletons/bison.m4 (b4_gsub): New. * data/skeletons/c-like.m4 (_b4_comment): Use it. * tests/m4.at: Check b4_gsub. --- data/skeletons/bison.m4 | 21 +++++++++++++++++++++ data/skeletons/c-like.m4 | 8 +++++--- tests/m4.at | 30 ++++++++++++++++++++++++++++-- 3 files changed, 54 insertions(+), 5 deletions(-) diff --git a/data/skeletons/bison.m4 b/data/skeletons/bison.m4 index 10bdfcb2..637d2fcb 100644 --- a/data/skeletons/bison.m4 +++ b/data/skeletons/bison.m4 @@ -19,6 +19,27 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. + +# m4_gsub(STRING, RE1, SUBST1, RE2, SUBST2, ...) +# ---------------------------------------------- +# m4 equivalent of +# +# $_ = STRING; +# s/RE1/SUBST1/g; +# s/RE2/SUBST2/g; +# ... +# +# Really similar to m4_bpatsubsts, but behaves properly with quotes. +# See m4.at's "Generating Comments". Super inelegant, but so far, I +# did not find any better solution. +m4_define([b4_gsub], +[m4_bpatsubst(m4_bpatsubst(m4_bpatsubst([[[[$1]]]], + [$2], [$3]), + [$4], [$5]), + [$6], [$7])]) + + + ## ---------------- ## ## Identification. ## ## ---------------- ## diff --git a/data/skeletons/c-like.m4 b/data/skeletons/c-like.m4 index fb0dc53b..1e5ab02c 100644 --- a/data/skeletons/c-like.m4 +++ b/data/skeletons/c-like.m4 @@ -17,6 +17,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. + # _b4_comment(TEXT, OPEN, CONTINUE, END) # -------------------------------------- # Put TEXT in comment. Avoid trailing spaces: don't indent empty lines. @@ -27,9 +28,10 @@ # # Prefix all the output lines with PREFIX. m4_define([_b4_comment], -[$2[]m4_bpatsubsts(m4_expand([$1]), - [[*]/], [*\\/], - [/[*]], [/\\*], [ +[$2[]b4_gsub(m4_expand([$1]), + [[*]/], [*\\/], + [/[*]], [/\\*], + [ \(.\)], [ $3\1])$4]) diff --git a/tests/m4.at b/tests/m4.at index 440e975a..6a2ff83f 100644 --- a/tests/m4.at +++ b/tests/m4.at @@ -29,18 +29,44 @@ AT_DATA([input.m4], [[m4@&t@_include(b4_skeletonsdir/[c.m4]) b4_output_begin([output.txt]) + +b4_gsub([[abcd]], + [a], [b]) +b4_gsub([[abcd]], + [a], [b], + [b], [c], + [c], [d]) + +_b4_comment([["/* () */"]]) +_b4_comment([["/* ( */"]]) +_b4_comment([["/* ) */"]]) +_b4_comment([["/* [] */"]]) + b4_comment([["/* () */"]]) b4_comment([["/* ( */"]]) b4_comment([["/* ) */"]]) +b4_comment([["/* [] */"]]) + b4_output_end([output.txt]) ]]) AT_BISON_CHECK([-S ./input.m4 input.y]) AT_CHECK([cat output.txt], [], -[/* "/\* () *\/" */ +[[ +[bbcd] +[dddd] + +"/\* () *\/" +"/\* ( *\/" +"/\* ) *\/" +"/\* [] *\/" + +/* "/\* () *\/" */ /* "/\* ( *\/" */ /* "/\* ) *\/" */ -]) +/* "/\* [] *\/" */ + +]]) AT_CLEANUP -- 2.26.2
