Skip to content

Commit 0455de1

Browse files
committed
Move $R" prefix out from is_encoding_prefix_and()
As there is only one place where there is a check for `$R"` I have moved this check outside from is_encoding_prefix_and() function. This prefix is now check directly after maching `$` in lex_line(). Update comment section of is_encoding_prefix_and() to include all prefixes that are supported by the function.
1 parent 11c88d3 commit 0455de1

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

source/lex.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -898,7 +898,7 @@ auto lex_line(
898898
auto peek3 = peek(3);
899899

900900
//G encoding-prefix: one of
901-
//G 'u8' 'u'
901+
//G 'u8' 'u' 'uR' 'u8R' 'U' 'UR' 'L' 'LR' 'R'
902902
//G
903903
auto is_encoding_prefix_and = [&](char next) {
904904
if (line[i] == next) { return 1; } // "
@@ -917,7 +917,6 @@ auto lex_line(
917917
else if (peek1 == 'R' && peek2 == next) { return 3; } // LR"
918918
}
919919
else if (line[i] == 'R' && peek1 == next) { return 2; } // R"
920-
else if (line[i] == '$' && peek1 == 'R' && peek2 == next) { return 3; } // $R"
921920
return 0;
922921
};
923922

@@ -1167,10 +1166,10 @@ auto lex_line(
11671166
store(1, lexeme::QuestionMark);
11681167

11691168
break;case '$':
1170-
if (auto j = is_encoding_prefix_and('\"'); peek(j-2) == 'R') {
1169+
if (peek1 == 'R' && peek2 == '"') {
11711170
// if peek(j-2) is 'R' it means that we deal with raw-string literal
1172-
auto R_pos = i + j - 2;
1173-
auto seq_pos = i + j;
1171+
auto R_pos = i + 1;
1172+
auto seq_pos = i + 3;
11741173

11751174
if (auto paren_pos = line.find("(", seq_pos); paren_pos != std::string::npos) {
11761175
auto opening_seq = line.substr(i, paren_pos - i + 1);
@@ -1215,8 +1214,8 @@ auto lex_line(
12151214
}
12161215
else {
12171216
errors.emplace_back(
1218-
source_position(lineno, i + j - 2),
1219-
"invalid new-line in raw string delimiter \"" + std::string(&line[i],j)
1217+
source_position(lineno, i + 1),
1218+
"invalid new-line in raw string delimiter \"" + std::string(&line[i],3)
12201219
+ "\" - stray 'R' in program \""
12211220
);
12221221
}

0 commit comments

Comments
 (0)