diff options
Diffstat (limited to 'Parser/pegen.c')
-rw-r--r-- | Parser/pegen.c | 46 |
1 files changed, 23 insertions, 23 deletions
diff --git a/Parser/pegen.c b/Parser/pegen.c index 3472d48..3e8ddfb 100644 --- a/Parser/pegen.c +++ b/Parser/pegen.c @@ -139,27 +139,6 @@ _create_dummy_identifier(Parser *p) return _PyPegen_new_identifier(p, ""); } -static inline Py_ssize_t -byte_offset_to_character_offset(PyObject *line, Py_ssize_t col_offset) -{ - const char *str = PyUnicode_AsUTF8(line); - if (!str) { - return 0; - } - Py_ssize_t len = strlen(str); - if (col_offset > len + 1) { - col_offset = len + 1; - } - assert(col_offset >= 0); - PyObject *text = PyUnicode_DecodeUTF8(str, col_offset, "replace"); - if (!text) { - return 0; - } - Py_ssize_t size = PyUnicode_GET_LENGTH(text); - Py_DECREF(text); - return size; -} - const char * _PyPegen_get_expr_name(expr_ty e) { @@ -418,6 +397,27 @@ get_error_line(Parser *p, Py_ssize_t lineno) return PyUnicode_DecodeUTF8(cur_line, next_newline - cur_line, "replace"); } +Py_ssize_t +_PyPegen_byte_offset_to_character_offset(PyObject *line, Py_ssize_t col_offset) +{ + const char *str = PyUnicode_AsUTF8(line); + if (!str) { + return 0; + } + Py_ssize_t len = strlen(str); + if (col_offset > len + 1) { + col_offset = len + 1; + } + assert(col_offset >= 0); + PyObject *text = PyUnicode_DecodeUTF8(str, col_offset, "replace"); + if (!text) { + return 0; + } + Py_ssize_t size = PyUnicode_GET_LENGTH(text); + Py_DECREF(text); + return size; +} + void * _PyPegen_raise_error_known_location(Parser *p, PyObject *errtype, Py_ssize_t lineno, Py_ssize_t col_offset, @@ -498,9 +498,9 @@ _PyPegen_raise_error_known_location(Parser *p, PyObject *errtype, Py_ssize_t end_col_number = end_col_offset; if (p->tok->encoding != NULL) { - col_number = byte_offset_to_character_offset(error_line, col_offset); + col_number = _PyPegen_byte_offset_to_character_offset(error_line, col_offset); end_col_number = end_col_number > 0 ? - byte_offset_to_character_offset(error_line, end_col_offset) : + _PyPegen_byte_offset_to_character_offset(error_line, end_col_offset) : end_col_number; } tmp = Py_BuildValue("(OiiNii)", p->tok->filename, lineno, col_number, error_line, end_lineno, end_col_number); |