Skip to content

gh-153569: consolidate tokenizer source and lexer state - #156484

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

gh-153569: consolidate tokenizer source and lexer state#156484
pablogsal wants to merge 7 commits into
python:mainfrom
pablogsal:gh-153569-tokenizer-validation-tools-clean

Conversation

@pablogsal

@pablogsal pablogsal commented Aug 27, 2026

Copy link
Copy Markdown
Member

Consolidate tokenizer source and lexer state after #156482.

Replace the generic lexer mode array with active formatted-string frames that hold expression and comment spans. Carry raw-string context with emitted and cached parser tokens, so interpreting a token does not depend on the current frame. Keep field entry, punctuation, closing, and debug-expression transitions together in the string scanner, with explicit dispatch over its three modes.

Group indentation and logical-line state in a dedicated layout module, with operations for leading whitespace, continuations, pending indent/dedent tokens, and newline classification. Keep normal and alternate indentation columns together in each stack entry.

Give the reader ownership of input-specific state and source-retention decisions. Derive locations and failure status from existing scanner state, and keep buffer relocation inside the reader instead of a separate lexer buffer layer.

#156654 builds on this to replace the remaining scanner pointers and complete the opaque consumer API.

Comment thread Modules/_xxtestfuzz/fuzzer.c Outdated
@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 3 times, most recently 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
@pablogsal
pablogsal force-pushed the gh-153569-tokenizer-validation-tools-clean branch from 73741c4 to 3ce81ac Compare August 30, 2026 11:12
@pablogsal pablogsal changed the title gh-153569: simplify tokenizer and formatted-string state gh-153569: store tokenizer state as source spans Aug 30, 2026
@pablogsal
pablogsal force-pushed the gh-153569-tokenizer-validation-tools-clean branch 2 times, most recently from 6e223e0 to 64893b4 Compare August 30, 2026 11:26
@pablogsal pablogsal changed the title gh-153569: store tokenizer state as source spans gh-153569: remove unused tokenizer cursor support Aug 30, 2026
@pablogsal
pablogsal force-pushed the gh-153569-tokenizer-validation-tools-clean branch from 64893b4 to bdeeeb6 Compare August 30, 2026 13:16
@pablogsal pablogsal changed the title gh-153569: remove unused tokenizer cursor support gh-153569: remove the unused tokenizer cursor and line index Aug 30, 2026
@pablogsal
pablogsal force-pushed the gh-153569-tokenizer-validation-tools-clean branch 3 times, most recently from 9318772 to 056e86e Compare September 5, 2026 17:46
@pablogsal
pablogsal force-pushed the gh-153569-tokenizer-validation-tools-clean branch 3 times, most recently from da9dfb7 to 1a1a3c7 Compare September 6, 2026 20:24
@pablogsal
pablogsal marked this pull request as ready for review September 6, 2026 20:31
@pablogsal
pablogsal force-pushed the gh-153569-tokenizer-validation-tools-clean branch from 1a1a3c7 to 3ef307f Compare September 6, 2026 20:57
@pablogsal pablogsal changed the title gh-153569: remove the unused tokenizer cursor and line index gh-153569: consolidate tokenizer state around source spans Sep 6, 2026
Formatted-string expressions and comments can outlive the buffer window where
scanning began. Pointer boundaries require buffer relocation to repair tokenizer
state.

Record logical source ranges instead. Retain the active input window while a
formatted string is open, give each mode ownership of its comment spans, and
materialize text through shared span views.
@pablogsal
pablogsal force-pushed the gh-153569-tokenizer-validation-tools-clean branch from 3ef307f to 177eca5 Compare September 6, 2026 21:37
@pablogsal pablogsal changed the title gh-153569: consolidate tokenizer state around source spans gh-153569: consolidate tokenizer source and lexer state Sep 6, 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