3 ms·
Ask HN: Examples of meta programming or AST-hacking in Python?
I've found a few promising examples of AST-hacking within Python, but I'd like to know if anyone has some more.
Here's what I've found:
http://blaag.haard.se/Using-the-AST-to-hack-constants-into-Python/
http://hackflow.com/blog/2015/03/29/metaprogramming-beyond-decency/
I'd also be interested in just seeing people implementing domain specific languages in Python, using Pyparsing or other techniques.
- dalke 11y agoBefore 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/08/30/gardensnake_language.html http://www.dalkescientific.com/writings/diary/archive/2006/0..., and http://www.dalkescientific.com/writings/diary/archive/2010/02/22/instrumenting_the_ast.html http://www.dalkescientific.com/writings/diary/archive/2010/0... . Those seem like something you're looking for.
- jonjacky 11y agoHy is a Lisp that compiles to Python AST and then to Python bytecode: https://github.com/hylang/hy/blob/master/docs/language/internals.rst https://github.com/hylang/hy/blob/master/docs/language/inter...
- gjenks 11y agoI 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-matching/macro.html http://www.grantjenks.com/docs/pypatt-python-pattern-matchin... Source: https://github.com/grantjenks/pypatt_python_pattern_matching/blob/master/pypatt/macro.py https://github.com/grantjenks/pypatt_python_pattern_matching...