summaryrefslogtreecommitdiffstats
path: root/Parser/tokenizer.c
Commit message (Collapse)AuthorAgeFilesLines
* gh-104169: Refactor tokenizer into lexer and wrappers (#110684)Lysandros Nikolaou2023-10-111-2951/+0
| | | | | | | | | | | * The lexer, which include the actual lexeme producing logic, goes into the `lexer` directory. * The wrappers, one wrapper per input mode (file, string, utf-8, and readline), go into the `tokenizer` directory and include logic for creating a lexer instance and managing the buffer for different modes. --------- Co-authored-by: Pablo Galindo <pablogsal@gmail.com> Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
* gh-110259: Fix f-strings with multiline expressions and format specs (#110271)Pablo Galindo Salgado2023-10-051-6/+18
| | | Signed-off-by: Pablo Galindo <pablogsal@gmail.com>
* gh-110014: Include explicitly <unistd.h> header (#110155)Victor Stinner2023-09-301-3/+5
| | | | | | | | | | | * Remove unused <locale.h> includes. * Remove unused <fcntl.h> include in traceback.h. * Remove redundant <assert.h> and <stddef.h> includes. They are already included by "Python.h". * Remove <object.h> include in faulthandler.c. Python.h already includes it. * Add missing <stdbool.h> in pycore_pythread.h if HAVE_PTHREAD_STUBS is defined. * Fix also warnings in pthread_stubs.h: don't redefine macros if they are already defined, like the __NEED_pthread_t macro.
* gh-88943: Improve syntax error for non-ASCII character that follows a ↵Serhiy Storchaka2023-09-071-1/+1
| | | | | numerical literal (GH-109081) It now points on the invalid non-ASCII character, not on the valid numerical literal.
* gh-108767: Replace ctype.h functions with pyctype.h functions (#108772)Victor Stinner2023-09-011-19/+18
| | | | | | | | | | | | | | Replace <ctype.h> locale dependent functions with Python "pyctype.h" locale independent functions: * Replace isalpha() with Py_ISALPHA(). * Replace isdigit() with Py_ISDIGIT(). * Replace isxdigit() with Py_ISXDIGIT(). * Replace tolower() with Py_TOLOWER(). Leave Modules/_sre/sre.c unchanged, it uses locale dependent functions on purpose. Include explicitly <ctype.h> in _decimal.c to get isascii().
* gh-107967: Fix infinite recursion on invalid escape sequence warning (#107968)Lysandros Nikolaou2023-08-151-0/+3
|
* gh-107015: Remove async_hacks from the tokenizer (#107018)Pablo Galindo Salgado2023-07-261-78/+0
|
* gh-106989: Remove tok report warnings (#106993)Menelaos Kotoglou2023-07-221-5/+0
|
* gh-104922: remove PY_SSIZE_T_CLEAN (#106315)Inada Naoki2023-07-021-1/+0
|
* gh-105938: Emit a SyntaxWarning for escaped braces in an f-string (#105939)Lysandros Nikolaou2023-06-201-3/+3
|
* gh-105820: Fix tok_mode expression buffer in file & readline tokenizer (#105828)Lysandros Nikolaou2023-06-151-3/+8
|
* gh-105718: Fix buffer allocation in tokenizer with readline (#105728)Lysandros Nikolaou2023-06-131-4/+0
|
* gh-105549: Tokenize separately NUMBER and NAME tokens and allow 0-prefixed ↵Pablo Galindo Salgado2023-06-091-3/+10
| | | | literals (#105555)
* gh-105259: Ensure we don't show newline characters for trailing NEWLINE ↵Pablo Galindo Salgado2023-06-061-0/+7
| | | | tokens (#105364)
* gh-105042: Disable unmatched parens syntax error in python tokenize (#105061)Lysandros Nikolaou2023-05-301-32/+33
|
* gh-105069: Add a readline-like callable to the tokenizer to consume input ↵Pablo Galindo Salgado2023-05-301-3/+133
| | | | iteratively (#105070)
* gh-105017: Include CRLF lines in strings and column numbers (#105030)Marta Gómez Macías2023-05-281-12/+26
| | | Co-authored-by: Pablo Galindo <pablogsal@gmail.com>
* gh-105017: Fix including additional NL token when using CRLF (#105022)Marta Gómez Macías2023-05-271-1/+1
| | | | Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
* Fix indentation in Parser/tokenizer.c (#105012)Petr Vaněk2023-05-271-1/+1
|
* gh-104866: Tokenize should emit NEWLINE after exiting block with comment ↵Lysandros Nikolaou2023-05-241-3/+6
| | | | (#104870)
* gh-102856: Allow comments inside multi-line f-string expresions (#104006)Cristián Maureira-Fredes2023-05-221-4/+0
|
* gh-98836: Extend PyUnicode_FromFormat() (GH-98838)Serhiy Storchaka2023-05-211-8/+3
| | | | | | | | | * Support for conversion specifiers o (octal) and X (uppercase hexadecimal). * Support for length modifiers j (intmax_t) and t (ptrdiff_t). * Length modifiers are now applied to all integer conversions. * Support for wchar_t C strings (%ls and %lV). * Support for variable width and precision (*). * Support for flag - (left alignment).
* gh-102856: Python tokenizer implementation for PEP 701 (#104323)Marta Gómez Macías2023-05-211-2/+55
| | | | | | | | | | | This commit replaces the Python implementation of the tokenize module with an implementation that reuses the real C tokenizer via a private extension module. The tokenize module now implements a compatibility layer that transforms tokens from the C tokenizer into Python tokenize tokens for backward compatibility. As the C tokenizer does not emit some tokens that the Python tokenizer provides (such as comments and non-semantic newlines), a new special mode has been added to the C tokenizer mode that currently is only used via the extension module that exposes it to the Python layer. This new mode forces the C tokenizer to emit these new extra tokens and add the appropriate metadata that is needed to match the old Python implementation. Co-authored-by: Pablo Galindo <pablogsal@gmail.com>
* gh-104658: Fix location of unclosed quote error for multiline f-strings ↵Pablo Galindo Salgado2023-05-201-2/+5
| | | | (#104660)
* Trim trailing whitespace and test on CI (#104275)Hugo van Kemenade2023-05-081-1/+1
| | | | Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
* gh-104169: Ensure the tokenizer doesn't overwrite previous errors (#104170)Pablo Galindo Salgado2023-05-041-0/+6
|
* gh-97556: Raise null bytes syntax error upon null in multiline string ↵Lysandros Nikolaou2023-05-041-1/+8
| | | | (GH-104136)
* gh-104016: Fixed off by 1 error in f string tokenizer (#104047)jx1242023-05-011-2/+5
| | | | | | Co-authored-by: sunmy2019 <59365878+sunmy2019@users.noreply.github.com> Co-authored-by: Ken Jin <kenjin@python.org> Co-authored-by: Pablo Galindo <pablogsal@gmail.com>
* gh-103824: fix use-after-free error in Parser/tokenizer.c (#103993)chgnrdv2023-05-011-0/+4
|
* gh-103656: Transfer f-string buffers to parser to avoid use-after-free ↵Lysandros Nikolaou2023-04-271-2/+32
| | | | | (GH-103896) Co-authored-by: Pablo Galindo <pablogsal@gmail.com>
* gh-103718: Correctly set f-string buffers in all cases (GH-103815)Lysandros Nikolaou2023-04-251-8/+6
| | | | | | Turns out we always need to remember/restore fstring buffers in all of the stack of tokenizer modes, cause they might change to `TOK_REGULAR_MODE` and have newlines inside the braces (which is when we need to reallocate the buffer and restore the fstring ones).
* GH-103727: Avoid advancing tokenizer too far in f-string mode (GH-103775)Lysandros Nikolaou2023-04-241-8/+10
|
* GH-103718: Correctly cache and restore f-string buffers when needed (GH-103719)Lysandros Nikolaou2023-04-231-11/+27
|
* gh-102856: Clean some of the PEP 701 tokenizer implementation (#103634)Pablo Galindo Salgado2023-04-191-71/+65
|
* gh-102856: Initial implementation of PEP 701 (#102855)Pablo Galindo Salgado2023-04-191-6/+483
| | | | | | Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com> Co-authored-by: Batuhan Taskaya <isidentical@gmail.com> Co-authored-by: Marta Gómez Macías <mgmacias@google.com> Co-authored-by: sunmy2019 <59365878+sunmy2019@users.noreply.github.com>
* gh-99891: Fix infinite recursion in the tokenizer when showing warnings ↵Pablo Galindo Salgado2022-11-301-0/+8
| | | | | (GH-99893) Automerge-Triggered-By: GH:pablogsal
* gh-99581: Fix a buffer overflow in the tokenizer when copying lines that ↵Pablo Galindo Salgado2022-11-201-1/+6
| | | | fill the available buffer (#99605)
* gh-99300: Use Py_NewRef() in Parser/ directory (#99330)Victor Stinner2022-11-101-2/+1
| | | | Replace Py_INCREF() with Py_NewRef() in C files of the Parser/ directory and in the PEG generator.
* gh-97997: Add col_offset field to tokenizer and use that for AST nodes (#98000)Lysandros Nikolaou2022-10-071-11/+41
|
* gh-97973: Return all necessary information from the tokenizer (GH-97984)Lysandros Nikolaou2022-10-061-103/+117
| | | | | Right now, the tokenizer only returns type and two pointers to the start and end of the token. This PR modifies the tokenizer to return the type and set all of the necessary information, so that the parser does not have to this.
* gh-96670: Raise SyntaxError when parsing NULL bytes (#97594)Pablo Galindo Salgado2022-09-271-4/+15
|
* gh-96678: Fix UB of null pointer arithmetic (GH-96782)Matthias Görgens2022-09-131-1/+1
| | | Automerge-Triggered-By: GH:pablogsal
* gh-96268: Fix loading invalid UTF-8 (#96270)Michael Droettboom2022-09-071-13/+45
| | | | | This makes tokenizer.c:valid_utf8 match stringlib/codecs.h:decode_utf8. It also fixes an off-by-one error introduced in 3.10 for the line number when the tokenizer reports bad UTF8.
* gh-96611: Fix error message for invalid UTF-8 in mid-multiline string (#96623)Michael Droettboom2022-09-061-0/+2
|
* gh-94360: Fix a tokenizer crash when reading encoded files with syntax ↵Pablo Galindo Salgado2022-07-051-1/+9
| | | | | | | | | | | errors from stdin (#94386) * gh-94360: Fix a tokenizer crash when reading encoded files with syntax errors from stdin Signed-off-by: Pablo Galindo <pablogsal@gmail.com> * nitty nit Co-authored-by: Łukasz Langa <lukasz@langa.pl>
* gh-93741: Add private C API _PyImport_GetModuleAttrString() (GH-93742)Serhiy Storchaka2022-06-141-5/+5
| | | | | | It combines PyImport_ImportModule() and PyObject_GetAttrString() and saves 4-6 lines of code on every use. Add also _PyImport_GetModuleAttr() which takes Python strings as arguments.
* GH-93207: Remove HAVE_STDARG_PROTOTYPES configure check for stdarg.h (#93215)Kumar Aditya2022-05-271-12/+0
|
* gh-93103: Parser uses PyConfig.parser_debug instead of Py_DebugFlag (#93106)Victor Stinner2022-05-241-1/+4
| | | | | | | * Replace deprecated Py_DebugFlag with PyConfig.parser_debug in the parser. * Add Parser.debug member. * Add tok_state.debug member. * Py_FrozenMain(): Replace Py_VerboseFlag with PyConfig.verbose.
* gh-92651: Remove the Include/token.h header file (#92652)Victor Stinner2022-05-111-3/+3
| | | | | | | | | | | | | | | Remove the token.h header file. There was never any public tokenizer C API. The token.h header file was only designed to be used by Python internals. Move Include/token.h to Include/internal/pycore_token.h. Including this header file now requires that the Py_BUILD_CORE macro is defined. It no longer checks for the Py_LIMITED_API macro. Rename functions: * PyToken_OneChar() => _PyToken_OneChar() * PyToken_TwoChars() => _PyToken_TwoChars() * PyToken_ThreeChars() => _PyToken_ThreeChars()
* gh-87999: Change warning type for numeric literal followed by keyword (GH-91980)Serhiy Storchaka2022-04-271-4/+6
| | | | | The warning emitted by the Python parser for a numeric literal immediately followed by keyword has been changed from deprecation warning to syntax warning.