aboutsummaryrefslogtreecommitdiff
path: root/py/lexer.c
diff options
context:
space:
mode:
authorDamien George <damien@micropython.org>2020-06-16 21:42:44 +1000
committerDamien George <damien@micropython.org>2020-06-16 22:02:24 +1000
commit178395031157f61af5426add2de1d76d91440b21 (patch)
tree4f4898ff7f2e707e5b5e4a7245422b07689fb338 /py/lexer.c
parent0fd91e39b1711772c88cfe4e0aaf817fe3387ba6 (diff)
py/compile: Implement PEP 572, assignment expressions with := operator.
The syntax matches CPython and the semantics are equivalent except that, unlike CPython, MicroPython allows using := to assign to comprehension iteration variables, because disallowing this would take a lot of code to check for it. The new compile-time option MICROPY_PY_ASSIGN_EXPR selects this feature and is enabled by default, following MICROPY_PY_ASYNC_AWAIT.
Diffstat (limited to 'py/lexer.c')
-rw-r--r--py/lexer.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/py/lexer.c b/py/lexer.c
index 10bb999af..7d2a251d4 100644
--- a/py/lexer.c
+++ b/py/lexer.c
@@ -174,7 +174,8 @@ STATIC void indent_pop(mp_lexer_t *lex) {
// this means if the start of two ops are the same then they are equal til the last char
STATIC const char *const tok_enc =
- "()[]{},:;~" // singles
+ "()[]{},;~" // singles
+ ":e=" // : :=
"<e=c<e=" // < <= << <<=
">e=c>e=" // > >= >> >>=
"*e=c*e=" // * *= ** **=
@@ -194,8 +195,9 @@ STATIC const uint8_t tok_enc_kind[] = {
MP_TOKEN_DEL_PAREN_OPEN, MP_TOKEN_DEL_PAREN_CLOSE,
MP_TOKEN_DEL_BRACKET_OPEN, MP_TOKEN_DEL_BRACKET_CLOSE,
MP_TOKEN_DEL_BRACE_OPEN, MP_TOKEN_DEL_BRACE_CLOSE,
- MP_TOKEN_DEL_COMMA, MP_TOKEN_DEL_COLON, MP_TOKEN_DEL_SEMICOLON, MP_TOKEN_OP_TILDE,
+ MP_TOKEN_DEL_COMMA, MP_TOKEN_DEL_SEMICOLON, MP_TOKEN_OP_TILDE,
+ MP_TOKEN_DEL_COLON, MP_TOKEN_OP_ASSIGN,
MP_TOKEN_OP_LESS, MP_TOKEN_OP_LESS_EQUAL, MP_TOKEN_OP_DBL_LESS, MP_TOKEN_DEL_DBL_LESS_EQUAL,
MP_TOKEN_OP_MORE, MP_TOKEN_OP_MORE_EQUAL, MP_TOKEN_OP_DBL_MORE, MP_TOKEN_DEL_DBL_MORE_EQUAL,
MP_TOKEN_OP_STAR, MP_TOKEN_DEL_STAR_EQUAL, MP_TOKEN_OP_DBL_STAR, MP_TOKEN_DEL_DBL_STAR_EQUAL,