blob: effb7113230e742fb0ceb52c349e47ba57f80fbf [file] [log] [blame]
Georg Brandl116aa622007-08-15 14:28:22 +00001:mod:`token` --- Constants used with Python parse trees
2=======================================================
3
4.. module:: token
5 :synopsis: Constants representing terminal nodes of the parse tree.
Terry Jan Reedyfa089b92016-06-11 15:02:54 -04006
Georg Brandl116aa622007-08-15 14:28:22 +00007.. sectionauthor:: Fred L. Drake, Jr. <fdrake@acm.org>
8
Raymond Hettingera1993682011-01-27 01:20:32 +00009**Source code:** :source:`Lib/token.py`
10
11--------------
Georg Brandl116aa622007-08-15 14:28:22 +000012
13This module provides constants which represent the numeric values of leaf nodes
14of the parse tree (terminal tokens). Refer to the file :file:`Grammar/Grammar`
15in the Python distribution for the definitions of the names in the context of
16the language grammar. The specific numeric values which the names map to may
17change between Python versions.
18
Georg Brandleec2d762010-10-17 09:46:11 +000019The module also provides a mapping from numeric codes to names and some
20functions. The functions mirror definitions in the Python C header files.
Georg Brandl116aa622007-08-15 14:28:22 +000021
22
23.. data:: tok_name
24
25 Dictionary mapping the numeric values of the constants defined in this module
26 back to name strings, allowing more human-readable representation of parse trees
27 to be generated.
28
29
30.. function:: ISTERMINAL(x)
31
32 Return true for terminal token values.
33
34
35.. function:: ISNONTERMINAL(x)
36
37 Return true for non-terminal token values.
38
39
40.. function:: ISEOF(x)
41
42 Return true if *x* is the marker indicating the end of input.
43
44
Georg Brandleec2d762010-10-17 09:46:11 +000045The token constants are:
46
47.. data:: ENDMARKER
48 NAME
49 NUMBER
50 STRING
51 NEWLINE
52 INDENT
53 DEDENT
54 LPAR
55 RPAR
56 LSQB
57 RSQB
58 COLON
59 COMMA
60 SEMI
61 PLUS
62 MINUS
63 STAR
64 SLASH
65 VBAR
66 AMPER
67 LESS
68 GREATER
69 EQUAL
70 DOT
71 PERCENT
Georg Brandleec2d762010-10-17 09:46:11 +000072 LBRACE
73 RBRACE
74 EQEQUAL
75 NOTEQUAL
76 LESSEQUAL
77 GREATEREQUAL
78 TILDE
79 CIRCUMFLEX
80 LEFTSHIFT
81 RIGHTSHIFT
82 DOUBLESTAR
83 PLUSEQUAL
84 MINEQUAL
85 STAREQUAL
86 SLASHEQUAL
87 PERCENTEQUAL
88 AMPEREQUAL
89 VBAREQUAL
90 CIRCUMFLEXEQUAL
91 LEFTSHIFTEQUAL
92 RIGHTSHIFTEQUAL
93 DOUBLESTAREQUAL
94 DOUBLESLASH
95 DOUBLESLASHEQUAL
96 AT
Benjamin Petersond51374e2014-04-09 23:55:56 -040097 ATEQUAL
Meador Ingeac007ba2011-12-23 22:30:16 -060098 RARROW
99 ELLIPSIS
Georg Brandleec2d762010-10-17 09:46:11 +0000100 OP
Yury Selivanov3dc74bf2015-12-17 18:26:41 -0500101 AWAIT
102 ASYNC
Georg Brandleec2d762010-10-17 09:46:11 +0000103 ERRORTOKEN
104 N_TOKENS
105 NT_OFFSET
106
Yury Selivanov3dc74bf2015-12-17 18:26:41 -0500107 .. versionchanged:: 3.5
108 Added :data:`AWAIT` and :data:`ASYNC` tokens. Starting with
109 Python 3.7, "async" and "await" will be tokenized as :data:`NAME`
110 tokens, and :data:`AWAIT` and :data:`ASYNC` will be removed.