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 value for "(".

token.RPARΒΆ

Token value for ")".

token.LSQBΒΆ

Token value for "[".

token.RSQBΒΆ

Token value for "]".

token.COLONΒΆ

Token value for ":".

token.COMMAΒΆ

Token value for ",".

token.SEMIΒΆ

Token value for ";".

token.PLUSΒΆ

Token value for "+".

token.MINUSΒΆ

Token value for "-".

token.STARΒΆ

Token value for "*".

token.SLASHΒΆ

Token value for "/".

token.VBARΒΆ

Token value for "|".

token.AMPERΒΆ

Token value for "&".

token.LESSΒΆ

Token value for "<".

token.GREATERΒΆ

Token value for ">".

token.EQUALΒΆ

Token value for "=".

token.DOTΒΆ

Token value for ".".

token.PERCENTΒΆ

Token value for "%".

token.LBRACEΒΆ

Token value for "{".

token.RBRACEΒΆ

Token value for "}".

token.EQEQUALΒΆ

Token value for "==".

token.NOTEQUALΒΆ

Token value for "!=".

token.LESSEQUALΒΆ

Token value for "<=".

token.GREATEREQUALΒΆ

Token value for ">=".

token.TILDEΒΆ

Token value for "~".

token.CIRCUMFLEXΒΆ

Token value for "^".

token.LEFTSHIFTΒΆ

Token value for "<<".

token.RIGHTSHIFTΒΆ

Token value for ">>".

token.DOUBLESTARΒΆ

Token value for "**".

token.PLUSEQUALΒΆ

Token value for "+=".

token.MINEQUALΒΆ

Token value for "-=".

token.STAREQUALΒΆ

Token value for "*=".

token.SLASHEQUALΒΆ

Token value for "/=".

token.PERCENTEQUALΒΆ

Token value for "%=".

token.AMPEREQUALΒΆ

Token value for "&=".

token.VBAREQUALΒΆ

Token value for "|=".

token.CIRCUMFLEXEQUALΒΆ

Token value for "^=".

token.LEFTSHIFTEQUALΒΆ

Token value for "<<=".

token.RIGHTSHIFTEQUALΒΆ

Token value for ">>=".

token.DOUBLESTAREQUALΒΆ

Token value for "**=".

token.DOUBLESLASHΒΆ

Token value for "//".

token.DOUBLESLASHEQUALΒΆ

Token value for "//=".

token.ATΒΆ

Token value for "@".

token.ATEQUALΒΆ

Token value for "@=".

token.RARROWΒΆ

Token value for "->".

token.ELLIPSISΒΆ

Token value for "...".

token.COLONEQUALΒΆ

Token value for ":=".

token.OPΒΆ
token.AWAITΒΆ
token.ASYNCΒΆ
token.TYPE_IGNOREΒΆ
token.TYPE_COMMENTΒΆ
token.ERRORTOKENΒΆ
token.N_TOKENSΒΆ
token.NT_OFFSETΒΆ

The following token type values aren’t used by the C tokenizer but are needed for the tokenize module.

token.COMMENTΒΆ

Token value used to indicate a comment.

token.NLΒΆ

Token value used to indicate a non-terminating newline. The NEWLINE token indicates the end of a logical line of Python code; NL tokens are generated when a logical line of code is continued over multiple physical lines.

token.ENCODINGΒΆ

Token value that indicates the encoding used to decode the source bytes into text. The first token returned by tokenize.tokenize() will always be an ENCODING token.

token.TYPE_COMMENT

Token value indicating that a type comment was recognized. Such tokens are only produced when ast.parse() is invoked with type_comments=True.

Changed in version 3.5: Added AWAIT and ASYNC tokens.

Changed in version 3.7: Added COMMENT, NL and ENCODING tokens.

Changed in version 3.7: Removed AWAIT and ASYNC tokens. β€œasync” and β€œawait” are now tokenized as NAME tokens.

Changed in version 3.8: Added TYPE_COMMENT, TYPE_IGNORE, COLONEQUAL. Added AWAIT and ASYNC tokens back (they’re needed to support parsing older Python versions for ast.parse() with feature_version set to 6 or lower).