Skip to content

Commit c99e6a2

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 a3c1ddf commit c99e6a2

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
@@ -1009,7 +1009,7 @@ auto lex_line(
10091009
auto peek3 = peek(3);
10101010

10111011
//G encoding-prefix: one of
1012-
//G 'u8' 'u'
1012+
//G 'u8' 'u' 'uR' 'u8R' 'U' 'UR' 'L' 'LR' 'R'
10131013
//G
10141014
auto is_encoding_prefix_and = [&](char next) {
10151015
if (line[i] == next) { return 1; } // "
@@ -1028,7 +1028,6 @@ auto lex_line(
10281028
else if (peek1 == 'R' && peek2 == next) { return 3; } // LR"
10291029
}
10301030
else if (line[i] == 'R' && peek1 == next) { return 2; } // R"
1031-
else if (line[i] == '$' && peek1 == 'R' && peek2 == next) { return 3; } // $R"
10321031
return 0;
10331032
};
10341033

@@ -1278,10 +1277,10 @@ auto lex_line(
12781277
store(1, lexeme::QuestionMark);
12791278

12801279
break;case '$':
1281-
if (auto j = is_encoding_prefix_and('\"'); peek(j-2) == 'R') {
1280+
if (peek1 == 'R' && peek2 == '"') {
12821281
// if peek(j-2) is 'R' it means that we deal with raw-string literal
1283-
auto R_pos = i + j - 2;
1284-
auto seq_pos = i + j;
1282+
auto R_pos = i + 1;
1283+
auto seq_pos = i + 3;
12851284

12861285
if (auto paren_pos = line.find("(", seq_pos); paren_pos != std::string::npos) {
12871286
auto opening_seq = line.substr(i, paren_pos - i + 1);
@@ -1326,8 +1325,8 @@ auto lex_line(
13261325
}
13271326
else {
13281327
errors.emplace_back(
1329-
source_position(lineno, i + j - 2),
1330-
"invalid new-line in raw string delimiter \"" + std::string(&line[i],j)
1328+
source_position(lineno, i + 1),
1329+
"invalid new-line in raw string delimiter \"" + std::string(&line[i],3)
13311330
+ "\" - stray 'R' in program \""
13321331
);
13331332
}

0 commit comments

Comments
 (0)