Skip to content

gh-153569: simplify tokenizer and formatted-string state - #156484

Draft
pablogsal wants to merge 19 commits into
python:mainfrom
pablogsal:gh-153569-tokenizer-validation-tools-clean
Draft

gh-153569: simplify tokenizer and formatted-string state#156484
pablogsal wants to merge 19 commits into
python:mainfrom
pablogsal:gh-153569-tokenizer-validation-tools-clean

Conversation

@pablogsal

@pablogsal pablogsal commented Aug 27, 2026

Copy link
Copy Markdown
Member

The tokenizer kept several copies of the same positions and a fixed 150-entry mode array in every tokenizer. F- and t-string state now lives in a small stack containing only active formatted strings, and an empty stack means normal tokenization. Expressions and comments use source spans, bracket depth comes from the existing delimiter stack, and f-, t-, and raw strings share the same prefix and quote handling. This removes the dummy regular mode, duplicated depth fields, pointer repair code, and the extra stack that comments used to need. It also keeps expression text correct around comments, nested strings, and format specs.

Prepared input is normalized once and stored in one owned buffer. The reader owns buffer growth and streamed formatted strings stay in the active window, so the old cursor and buffer APIs, source aliases, per-line tables, reader counters, and parser-side tokenizer state can go away. This follows #156482 as the next part of #153569.

Comment thread Modules/_xxtestfuzz/fuzzer.c Outdated
}

static int
fuzz_tokenizer(const char *data, size_t size)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move it to python/library-fuzzers (yes, name is a little misleading). We aren't adding anything to _xxtestfuzz as we are planning to move it all to the repository.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pablogsal a little ping FYI, since I see you're working on this.

@pablogsal pablogsal reopened this Aug 27, 2026
@pablogsal

Copy link
Copy Markdown
Member Author

Do not review until #156482 lands.

@pablogsal
pablogsal force-pushed the gh-153569-tokenizer-validation-tools-clean branch from 5505010 to 68400fb Compare August 28, 2026 18:40
@pablogsal pablogsal changed the title gh-153569: add tokenizer validation tools gh-153569: move f-string state to source spans Aug 28, 2026
@pablogsal
pablogsal force-pushed the gh-153569-tokenizer-validation-tools-clean branch from 68400fb to 7432a67 Compare August 28, 2026 19:35
@pablogsal
pablogsal force-pushed the gh-153569-tokenizer-validation-tools-clean branch from bb197e7 to 962c0c5 Compare August 28, 2026 22:44
@pablogsal
pablogsal force-pushed the gh-153569-tokenizer-validation-tools-clean branch from 962c0c5 to eae3e33 Compare August 28, 2026 23:48
@pablogsal pablogsal changed the title gh-153569: move f-string state to source spans gh-153569: simplify tokenizer state Aug 29, 2026
@pablogsal pablogsal changed the title gh-153569: simplify tokenizer state gh-153569: simplify tokenizer state and source storage Aug 29, 2026
@pablogsal pablogsal changed the title gh-153569: simplify tokenizer state and source storage gh-153569: simplify tokenizer and formatted-string state Aug 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants