diff options
author | Damien George <damien@micropython.org> | 2024-06-06 17:31:19 +1000 |
---|---|---|
committer | Damien George <damien@micropython.org> | 2024-06-06 17:34:28 +1000 |
commit | 3c8089d1b10683ee31ddbaeebd0b18c47bf6d09d (patch) | |
tree | 4a4ff4cd7d0591cf45e8fe34273903cb1fe3e4bc /py | |
parent | a066f2308f7b0d872352073cec0a945dca3a7a9c (diff) | |
download | micropython-3c8089d1b10683ee31ddbaeebd0b18c47bf6d09d.tar.gz micropython-3c8089d1b10683ee31ddbaeebd0b18c47bf6d09d.zip |
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>
Diffstat (limited to 'py')
-rw-r--r-- | py/lexer.c | 14 | ||||
-rw-r--r-- | py/lexer.h | 1 | ||||
-rw-r--r-- | py/parse.c | 3 |
3 files changed, 6 insertions, 12 deletions
diff --git a/py/lexer.c b/py/lexer.c index 2774759a15..48497663c5 100644 --- a/py/lexer.c +++ b/py/lexer.c @@ -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')) { + is_fstring = true; + n_char = 1; if (is_char_following(lex, 'r')) { - // raw-f-strings unsupported, immediately return (invalid) token. - lex->tok_kind = MP_TOKEN_FSTRING_RAW; - break; + is_raw = true; + n_char = 2; } - n_char = 1; - is_fstring = true; } #endif diff --git a/py/lexer.h b/py/lexer.h index 2d9d0447b8..e0b506b20b 100644 --- a/py/lexer.h +++ b/py/lexer.h @@ -46,7 +46,6 @@ typedef enum _mp_token_kind_t { MP_TOKEN_LONELY_STRING_OPEN, #if MICROPY_PY_FSTRINGS MP_TOKEN_MALFORMED_FSTRING, - MP_TOKEN_FSTRING_RAW, #endif MP_TOKEN_NEWLINE, diff --git a/py/parse.c b/py/parse.c index 1392303e6f..4ba9560734 100644 --- a/py/parse.c +++ b/py/parse.c @@ -1351,9 +1351,6 @@ mp_parse_tree_t mp_parse(mp_lexer_t *lex, mp_parse_input_kind_t input_kind) { } else if (lex->tok_kind == MP_TOKEN_MALFORMED_FSTRING) { exc = mp_obj_new_exception_msg(&mp_type_SyntaxError, MP_ERROR_TEXT("malformed f-string")); - } else if (lex->tok_kind == MP_TOKEN_FSTRING_RAW) { - exc = mp_obj_new_exception_msg(&mp_type_SyntaxError, - MP_ERROR_TEXT("raw f-strings are not supported")); #endif } else { exc = mp_obj_new_exception_msg(&mp_type_SyntaxError, |