[Python-ideas] AST Transformation Hooks for Domain Specific Languages
Carl M. Johnson
cmjohnson.mailinglist at gmail.com
Sat Apr 9 07:35:39 CEST 2011
> I did not realize you're proposing to skip parsing of the body of dsl
> function and just tuck all the code into Str literal.
If I can ask a noobish question, in that case, what's the advantage of
the new syntax over the currently existing ability to have a decorator
parse a docstring? Eg., an SQL DSL could be done today as
import dsl.sql
@dsl.sql
def lookup_address(name : dsl.sql.char, dob : dsl.sql.date):
"""select address
from people
where name = {name} and dob = {dob}"""
pass
If you can't bear to lose the docstring, you could instead write something like,
import dsl.sql
@dsl.sql
def lookup_address(name : dsl.sql.char, dob : dsl.sql.date):
"Looks up the address of a name and DOB."
return """select address
from people
where name = {name} and dob = {dob}"""
What's the advantage of the "def from" over this? Bear in mind that
this way of doing has the advantage of working with today's Python
syntax highlighters. ;-)
More information about the Python-ideas
mailing list