@@ -7,52 +7,44 @@ Abstract
77--------
88
99There'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.
1211
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 ``.)
2618
2719
2820Checklist
2921---------
3022
3123Note: sometimes things mysteriously don't work. Before giving up, try ``make clean ``.
3224
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 ``).
3628
3729* :file: `Grammar/Tokens ` is a place for adding new token types. After
3830 changing it, run ``make regen-token `` to regenerate :file: `Include/token.h `,
3931 :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 ``.
4234
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
4436 regen-ast `` to regenerate :file: `Include/Python-ast.h ` and :file: `Python/Python-ast.c `.
4537
4638* :file: `Parser/tokenizer.c ` contains the tokenization code. This is where you would
4739 add a new type of comment or string literal, for example.
4840
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.
5143
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 `).
5346
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.
5648
5749* Add some usage of your new syntax to ``test_grammar.py ``.
5850
0 commit comments