1
:mod:`token` --- Constants used with Python parse trees
2
=======================================================
5
:synopsis: Constants representing terminal nodes of the parse tree.
6
.. sectionauthor:: Fred L. Drake, Jr. <fdrake@acm.org>
8
**Source code:** :source:`Lib/token.py`
12
This module provides constants which represent the numeric values of leaf nodes
13
of the parse tree (terminal tokens). Refer to the file :file:`Grammar/Grammar`
14
in the Python distribution for the definitions of the names in the context of
15
the language grammar. The specific numeric values which the names map to may
16
change between Python versions.
18
The module also provides a mapping from numeric codes to names and some
19
functions. The functions mirror definitions in the Python C header files.
24
Dictionary mapping the numeric values of the constants defined in this module
25
back to name strings, allowing more human-readable representation of parse trees
29
.. function:: ISTERMINAL(x)
31
Return true for terminal token values.
34
.. function:: ISNONTERMINAL(x)
36
Return true for non-terminal token values.
39
.. function:: ISEOF(x)
41
Return true if *x* is the marker indicating the end of input.
44
The token constants are:
106
.. versionchanged:: 3.5
107
Added :data:`AWAIT` and :data:`ASYNC` tokens. Starting with
108
Python 3.7, "async" and "await" will be tokenized as :data:`NAME`
109
tokens, and :data:`AWAIT` and :data:`ASYNC` will be removed.
114
The second example for the :mod:`parser` module shows how to use the
115
:mod:`symbol` module.