From: <fwi...@us...> - 2008-06-25 22:46:16
|
Revision: 4773 http://jython.svn.sourceforge.net/jython/?rev=4773&view=rev Author: fwierzbicki Date: 2008-06-25 15:46:10 -0700 (Wed, 25 Jun 2008) Log Message: ----------- one pass support for arguments and keywords for Call. Modified Paths: -------------- trunk/sandbox/wierzbicki/backup/Python.g Modified: trunk/sandbox/wierzbicki/backup/Python.g =================================================================== --- trunk/sandbox/wierzbicki/backup/Python.g 2008-06-25 20:48:27 UTC (rev 4772) +++ trunk/sandbox/wierzbicki/backup/Python.g 2008-06-25 22:46:10 UTC (rev 4773) @@ -220,7 +220,7 @@ exprType e = (exprType)exprs.get(i); result.add(e); } - return (exprType[])result.toArray(new exprType[result.size()]); + return result.toArray(new exprType[result.size()]); } return new exprType[0]; } @@ -315,6 +315,23 @@ return new argumentsType(t, p, s, k, d); } + exprType[] extractArgs(List args) { + if (args == null) { + return new exprType[0]; + } + return (exprType[])args.toArray(new exprType[args.size()]); + } + + keywordType[] makeKeywords(List args) { + List<keywordType> k = new ArrayList<keywordType>(); + for(int i=0;i<args.size();i++) { + exprType[] e = (exprType[])args.get(i); + Name arg = (Name)e[0]; + k.add(new keywordType(arg, arg.id, e[1])); + } + return k.toArray(new keywordType[k.size()]); + } + Object makeFloat(Token t) { debug("makeFloat matched " + t.getText()); return Py.newFloat(Double.valueOf(t.getText())); @@ -1064,7 +1081,7 @@ ; //trailer: '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME -trailer : LPAREN (arglist -> ^(LPAREN<Call>[$LPAREN, null, new exprType[0\], new keywordType[0\], null, null]) +trailer : LPAREN (arglist -> ^(LPAREN<Call>[$LPAREN, null, makeExprs($arglist.args), makeKeywords($arglist.keywords), $arglist.starargs, $arglist.kwargs]) | -> ^(LPAREN<Call>[$LPAREN, null, new exprType[0\], new keywordType[0\], null, null]) ) RPAREN @@ -1152,14 +1169,19 @@ ; //arglist: (argument ',')* (argument [',']| '*' test [',' '**' test] | '**' test) -arglist returns [List args, exprType starargs, exprType kwargs] - : a+=argument (COMMA a+=argument)* +arglist returns [List args, List keywords, exprType starargs, exprType kwargs] +@init { + List arguments = new ArrayList(); + List kws = new ArrayList(); +} + : argument[arguments, kws] (COMMA argument[arguments, kws])* ( COMMA ( STAR s=test[expr_contextType.Load] (COMMA DOUBLESTAR k=test[expr_contextType.Load])? | DOUBLESTAR k=test[expr_contextType.Load] )? )? { - $args=$a; + $args=arguments; + $keywords=kws; $starargs=(exprType)$s.tree; $kwargs=(exprType)$k.tree; } @@ -1173,14 +1195,13 @@ ; //argument: test [gen_for] | test '=' test # Really [keyword '='] test -argument returns [exprType arg, exprType value] +argument[List arguments, List kws] : t1=test[expr_contextType.Load] ( (ASSIGN t2=test[expr_contextType.Load]) { - $arg=(exprType)$t1.tree; - $value=(exprType)$t2.tree; + $kws.add(new exprType[]{(exprType)$t1.tree, (exprType)$t2.tree}); } | gen_for //FIXME - | {$arg=(exprType)$t1.tree;} + | {$arguments.add($t1.tree);} ) ; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |