32.5. token β€” Constants used with Python parse treesΒΆ

Source code: Lib/token.py


This module provides constants which represent the numeric values of leaf nodes of the parse tree (terminal tokens). Refer to the file Grammar/Grammar in the Python distribution for the definitions of the names in the context of the language grammar. The specific numeric values which the names map to may change between Python versions.

The module also provides a mapping from numeric codes to names and some functions. The functions mirror definitions in the Python C header files.

token.tok_nameΒΆ

Dictionary mapping the numeric values of the constants defined in this module back to name strings, allowing more human-readable representation of parse trees to be generated.

token.ISTERMINAL(x)ΒΆ

Return true for terminal token values.

token.ISNONTERMINAL(x)ΒΆ

Return true for non-terminal token values.

token.ISEOF(x)ΒΆ

Return true if x is the marker indicating the end of input.

The token constants are:

token.ENDMARKERΒΆ
token.NAMEΒΆ
token.NUMBERΒΆ
token.STRINGΒΆ
token.NEWLINEΒΆ
token.INDENTΒΆ
token.DEDENTΒΆ
token.LPARΒΆ
token.RPARΒΆ
token.LSQBΒΆ
token.RSQBΒΆ
token.COLONΒΆ
token.COMMAΒΆ
token.SEMIΒΆ
token.PLUSΒΆ
token.MINUSΒΆ
token.STARΒΆ
token.SLASHΒΆ
token.VBARΒΆ
token.AMPERΒΆ
token.LESSΒΆ
token.GREATERΒΆ
token.EQUALΒΆ
token.DOTΒΆ
token.PERCENTΒΆ
token.LBRACEΒΆ
token.RBRACEΒΆ
token.EQEQUALΒΆ
token.NOTEQUALΒΆ
token.LESSEQUALΒΆ
token.GREATEREQUALΒΆ
token.TILDEΒΆ
token.CIRCUMFLEXΒΆ
token.LEFTSHIFTΒΆ
token.RIGHTSHIFTΒΆ
token.DOUBLESTARΒΆ
token.PLUSEQUALΒΆ
token.MINEQUALΒΆ
token.STAREQUALΒΆ
token.SLASHEQUALΒΆ
token.PERCENTEQUALΒΆ
token.AMPEREQUALΒΆ
token.VBAREQUALΒΆ
token.CIRCUMFLEXEQUALΒΆ
token.LEFTSHIFTEQUALΒΆ
token.RIGHTSHIFTEQUALΒΆ
token.DOUBLESTAREQUALΒΆ
token.DOUBLESLASHΒΆ
token.DOUBLESLASHEQUALΒΆ
token.ATΒΆ
token.ATEQUALΒΆ
token.RARROWΒΆ
token.ELLIPSISΒΆ
token.OPΒΆ
token.AWAITΒΆ
token.ASYNCΒΆ
token.ERRORTOKENΒΆ
token.N_TOKENSΒΆ
token.NT_OFFSETΒΆ

Changed in version 3.5: Added AWAIT and ASYNC tokens. Starting with Python 3.7, β€œasync” and β€œawait” will be tokenized as NAME tokens, and AWAIT and ASYNC will be removed.