Skip to content

Fix string literals with prefix, closes #298 #299

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions regression-tests/pure2-various-string-literals.cpp2
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
main: () = {
s1 := u"u\"";
s2 := U"U\"";
s3 := u8"u8\"";
s4 := L"L\"";
s5 := R"(R")";
s6 := uR"(uR")";
s7 := u8R"(u8R")";
s8 := UR"(UR")";
s9 := LR"(LR")";
}
23 changes: 23 additions & 0 deletions regression-tests/test-results/pure2-various-string-literals.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

#define CPP2_USE_MODULES Yes

#include "cpp2util.h"

#line 1 "pure2-various-string-literals.cpp2"
auto main() -> int;

//=== Cpp2 definitions ==========================================================

#line 1 "pure2-various-string-literals.cpp2"
auto main() -> int{
auto s1 {u"u\""};
auto s2 {U"U\""};
auto s3 {u8"u8\""};
auto s4 {L"L\""};
auto s5 {R"(R")"};
auto s6 {uR"(uR")"};
auto s7 {u8R"(u8R")"};
auto s8 {UR"(UR")"};
auto s9 {LR"(LR")"};
}

11 changes: 11 additions & 0 deletions regression-tests/test-results/pure2-various-string-literals.cpp2
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
main: () = {
s1 := u"u\"";
s2 := U"U\"";
s3 := u8"u8\"";
s4 := L"L\"";
s5 := R"(R")";
s6 := uR"(uR")";
s7 := u8R"(u8R")";
s8 := UR"(UR")";
s9 := LR"(LR")";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pure2-various-string-literals.cpp2... ok (all Cpp2, passes safety checks)

4 changes: 3 additions & 1 deletion source/lex.h
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,9 @@ auto expand_string_literal(
++pos;
auto current_start = pos; // the current offset before which the string has been added to ret

auto parts = string_parts{"\"", "\"", string_parts::on_both_ends};
auto parts = string_parts{std::string(text.substr(0, current_start)), // begin sequence ", U", u8" depends on the string type
"\"", // end sequence
string_parts::on_both_ends}; // add opening and closing sequence to generated string

// Now we're on the first character of the string itself
for (
Expand Down