Address dpgeorge feedback - largely simplifications
This commit is contained in:
parent
3a7a5ba686
commit
40bc05ee1e
24
py/lexer.c
24
py/lexer.c
@ -129,29 +129,21 @@ STATIC bool is_tail_of_identifier(mp_lexer_t *lex) {
|
||||
|
||||
STATIC void swap_char_banks(mp_lexer_t *lex) {
|
||||
if (lex->vstr_postfix_processing) {
|
||||
unichar h0, h1, h2;
|
||||
lex->chr3 = lex->chr0;
|
||||
lex->chr4 = lex->chr1;
|
||||
lex->chr5 = lex->chr2;
|
||||
lex->chr0 = lex->vstr_postfix.buf[0];
|
||||
lex->chr1 = lex->vstr_postfix.buf[1];
|
||||
lex->chr2 = lex->vstr_postfix.buf[2];
|
||||
|
||||
h0 = lex->chr0;
|
||||
h1 = lex->chr1;
|
||||
h2 = lex->chr2;
|
||||
|
||||
lex->chr0 = lex->vstr_postfix.len > 0 ? lex->vstr_postfix.buf[0] : 0;
|
||||
lex->chr1 = lex->vstr_postfix.len > 1 ? lex->vstr_postfix.buf[1] : 0;
|
||||
lex->chr2 = lex->vstr_postfix.len > 2 ? lex->vstr_postfix.buf[2] : 0;
|
||||
lex->chr3 = h0;
|
||||
lex->chr4 = h1;
|
||||
lex->chr5 = h2;
|
||||
|
||||
lex->vstr_postfix_idx = lex->vstr_postfix.len > 2 ? 3 : lex->vstr_postfix.len;
|
||||
lex->vstr_postfix_idx = 3;
|
||||
} else {
|
||||
// blindly reset to the "backup" bank when done postfix processing
|
||||
// this restores control to the mp_reader
|
||||
lex->chr0 = lex->chr3;
|
||||
lex->chr1 = lex->chr4;
|
||||
lex->chr2 = lex->chr5;
|
||||
lex->chr3 = 0;
|
||||
lex->chr4 = 0;
|
||||
lex->chr5 = 0;
|
||||
// willfully ignoring setting chr3-5 here - WARNING consider those garbage data now
|
||||
|
||||
vstr_reset(&lex->vstr_postfix);
|
||||
lex->vstr_postfix_idx = 0;
|
||||
|
12
py/parse.c
12
py/parse.c
@ -1178,6 +1178,7 @@ mp_parse_tree_t mp_parse(mp_lexer_t *lex, mp_parse_input_kind_t input_kind) {
|
||||
exc = mp_obj_new_exception_msg(&mp_type_IndentationError,
|
||||
translate("unindent does not match any outer indentation level"));
|
||||
break;
|
||||
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_DETAILED
|
||||
case MP_TOKEN_FSTRING_BACKSLASH:
|
||||
exc = mp_obj_new_exception_msg(&mp_type_SyntaxError,
|
||||
translate("f-string expression part cannot include a backslash"));
|
||||
@ -1202,6 +1203,17 @@ mp_parse_tree_t mp_parse(mp_lexer_t *lex, mp_parse_input_kind_t input_kind) {
|
||||
exc = mp_obj_new_exception_msg(&mp_type_NotImplementedError,
|
||||
translate("raw f-strings are not implemented"));
|
||||
break;
|
||||
#else
|
||||
case MP_TOKEN_FSTRING_BACKSLASH:
|
||||
case MP_TOKEN_FSTRING_COMMENT:
|
||||
case MP_TOKEN_FSTRING_UNCLOSED:
|
||||
case MP_TOKEN_FSTRING_UNOPENED:
|
||||
case MP_TOKEN_FSTRING_EMPTY_EXP:
|
||||
case MP_TOKEN_FSTRING_RAW:
|
||||
exc = mp_obj_new_exception_msg(&mp_type_SyntaxError,
|
||||
translate("malformed f-string"));
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
exc = mp_obj_new_exception_msg(&mp_type_SyntaxError,
|
||||
translate("invalid syntax"));
|
||||
|
@ -111,16 +111,3 @@ assert ('a' 'b' f'{x}' f'str<{y:^4}>' 'd' 'e') == 'ab10str< hi >de'
|
||||
|
||||
# Other tests
|
||||
assert f'{{{4*10}}}' == '{40}'
|
||||
|
||||
try:
|
||||
eval("fr''")
|
||||
except NotImplementedError:
|
||||
pass
|
||||
else:
|
||||
raise RuntimeError('expected raw f-string to raise NotImplementedError')
|
||||
try:
|
||||
eval("rf''")
|
||||
except NotImplementedError:
|
||||
pass
|
||||
else:
|
||||
raise RuntimeError('expected raw f-string to raise NotImplementedError')
|
||||
|
Loading…
Reference in New Issue
Block a user