Skip to content

Commit 085e492

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 5852c58 commit 085e492

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
@@ -1007,7 +1007,7 @@ auto lex_line(
10071007
auto peek3 = peek(3);
10081008

10091009
//G encoding-prefix: one of
1010-
//G 'u8' 'u'
1010+
//G 'u8' 'u' 'uR' 'u8R' 'U' 'UR' 'L' 'LR' 'R'
10111011
//G
10121012
auto is_encoding_prefix_and = [&](char next) {
10131013
if (line[i] == next) { return 1; } // "
@@ -1026,7 +1026,6 @@ auto lex_line(
10261026
else if (peek1 == 'R' && peek2 == next) { return 3; } // LR"
10271027
}
10281028
else if (line[i] == 'R' && peek1 == next) { return 2; } // R"
1029-
else if (line[i] == '$' && peek1 == 'R' && peek2 == next) { return 3; } // $R"
10301029
return 0;
10311030
};
10321031

@@ -1276,10 +1275,10 @@ auto lex_line(
12761275
store(1, lexeme::QuestionMark);
12771276

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

12841283
if (auto paren_pos = line.find("(", seq_pos); paren_pos != std::string::npos) {
12851284
auto opening_seq = line.substr(i, paren_pos - i + 1);
@@ -1324,8 +1323,8 @@ auto lex_line(
13241323
}
13251324
else {
13261325
errors.emplace_back(
1327-
source_position(lineno, i + j - 2),
1328-
"invalid new-line in raw string delimiter \"" + std::string(&line[i],j)
1326+
source_position(lineno, i + 1),
1327+
"invalid new-line in raw string delimiter \"" + std::string(&line[i],3)
13291328
+ "\" - stray 'R' in program \""
13301329
);
13311330
}

0 commit comments

Comments
 (0)