上一话题

symtable — 访问编译器的符号表

下一话题
就业培训     下载中心     Wiki     联络
登录   注册

Log
  1. 首页
  2. Python 3.12.4
  3. 索引
  4. 模块
  5. 下一
  6. 上一
  7. Python 标准库
  8. Python 语言服务
  9. token — 用于 Python 剖析树的常量

token — 用于 Python 剖析树的常量 ¶

源代码: 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.

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 ) ¶

返回 True for terminal token values.

token. ISNONTERMINAL ( x ) ¶

返回 True for non-terminal token values.

token. ISEOF ( x ) ¶

返回 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. 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 ¶

The following token type values aren’t used by the C tokenizer but are needed for the tokenize 模块。

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 .

3.5 版改变: 添加 AWAIT and ASYNC tokens.

3.7 版改变: 添加 COMMENT , NL and ENCODING tokens.

3.7 版改变: 移除 AWAIT and ASYNC tokens. “async” and “await” are now tokenized as NAME tokens.

3.8 版改变: 添加 TYPE_COMMENT , TYPE_IGNORE , COLONEQUAL 。添加 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).

上一话题

symtable — 访问编译器的符号表

下一话题

keyword — 测试 Python 关键词

本页

  • 报告 Bug
  • 展示源

快速搜索

键入搜索术语或模块、类、函数名称。

  1. 首页
  2. Python 3.12.4
  3. 索引
  4. 模块
  5. 下一
  6. 上一
  7. Python 标准库
  8. Python 语言服务
  9. token — 用于 Python 剖析树的常量

版权所有  © 2014-2026 乐数软件    

工业和信息化部: 粤ICP备14079481号-1