summaryrefslogtreecommitdiff
path: root/py/lexer.c
diff options
context:
space:
mode:
Diffstat (limited to 'py/lexer.c')
-rw-r--r--py/lexer.c36
1 files changed, 17 insertions, 19 deletions
diff --git a/py/lexer.c b/py/lexer.c
index ac406bd46..39e9662f6 100644
--- a/py/lexer.c
+++ b/py/lexer.c
@@ -473,25 +473,23 @@ STATIC void parse_string_literal(mp_lexer_t *lex, bool is_raw, bool is_fstring)
}
}
if (c != MP_LEXER_EOF) {
- if (MICROPY_PY_BUILTINS_STR_UNICODE_DYNAMIC) {
- if (c < 0x110000 && lex->tok_kind == MP_TOKEN_STRING) {
- vstr_add_char(&lex->vstr, c);
- } else if (c < 0x100 && lex->tok_kind == MP_TOKEN_BYTES) {
- vstr_add_byte(&lex->vstr, c);
- } else {
- // unicode character out of range
- // this raises a generic SyntaxError; could provide more info
- lex->tok_kind = MP_TOKEN_INVALID;
- }
- } else {
- // without unicode everything is just added as an 8-bit byte
- if (c < 0x100) {
- vstr_add_byte(&lex->vstr, c);
- } else {
- // 8-bit character out of range
- // this raises a generic SyntaxError; could provide more info
- lex->tok_kind = MP_TOKEN_INVALID;
- }
+ #if MICROPY_PY_BUILTINS_STR_UNICODE
+ if (c < 0x110000 && lex->tok_kind == MP_TOKEN_STRING) {
+ // Valid unicode character in a str object.
+ vstr_add_char(&lex->vstr, c);
+ } else if (c < 0x100 && lex->tok_kind == MP_TOKEN_BYTES) {
+ // Valid byte in a bytes object.
+ vstr_add_byte(&lex->vstr, c);
+ }
+ #else
+ if (c < 0x100) {
+ // Without unicode everything is just added as an 8-bit byte.
+ vstr_add_byte(&lex->vstr, c);
+ }
+ #endif
+ else {
+ // Character out of range; this raises a generic SyntaxError.
+ lex->tok_kind = MP_TOKEN_INVALID;
}
}
} else {