<div class="gmail_quote">On Fri, Apr 8, 2011 at 11:35 PM, Carl M. Johnson <span dir="ltr"><<a href="mailto:cmjohnson.mailinglist@gmail.com">cmjohnson.mailinglist@gmail.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">> I did not realize you're proposing to skip parsing of the body of dsl<br>
> function and just tuck all the code into Str literal.<br>
<br>
</div>If I can ask a noobish question, in that case, what's the advantage of<br>
the new syntax over the currently existing ability to have a decorator<br>
parse a docstring? Eg., an SQL DSL could be done today as<br>
<br>
<br>
import dsl.sql<br>
<br>
@dsl.sql<br>
def lookup_address(name : dsl.sql.char, dob : dsl.sql.date):<br>
<div class="im"> """select address<br>
from people<br>
where name = {name} and dob = {dob}"""<br>
</div> pass<br>
<br>
If you can't bear to lose the docstring, you could instead write something like,<br>
<br>
<br>
import dsl.sql<br>
<br>
@dsl.sql<br>
def lookup_address(name : dsl.sql.char, dob : dsl.sql.date):<br>
"Looks up the address of a name and DOB."<br>
return """select address<br>
<div class="im"> from people<br>
where name = {name} and dob = {dob}"""<br>
<br>
<br>
<br>
</div>What's the advantage of the "def from" over this? Bear in mind that<br>
this way of doing has the advantage of working with today's Python<br>
syntax highlighters. ;-)<br>
<div><div></div><div class="h5">_______________________________________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org">Python-ideas@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/python-ideas" target="_blank">http://mail.python.org/mailman/listinfo/python-ideas</a><br>
</div></div></blockquote></div><br><div>My understanding is that the AST transformation is done at compile-time, while the decorator happens at run-time. So your .pyc file gets your transformed code.</div>