python-peps/pep-0306.txt

99 lines
3.0 KiB
Plaintext
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

PEP: 306
Title: How to Change Python's Grammar
Version: $Revision$
Last-Modified: $Date$
Author: Michael Hudson <mwh@python.net>, Jack Diederich <jackdied@gmail.com>, Nick Coghlan <ncoghlan@gmail.com>
Status: Active
Type: Informational
Content-Type: text/plain
Created: 29-Jan-2003
Post-History: 30-Jan-2003
Abstract
There's more to changing Python's grammar than editing
Grammar/Grammar and Python/compile.c. This PEP aims to be a
checklist of places that must also be fixed.
It is probably incomplete. If you see omissions, just add them if
you can -- you are not going to offend the author's sense of
ownership. Otherwise submit a bug or patch and assign it to mwh.
This PEP is not intended to be an instruction manual on Python
grammar hacking, for several reasons.
Rationale
People are getting this wrong all the time; it took well over a
year before someone noticed[1] that adding the floor division
operator (//) broke the parser module.
Checklist
__ Grammar/Grammar: OK, you'd probably worked this one out :)
__ Parser/Python.asdl may need changes to match the Grammar.
Use Parser/asdl_c.py to regenerate Include/Python-ast.h
__ Python/Python-ast.c may need changes to create the AST
objects involved with the Grammar change. Lib/compiler/ast.py
will need matching changes to the pure-python AST objects.
__ Parser/pgen needs to be rerun to regenerate Include/graminit.h
and Python/graminit.c
__ Python/symbtable.c: This handles the symbol collection pass
that happens immediately before the compilation pass
__ Python/compile.c: You will need to create or modify the
compiler_* functions for your productions.
__ You may need to regenerate Lib/symbol.py and/or Lib/token.py
and/or Lib/keyword.py
__ The parser module. Add some of your new syntax to test_parser,
bang on parsermodule.c until it passes.
__ The compiler package. A good test is to compile the standard
library and test suite with the compiler package and then check
it runs. You did add some of your new syntax to the test
suite, didn't you?
__ If you've gone so far as to change the token structure of
Python, then the Lib/tokenizer.py library module will need to
be changed.
__ Certain changes may require tweaks to the library module
pyclbr.
__ Documentation must be written!
__ After everything's been checked in, you're likely to see a new
change to Python/Python-ast.c. This is because this
(generated) file contains the SVN version of the source from
which it was generated. There's no way to avoid this; you just
have to submit this file separately.
References
[1] SF Bug #676521, parser module validation failure
http://www.python.org/sf/676521
Copyright
This document has been placed in the public domain.
Local Variables:
mode: indented-text
indent-tabs-mode: nil
sentence-end-double-space: t
fill-column: 70
End: