[Compiler-sig] Help with the AST re decorators

Neil Schemenauer nas at arctrix.com
Sat Apr 2 03:57:26 CEST 2005


I'm trying to add support to the AST compiler for decorators.  I'm
stuck in trying to represent them in ASDL.  This is what I currently
have:

        stmt = FunctionDef(decorator* decorators, identifier name,
                           arguments args, stmt* body)
             | ...

        decorator = (identifier name, arglist* args)

        
        arglist = ArgList(expr* args, keyword* keywords, expr? starargs,
                          expr? kwargs)
        

Although I have quite a bit of the implementation done, I don't like
the ArgList node.  Perhaps this would be better:

        stmt = FunctionDef(decorator* decorators, identifier name,
                           arguments args, stmt* body)
             | ...

        expr = CallExpr(call c)
             | ...

        decorator = DecoratorName(identifier name)
                  | DecoratorCall(call c)

        
        call = Call(expr func, expr* args, keyword* keywords,
                    expr? starargs, expr? kwargs)

A decorator call is basically a function call, the only difference
being that the func expression must be a dotted_name.  The second
definition seems fairly clumsy as well.  Any advice?

  Neil


More information about the Compiler-sig mailing list