| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 863d54c commit 30d5205
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -800,6 +800,10 @@ Glossary | |||
| 800 | 800 | thread removes *key* from *mapping* after the test, but before the lookup. | |
| 801 | 801 | This issue can be solved with locks or by using the EAFP approach. | |
| 802 | 802 | ||
| 803 | + lexical analyzer | ||
| 804 | + | ||
| 805 | + Formal name for the *tokenizer*; see :term:`token`. | ||
| 806 | + | ||
| 803 | 807 | list | |
| 804 | 808 | A built-in Python :term:`sequence`. Despite its name it is more akin | |
| 805 | 809 | to an array in other languages than to a linked list since access to | |
@@ -1291,6 +1295,17 @@ Glossary | |||
| 1291 | 1295 | See also :term:`binary file` for a file object able to read and write | |
| 1292 | 1296 | :term:`bytes-like objects <bytes-like object>`. | |
| 1293 | 1297 | ||
| 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 | + | ||
| 1294 | 1309 | triple-quoted string | |
| 1295 | 1310 | A string which is bound by three instances of either a quotation mark | |
| 1296 | 1311 | (") or an apostrophe ('). While they don't provide any functionality | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -8,8 +8,9 @@ Lexical analysis | |||
| 8 | 8 | .. index:: lexical analysis, parser, token | |
| 9 | 9 | ||
| 10 | 10 | 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. | ||
| 13 | 14 | ||
| 14 | 15 | Python reads program text as Unicode code points; the encoding of a source file | |
| 15 | 16 | can be given by an encoding declaration and defaults to UTF-8, see :pep:`3120` | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -24,11 +24,12 @@ complaint you get while you are still learning Python:: | |||
| 24 | 24 | SyntaxError: invalid syntax | |
| 25 | 25 | ||
| 26 | 26 | 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. | ||
| 32 | 33 | ||
| 33 | 34 | ||
| 34 | 35 | .. _tut-exceptions: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -37,10 +37,10 @@ Alternatives to the Interactive Interpreter | |||
| 37 | 37 | ||
| 38 | 38 | This facility is an enormous step forward compared to earlier versions of the | |
| 39 | 39 | 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. | ||
| 44 | 44 | ||
| 45 | 45 | One alternative enhanced interactive interpreter that has been around for quite | |
| 46 | 46 | some time is IPython_, which features tab completion, object exploration and | |
| Back | FazBrowse Home | New Git URL |
0 commit comments