Skip to content

Commit ad74942

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 e906eda commit ad74942

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
@@ -982,7 +982,7 @@ auto lex_line(
982982
auto peek3 = peek(3);
983983

984984
//G encoding-prefix: one of
985-
//G 'u8' 'u'
985+
//G 'u8' 'u' 'uR' 'u8R' 'U' 'UR' 'L' 'LR' 'R'
986986
//G
987987
auto is_encoding_prefix_and = [&](char next) {
988988
if (line[i] == next) { return 1; } // "
@@ -1001,7 +1001,6 @@ auto lex_line(
10011001
else if (peek1 == 'R' && peek2 == next) { return 3; } // LR"
10021002
}
10031003
else if (line[i] == 'R' && peek1 == next) { return 2; } // R"
1004-
else if (line[i] == '$' && peek1 == 'R' && peek2 == next) { return 3; } // $R"
10051004
return 0;
10061005
};
10071006

@@ -1251,10 +1250,10 @@ auto lex_line(
12511250
store(1, lexeme::QuestionMark);
12521251

12531252
break;case '$':
1254-
if (auto j = is_encoding_prefix_and('\"'); peek(j-2) == 'R') {
1253+
if (peek1 == 'R' && peek2 == '"') {
12551254
// if peek(j-2) is 'R' it means that we deal with raw-string literal
1256-
auto R_pos = i + j - 2;
1257-
auto seq_pos = i + j;
1255+
auto R_pos = i + 1;
1256+
auto seq_pos = i + 3;
12581257

12591258
if (auto paren_pos = line.find("(", seq_pos); paren_pos != std::string::npos) {
12601259
auto opening_seq = line.substr(i, paren_pos - i + 1);
@@ -1299,8 +1298,8 @@ auto lex_line(
12991298
}
13001299
else {
13011300
errors.emplace_back(
1302-
source_position(lineno, i + j - 2),
1303-
"invalid new-line in raw string delimiter \"" + std::string(&line[i],j)
1301+
source_position(lineno, i + 1),
1302+
"invalid new-line in raw string delimiter \"" + std::string(&line[i],3)
13041303
+ "\" - stray 'R' in program \""
13051304
);
13061305
}

0 commit comments

Comments
 (0)