diff options
| author | Jeff Epler <jepler@gmail.com> | 2020-03-09 08:33:47 -0500 |
|---|---|---|
| committer | Jeff Epler <jepler@gmail.com> | 2020-03-09 09:03:25 -0500 |
| commit | 32647cd9b41c26003df0bdc385353f6a24b727d7 (patch) | |
| tree | ea6d7df1de060d757a3004a680797559b742d4db /py | |
| parent | acd7b8932f9ae4dc03d28ebcf13795de5e913368 (diff) | |
lexer: catch concatenation of f'' and '' strings
This turns the "edge case" into a parse-time error.
Diffstat (limited to 'py')
| -rw-r--r-- | py/lexer.c | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/py/lexer.c b/py/lexer.c index c3f4e6506..80f8f043c 100644 --- a/py/lexer.c +++ b/py/lexer.c @@ -583,6 +583,8 @@ void mp_lexer_to_next(mp_lexer_t *lex) { // MP_TOKEN_END is used to indicate that this is the first string token lex->tok_kind = MP_TOKEN_END; + bool saw_normal = false, saw_fstring = false; + // Loop to accumulate string/bytes literals do { // parse type codes @@ -619,6 +621,17 @@ void mp_lexer_to_next(mp_lexer_t *lex) { is_fstring = true; } + if (is_fstring) { + saw_fstring = true; + } else { + saw_normal = true; + } + + if (saw_fstring && saw_normal) { + // Can't concatenate f-string with normal string + break; + } + // Set or check token kind if (lex->tok_kind == MP_TOKEN_END) { lex->tok_kind = kind; |
