Commit 379ea8d7 authored by Stefan Behnel's avatar Stefan Behnel

Rewrite fstring parsing to match CPython 3.6 and the updated PEP 498

- resolve string escapes  only outside of fstring expressions
- reject backslashes inside of fstring expressions
Also make some fstring errors non-fatal to keep parsing.
parent 634c41aa
...@@ -68,10 +68,11 @@ cdef p_opt_string_literal(PyrexScanner s, required_type=*) ...@@ -68,10 +68,11 @@ cdef p_opt_string_literal(PyrexScanner s, required_type=*)
cdef bint check_for_non_ascii_characters(unicode string) cdef bint check_for_non_ascii_characters(unicode string)
@cython.locals(systr=unicode, is_python3_source=bint, is_raw=bint) @cython.locals(systr=unicode, is_python3_source=bint, is_raw=bint)
cdef p_string_literal(PyrexScanner s, kind_override=*) cdef p_string_literal(PyrexScanner s, kind_override=*)
@cython.locals(i=Py_ssize_t, size=Py_ssize_t) cdef _append_escape_sequence(kind, builder, unicode escape_sequence, PyrexScanner s)
cdef list p_f_string(PyrexScanner s, unicode_value, pos) @cython.locals(i=Py_ssize_t, size=Py_ssize_t, c=Py_UCS4)
cdef list p_f_string(PyrexScanner s, unicode unicode_value, pos, bint is_raw)
@cython.locals(i=Py_ssize_t, size=Py_ssize_t, c=Py_UCS4, quote_char=Py_UCS4, NO_CHAR=Py_UCS4) @cython.locals(i=Py_ssize_t, size=Py_ssize_t, c=Py_UCS4, quote_char=Py_UCS4, NO_CHAR=Py_UCS4)
cdef tuple p_f_string_expr(PyrexScanner s, unicode_value, pos, Py_ssize_t starting_index) cdef tuple p_f_string_expr(PyrexScanner s, unicode_value, pos, Py_ssize_t starting_index, bint is_raw)
cdef p_list_maker(PyrexScanner s) cdef p_list_maker(PyrexScanner s)
cdef p_comp_iter(PyrexScanner s, body) cdef p_comp_iter(PyrexScanner s, body)
cdef p_comp_for(PyrexScanner s, body) cdef p_comp_for(PyrexScanner s, body)
......
This diff is collapsed.
...@@ -18,6 +18,15 @@ max_long = LONG_MAX ...@@ -18,6 +18,15 @@ max_long = LONG_MAX
min_long = LONG_MIN min_long = LONG_MIN
def escaping():
"""
>>> escaping()
"""
assert f'{{{{{"abc"}}}}}{{}}{{' == '{{abc}}{}{'
assert f'\x7b}}' == '{}'
assert f'{"{{}}"}' == '{{}}'
def format2(ab, cd): def format2(ab, cd):
""" """
>>> a, b, c = format2(1, 2) >>> a, b, c = format2(1, 2)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment