[Python-ideas] AST Transformation Hooks for Domain Specific Languages

Nick Coghlan ncoghlan at gmail.com
Sat Apr 9 11:12:11 CEST 2011


On Sat, Apr 9, 2011 at 4:06 PM, Eric Snow <ericsnowcurrently at gmail.com> wrote:
>> @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. ;-)
>
> 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.

Yep - it's the move to compile time metaprogramming that makes ideas
like this one and tools like Mython interesting. Everything else is
too close to what can already be done with decorators and metaclasses
to justify the additional complexity.

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia



More information about the Python-ideas mailing list