diff --git a/NEWS b/NEWS index 43d09e8d..23a935fa 100644 --- a/NEWS +++ b/NEWS @@ -6,6 +6,12 @@ GNU Bison NEWS Some tests were fixed. + When token aliases contain comment delimiters: + + %token FOO "/* foo */" + + bison used to emit "nested" comments, which is invalid C. + * Noteworthy changes in release 3.6.1 (2020-05-10) [stable] ** Bug fixes diff --git a/data/skeletons/c-like.m4 b/data/skeletons/c-like.m4 index e0460d48..fb0dc53b 100644 --- a/data/skeletons/c-like.m4 +++ b/data/skeletons/c-like.m4 @@ -22,10 +22,14 @@ # Put TEXT in comment. Avoid trailing spaces: don't indent empty lines. # Avoid adding indentation to the first line, as the indentation comes # from OPEN. That's why we don't patsubst([$1], [^\(.\)], [ \1]). +# Turn "*/" in TEXT into "* /" so that we don't unexpectedly close +# the comments before its end. # # Prefix all the output lines with PREFIX. m4_define([_b4_comment], -[$2[]m4_bpatsubst(m4_expand([[$1]]), [ +[$2[]m4_bpatsubsts(m4_expand([$1]), + [[*]/], [*\\/], + [/[*]], [/\\*], [ \(.\)], [ $3\1])$4]) diff --git a/tests/input.at b/tests/input.at index 77fa3e59..cc72ddc8 100644 --- a/tests/input.at +++ b/tests/input.at @@ -1424,6 +1424,11 @@ char quote[] = "@:>@@:>@,"; /* Exercise quotes in strings. */ %token FAKE "fake @<:@@:>@ \a\b\f\n\r\t\v\"\'\?\\\u005B\U0000005c ??!??'??(??)??-??/?? \x1\1" +/* Beware of the generated comments that embed string aliases that + might close the comment. */ +%token COMMENT_CLOSE "*/" +%token COMMENT "/* comment */" + %% /* Exercise M4 quoting: '@:>@@:>@', @<:@, 1. */ exp: '@<:@' '\1' two '$' '@' '{' oline output.or.oline.opt diff --git a/tests/local.mk b/tests/local.mk index fac8426f..a62fe267 100644 --- a/tests/local.mk +++ b/tests/local.mk @@ -56,6 +56,7 @@ TESTSUITE_AT = \ %D%/java.at \ %D%/javapush.at \ %D%/local.at \ + %D%/m4.at \ %D%/named-refs.at \ %D%/output.at \ %D%/package.m4 \ diff --git a/tests/m4.at b/tests/m4.at new file mode 100644 index 00000000..440e975a --- /dev/null +++ b/tests/m4.at @@ -0,0 +1,46 @@ +# Basic m4 macros. -*- Autotest -*- + +# Copyright (C) 2020 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +AT_BANNER([[M4 Macros.]]) + + +AT_SETUP([Generating Comments]) + +AT_DATA([input.y], +[%% +exp: +]) + +AT_DATA([input.m4], +[[m4@&t@_include(b4_skeletonsdir/[c.m4]) + +b4_output_begin([output.txt]) +b4_comment([["/* () */"]]) +b4_comment([["/* ( */"]]) +b4_comment([["/* ) */"]]) +b4_output_end([output.txt]) +]]) + +AT_BISON_CHECK([-S ./input.m4 input.y]) + +AT_CHECK([cat output.txt], [], +[/* "/\* () *\/" */ +/* "/\* ( *\/" */ +/* "/\* ) *\/" */ +]) + +AT_CLEANUP diff --git a/tests/testsuite.at b/tests/testsuite.at index e2b72b84..44393db5 100644 --- a/tests/testsuite.at +++ b/tests/testsuite.at @@ -16,6 +16,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +# Basic M4 macros. +m4_include([m4.at]) # Resistance to user bugs. m4_include([input.at])