Skip to content

Commit 30d5205

Browse files
encukouAA-Turner
andauthored
pythongh-116666: Add "token" glossary term (pythonGH-130888)
Add glossary entry for `token`, and link to it. Avoid talking about tokens in the SyntaxError intro (errors.rst); at this point tokenization is too much of a technical detail. (Even to an advanced reader, the fact that a *single* token is highlighted isn't too relevant. Also, we don't need to guarantee that it's a single token.) Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
1 parent 863d54c commit 30d5205

File tree

4 files changed

+28
-11
lines changed

4 files changed

+28
-11
lines changed

Doc/glossary.rst

+15
Original file line numberDiff line numberDiff line change
@@ -800,6 +800,10 @@ Glossary
800800
thread removes *key* from *mapping* after the test, but before the lookup.
801801
This issue can be solved with locks or by using the EAFP approach.
802802

803+
lexical analyzer
804+
805+
Formal name for the *tokenizer*; see :term:`token`.
806+
803807
list
804808
A built-in Python :term:`sequence`. Despite its name it is more akin
805809
to an array in other languages than to a linked list since access to
@@ -1291,6 +1295,17 @@ Glossary
12911295
See also :term:`binary file` for a file object able to read and write
12921296
:term:`bytes-like objects <bytes-like object>`.
12931297

1298+
token
1299+
1300+
A small unit of source code, generated by the
1301+
:ref:`lexical analyzer <lexical>` (also called the *tokenizer*).
1302+
Names, numbers, strings, operators,
1303+
newlines and similar are represented by tokens.
1304+
1305+
The :mod:`tokenize` module exposes Python's lexical analyzer.
1306+
The :mod:`token` module contains information on the various types
1307+
of tokens.
1308+
12941309
triple-quoted string
12951310
A string which is bound by three instances of either a quotation mark
12961311
(") or an apostrophe ('). While they don't provide any functionality

Doc/reference/lexical_analysis.rst

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ Lexical analysis
88
.. index:: lexical analysis, parser, token
99

1010
A Python program is read by a *parser*. Input to the parser is a stream of
11-
*tokens*, generated by the *lexical analyzer*. This chapter describes how the
12-
lexical analyzer breaks a file into tokens.
11+
:term:`tokens <token>`, generated by the *lexical analyzer* (also known as
12+
the *tokenizer*).
13+
This chapter describes how the lexical analyzer breaks a file into tokens.
1314

1415
Python reads program text as Unicode code points; the encoding of a source file
1516
can be given by an encoding declaration and defaults to UTF-8, see :pep:`3120`

Doc/tutorial/errors.rst

+6-5
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,12 @@ complaint you get while you are still learning Python::
2424
SyntaxError: invalid syntax
2525

2626
The parser repeats the offending line and displays little arrows pointing
27-
at the token in the line where the error was detected. The error may be
28-
caused by the absence of a token *before* the indicated token. In the
29-
example, the error is detected at the function :func:`print`, since a colon
30-
(``':'``) is missing before it. File name and line number are printed so you
31-
know where to look in case the input came from a script.
27+
at the place where the error was detected. Note that this is not always the
28+
place that needs to be fixed. In the example, the error is detected at the
29+
function :func:`print`, since a colon (``':'``) is missing just before it.
30+
31+
The file name (``<stdin>`` in our example) and line number are printed so you
32+
know where to look in case the input came from a file.
3233

3334

3435
.. _tut-exceptions:

Doc/tutorial/interactive.rst

+4-4
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ Alternatives to the Interactive Interpreter
3737

3838
This facility is an enormous step forward compared to earlier versions of the
3939
interpreter; however, some wishes are left: It would be nice if the proper
40-
indentation were suggested on continuation lines (the parser knows if an indent
41-
token is required next). The completion mechanism might use the interpreter's
42-
symbol table. A command to check (or even suggest) matching parentheses,
43-
quotes, etc., would also be useful.
40+
indentation were suggested on continuation lines (the parser knows if an
41+
:data:`~token.INDENT` token is required next). The completion mechanism might
42+
use the interpreter's symbol table. A command to check (or even suggest)
43+
matching parentheses, quotes, etc., would also be useful.
4444

4545
One alternative enhanced interactive interpreter that has been around for quite
4646
some time is IPython_, which features tab completion, object exploration and

0 commit comments

Comments
 (0)