Skip to content

Commit

Permalink
Re #449: C/C++/Java printer: escape newlines etc. in Char
Browse files Browse the repository at this point in the history
  • Loading branch information
andreasabel committed Jul 26, 2023
1 parent 571c907 commit 8309208
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
7 changes: 4 additions & 3 deletions source/src/BNFC/Backend/C/CFtoCPrinter.hs
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,10 @@ mkCFile cf groups = concat
"}",
"void ppChar(Char c, int i)",
"{",
" char tmp[4];",
" sprintf(tmp, \"'%c'\", c);",
" renderS(tmp);",
" bufAppendC('\\'');",
" bufEscapeC(c);",
" bufAppendC('\\'');",
" bufAppendC(' ');",
"}",
"void ppString(String s, int i)",
"{",
Expand Down
7 changes: 4 additions & 3 deletions source/src/BNFC/Backend/CPP/PrettyPrinter.hs
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,10 @@ mkCFile useStl inPackage cf groups = concat
"",
"void PrintAbsyn::visitChar(Char c)",
"{",
" char tmp[4];",
" sprintf(tmp, \"'%c'\", c);",
" render(tmp);",
" bufAppend('\\'');",
" bufEscape(c);",
" bufAppend('\\'');",
" bufAppend(' ');",
"}",
"",
"void PrintAbsyn::visitString(String s)",
Expand Down
4 changes: 2 additions & 2 deletions source/src/BNFC/Backend/Java/CFtoJavaPrinter15.hs
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ cf2JavaPrinter packageBase packageAbsyn cf =
" private static void pp(Integer n, int _i_) { buf_.append(n); buf_.append(\" \"); }",
" private static void pp(Double d, int _i_) { buf_.append(String.format(java.util.Locale.ROOT, \"%.15g \", d)); }",
" private static void pp(String s, int _i_) { buf_.append(s); buf_.append(\" \"); }",
" private static void pp(Character c, int _i_) { buf_.append(\"'\" + c.toString() + \"'\"); buf_.append(\" \"); }",
" private static void pp(Character c, int _i_) { buf_.append(\"'\" + escape(c.toString()) + \"'\"); buf_.append(\" \"); }",
" private static void sh(Integer n) { render(n.toString()); }",
" private static void sh(Double d) { render(String.format(java.util.Locale.ROOT, \"%.15g\", d)); }",
" private static void sh(Character c) { render(\"'\" + c.toString() + \"'\"); }",
" private static void sh(Character c) { render(\"'\" + escape(c.toString()) + \"'\"); }",
" private static void sh(String s) { printQuoted(s); }",
"",
" private static void printQuoted(String s) { render(\"\\\"\" + escape(s) + \"\\\"\"); }",
Expand Down

0 comments on commit 8309208

Please sign in to comment.