
Ask HN: Examples of meta programming or AST-hacking in Python? - true_religion
I&#x27;ve found a few promising examples of AST-hacking within Python, but I&#x27;d like to know if anyone has some more.<p>Here&#x27;s what I&#x27;ve found:<p>http:&#x2F;&#x2F;blaag.haard.se&#x2F;Using-the-AST-to-hack-constants-into-Python&#x2F;<p>http:&#x2F;&#x2F;hackflow.com&#x2F;blog&#x2F;2015&#x2F;03&#x2F;29&#x2F;metaprogramming-beyond-decency&#x2F;<p>I&#x27;d also be interested in just seeing people implementing domain specific languages in Python, using Pyparsing or other techniques.
======
gjenks
I wrote a Python module called PyPatt that implements Pythonic Pattern
Matching as you'd find in functional languages. There's both a function-based
and macro-based version. The macro version is deprecated but was used for a
while.

Docs: [http://www.grantjenks.com/docs/pypatt-python-pattern-
matchin...](http://www.grantjenks.com/docs/pypatt-python-pattern-
matching/macro.html) Source:
[https://github.com/grantjenks/pypatt_python_pattern_matching...](https://github.com/grantjenks/pypatt_python_pattern_matching/blob/master/pypatt/macro.py)

------
dalke
Before the new AST module was added, I wrote
[http://dalkescientific.com/Python/python4ply-
tutorial.html](http://dalkescientific.com/Python/python4ply-tutorial.html) ,
[http://www.dalkescientific.com/writings/diary/archive/2006/0...](http://www.dalkescientific.com/writings/diary/archive/2006/08/30/gardensnake_language.html),
and
[http://www.dalkescientific.com/writings/diary/archive/2010/0...](http://www.dalkescientific.com/writings/diary/archive/2010/02/22/instrumenting_the_ast.html)
. Those seem like something you're looking for.

------
jonjacky
Hy is a Lisp that compiles to Python AST and then to Python bytecode:

[https://github.com/hylang/hy/blob/master/docs/language/inter...](https://github.com/hylang/hy/blob/master/docs/language/internals.rst)

