Help with the AST re decorators

Neil Schemenauer <[email protected]> Fri, 1 Apr 2005 18:57:26 -0700
Newsgroups gmane.comp.python.compiler
Message-ID <[email protected]>
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