Ideas: making it easier to extend Python’s syntax

ideas current working version: 0.3.6; Code on Github

ideas logo

You have an Excellent Idea ® to change the Python syntax and want to find a way to include your Excellent Idea ® in your Python programs. According to Python Developers Guide, this might be doable if you are willing to follow “a few steps” including:

  1. Get a copy of the CPython’s code repository and all the required compilers for your platform.

  2. Modify the grammar file to add rules for the new syntax.

  3. Modify the AST generation code; this requires a knowledge of C

  4. Compile the AST into bytecode

  5. Recompile the modified Python interpreter

This … can be a rather daunting task. It might get a bit easier if you grab a copy of the currently unpublished book by Anthony Shaw, CPython Internals and read it from cover to cover, but it will still remain a major task. Furthermore, it would not be easy to share your work with others so that they can try it out.

However, there is a simpler way: it is possible to run code with a modified syntax using import hooks. [1]

Important

This entire project is meant as enabling easy experiments with changes to Python’s normal syntax. Some (most?) of the examples are definitely not reliable enough to be included in code used by anyone other than yourself.