From: <fwi...@us...> - 2007-12-08 20:39:50
|
Revision: 3777 http://jython.svn.sourceforge.net/jython/?rev=3777&view=rev Author: fwierzbicki Date: 2007-12-08 12:39:48 -0800 (Sat, 08 Dec 2007) Log Message: ----------- Start of ClassDef -- still needs some work, especially if multiple bases or bases with dotted names. Modified Paths: -------------- trunk/sandbox/ast/grammar/Python.g trunk/sandbox/ast/grammar/PythonWalker.g Modified: trunk/sandbox/ast/grammar/Python.g =================================================================== --- trunk/sandbox/ast/grammar/Python.g 2007-12-08 18:10:06 UTC (rev 3776) +++ trunk/sandbox/ast/grammar/Python.g 2007-12-08 20:39:48 UTC (rev 3777) @@ -643,7 +643,7 @@ //classdef: 'class' NAME ['(' testlist ')'] ':' suite classdef: 'class' NAME (LPAREN testlist RPAREN)? COLON suite - -> ^(ClassDef ^(Name NAME) ^(Bases testlist)? ^(Body suite)) + -> ^(ClassDef ^(Name NAME) ^(Bases testlist?) ^(Body suite)) ; //arglist: (argument ',')* (argument [',']| '*' test [',' '**' test] | '**' test) Modified: trunk/sandbox/ast/grammar/PythonWalker.g =================================================================== --- trunk/sandbox/ast/grammar/PythonWalker.g 2007-12-08 18:10:06 UTC (rev 3776) +++ trunk/sandbox/ast/grammar/PythonWalker.g 2007-12-08 20:39:48 UTC (rev 3777) @@ -69,6 +69,12 @@ return new Module(t, s); } + private ClassDef makeClassDef(PythonTree t, PythonTree nameToken, List bases, List body) { + exprType[] b = (exprType[])bases.toArray(new exprType[bases.size()]); + stmtType[] s = (stmtType[])body.toArray(new stmtType[body.size()]); + return new ClassDef(t, nameToken.getText(), b, s); + } + private FunctionDef makeFunctionDef(PythonTree t, PythonTree nameToken, argumentsType args, List funcStatements, List decorators) { argumentsType a; debug("Matched FunctionDef"); @@ -285,7 +291,7 @@ } | ^(augassign targ=test[expr_contextType.Load] value=test[expr_contextType.Load]) { } - | ^(Assign targets ^(Value value=test[expr_contextType.Store])) { + | ^(Assign targets ^(Value value=test[expr_contextType.Load])) { debug("Matched Assign"); exprType[] e = new exprType[$targets.etypes.size()]; for(int i=0;i<$targets.etypes.size();i++) { @@ -307,7 +313,7 @@ ; target[List etypes] - : ^(Target test[expr_contextType.Load]) { + : ^(Target test[expr_contextType.Store]) { etypes.add($test.etype); } ; @@ -548,11 +554,24 @@ ; classdef - : ^(ClassDef ^(Name NAME) (^(Bases test[expr_contextType.Load]))? ^(Body suite)) { - debug("class matched"); + : ^(ClassDef ^(Name classname=NAME) bases ^(Body stmts)) { + $stmts::statements.add(makeClassDef($ClassDef, $classname, $bases.names, $stmts.stypes)); } ; +bases returns [List names] +@init { + List nms = new ArrayList(); +} + :^(Bases base[nms]*) { + $names = nms; + } + ; + +base[List names] + : test[expr_contextType.Store] {names.add($test.etype);} + ; + arglist : ^(Arguments argument+) (^(StarArgs test[expr_contextType.Load]))? (^(KWArgs test[expr_contextType.Load]))? | ^(StarArgs test[expr_contextType.Load]) (^(KWArgs test[expr_contextType.Load]))? This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |