@@ -7,52 +7,44 @@ Abstract
7
7
--------
8
8
9
9
There's more to changing Python's grammar than editing
10
- :file: `Grammar/Grammar `. This document aims to be a
11
- checklist of places that must also be fixed.
10
+ :file: `Grammar/python.gram `. Here's a checklist.
12
11
13
- It is probably incomplete. If you see omissions, submit a bug or patch.
14
-
15
- This document is not intended to be an instruction manual on Python
16
- grammar hacking, for several reasons.
17
-
18
-
19
- Rationale
20
- ---------
21
-
22
- People are getting this wrong all the time; it took well over a
23
- year before someone `noticed <https://bugs.python.org/issue676521 >`_
24
- that adding the floor division
25
- operator (``// ``) broke the :mod: `parser ` module.
12
+ NOTE: These instructions are for Python 3.9 and beyond. Earlier
13
+ versions use a different parser technology. You probably shouldn't
14
+ try to change the grammar of earlier Python versions, but if you
15
+ really want to, use GitHub to track down the earlier version of this
16
+ file in the devguide. (Python 3.9 itself actually supports both
17
+ parsers; the old parser can be invoked by passing ``-X oldparser ``.)
26
18
27
19
28
20
Checklist
29
21
---------
30
22
31
23
Note: sometimes things mysteriously don't work. Before giving up, try ``make clean ``.
32
24
33
- * :file: `Grammar/Grammar `: OK, you'd probably worked this one out. :-) After changing
34
- it, run ``make regen-grammar ``, to regenerate :file: `Include/graminit.h ` and
35
- :file: ` Python/graminit.c `. (This runs Python's parser generator, ``Python/pgen ``).
25
+ * :file: `Grammar/python.gram `: The grammar, with actions that build AST nodes. After changing
26
+ it, run ``make regen-pegen ``, to regenerate :file: `Parser/parser.c `.
27
+ (This runs Python's parser generator, ``Tools/peg_generator ``).
36
28
37
29
* :file: `Grammar/Tokens ` is a place for adding new token types. After
38
30
changing it, run ``make regen-token `` to regenerate :file: `Include/token.h `,
39
31
:file: `Parser/token.c `, :file: `Lib/token.py ` and
40
- :file: `Doc/library/token-list.inc `. If you change both ``Grammar `` and ``Tokens ``,
41
- run ``make regen-tokens `` before ``make regen-grammar ``.
32
+ :file: `Doc/library/token-list.inc `. If you change both ``python.gram `` and ``Tokens ``,
33
+ run ``make regen-token `` before ``make regen-pegen ``.
42
34
43
- * :file: `Parser/Python.asdl ` may need changes to match the Grammar . Then run ``make
35
+ * :file: `Parser/Python.asdl ` may need changes to match the grammar . Then run ``make
44
36
regen-ast `` to regenerate :file: `Include/Python-ast.h ` and :file: `Python/Python-ast.c `.
45
37
46
38
* :file: `Parser/tokenizer.c ` contains the tokenization code. This is where you would
47
39
add a new type of comment or string literal, for example.
48
40
49
- * :file: `Python/ast.c ` will need changes to create the AST objects involved with the
50
- Grammar change.
41
+ * :file: `Python/ast.c ` will need changes to validate AST objects involved with the
42
+ grammar change.
51
43
52
- * The :doc: `compiler ` has its own page.
44
+ * :file: `Python/ast_unparse.c ` will need changes to unparse AST objects involved with the
45
+ grammar change ("unparsing" is used to turn annotations into strings per :pep: `563 `).
53
46
54
- * The :mod: `parser ` module. Add some of your new syntax to ``test_parser ``,
55
- bang on :file: `Modules/parsermodule.c ` until it passes.
47
+ * The :doc: `compiler ` has its own page.
56
48
57
49
* Add some usage of your new syntax to ``test_grammar.py ``.
58
50
0 commit comments