Skip to content

Commit

Permalink
Merge pull request lcompilers#1500 from gptsarthak/main
Browse files Browse the repository at this point in the history
Fixed Printing of Escape Sequences
  • Loading branch information
certik committed Feb 5, 2023
2 parents acd593e + 5d08012 commit 5ba2a2a
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/libasr/codegen/asr_to_c_cpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -836,9 +836,9 @@ R"(#include <stdio.h>
if (s[idx] == '\n') {
src += "\\n";
} else if (s[idx] == '\\') {
src += "\\\\";
src += "\\";
} else if (s[idx] == '\"') {
src += "\\\"";
src += "\"";
} else {
src += s[idx];
}
Expand Down
4 changes: 2 additions & 2 deletions src/libasr/codegen/asr_to_julia.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1422,9 +1422,9 @@ class ASRToJuliaVisitor : public ASR::BaseVisitor<ASRToJuliaVisitor>
if (s[idx] == '\n') {
src += "\\n";
} else if (s[idx] == '\\') {
src += "\\\\";
src += "\\";
} else if (s[idx] == '\"') {
src += "\\\"";
src += "\"";
} else {
src += s[idx];
}
Expand Down
3 changes: 3 additions & 0 deletions src/lpython/parser/semantics.h
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,9 @@ char* unescape(Allocator &al, LCompilers::Str &s) {
if (s.p[idx] == '\\' && s.p[idx+1] == 'n') {
x += "\n";
idx++;
} else if (s.p[idx] == '\\' && s.p[idx+1] == '\'') {
x += "'";
idx++;
} else {
x += s.p[idx];
}
Expand Down
2 changes: 1 addition & 1 deletion tests/reference/ast_new-string2-44323ea.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"outfile": null,
"outfile_hash": null,
"stdout": "ast_new-string2-44323ea.stdout",
"stdout_hash": "c53164138eddb106cd7e13ab552e7b9f5978e3a7649708ece0ceb1db",
"stdout_hash": "b6bd901a34260e3a2109285fb3f422406e6e5147e9932713dcd9f138",
"stderr": null,
"stderr_hash": null,
"returncode": 0
Expand Down
2 changes: 1 addition & 1 deletion tests/reference/ast_new-string2-44323ea.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ class a:
" ())] [])) (Expr (ConstantStr "
"\\"
" ())) (Expr (ConstantStr "
'\\'
'\'
" ()))] [])

0 comments on commit 5ba2a2a

Please sign in to comment.