py/lexer: Support raw f-strings.

Support for raw str/bytes already exists, and extending that to raw
f-strings is easy.  It also reduces code size because it eliminates an
error message.

Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
Damien George
2024-06-06 17:31:19 +10:00
parent a066f2308f
commit 3c8089d1b1
6 changed files with 13 additions and 23 deletions

View File

@@ -661,21 +661,19 @@ void mp_lexer_to_next(mp_lexer_t *lex) {
}
#if MICROPY_PY_FSTRINGS
if (is_char_following(lex, 'f')) {
// raw-f-strings unsupported, immediately return (invalid) token.
lex->tok_kind = MP_TOKEN_FSTRING_RAW;
break;
is_fstring = true;
n_char = 2;
}
#endif
}
#if MICROPY_PY_FSTRINGS
else if (is_char(lex, 'f')) {
if (is_char_following(lex, 'r')) {
// raw-f-strings unsupported, immediately return (invalid) token.
lex->tok_kind = MP_TOKEN_FSTRING_RAW;
break;
}
n_char = 1;
is_fstring = true;
n_char = 1;
if (is_char_following(lex, 'r')) {
is_raw = true;
n_char = 2;
}
}
#endif