Skip to content

Commit 6f85448

Browse files
authored
Fix parsing of string literals that contains //, closes #442 (#444)
In the following code: ```cpp main: () = { { std::cout << "//456"; } //error :()->_ = { return "//Error"; }; b:="/* error even without {} block"; } error: (x) -> _ = { return "//"; } ``` `//` and `/*` inside string literals are parsed as begining of comments. Current change solves that. The missing is handling of raw string literals. Closes #442
1 parent 4f87037 commit 6f85448

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

source/io.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -693,13 +693,20 @@ auto process_cpp2_line(
693693
auto found_end = false;
694694

695695
auto prev = ' ';
696+
auto in_string_literal = false;
697+
696698
for (auto i = colno_t{0}; i < ssize(line); ++i) {
697699

698700
if (in_comment) {
699701
switch (line[i]) {
700702
break;case '/': if (prev == '*') { in_comment = false; }
701703
break;default: ;
702704
}
705+
} else if (in_string_literal) {
706+
switch (line[i]) {
707+
break;case '"': if (prev != '\\') { in_string_literal = false; }
708+
break;default: ;
709+
}
703710
}
704711

705712
else {
@@ -732,6 +739,9 @@ auto process_cpp2_line(
732739
break;case '/':
733740
if (prev == '/') { in_comment = false; return false; }
734741

742+
break;case '"':
743+
if (prev != '\\') { in_string_literal = true; }
744+
735745
break;default: ;
736746
}
737747
}

0 commit comments

Comments
 (0)