token --- Constantes utilisées avec les arbres d'analyse Python (parse trees)

Code source : 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/Tokens 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.

Le module fournit également une correspondance entre les codes numériques et les noms et certaines fonctions. Les fonctions reflètent les définitions des fichiers d'en-tête C de Python.

token.tok_name

Dictionnaire faisant correspondre les valeurs numériques des constantes définies dans ce module à leurs noms, permettant de générer une représentation plus humaine des arbres syntaxiques.

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.

Les constantes associées aux jetons sont :

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.EXCLAMATION

Token value for "!".

token.OP
token.AWAIT
token.ASYNC
token.TYPE_IGNORE
token.TYPE_COMMENT
token.SOFT_KEYWORD
token.FSTRING_START
token.FSTRING_MIDDLE
token.FSTRING_END
token.COMMENT
token.NL
token.ERRORTOKEN
token.N_TOKENS
token.NT_OFFSET

Les types de jetons suivants ne sont pas utilisés par l'analyseur lexical C mais sont requis par le module tokenize.

token.COMMENT

Valeur du jeton utilisée pour indiquer un commentaire.

token.NL

Valeur du jeton utilisée pour indiquer un retour à la ligne non terminal. Le jeton NEWLINE indique la fin d'une ligne logique de code Python; les jetons NL sont générés quand une ligne logique de code s'étend sur plusieurs lignes.

token.ENCODING

Valeur de jeton qui indique l'encodage utilisé pour décoder le fichier initial. Le premier jeton renvoyé par tokenize.tokenize() sera toujours un jeton ENCODING.

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.

Modifié dans la version 3.5: Ajout des jetons AWAIT et ASYNC.

Modifié dans la version 3.7: Ajout des jetons COMMENT, NL et ENCODING.

Modifié dans la version 3.7: Suppression des jetons AWAIT et ASYNC. async et await sont maintenant transformés en jetons NAME.

Modifié dans la 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).