Documentation
¶
Overview ¶
Package tokenize is the Go port of cpython/Python/Python-tokenize.c. The C file is the Python-visible wrapper around the parser's lexer; it exposes the TokenizerIter class that `tokenize.tokenize()` in the stdlib delegates to.
The token kind constants live in the sibling token package, mirroring CPython's split between Include/internal/pycore_token.h (consumed by the C tokenizer) and Lib/token.py (re-exported by Lib/tokenize.py).
CPython: Python/Python-tokenize.c
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Iter ¶
type Iter struct {
// contains filtered or unexported fields
}
Iter is the Go-side TokenizerIter equivalent. Next advances the underlying lexer state by one token; EOF is reported as io.EOF.
CPython: Python/Python-tokenize.c tokenizeriterobject
func New ¶
New constructs an Iter over a source string. extraTokens enables the COMMENT / NL / ENCODING / NEWLINE-at-EOF tokens that the stdlib filters out by default.
CPython: Python/Python-tokenize.c tokenizeriter_new (source path)
func NewReadline ¶
NewReadline constructs an Iter that pulls source lines from a readline-shaped callable, the same shape io.TextIO.readline has on the Python side. The callback returns one line of source (including any trailing newline) or io.EOF at end of stream.
CPython: Python/Python-tokenize.c tokenizeriter_new (readline path)