Skip to content

Commit 4969832

Browse files
committed
Address dpgeorge feedback - largely simplifications
1 parent 31b9b94 commit 4969832

File tree

3 files changed

+21
-32
lines changed

3 files changed

+21
-32
lines changed

py/lexer.c

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -127,29 +127,21 @@ STATIC bool is_tail_of_identifier(mp_lexer_t *lex) {
127127

128128
STATIC void swap_char_banks(mp_lexer_t *lex) {
129129
if (lex->vstr_postfix_processing) {
130-
unichar h0, h1, h2;
131-
132-
h0 = lex->chr0;
133-
h1 = lex->chr1;
134-
h2 = lex->chr2;
135-
136-
lex->chr0 = lex->vstr_postfix.len > 0 ? lex->vstr_postfix.buf[0] : 0;
137-
lex->chr1 = lex->vstr_postfix.len > 1 ? lex->vstr_postfix.buf[1] : 0;
138-
lex->chr2 = lex->vstr_postfix.len > 2 ? lex->vstr_postfix.buf[2] : 0;
139-
lex->chr3 = h0;
140-
lex->chr4 = h1;
141-
lex->chr5 = h2;
142-
143-
lex->vstr_postfix_idx = lex->vstr_postfix.len > 2 ? 3 : lex->vstr_postfix.len;
130+
lex->chr3 = lex->chr0;
131+
lex->chr4 = lex->chr1;
132+
lex->chr5 = lex->chr2;
133+
lex->chr0 = lex->vstr_postfix.buf[0];
134+
lex->chr1 = lex->vstr_postfix.buf[1];
135+
lex->chr2 = lex->vstr_postfix.buf[2];
136+
137+
lex->vstr_postfix_idx = 3;
144138
} else {
145139
// blindly reset to the "backup" bank when done postfix processing
146140
// this restores control to the mp_reader
147141
lex->chr0 = lex->chr3;
148142
lex->chr1 = lex->chr4;
149143
lex->chr2 = lex->chr5;
150-
lex->chr3 = 0;
151-
lex->chr4 = 0;
152-
lex->chr5 = 0;
144+
// willfully ignoring setting chr3-5 here - WARNING consider those garbage data now
153145

154146
vstr_reset(&lex->vstr_postfix);
155147
lex->vstr_postfix_idx = 0;

py/parse.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1149,6 +1149,7 @@ mp_parse_tree_t mp_parse(mp_lexer_t *lex, mp_parse_input_kind_t input_kind) {
11491149
exc = mp_obj_new_exception_msg(&mp_type_IndentationError,
11501150
"unindent does not match any outer indentation level");
11511151
break;
1152+
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_DETAILED
11521153
case MP_TOKEN_FSTRING_BACKSLASH:
11531154
exc = mp_obj_new_exception_msg(&mp_type_SyntaxError,
11541155
"f-string expression part cannot include a backslash");
@@ -1173,6 +1174,17 @@ mp_parse_tree_t mp_parse(mp_lexer_t *lex, mp_parse_input_kind_t input_kind) {
11731174
exc = mp_obj_new_exception_msg(&mp_type_NotImplementedError,
11741175
"raw f-strings are not implemented");
11751176
break;
1177+
#else
1178+
case MP_TOKEN_FSTRING_BACKSLASH:
1179+
case MP_TOKEN_FSTRING_COMMENT:
1180+
case MP_TOKEN_FSTRING_UNCLOSED:
1181+
case MP_TOKEN_FSTRING_UNOPENED:
1182+
case MP_TOKEN_FSTRING_EMPTY_EXP:
1183+
case MP_TOKEN_FSTRING_RAW:
1184+
exc = mp_obj_new_exception_msg(&mp_type_SyntaxError,
1185+
"malformed f-string");
1186+
break;
1187+
#endif
11761188
default:
11771189
exc = mp_obj_new_exception_msg(&mp_type_SyntaxError,
11781190
"invalid syntax");

tests/basics/string_pep498_fstring.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -113,18 +113,3 @@ def foo():
113113

114114
# Other tests
115115
assert f'{{{4*10}}}' == '{40}'
116-
117-
try:
118-
eval("fr''")
119-
except NotImplementedError:
120-
pass
121-
else:
122-
if sys.implementation.name in {'micropython', 'circuitpython'}:
123-
raise RuntimeError('expected raw f-string to raise NotImplementedError')
124-
try:
125-
eval("rf''")
126-
except NotImplementedError:
127-
pass
128-
else:
129-
if sys.implementation.name in {'micropython', 'circuitpython'}:
130-
raise RuntimeError('expected raw f-string to raise NotImplementedError')

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy