J2 decorator grammar

Robert Brewer fumanchu at amor.org
Sat Aug 21 00:11:31 EDT 2004

> Michael Sparks wrote:
> > decorator: dotted_name [ '(' [arglist] ')' ]
> > funcdef: ['decorate' ':' NEWLINE INDENT decorators DEDENT ] 
> 'def' NAME
> parameters ':' suite
> Would you consider this instead?
> decorator_suite: expression_stmt | NEWLINE INDENT expression_stmt+
> funcdef: ['decorate' ':' decorator_suite] 'def' NAME parameters ':'
> suite

Never mind on re-using 'expression_stmt'; it's easiest right now just to
keep the com_decorator() approach. But it still might be nice to go with
a new, explicit suite. It's more in line with the other compound_stmt
grammars. In addition, it might help solve your scoping issue to handle.

decorator: dotted_name [ '(' [arglist] ')' ]
decorator_suite: decorator | NEWLINE INDENT decorator+ DEDENT
funcdef: ['decorate' ':' decorator_suite] 'def' NAME parameters ':'

Did you ever fix the scope issue? Might it have something to do with:

static void
symtable_node(struct symtable *st, node *n)
	int i;

	switch (TYPE(n)) {
	case funcdef: {
		char *func_name;
		if (NCH(n) == 6)
			symtable_node(st, CHILD(n, 0));

..I would think changing "if (NCH(n) == 6)" to 11 for your existing
grammar would "do the same thing" for J2 that this does for A1.

Robert Brewer
Amor Ministries
fumanchu at amor.org

More information about the Python-list mailing list