bison icon indicating copy to clipboard operation
bison copied to clipboard

Cannot use C++ multiline raw strings in grammar file

Open zmajeed opened this issue 9 months ago • 0 comments

A C++ raw string literal that spans more than one line gives an error

The grammar file

1  // rawstring.y
2  %%
3  start: %empty
4  %%
5  #include <iostream>
6  using namespace std;

7  int main() {
8    cout << R"%(raw string on one line)%" << "\n";
9    cout << R"%(multiline raw string
10  )%";
11  }

Run bison

bison -Wall -Wdangling-alias -Werror rawstring.y

rawstring.y:10.12-11.0: error: missing ‘"’ at end of line
   10 |   cout << R"%(multiline raw string
      |            ^~~~~~~~~~~~~~~~~~~~~~~
rawstring.y:11.3-12.0: error: missing ‘"’ at end of line
   11 | )%";

No problems with the raw string on line 8 - but the second one on lines 9-10 doesn't work

Separate issue but the column number is wrong in the location "10.12" printed in the error message

bison --version

bison (GNU Bison) 3.8.2

zmajeed avatar May 08 '24 10:05 zmajeed