py/lexer: Support nested [] and {} characters within f-string params.

Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
Damien George
2021-11-19 10:36:16 +11:00
parent 196d26848a
commit 11ed94797d
3 changed files with 20 additions and 6 deletions

View File

@@ -22,6 +22,13 @@ def foo(a, b):
return f'{x}{y}{a}{b}'
print(foo(7, 8))
# ':' character within {...} that should not be interpreted as format specifiers.
print(f"a{[0,1,2][0:2]}")
print(f"a{[0,15,2][0:2][-1]:04x}")
# Nested '{' and '}' characters.
print(f"a{ {0,1,2}}")
# PEP-0498 specifies that '\\' and '#' must be disallowed explicitly, whereas
# MicroPython relies on the syntax error as a result of the substitution.