summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--py/lexer.c14
-rw-r--r--py/lexer.h1
-rw-r--r--py/parse.c3
-rw-r--r--tests/basics/string_fstring.py4
-rw-r--r--tests/cmdline/cmd_parsetree.py.exp4
-rw-r--r--tests/cpydiff/core_fstring_raw.py8
6 files changed, 12 insertions, 22 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,
diff --git a/tests/basics/string_fstring.py b/tests/basics/string_fstring.py
index 3a8969272d..d94cc0cd3e 100644
--- a/tests/basics/string_fstring.py
+++ b/tests/basics/string_fstring.py
@@ -75,3 +75,7 @@ print(
f"cd---------------------------------"
f"e{y}f---------------------------------"
)
+
+# Raw f-strings.
+print(rf"\r\a\w {'f'} \s\t\r\i\n\g")
+print(fr"\r{x}")
diff --git a/tests/cmdline/cmd_parsetree.py.exp b/tests/cmdline/cmd_parsetree.py.exp
index 6ec553b8a9..672c212a96 100644
--- a/tests/cmdline/cmd_parsetree.py.exp
+++ b/tests/cmdline/cmd_parsetree.py.exp
@@ -1,6 +1,6 @@
----------------
[ 1] file_input_2(1) (n=10)
- tok(6)
+ tok(5)
[ 4] \(rule\|for_stmt\)(22) (n=4)
id(i)
[ 4] \(rule\|atom_paren\)(45) (n=1)
@@ -9,7 +9,7 @@
NULL
[ 6] \(rule\|expr_stmt\)(5) (n=2)
id(a)
- tok(16)
+ tok(15)
[ 7] \(rule\|expr_stmt\)(5) (n=2)
id(b)
str(str)
diff --git a/tests/cpydiff/core_fstring_raw.py b/tests/cpydiff/core_fstring_raw.py
deleted file mode 100644
index 84e265f70f..0000000000
--- a/tests/cpydiff/core_fstring_raw.py
+++ /dev/null
@@ -1,8 +0,0 @@
-"""
-categories: Core
-description: Raw f-strings are not supported
-cause: MicroPython is optimised for code space.
-workaround: Unknown
-"""
-
-rf"hello"