Showing content from http://mail.python.org/pipermail/python-dev/attachments/20110408/ca5ccc59/attachment.html below:
<div class="gmail_quote">On Fri, Apr 8, 2011 at 10:50 AM, David Malcolm <span dir="ltr"><<a href="mailto:dmalcolm@redhat.com">dmalcolm@redhat.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="im">On Fri, 2011-04-08 at 21:29 +1000, Nick Coghlan wrote:<br>
> A few odds and ends from recent discussions finally clicked into<br>
> something potentially interesting earlier this evening. Or possibly<br>
> just something insane. I'm not quite decided on that point as yet (but<br>
> leaning towards the latter).<br>
<br>
</div>I too am leaning towards the latter (I'm afraid my first thought was to<br>
check the date on the email); as Michael said, I too don't think it<br>
<div class="im">stands much of a chance in core.<br>
<br>
</div><div class="im">> Anyway, without further ado, I present:<br>
><br>
> AST Transformation Hooks for Domain Specific Languages<br>
> ======================================================<br>
<br>
</div>This reminds me a lot of Mython:<br>
<a href="http://mython.org/" target="_blank">http://mython.org/</a><br>
If you haven't seen it, it's well worth a look.<br>
<br>
My favourite use case for this kind of thing is having the ability to<br>
embed shell pipelines into Python code, by transforming bash-style<br>
syntax into subprocess calls (it's almost possible to do all this in<br>
regular Python by overloading the | and > operators, but not quite).<br>
<div class="im"><br>
> Consider:<br>
><br>
> # In some other module<br>
> ast.register_dsl("dsl.sql", dsl.sql.TransformAST)<br>
<br>
</div>Where is this registered? Do you have to import this "other module"<br>
before importing the module using "dsl.sql" ? It sounds like this is<br>
global state for the interpreter.<br>
<div class="im"><br>
> # In a module using that DSL<br>
<br>
</div>How is this usage expressed? via the following line?<br>
<br>
> import dsl.sql<br>
<br>
I see the "import dsl.sql" here, but surely you have to somehow process<br>
the "import" in order to handle the rest of the parsing.<br>
<br>
This is reminiscent of the "from __future__ " specialcasing in the<br>
parser. But from my understanding of CPython's Python/future.c, you<br>
already have an AST at that point (mod_ty, from Python/compile.c).<br>
There seems to be a chicken-and-egg problem with this proposal.<br>
<br>
Though another syntax might read:<br>
<br>
from __dsl__ import sql<br>
<br>
to perhaps emphasize that something magical is about to happen.<br>
<br>
[...snip example of usage of a DSL, and the AST it gets parsed to...]<br>
<br>
Where and how would the bytes of the file usage the DSL get converted to<br>
an in-memory tree representation?<br>
<br>
IIRC, manipulating AST nodes in CPython requires some care: the parser<br>
has its own allocator (PyArena), and the entities it allocates have a<br>
shared lifetime that ends when PyArena_Free occurs.<br>
<div class="im"><br>
> So there you are, that's the crazy idea. The stoning of the heretic<br>
> may now commence :)<br>
<br>
</div>Or, less violently, take it to python-ideas? (though I'm not subscribed<br>
there, fwiw, make of that what you will)<br>
<br>
One "exciting" aspect of this is that if someone changes the DSL file,<br>
the meaning of all of your code changes from under you. This may or may<br>
not be a sane approach to software development :)<br>
<br>
(I also worry what this means e.g. for people writing text editors,<br>
syntax highlighters, etc; insert usual Alan Perlis quote about syntactic<br>
sugar causing cancer of the semicolon)<br>
<br>
Also, insert usual comments about the need to think about how<br>
non-CPython implementations of Python would go about implementing such<br>
ideas.<br>
<div class="im"><br>
> Where this idea came from was the various discussions about "make<br>
> statement" style constructs and a conversation I had with Eric Snow at<br>
> Pycon about function definition time really being *too late* to do<br>
> anything particularly interesting that couldn't already be handled<br>
> better in other ways. Some tricks Dave Malcolm had done to support<br>
> Python level manipulation of the AST during compilation also played a<br>
> big part, as did Eugene Toder's efforts to add an AST optimisation<br>
> step to the compilation process.<br>
<br>
</div>Like I said earlier, have a look at Mython<br>
<br>
Hope this is helpful<br>
Dave<br>
<div><div></div><div class="h5"><br>
_______________________________________________<br>
Python-Dev mailing list<br>
<a href="mailto:Python-Dev@python.org">Python-Dev@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/python-dev" target="_blank">http://mail.python.org/mailman/listinfo/python-dev</a><br>
Unsubscribe: <a href="http://mail.python.org/mailman/options/python-dev/ericsnowcurrently%40gmail.com" target="_blank">http://mail.python.org/mailman/options/python-dev/ericsnowcurrently%40gmail.com</a></div></div></blockquote>
<div><br></div><div>Someone brought up some of the same stuff in the python-ideas thread and Nick responded there, particularly about the import question.</div></div><br>
RetroSearch is an open source project built by @garambo
| Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4