Skip to content

Commit 0a31284

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 f3cd293 commit 0a31284

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
@@ -1003,7 +1003,7 @@ auto lex_line(
10031003
auto peek3 = peek(3);
10041004

10051005
//G encoding-prefix: one of
1006-
//G 'u8' 'u'
1006+
//G 'u8' 'u' 'uR' 'u8R' 'U' 'UR' 'L' 'LR' 'R'
10071007
//G
10081008
auto is_encoding_prefix_and = [&](char next) {
10091009
if (line[i] == next) { return 1; } // "
@@ -1022,7 +1022,6 @@ auto lex_line(
10221022
else if (peek1 == 'R' && peek2 == next) { return 3; } // LR"
10231023
}
10241024
else if (line[i] == 'R' && peek1 == next) { return 2; } // R"
1025-
else if (line[i] == '$' && peek1 == 'R' && peek2 == next) { return 3; } // $R"
10261025
return 0;
10271026
};
10281027

@@ -1272,10 +1271,10 @@ auto lex_line(
12721271
store(1, lexeme::QuestionMark);
12731272

12741273
break;case '$':
1275-
if (auto j = is_encoding_prefix_and('\"'); peek(j-2) == 'R') {
1274+
if (peek1 == 'R' && peek2 == '"') {
12761275
// if peek(j-2) is 'R' it means that we deal with raw-string literal
1277-
auto R_pos = i + j - 2;
1278-
auto seq_pos = i + j;
1276+
auto R_pos = i + 1;
1277+
auto seq_pos = i + 3;
12791278

12801279
if (auto paren_pos = line.find("(", seq_pos); paren_pos != std::string::npos) {
12811280
auto opening_seq = line.substr(i, paren_pos - i + 1);
@@ -1320,8 +1319,8 @@ auto lex_line(
13201319
}
13211320
else {
13221321
errors.emplace_back(
1323-
source_position(lineno, i + j - 2),
1324-
"invalid new-line in raw string delimiter \"" + std::string(&line[i],j)
1322+
source_position(lineno, i + 1),
1323+
"invalid new-line in raw string delimiter \"" + std::string(&line[i],3)
13251324
+ "\" - stray 'R' in program \""
13261325
);
13271326
}

0 commit comments

Comments
 (0)