This is a quick post about how you can hack the Python grammar and define your own constructs.
In this short tutorial we’ll be seeing how you can define your own words to replace the
pass statement in Python.
Here’s what you’ll need to do:
Start by cloning the CPython repository and installing the dev version of Python3
git clone https://github.com/python/cpython.git cd cpython ./configure make -j2 -s
Grammar/Grammar, and add to the
pass_stmtdirective as follows:
... pass_stmt: 'pass' | 'proceed' | 'anythingyouwant' ...
Regenerate the grammar by running:
Recompile the Python source code
make -j2 -s
Run the Python interpreter
./python.exe -X oldparser
Use the pass statement in your code and verify that it works, and feel proud!
def foo(): proceed foo()
That’s it! Pretty amazing isn’t it? 😃