diff options
author | shadchin <shadchin@yandex-team.ru> | 2022-02-10 16:44:30 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:44:30 +0300 |
commit | 2598ef1d0aee359b4b6d5fdd1758916d5907d04f (patch) | |
tree | 012bb94d777798f1f56ac1cec429509766d05181 /contrib/tools/cython/Cython/Compiler/Parsing.py | |
parent | 6751af0b0c1b952fede40b19b71da8025b5d8bcf (diff) | |
download | ydb-2598ef1d0aee359b4b6d5fdd1758916d5907d04f.tar.gz |
Restoring authorship annotation for <shadchin@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'contrib/tools/cython/Cython/Compiler/Parsing.py')
-rw-r--r-- | contrib/tools/cython/Cython/Compiler/Parsing.py | 56 |
1 files changed, 28 insertions, 28 deletions
diff --git a/contrib/tools/cython/Cython/Compiler/Parsing.py b/contrib/tools/cython/Cython/Compiler/Parsing.py index 4d2f12a24a..40862bcee6 100644 --- a/contrib/tools/cython/Cython/Compiler/Parsing.py +++ b/contrib/tools/cython/Cython/Compiler/Parsing.py @@ -882,7 +882,7 @@ def p_string_literal(s, kind_override=None): pos = s.position() is_python3_source = s.context.language_level >= 3 has_non_ascii_literal_characters = False - string_start_pos = (pos[0], pos[1], pos[2] + len(s.systring)) + string_start_pos = (pos[0], pos[1], pos[2] + len(s.systring)) kind_string = s.systring.rstrip('"\'').lower() if len(kind_string) > 1: if len(set(kind_string)) != len(kind_string): @@ -966,7 +966,7 @@ def p_string_literal(s, kind_override=None): s.error("bytes can only contain ASCII literal characters.", pos=pos) bytes_value = None if kind == 'f': - unicode_value = p_f_string(s, unicode_value, string_start_pos, is_raw='r' in kind_string) + unicode_value = p_f_string(s, unicode_value, string_start_pos, is_raw='r' in kind_string) s.next() return (kind, bytes_value, unicode_value) @@ -1038,10 +1038,10 @@ _parse_escape_sequences_raw, _parse_escape_sequences = [re.compile(( for is_raw in (True, False)] -def _f_string_error_pos(pos, string, i): - return (pos[0], pos[1], pos[2] + i + 1) # FIXME: handle newlines in string - - +def _f_string_error_pos(pos, string, i): + return (pos[0], pos[1], pos[2] + i + 1) # FIXME: handle newlines in string + + def p_f_string(s, unicode_value, pos, is_raw): # Parses a PEP 498 f-string literal into a list of nodes. Nodes are either UnicodeNodes # or FormattedValueNodes. @@ -1055,7 +1055,7 @@ def p_f_string(s, unicode_value, pos, is_raw): end = next_start match = _parse_seq(unicode_value, next_start) if match is None: - error(_f_string_error_pos(pos, unicode_value, next_start), "Invalid escape sequence") + error(_f_string_error_pos(pos, unicode_value, next_start), "Invalid escape sequence") next_start = match.end() part = match.group() @@ -1079,8 +1079,8 @@ def p_f_string(s, unicode_value, pos, is_raw): if part == '}}': builder.append('}') else: - error(_f_string_error_pos(pos, unicode_value, end), - "f-string: single '}' is not allowed") + error(_f_string_error_pos(pos, unicode_value, end), + "f-string: single '}' is not allowed") else: builder.append(part) @@ -1101,20 +1101,20 @@ def p_f_string_expr(s, unicode_value, pos, starting_index, is_raw): nested_depth = 0 quote_char = NO_CHAR in_triple_quotes = False - backslash_reported = False + backslash_reported = False while True: if i >= size: - break # error will be reported below + break # error will be reported below c = unicode_value[i] if quote_char != NO_CHAR: if c == '\\': - # avoid redundant error reports along '\' sequences - if not backslash_reported: - error(_f_string_error_pos(pos, unicode_value, i), - "backslashes not allowed in f-strings") - backslash_reported = True + # avoid redundant error reports along '\' sequences + if not backslash_reported: + error(_f_string_error_pos(pos, unicode_value, i), + "backslashes not allowed in f-strings") + backslash_reported = True elif c == quote_char: if in_triple_quotes: if i + 2 < size and unicode_value[i + 1] == c and unicode_value[i + 2] == c: @@ -1133,8 +1133,8 @@ def p_f_string_expr(s, unicode_value, pos, starting_index, is_raw): elif nested_depth != 0 and c in '}])': nested_depth -= 1 elif c == '#': - error(_f_string_error_pos(pos, unicode_value, i), - "format string cannot include #") + error(_f_string_error_pos(pos, unicode_value, i), + "format string cannot include #") elif nested_depth == 0 and c in '!:}': # allow != as a special case if c == '!' and i + 1 < size and unicode_value[i + 1] == '=': @@ -1150,13 +1150,13 @@ def p_f_string_expr(s, unicode_value, pos, starting_index, is_raw): expr_pos = (pos[0], pos[1], pos[2] + starting_index + 2) # TODO: find exact code position (concat, multi-line, ...) if not expr_str.strip(): - error(_f_string_error_pos(pos, unicode_value, starting_index), - "empty expression not allowed in f-string") + error(_f_string_error_pos(pos, unicode_value, starting_index), + "empty expression not allowed in f-string") if terminal_char == '!': i += 1 if i + 2 > size: - pass # error will be reported below + pass # error will be reported below else: conversion_char = unicode_value[i] i += 1 @@ -1169,7 +1169,7 @@ def p_f_string_expr(s, unicode_value, pos, starting_index, is_raw): start_format_spec = i + 1 while True: if i >= size: - break # error will be reported below + break # error will be reported below c = unicode_value[i] if not in_triple_quotes and not in_string: if c == '{': @@ -1191,9 +1191,9 @@ def p_f_string_expr(s, unicode_value, pos, starting_index, is_raw): format_spec_str = unicode_value[start_format_spec:i] if terminal_char != '}': - error(_f_string_error_pos(pos, unicode_value, i), - "missing '}' in format string expression" + ( - ", found '%s'" % terminal_char if terminal_char else "")) + error(_f_string_error_pos(pos, unicode_value, i), + "missing '}' in format string expression" + ( + ", found '%s'" % terminal_char if terminal_char else "")) # parse the expression as if it was surrounded by parentheses buf = StringIO('(%s)' % expr_str) @@ -1202,7 +1202,7 @@ def p_f_string_expr(s, unicode_value, pos, starting_index, is_raw): # validate the conversion char if conversion_char is not None and not ExprNodes.FormattedValueNode.find_conversion_func(conversion_char): - error(expr_pos, "invalid conversion character '%s'" % conversion_char) + error(expr_pos, "invalid conversion character '%s'" % conversion_char) # the format spec is itself treated like an f-string if format_spec_str: @@ -2254,7 +2254,7 @@ def p_statement(s, ctx, first_statement = 0): s.error('decorator not allowed here') s.level = ctx.level decorators = p_decorators(s) - if not ctx.allow_struct_enum_decorator and s.sy not in ('def', 'cdef', 'cpdef', 'class', 'async'): + if not ctx.allow_struct_enum_decorator and s.sy not in ('def', 'cdef', 'cpdef', 'class', 'async'): if s.sy == 'IDENT' and s.systring == 'async': pass # handled below else: @@ -2683,7 +2683,7 @@ def looking_at_expr(s): s.put_back(*saved) elif s.sy == '[': s.next() - is_type = s.sy == ']' or not looking_at_expr(s) # could be a nested template type + is_type = s.sy == ']' or not looking_at_expr(s) # could be a nested template type s.put_back(*saved) dotted_path.reverse() |