fix: do not emit nested comments

With input such as

    %token<fl> yVL_CLOCK "/*verilator sc_clock*/"

we generate

    yVL_CLOCK = 610,      /* "/*verilator sc_clock*/"  */

which is invalid since the comment will actually be closed on the
first "*/".  Let's turn "*/" into "*\/" to avoid this.  But GCC will
also warn about "/*" inside a comment, so let's "escape" it too.

Reported by Huang Rui.
https://github.com/akimd/bison/issues/38

* data/skeletons/c-like.m4 (_b4_comment): Escape comment delimiters in
comments.
* tests/input.at (Torturing the Scanner): Check thes cases.
* tests/m4.at: New.
This commit is contained in:
Akim Demaille
2020-05-15 08:13:44 +02:00
parent 6a28e6d412
commit 465babb635
6 changed files with 65 additions and 1 deletions

View File

@@ -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