You can subscribe to this list here.
2000 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(1) |
Nov
(107) |
Dec
(67) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2001 |
Jan
(76) |
Feb
(125) |
Mar
(72) |
Apr
(13) |
May
(18) |
Jun
(12) |
Jul
(129) |
Aug
(47) |
Sep
(1) |
Oct
(36) |
Nov
(128) |
Dec
(124) |
2002 |
Jan
(59) |
Feb
|
Mar
(14) |
Apr
(14) |
May
(72) |
Jun
(9) |
Jul
(3) |
Aug
(5) |
Sep
(18) |
Oct
(65) |
Nov
(28) |
Dec
(12) |
2003 |
Jan
(10) |
Feb
(2) |
Mar
(4) |
Apr
(33) |
May
(21) |
Jun
(9) |
Jul
(29) |
Aug
(34) |
Sep
(4) |
Oct
(8) |
Nov
(15) |
Dec
(4) |
2004 |
Jan
(26) |
Feb
(12) |
Mar
(11) |
Apr
(9) |
May
(7) |
Jun
|
Jul
(5) |
Aug
|
Sep
(3) |
Oct
(7) |
Nov
(1) |
Dec
(10) |
2005 |
Jan
(2) |
Feb
(72) |
Mar
(16) |
Apr
(39) |
May
(48) |
Jun
(97) |
Jul
(57) |
Aug
(13) |
Sep
(16) |
Oct
(24) |
Nov
(100) |
Dec
(24) |
2006 |
Jan
(15) |
Feb
(34) |
Mar
(33) |
Apr
(31) |
May
(79) |
Jun
(64) |
Jul
(41) |
Aug
(64) |
Sep
(31) |
Oct
(46) |
Nov
(55) |
Dec
(37) |
2007 |
Jan
(32) |
Feb
(61) |
Mar
(11) |
Apr
(58) |
May
(46) |
Jun
(30) |
Jul
(94) |
Aug
(93) |
Sep
(86) |
Oct
(69) |
Nov
(125) |
Dec
(177) |
2008 |
Jan
(169) |
Feb
(97) |
Mar
(74) |
Apr
(113) |
May
(120) |
Jun
(334) |
Jul
(215) |
Aug
(237) |
Sep
(72) |
Oct
(189) |
Nov
(126) |
Dec
(160) |
2009 |
Jan
(180) |
Feb
(45) |
Mar
(98) |
Apr
(140) |
May
(151) |
Jun
(71) |
Jul
(107) |
Aug
(119) |
Sep
(73) |
Oct
(121) |
Nov
(14) |
Dec
(6) |
2010 |
Jan
(13) |
Feb
(9) |
Mar
(10) |
Apr
(64) |
May
(3) |
Jun
(16) |
Jul
(7) |
Aug
(23) |
Sep
(17) |
Oct
(37) |
Nov
(5) |
Dec
(8) |
2011 |
Jan
(10) |
Feb
(11) |
Mar
(77) |
Apr
(11) |
May
(2) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: <fwi...@us...> - 2008-08-25 20:36:12
|
Revision: 5246 http://jython.svn.sourceforge.net/jython/?rev=5246&view=rev Author: fwierzbicki Date: 2008-08-25 20:36:04 +0000 (Mon, 25 Aug 2008) Log Message: ----------- Fixed fplist, subscripts (especially extslice) and enable Interactive and Expression (single and eval). regrtest.py is now running. Modified Paths: -------------- branches/nowalker/grammar/Python.g branches/nowalker/src/org/python/antlr/ExpressionParser.java branches/nowalker/src/org/python/antlr/GrammarActions.java branches/nowalker/src/org/python/antlr/InteractiveParser.java Modified: branches/nowalker/grammar/Python.g =================================================================== --- branches/nowalker/grammar/Python.g 2008-08-25 18:44:46 UTC (rev 5245) +++ branches/nowalker/grammar/Python.g 2008-08-25 20:36:04 UTC (rev 5246) @@ -76,8 +76,6 @@ DEDENT; PYNODE; - Interactive; - Expression; } @header { @@ -110,6 +108,7 @@ import org.python.antlr.ast.excepthandlerType; import org.python.antlr.ast.Exec; import org.python.antlr.ast.Expr; +import org.python.antlr.ast.Expression; import org.python.antlr.ast.exprType; import org.python.antlr.ast.expr_contextType; import org.python.antlr.ast.ExtSlice; @@ -122,6 +121,7 @@ import org.python.antlr.ast.Import; import org.python.antlr.ast.ImportFrom; import org.python.antlr.ast.Index; +import org.python.antlr.ast.Interactive; import org.python.antlr.ast.keywordType; import org.python.antlr.ast.ListComp; import org.python.antlr.ast.Lambda; @@ -272,10 +272,23 @@ } //single_input: NEWLINE | simple_stmt | compound_stmt NEWLINE -single_input : NEWLINE* EOF -> ^(Interactive) - | simple_stmt NEWLINE* EOF -> ^(Interactive simple_stmt) - | compound_stmt NEWLINE+ EOF -> ^(Interactive compound_stmt) - ; +single_input +@init { + modType mtype = null; +} +@after { + $single_input.tree = mtype; +} + : NEWLINE* EOF { + mtype = new Interactive($single_input.start, new stmtType[0]); + } + | simple_stmt NEWLINE* EOF { + mtype = new Interactive($single_input.start, actions.makeStmts($simple_stmt.stypes)); + } + | compound_stmt NEWLINE+ EOF { + mtype = new Interactive($single_input.start, actions.makeStmts($compound_stmt.tree)); + } + ; //file_input: (NEWLINE | stmt)* ENDMARKER file_input @@ -294,8 +307,17 @@ ; //eval_input: testlist NEWLINE* ENDMARKER -eval_input : LEADING_WS? (NEWLINE)* testlist[expr_contextType.Load] (NEWLINE)* EOF -> ^(Expression testlist) - ; +eval_input +@init { + modType mtype = null; +} +@after { + $eval_input.tree = mtype; +} + : LEADING_WS? (NEWLINE)* testlist[expr_contextType.Load] (NEWLINE)* EOF { + mtype = new Expression($eval_input.start, (exprType)$testlist.tree); + } + ; //not in CPython's Grammar file dotted_attr returns [exprType etype] @@ -422,9 +444,9 @@ fpdef[expr_contextType ctype] : NAME -> ^(PYNODE<Name>[$NAME, $NAME.text, ctype]) | (LPAREN fpdef[null] COMMA) => LPAREN fplist RPAREN + -> ^(LPAREN<Tuple>[$fplist.start, actions.makeExprs($fplist.etypes), expr_contextType.Store]) + | LPAREN fplist RPAREN -> fplist - | LPAREN fplist RPAREN - -> ^(LPAREN<Tuple>[$fplist.start, actions.makeExprs($fplist.etypes), expr_contextType.Store]) ; //fplist: fpdef (',' fpdef)* [','] @@ -673,7 +695,7 @@ $exec_stmt.tree = stype; } : EXEC expr[expr_contextType.Load] (IN t1=test[expr_contextType.Load] (COMMA t2=test[expr_contextType.Load])?)? { - stype = new Exec($expr.start, (exprType)$expr.tree, (exprType)$t1.tree, (exprType)$t2.tree); + stype = new Exec($EXEC, (exprType)$expr.tree, (exprType)$t1.tree, (exprType)$t2.tree); } ; @@ -1142,37 +1164,49 @@ //subscriptlist: subscript (',' subscript)* [','] //FIXME: tuples not always created when commas are present. subscriptlist[Token begin] returns [exprType etype] +@init { + exprType etype = null; +} @after { - $subscriptlist.tree = $etype; + $subscriptlist.tree = etype; } - : sub+=subscript (options {greedy=true;}:COMMA sub+=subscript)* (COMMA)? { - sliceType s; + : sub+=subscript (options {greedy=true;}:c1=COMMA sub+=subscript)* (c2=COMMA)? { + boolean isTuple = false; + if ($c1 != null || $c2 != null) { + isTuple = true; + } + sliceType s = null; List sltypes = $sub; - if (sltypes.size() == 0) { - s = null; - } else if (sltypes.size() == 1){ - s = (sliceType)sltypes.get(0); - } else { + boolean extslice = false; + + //NEW LOGIC + if (isTuple) { sliceType[] st; - //FIXME: here I am using ClassCastException to decide if sltypes is populated with Index - // only. Clearly this is not the best way to do this but it's late. Somebody do - // something better please :) -- (hopefully a note to self) - try { - Iterator iter = sltypes.iterator(); - List etypes = new ArrayList(); - while (iter.hasNext()) { - Index i = (Index)iter.next(); + List etypes = new ArrayList(); + for (Object o : sltypes) { + if (o instanceof Index) { + Index i = (Index)o; etypes.add(i.value); + } else { + extslice = true; + break; } + } + if (!extslice) { exprType[] es = (exprType[])etypes.toArray(new exprType[etypes.size()]); - exprType t = new Tuple($subscriptlist.start, es, expr_contextType.Load); - s = new Index($subscriptlist.start, t); - } catch (ClassCastException cc) { - st = (sliceType[])sltypes.toArray(new sliceType[sltypes.size()]); - s = new ExtSlice($subscriptlist.start, st); + exprType t = new Tuple($begin, es, expr_contextType.Load); + s = new Index($begin, t); } + } else if (sltypes.size() == 1) { + s = (sliceType)sltypes.get(0); + } else if (sltypes.size() != 0) { + extslice = true; } - $etype = new Subscript($begin, null, s, $expr::ctype); + if (extslice) { + sliceType[] st = (sliceType[])sltypes.toArray(new sliceType[sltypes.size()]); + s = new ExtSlice($begin, st); + } + etype = new Subscript($begin, null, s, $expr::ctype); } ; @@ -1194,7 +1228,8 @@ ; //sliceop: ':' [test] -sliceop : COLON (test[expr_contextType.Load])? -> test +sliceop : COLON (test[expr_contextType.Load] -> test + )? ; //exprlist: expr (',' expr)* [','] Modified: branches/nowalker/src/org/python/antlr/ExpressionParser.java =================================================================== --- branches/nowalker/src/org/python/antlr/ExpressionParser.java 2008-08-25 18:44:46 UTC (rev 5245) +++ branches/nowalker/src/org/python/antlr/ExpressionParser.java 2008-08-25 20:36:04 UTC (rev 5246) @@ -34,6 +34,7 @@ try { PythonParser.eval_input_return r = parser.eval_input(); + tree = (modType)r.tree; //CommonTreeNodeStream nodes = new CommonTreeNodeStream((Tree)r.tree); //nodes.setTokenStream(tokens); //PythonWalker walker = new PythonWalker(nodes); Modified: branches/nowalker/src/org/python/antlr/GrammarActions.java =================================================================== --- branches/nowalker/src/org/python/antlr/GrammarActions.java 2008-08-25 18:44:46 UTC (rev 5245) +++ branches/nowalker/src/org/python/antlr/GrammarActions.java 2008-08-25 20:36:04 UTC (rev 5246) @@ -185,6 +185,10 @@ return o; } + stmtType[] makeStmts(PythonTree t) { + return new stmtType[]{(stmtType)t}; + } + stmtType[] makeStmts(List stmts) { if (stmts != null) { List<stmtType> result = new ArrayList<stmtType>(); Modified: branches/nowalker/src/org/python/antlr/InteractiveParser.java =================================================================== --- branches/nowalker/src/org/python/antlr/InteractiveParser.java 2008-08-25 18:44:46 UTC (rev 5245) +++ branches/nowalker/src/org/python/antlr/InteractiveParser.java 2008-08-25 20:36:04 UTC (rev 5246) @@ -39,6 +39,7 @@ try { PythonParser.single_input_return r = parser.single_input(); + tree = (modType)r.tree; //CommonTreeNodeStream nodes = new CommonTreeNodeStream((Tree)r.tree); //nodes.setTokenStream(tokens); //PythonWalker walker = new PythonWalker(nodes); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-08-25 18:44:52
|
Revision: 5245 http://jython.svn.sourceforge.net/jython/?rev=5245&view=rev Author: fwierzbicki Date: 2008-08-25 18:44:46 +0000 (Mon, 25 Aug 2008) Log Message: ----------- Fix build.xml (oops) Fix Generator Expression assignments and multi-statement simple_stmt. Modified Paths: -------------- branches/nowalker/build.xml branches/nowalker/grammar/Python.g branches/nowalker/src/org/python/antlr/GrammarActions.java Modified: branches/nowalker/build.xml =================================================================== --- branches/nowalker/build.xml 2008-08-25 15:25:24 UTC (rev 5244) +++ branches/nowalker/build.xml 2008-08-25 18:44:46 UTC (rev 5245) @@ -318,7 +318,9 @@ change to grammar files. If you are working on the grammars you might want to comment this out, as a clean is really only needed if you change the tokens defined in Python.g (and cleans make the build slow) --> + <antcall target="clean"/> <!-- force jarjar build --> + <property name="jarjar.needed" value="true" /> </target> <target name ="prepare-output" depends="init,needed-check,clean-if-antlr-needed,make-output-dirs"/> Modified: branches/nowalker/grammar/Python.g =================================================================== --- branches/nowalker/grammar/Python.g 2008-08-25 15:25:24 UTC (rev 5244) +++ branches/nowalker/grammar/Python.g 2008-08-25 18:44:46 UTC (rev 5245) @@ -279,8 +279,18 @@ //file_input: (NEWLINE | stmt)* ENDMARKER file_input - : (NEWLINE | s+=stmt)+ -> ^(PYNODE<Module>[$file_input.start, actions.makeStmts($s)]) - | -> ^(PYNODE<Module>[$file_input.start, new stmtType[0\]]) +@init { + modType mtype = null; + List stypes = new ArrayList(); +} +@after { + $file_input.tree = mtype; +} + : (NEWLINE + | stmt {stypes.addAll($stmt.stypes);} + )* { + mtype = new Module($file_input.start, actions.makeStmts(stypes)); + } ; //eval_input: testlist NEWLINE* ENDMARKER @@ -424,14 +434,21 @@ ; //stmt: simple_stmt | compound_stmt -stmt : simple_stmt - | compound_stmt - ; +stmt returns [List stypes] + : simple_stmt {$stypes = $simple_stmt.stypes;} + | compound_stmt { + $stypes = new ArrayList(); + $stypes.add($compound_stmt.tree); + } + ; //simple_stmt: small_stmt (';' small_stmt)* [';'] NEWLINE -simple_stmt : small_stmt (options {greedy=true;}:SEMI small_stmt)* (SEMI)? NEWLINE - -> small_stmt+ - ; +simple_stmt returns [List stypes] + : s+=small_stmt (options {greedy=true;}:SEMI s+=small_stmt)* (SEMI)? NEWLINE { + $stypes = $s; + } + ; + //small_stmt: (expr_stmt | print_stmt | del_stmt | pass_stmt | flow_stmt | // import_stmt | global_stmt | exec_stmt | assert_stmt) small_stmt : expr_stmt @@ -760,8 +777,13 @@ //suite: simple_stmt | NEWLINE INDENT stmt+ DEDENT suite returns [List stypes] - : ss+=simple_stmt {$stypes = $ss;} - | NEWLINE! INDENT (s+=stmt)+ DEDENT {$stypes = $s;} +@init { + $stypes = new ArrayList(); +} + : simple_stmt {$stypes = $simple_stmt.stypes;} + | NEWLINE! INDENT + (stmt {$stypes.addAll($stmt.stypes);} + )+ DEDENT ; //test: or_test ['if' or_test 'else' test] | lambdef Modified: branches/nowalker/src/org/python/antlr/GrammarActions.java =================================================================== --- branches/nowalker/src/org/python/antlr/GrammarActions.java 2008-08-25 15:25:24 UTC (rev 5244) +++ branches/nowalker/src/org/python/antlr/GrammarActions.java 2008-08-25 18:44:46 UTC (rev 5245) @@ -296,8 +296,11 @@ if (tree instanceof Context) { ((Context)tree).setContext(context); } - for (int i=0; i<tree.getChildCount(); i++) { - if (!(tree instanceof ListComp) && !(tree instanceof GeneratorExp)) { + if (tree instanceof GeneratorExp) { + GeneratorExp g = (GeneratorExp)tree; + recurseSetContext(g.elt, context); + } else if (!(tree instanceof ListComp)) { + for (int i=0; i<tree.getChildCount(); i++) { recurseSetContext(tree.getChild(i), context); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-08-25 15:45:52
|
Revision: 5244 http://jython.svn.sourceforge.net/jython/?rev=5244&view=rev Author: fwierzbicki Date: 2008-08-25 15:25:24 +0000 (Mon, 25 Aug 2008) Log Message: ----------- Clean up creation of stmtType[] and exprType[]. Modified Paths: -------------- branches/nowalker/src/org/python/antlr/GrammarActions.java Modified: branches/nowalker/src/org/python/antlr/GrammarActions.java =================================================================== --- branches/nowalker/src/org/python/antlr/GrammarActions.java 2008-08-25 14:21:29 UTC (rev 5243) +++ branches/nowalker/src/org/python/antlr/GrammarActions.java 2008-08-25 15:25:24 UTC (rev 5244) @@ -236,27 +236,21 @@ } stmtType makeTryExcept(Token t, List body, List handlers, List orelse, List finBody) { - stmtType[] b = (stmtType[])body.toArray(new stmtType[body.size()]); + stmtType[] b = makeStmts(body); excepthandlerType[] e = (excepthandlerType[])handlers.toArray(new excepthandlerType[handlers.size()]); - stmtType[] o; - if (orelse != null) { - o = (stmtType[])orelse.toArray(new stmtType[orelse.size()]); - } else { - o = new stmtType[0]; - } - + stmtType[] o = makeStmts(orelse); stmtType te = new TryExcept(t, b, e, o); if (finBody == null) { return te; } - stmtType[] f = (stmtType[])finBody.toArray(new stmtType[finBody.size()]); + stmtType[] f = makeStmts(finBody); stmtType[] mainBody = new stmtType[]{te}; return new TryFinally(t, mainBody, f); } TryFinally makeTryFinally(Token t, List body, List finBody) { - stmtType[] b = (stmtType[])body.toArray(new stmtType[body.size()]); - stmtType[] f = (stmtType[])finBody.toArray(new stmtType[finBody.size()]); + stmtType[] b = makeStmts(body); + stmtType[] f = makeStmts(finBody); return new TryFinally(t, b, f); } @@ -271,13 +265,8 @@ } else { a = new argumentsType(t, new exprType[0], null, null, new exprType[0]); } - stmtType[] s = (stmtType[])funcStatements.toArray(new stmtType[funcStatements.size()]); - exprType[] d; - if (decorators != null) { - d = (exprType[])decorators.toArray(new exprType[decorators.size()]); - } else { - d = new exprType[0]; - } + stmtType[] s = makeStmts(funcStatements); + exprType[] d = makeExprs(decorators); return new FunctionDef(t, nameToken.getText(), a, s, d); } @@ -317,13 +306,8 @@ argumentsType makeArgumentsType(Token t, List params, Token snameToken, Token knameToken, List defaults) { - exprType[] p; - if (params == null) { - p = new exprType[0]; - } else { - p = (exprType[])params.toArray(new exprType[params.size()]); - } - exprType[] d = (exprType[])defaults.toArray(new exprType[defaults.size()]); + exprType[] p = makeExprs(params); + exprType[] d = makeExprs(defaults); String s; String k; if (snameToken == null) { @@ -340,10 +324,7 @@ } exprType[] extractArgs(List args) { - if (args == null) { - return new exprType[0]; - } - return (exprType[])args.toArray(new exprType[args.size()]); + return makeExprs(args); } keywordType[] makeKeywords(List args) { @@ -475,12 +456,7 @@ //FROM Walker: modType makeMod(PythonTree t, List stmts) { - stmtType[] s; - if (stmts != null) { - s = (stmtType[])stmts.toArray(new stmtType[stmts.size()]); - } else { - s = new stmtType[0]; - } + stmtType[] s = makeStmts(stmts); return new Module(t, s); } @@ -489,12 +465,7 @@ } modType makeInteractive(PythonTree t, List stmts) { - stmtType[] s; - if (stmts == null) { - s = new stmtType[0]; - } else { - s = (stmtType[])stmts.toArray(new stmtType[stmts.size()]); - } + stmtType[] s = makeStmts(stmts); return new Interactive(t, s); } @@ -503,16 +474,16 @@ return errorHandler.errorStmt(t); } cantBeNone(nameToken); - exprType[] b = (exprType[])bases.toArray(new exprType[bases.size()]); - stmtType[] s = (stmtType[])body.toArray(new stmtType[body.size()]); + exprType[] b = makeExprs(bases); + stmtType[] s = makeStmts(body); return new ClassDef(t, nameToken.getText(), b, s); } argumentsType makeArgumentsType(PythonTree t, List params, PythonTree snameToken, PythonTree knameToken, List defaults) { - exprType[] p = (exprType[])params.toArray(new exprType[params.size()]); - exprType[] d = (exprType[])defaults.toArray(new exprType[defaults.size()]); + exprType[] p = makeExprs(params); + exprType[] d = makeExprs(defaults); String s; String k; if (snameToken == null) { @@ -529,27 +500,22 @@ } stmtType makeTryExcept(PythonTree t, List body, List handlers, List orelse, List finBody) { - stmtType[] b = (stmtType[])body.toArray(new stmtType[body.size()]); + stmtType[] b = makeStmts(body); excepthandlerType[] e = (excepthandlerType[])handlers.toArray(new excepthandlerType[handlers.size()]); - stmtType[] o; - if (orelse != null) { - o = (stmtType[])orelse.toArray(new stmtType[orelse.size()]); - } else { - o = new stmtType[0]; - } + stmtType[] o = makeStmts(orelse); stmtType te = new TryExcept(t, b, e, o); if (finBody == null) { return te; } - stmtType[] f = (stmtType[])finBody.toArray(new stmtType[finBody.size()]); + stmtType[] f = makeStmts(finBody); stmtType[] mainBody = new stmtType[]{te}; return new TryFinally(t, mainBody, f); } TryFinally makeTryFinally(PythonTree t, List body, List finBody) { - stmtType[] b = (stmtType[])body.toArray(new stmtType[body.size()]); - stmtType[] f = (stmtType[])finBody.toArray(new stmtType[finBody.size()]); + stmtType[] b = makeStmts(body); + stmtType[] f = makeStmts(finBody); return new TryFinally(t, b, f); } @@ -557,18 +523,8 @@ if (test == null) { return errorHandler.errorStmt(t); } - stmtType[] o; - if (orelse != null) { - o = (stmtType[])orelse.toArray(new stmtType[orelse.size()]); - } else { - o = new stmtType[0]; - } - stmtType[] b; - if (body != null) { - b = (stmtType[])body.toArray(new stmtType[body.size()]); - } else { - b = new stmtType[0]; - } + stmtType[] o = makeStmts(orelse); + stmtType[] b = makeStmts(body); return new If(t, test, b, o); } @@ -576,13 +532,8 @@ if (test == null) { return errorHandler.errorStmt(t); } - stmtType[] o; - if (orelse != null) { - o = (stmtType[])orelse.toArray(new stmtType[orelse.size()]); - } else { - o = new stmtType[0]; - } - stmtType[] b = (stmtType[])body.toArray(new stmtType[body.size()]); + stmtType[] o = makeStmts(orelse); + stmtType[] b = makeStmts(body); return new While(t, test, b, o); } @@ -591,13 +542,8 @@ return errorHandler.errorStmt(t); } cantBeNone(target); - stmtType[] o; - if (orelse != null) { - o = (stmtType[])orelse.toArray(new stmtType[orelse.size()]); - } else { - o = new stmtType[0]; - } - stmtType[] b = (stmtType[])body.toArray(new stmtType[body.size()]); + stmtType[] o = makeStmts(orelse); + stmtType[] b = makeStmts(body); return new For(t, target, iter, b, o); } @@ -609,18 +555,8 @@ if (func == null) { return errorHandler.errorExpr(t); } - exprType[] a; - keywordType[] k; - if (args == null) { - a = new exprType[0]; - } else { - a = (exprType[])args.toArray(new exprType[args.size()]); - } - if (keywords == null) { - k = new keywordType[0]; - } else { - k = (keywordType[])keywords.toArray(new keywordType[keywords.size()]); - } + keywordType[] k = makeKeywords(keywords); + exprType[] a = makeExprs(args); return new Call(t, func, a, k, starargs, kwargs); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-08-25 14:21:36
|
Revision: 5243 http://jython.svn.sourceforge.net/jython/?rev=5243&view=rev Author: fwierzbicki Date: 2008-08-25 14:21:29 +0000 (Mon, 25 Aug 2008) Log Message: ----------- Fix generator expressions, rename all "stmts" in Python.g to "stypes". Modified Paths: -------------- branches/nowalker/grammar/Python.g branches/nowalker/src/org/python/antlr/GrammarActions.java Modified: branches/nowalker/grammar/Python.g =================================================================== --- branches/nowalker/grammar/Python.g 2008-08-24 09:38:22 UTC (rev 5242) +++ branches/nowalker/grammar/Python.g 2008-08-25 14:21:29 UTC (rev 5243) @@ -358,7 +358,7 @@ //funcdef: [decorators] 'def' NAME parameters ':' suite funcdef : decorators? DEF NAME parameters COLON suite - -> ^(DEF<FunctionDef>[$DEF, $NAME.text, $parameters.args, actions.makeStmts($suite.stmts), + -> ^(DEF<FunctionDef>[$DEF, $NAME.text, $parameters.args, actions.makeStmts($suite.stypes), actions.makeExprs($decorators.etypes)]) ; @@ -677,12 +677,12 @@ //if_stmt: 'if' test ':' suite ('elif' test ':' suite)* ['else' ':' suite] if_stmt: IF test[expr_contextType.Load] COLON ifsuite=suite elifs+=elif_clause* (ORELSE COLON elsesuite=suite)? - -> ^(IF<If>[$IF, (exprType)$test.tree, actions.makeStmts($ifsuite.stmts), actions.makeElses($elsesuite.stmts, $elifs)]) + -> ^(IF<If>[$IF, (exprType)$test.tree, actions.makeStmts($ifsuite.stypes), actions.makeElses($elsesuite.stypes, $elifs)]) ; //not in CPython's Grammar file elif_clause : ELIF test[expr_contextType.Load] COLON suite - -> ^(ELIF<If>[$ELIF, (exprType)$test.tree, actions.makeStmts($suite.stmts), new stmtType[0\]]) + -> ^(ELIF<If>[$ELIF, (exprType)$test.tree, actions.makeStmts($suite.stypes), new stmtType[0\]]) ; //while_stmt: 'while' test ':' suite ['else' ':' suite] @@ -694,7 +694,7 @@ $while_stmt.tree = stype; } : WHILE test[expr_contextType.Load] COLON s1=suite (ORELSE COLON s2=suite)? { - stype = actions.makeWhile($WHILE, (exprType)$test.tree, $s1.stmts, $s2.stmts); + stype = actions.makeWhile($WHILE, (exprType)$test.tree, $s1.stypes, $s2.stypes); } ; @@ -707,7 +707,7 @@ $for_stmt.tree = stype; } : FOR exprlist[expr_contextType.Store] IN testlist[expr_contextType.Load] COLON s1=suite (ORELSE COLON s2=suite)? { - stype = actions.makeFor($FOR, $exprlist.etype, (exprType)$testlist.tree, $s1.stmts, $s2.stmts); + stype = actions.makeFor($FOR, $exprlist.etype, (exprType)$testlist.tree, $s1.stypes, $s2.stypes); } ; @@ -725,10 +725,10 @@ } : TRY COLON trysuite=suite ( e+=except_clause+ (ORELSE COLON elsesuite=suite)? (FINALLY COLON finalsuite=suite)? { - stype = actions.makeTryExcept($TRY, $trysuite.stmts, $e, $elsesuite.stmts, $finalsuite.stmts); + stype = actions.makeTryExcept($TRY, $trysuite.stypes, $e, $elsesuite.stypes, $finalsuite.stypes); } | FINALLY COLON finalsuite=suite { - stype = actions.makeTryFinally($TRY, $trysuite.stmts, $finalsuite.stmts); + stype = actions.makeTryFinally($TRY, $trysuite.stypes, $finalsuite.stypes); } ) ; @@ -742,7 +742,7 @@ $with_stmt.tree = stype; } :WITH test[expr_contextType.Load] (with_var)? COLON suite { - stype = new With($WITH, (exprType)$test.tree, $with_var.etype, actions.makeStmts($suite.stmts)); + stype = new With($WITH, (exprType)$test.tree, $with_var.etype, actions.makeStmts($suite.stypes)); } ; @@ -755,13 +755,13 @@ //except_clause: 'except' [test [',' test]] except_clause : EXCEPT (t1=test[expr_contextType.Load] (COMMA t2=test[expr_contextType.Store])?)? COLON suite - -> ^(EXCEPT<excepthandlerType>[$EXCEPT, (exprType)$t1.tree, (exprType)$t2.tree, actions.makeStmts($suite.stmts), $EXCEPT.getLine(), $EXCEPT.getCharPositionInLine()]) + -> ^(EXCEPT<excepthandlerType>[$EXCEPT, (exprType)$t1.tree, (exprType)$t2.tree, actions.makeStmts($suite.stypes), $EXCEPT.getLine(), $EXCEPT.getCharPositionInLine()]) ; //suite: simple_stmt | NEWLINE INDENT stmt+ DEDENT -suite returns [List stmts] - : ss+=simple_stmt {$stmts = $ss;} - | NEWLINE! INDENT (s+=stmt)+ DEDENT {$stmts = $s;} +suite returns [List stypes] + : ss+=simple_stmt {$stypes = $ss;} + | NEWLINE! INDENT (s+=stmt)+ DEDENT {$stypes = $s;} ; //test: or_test ['if' or_test 'else' test] | lambdef @@ -1085,7 +1085,7 @@ if (e instanceof Context) { ((Context)e).setContext(expr_contextType.Load); } - etype = new GeneratorExp($gen_for.start, (exprType)$t.get(0), c); + etype = new GeneratorExp($testlist_gexp.start, (exprType)$t.get(0), c); } ) ) @@ -1233,7 +1233,7 @@ $classdef.tree = stype; } :CLASS NAME (LPAREN testlist[expr_contextType.Load]? RPAREN)? COLON suite { - stype = new ClassDef($CLASS, $NAME.getText(), actions.makeBases((exprType)$testlist.tree), actions.makeStmts($suite.stmts)); + stype = new ClassDef($CLASS, $NAME.getText(), actions.makeBases((exprType)$testlist.tree), actions.makeStmts($suite.stypes)); } ; Modified: branches/nowalker/src/org/python/antlr/GrammarActions.java =================================================================== --- branches/nowalker/src/org/python/antlr/GrammarActions.java 2008-08-24 09:38:22 UTC (rev 5242) +++ branches/nowalker/src/org/python/antlr/GrammarActions.java 2008-08-25 14:21:29 UTC (rev 5243) @@ -308,7 +308,7 @@ ((Context)tree).setContext(context); } for (int i=0; i<tree.getChildCount(); i++) { - if (!(tree instanceof ListComp)) { + if (!(tree instanceof ListComp) && !(tree instanceof GeneratorExp)) { recurseSetContext(tree.getChild(i), context); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-08-24 09:38:26
|
Revision: 5242 http://jython.svn.sourceforge.net/jython/?rev=5242&view=rev Author: fwierzbicki Date: 2008-08-24 09:38:22 +0000 (Sun, 24 Aug 2008) Log Message: ----------- check for PythonTree in makeStmts. Modified Paths: -------------- branches/nowalker/src/org/python/antlr/GrammarActions.java Modified: branches/nowalker/src/org/python/antlr/GrammarActions.java =================================================================== --- branches/nowalker/src/org/python/antlr/GrammarActions.java 2008-08-24 02:04:43 UTC (rev 5241) +++ branches/nowalker/src/org/python/antlr/GrammarActions.java 2008-08-24 09:38:22 UTC (rev 5242) @@ -192,6 +192,11 @@ Object o = stmts.get(i); if (o instanceof stmtType) { result.add((stmtType)o); + } else if (o instanceof PythonTree) { + PythonTree t = (PythonTree)o; + for (int j=0; j<t.getChildCount(); j++) { + result.add((stmtType)t.getChild(i)); + } } else { result.add((stmtType)((PythonParser.stmt_return)o).tree); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-08-24 02:04:46
|
Revision: 5241 http://jython.svn.sourceforge.net/jython/?rev=5241&view=rev Author: fwierzbicki Date: 2008-08-24 02:04:43 +0000 (Sun, 24 Aug 2008) Log Message: ----------- Fix lambda without args. Modified Paths: -------------- branches/nowalker/grammar/Python.g Modified: branches/nowalker/grammar/Python.g =================================================================== --- branches/nowalker/grammar/Python.g 2008-08-23 23:03:59 UTC (rev 5240) +++ branches/nowalker/grammar/Python.g 2008-08-24 02:04:43 UTC (rev 5241) @@ -1092,9 +1092,21 @@ ; //lambdef: 'lambda' [varargslist] ':' test -lambdef: LAMBDA (varargslist)? COLON test[expr_contextType.Load] {debug("parsed lambda");} - -> ^(LAMBDA<Lambda>[$LAMBDA, $varargslist.args, (exprType)$test.tree]) - ; +lambdef +@init { + exprType etype = null; +} +@after { + $lambdef.tree = etype; +} + : LAMBDA (varargslist)? COLON test[expr_contextType.Load] { + argumentsType a = $varargslist.args; + if (a == null) { + a = new argumentsType($LAMBDA, new exprType[0], null, null, new exprType[0]); + } + etype = new Lambda($LAMBDA, a, (exprType)$test.tree); + } + ; //trailer: '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME trailer [Token begin]: LPAREN (arglist -> ^(LPAREN<Call>[$begin, null, actions.makeExprs($arglist.args), actions.makeKeywords($arglist.keywords), $arglist.starargs, $arglist.kwargs]) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-08-23 23:04:04
|
Revision: 5240 http://jython.svn.sourceforge.net/jython/?rev=5240&view=rev Author: fwierzbicki Date: 2008-08-23 23:03:59 +0000 (Sat, 23 Aug 2008) Log Message: ----------- Make PythonTree's toStringTree more easily comparable with ast/astview.py output. This will help with the walkerless Python.g, as it doesn't quite parse ast/astview.py yet. Modified Paths: -------------- branches/nowalker/grammar/Python.g branches/nowalker/src/org/python/antlr/GrammarActions.java Modified: branches/nowalker/grammar/Python.g =================================================================== --- branches/nowalker/grammar/Python.g 2008-08-23 19:43:19 UTC (rev 5239) +++ branches/nowalker/grammar/Python.g 2008-08-23 23:03:59 UTC (rev 5240) @@ -981,7 +981,7 @@ $power.tree = $etype; } } - : atom (t+=trailer)* (options {greedy=true;}:DOUBLESTAR factor)? { + : atom (t+=trailer[$atom.start])* (options {greedy=true;}:DOUBLESTAR factor)? { if ($t != null) { exprType current = (exprType)$atom.tree; //for(int i = $t.size() - 1; i > -1; i--) { @@ -1054,7 +1054,7 @@ ( list_for[gens] { Collections.reverse(gens); comprehensionType[] c = (comprehensionType[])gens.toArray(new comprehensionType[gens.size()]); - etype = new ListComp($lbrack, (exprType)$t.get(0), c); + etype = new ListComp($listmaker.start, (exprType)$t.get(0), c); } | (options {greedy=true;}:COMMA t+=test[expr_contextType.Load])* { etype = new org.python.antlr.ast.List($lbrack, actions.makeExprs($t), $expr::ctype); @@ -1097,17 +1097,17 @@ ; //trailer: '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME -trailer : LPAREN (arglist -> ^(LPAREN<Call>[$LPAREN, null, actions.makeExprs($arglist.args), actions.makeKeywords($arglist.keywords), $arglist.starargs, $arglist.kwargs]) +trailer [Token begin]: LPAREN (arglist -> ^(LPAREN<Call>[$begin, null, actions.makeExprs($arglist.args), actions.makeKeywords($arglist.keywords), $arglist.starargs, $arglist.kwargs]) | -> ^(LPAREN<Call>[$LPAREN, null, new exprType[0\], new keywordType[0\], null, null]) ) RPAREN - | LBRACK s=subscriptlist RBRACK -> $s - | DOT attr -> ^(DOT<Attribute>[$DOT, null, $attr.text, $expr::ctype]) + | LBRACK s=subscriptlist[begin] RBRACK -> $s + | DOT attr -> ^(DOT<Attribute>[$begin, null, $attr.text, $expr::ctype]) ; //subscriptlist: subscript (',' subscript)* [','] //FIXME: tuples not always created when commas are present. -subscriptlist returns [exprType etype] +subscriptlist[Token begin] returns [exprType etype] @after { $subscriptlist.tree = $etype; } @@ -1138,7 +1138,7 @@ s = new ExtSlice($subscriptlist.start, st); } } - $etype = new Subscript($subscriptlist.start, null, s, $expr::ctype); + $etype = new Subscript($begin, null, s, $expr::ctype); } ; @@ -1169,7 +1169,10 @@ $etype = new Tuple($exprlist.start, actions.makeExprs($e), ctype); } | expr[ctype] { + //System.out.println("expecting " + ctype); $etype = (exprType)$expr.tree; + //System.out.println("got " + ((Name)$etype).ctx); + } ; Modified: branches/nowalker/src/org/python/antlr/GrammarActions.java =================================================================== --- branches/nowalker/src/org/python/antlr/GrammarActions.java 2008-08-23 19:43:19 UTC (rev 5239) +++ branches/nowalker/src/org/python/antlr/GrammarActions.java 2008-08-23 23:03:59 UTC (rev 5240) @@ -303,7 +303,9 @@ ((Context)tree).setContext(context); } for (int i=0; i<tree.getChildCount(); i++) { - recurseSetContext(tree.getChild(i), context); + if (!(tree instanceof ListComp)) { + recurseSetContext(tree.getChild(i), context); + } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-08-23 19:43:21
|
Revision: 5239 http://jython.svn.sourceforge.net/jython/?rev=5239&view=rev Author: fwierzbicki Date: 2008-08-23 19:43:19 +0000 (Sat, 23 Aug 2008) Log Message: ----------- Fine tuning List and Assign col position. Modified Paths: -------------- branches/nowalker/build.xml branches/nowalker/grammar/Python.g Modified: branches/nowalker/build.xml =================================================================== --- branches/nowalker/build.xml 2008-08-23 19:19:16 UTC (rev 5238) +++ branches/nowalker/build.xml 2008-08-23 19:43:19 UTC (rev 5239) @@ -318,9 +318,7 @@ change to grammar files. If you are working on the grammars you might want to comment this out, as a clean is really only needed if you change the tokens defined in Python.g (and cleans make the build slow) --> - <antcall target="clean"/> <!-- force jarjar build --> - <property name="jarjar.needed" value="true" /> </target> <target name ="prepare-output" depends="init,needed-check,clean-if-antlr-needed,make-output-dirs"/> Modified: branches/nowalker/grammar/Python.g =================================================================== --- branches/nowalker/grammar/Python.g 2008-08-23 19:19:16 UTC (rev 5238) +++ branches/nowalker/grammar/Python.g 2008-08-23 19:43:19 UTC (rev 5239) @@ -464,8 +464,8 @@ ) |(testlist[null] ASSIGN) => lhs=testlist[expr_contextType.Store] ( - | ((at=ASSIGN t+=testlist[expr_contextType.Store])+ -> ^(PYNODE<Assign>[$at, actions.makeAssignTargets((exprType)$lhs.tree, $t), actions.makeAssignValue($t)])) - | ((ay=ASSIGN y2+=yield_expr)+ -> ^(PYNODE<Assign>[$ay, actions.makeAssignTargets((exprType)$lhs.tree, $y2), actions.makeAssignValue($y2)])) + | ((at=ASSIGN t+=testlist[expr_contextType.Store])+ -> ^(PYNODE<Assign>[$lhs.start, actions.makeAssignTargets((exprType)$lhs.tree, $t), actions.makeAssignValue($t)])) + | ((ay=ASSIGN y2+=yield_expr)+ -> ^(PYNODE<Assign>[$lhs.start, actions.makeAssignTargets((exprType)$lhs.tree, $y2), actions.makeAssignValue($y2)])) ) | lhs=testlist[expr_contextType.Load] -> PYNODE<Expr>[$lhs.start, (exprType)$lhs.tree] ) @@ -1022,7 +1022,7 @@ ) RPAREN | LBRACK - (listmaker -> listmaker + (listmaker[$LBRACK] -> listmaker | -> ^(LBRACK<org.python.antlr.ast.List>[$LBRACK, new exprType[0\], $expr::ctype]) ) RBRACK @@ -1042,7 +1042,7 @@ ; //listmaker: test ( list_for | (',' test)* [','] ) -listmaker +listmaker[Token lbrack] @init { List gens = new ArrayList(); exprType etype = null; @@ -1054,10 +1054,10 @@ ( list_for[gens] { Collections.reverse(gens); comprehensionType[] c = (comprehensionType[])gens.toArray(new comprehensionType[gens.size()]); - etype = new ListComp($listmaker.start, (exprType)$t.get(0), c); + etype = new ListComp($lbrack, (exprType)$t.get(0), c); } | (options {greedy=true;}:COMMA t+=test[expr_contextType.Load])* { - etype = new org.python.antlr.ast.List($listmaker.start, actions.makeExprs($t), $expr::ctype); + etype = new org.python.antlr.ast.List($lbrack, actions.makeExprs($t), $expr::ctype); } ) (COMMA)? ; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-08-23 19:19:18
|
Revision: 5238 http://jython.svn.sourceforge.net/jython/?rev=5238&view=rev Author: fwierzbicki Date: 2008-08-23 19:19:16 +0000 (Sat, 23 Aug 2008) Log Message: ----------- BinOp now works in one pass. Modified Paths: -------------- branches/nowalker/grammar/Python.g branches/nowalker/src/org/python/antlr/GrammarActions.java Modified: branches/nowalker/grammar/Python.g =================================================================== --- branches/nowalker/grammar/Python.g 2008-08-23 02:33:48 UTC (rev 5237) +++ branches/nowalker/grammar/Python.g 2008-08-23 19:19:16 UTC (rev 5238) @@ -855,75 +855,114 @@ $expr::ctype = ect; } @after { - if ($expr.tree instanceof BinOp) { - BinOp b = (BinOp)$expr.tree; - b.left = (exprType)b.getChild(0); - b.right = (exprType)b.getChild(1); - switch (b.getType()) { - case PLUS: - b.op = operatorType.Add; - break; - case MINUS: - b.op = operatorType.Sub; - break; - case STAR: - b.op = operatorType.Mult; - break; - case SLASH: - b.op = operatorType.Div; - break; - case PERCENT: - b.op = operatorType.Mod; - break; - case DOUBLESLASH: - b.op = operatorType.FloorDiv; - break; - case AMPER: - b.op = operatorType.BitAnd; - break; - case VBAR: - b.op = operatorType.BitOr; - break; - case CIRCUMFLEX: - b.op = operatorType.BitXor; - break; - case LEFTSHIFT: - b.op = operatorType.LShift; - break; - case RIGHTSHIFT: - b.op = operatorType.RShift; - break; - case DOUBLESTAR: - b.op = operatorType.Pow; - break; - } + if ($op != null) { + $expr.tree = actions.makeBinOp($left.tree, operatorType.BitOr, $right); } } - : xor_expr (VBAR<BinOp>^ xor_expr)* + : left=xor_expr + ( (op=VBAR right+=xor_expr + )+ + | -> $left + ) ; + //xor_expr: and_expr ('^' and_expr)* -xor_expr : and_expr (CIRCUMFLEX<BinOp>^ and_expr)* - ; +xor_expr +@after { + if ($op != null) { + $xor_expr.tree = actions.makeBinOp($left.tree, operatorType.BitXor, $right); + } +} + : left=and_expr + ( (op=CIRCUMFLEX right+=and_expr + )+ + | -> $left + ) + ; //and_expr: shift_expr ('&' shift_expr)* -and_expr : shift_expr (AMPER<BinOp>^ shift_expr)* - ; +and_expr +@after { + if ($op != null) { + $and_expr.tree = actions.makeBinOp($left.tree, operatorType.BitAnd, $right); + } +} + : left=shift_expr + ( (op=AMPER right+=shift_expr + )+ + | -> $left + ) + ; //shift_expr: arith_expr (('<<'|'>>') arith_expr)* -shift_expr : arith_expr ((LEFTSHIFT<BinOp>^|RIGHTSHIFT<BinOp>^) arith_expr)* - ; +shift_expr +@init { + List ops = new ArrayList(); +} +@after { + if (!ops.isEmpty()) { + $shift_expr.tree = actions.makeBinOp($left.tree, ops, $right); + } +} + : left=arith_expr + ( ( shift_op right+=arith_expr {ops.add($shift_op.op);} + )+ + | -> $left + ) + ; +shift_op returns [operatorType op] + : LEFTSHIFT {$op = operatorType.LShift;} + | RIGHTSHIFT {$op = operatorType.RShift;} + ; + //arith_expr: term (('+'|'-') term)* - arith_expr - :term ((PLUS<BinOp>^|MINUS<BinOp>^) term)* +@init { + List ops = new ArrayList(); +} +@after { + if (!ops.isEmpty()) { + $arith_expr.tree = actions.makeBinOp($left.tree, ops, $right); + } +} + : left=term + ( (arith_op right+=term {ops.add($arith_op.op);} + )+ + | -> $left + ) ; +arith_op returns [operatorType op] + : PLUS {$op = operatorType.Add;} + | MINUS {$op = operatorType.Sub;} + ; + //term: factor (('*'|'/'|'%'|'//') factor)* -term : factor ((STAR<BinOp>^ | SLASH<BinOp>^ | PERCENT<BinOp>^ | DOUBLESLASH<BinOp>^ ) factor)* - ; +term +@init { + List ops = new ArrayList(); +} +@after { + if (!ops.isEmpty()) { + $term.tree = actions.makeBinOp($left.tree, ops, $right); + } +} + : left=factor + ( (term_op right+=factor {ops.add($term_op.op);} + )+ + | -> $left + ) + ; +term_op returns [operatorType op] + :STAR {$op = operatorType.Mult;} + |SLASH {$op = operatorType.Div;} + |PERCENT {$op = operatorType.Mod;} + |DOUBLESLASH {$op = operatorType.FloorDiv;} + ; + //factor: ('+'|'-'|'~') factor | power factor returns [exprType etype] @after { Modified: branches/nowalker/src/org/python/antlr/GrammarActions.java =================================================================== --- branches/nowalker/src/org/python/antlr/GrammarActions.java 2008-08-23 02:33:48 UTC (rev 5237) +++ branches/nowalker/src/org/python/antlr/GrammarActions.java 2008-08-23 19:19:16 UTC (rev 5238) @@ -737,4 +737,23 @@ values.addAll(right); return new BoolOp(left, op, makeExprs(values)); } + + BinOp makeBinOp(PythonTree left, operatorType op, List rights) { + BinOp current = new BinOp(left, (exprType)left, op, (exprType)rights.get(0)); + for (int i = 1; i< rights.size(); i++) { + exprType right = (exprType)rights.get(i); + current = new BinOp(left, current, op, right); + } + return current; + } + + BinOp makeBinOp(PythonTree left, List ops, List rights) { + BinOp current = new BinOp(left, (exprType)left, (operatorType)ops.get(0), (exprType)rights.get(0)); + for (int i = 1; i< rights.size(); i++) { + exprType right = (exprType)rights.get(i); + operatorType op = (operatorType)ops.get(i); + current = new BinOp(left, current, op, right); + } + return current; + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-08-23 02:33:53
|
Revision: 5237 http://jython.svn.sourceforge.net/jython/?rev=5237&view=rev Author: fwierzbicki Date: 2008-08-23 02:33:48 +0000 (Sat, 23 Aug 2008) Log Message: ----------- Add expr types to BaseTree children. Modified Paths: -------------- branches/nowalker/ast/asdl_antlr.py branches/nowalker/src/org/python/antlr/GrammarActions.java branches/nowalker/src/org/python/antlr/ast/Assert.java branches/nowalker/src/org/python/antlr/ast/Assign.java branches/nowalker/src/org/python/antlr/ast/Attribute.java branches/nowalker/src/org/python/antlr/ast/AugAssign.java branches/nowalker/src/org/python/antlr/ast/BinOp.java branches/nowalker/src/org/python/antlr/ast/Call.java branches/nowalker/src/org/python/antlr/ast/Compare.java branches/nowalker/src/org/python/antlr/ast/Exec.java branches/nowalker/src/org/python/antlr/ast/Expr.java branches/nowalker/src/org/python/antlr/ast/Expression.java branches/nowalker/src/org/python/antlr/ast/For.java branches/nowalker/src/org/python/antlr/ast/GeneratorExp.java branches/nowalker/src/org/python/antlr/ast/If.java branches/nowalker/src/org/python/antlr/ast/IfExp.java branches/nowalker/src/org/python/antlr/ast/Index.java branches/nowalker/src/org/python/antlr/ast/Lambda.java branches/nowalker/src/org/python/antlr/ast/ListComp.java branches/nowalker/src/org/python/antlr/ast/Print.java branches/nowalker/src/org/python/antlr/ast/Raise.java branches/nowalker/src/org/python/antlr/ast/Repr.java branches/nowalker/src/org/python/antlr/ast/Return.java branches/nowalker/src/org/python/antlr/ast/Slice.java branches/nowalker/src/org/python/antlr/ast/Subscript.java branches/nowalker/src/org/python/antlr/ast/UnaryOp.java branches/nowalker/src/org/python/antlr/ast/While.java branches/nowalker/src/org/python/antlr/ast/With.java branches/nowalker/src/org/python/antlr/ast/Yield.java branches/nowalker/src/org/python/antlr/ast/comprehensionType.java branches/nowalker/src/org/python/antlr/ast/excepthandlerType.java branches/nowalker/src/org/python/antlr/ast/keywordType.java Modified: branches/nowalker/ast/asdl_antlr.py =================================================================== --- branches/nowalker/ast/asdl_antlr.py 2008-08-22 23:03:45 UTC (rev 5236) +++ branches/nowalker/ast/asdl_antlr.py 2008-08-23 02:33:48 UTC (rev 5237) @@ -260,12 +260,15 @@ if f.typedef is not None and f.typedef.simple: not_simple = False #For now ignoring String -- will want to revisit - if f.seq and not_simple and not fparg.startswith("String"): - self.emit("if (%s != null) {" % f.name, depth+1); - self.emit("for(int i%(name)s=0;i%(name)s<%(name)s.length;i%(name)s++) {" % {"name":f.name}, depth+2) - self.emit("addChild(%s[i%s]);" % (f.name, f.name), depth+3) - self.emit("}", depth+2) - self.emit("}", depth+1) + if not_simple and not fparg.startswith("String"): + if f.seq: + self.emit("if (%s != null) {" % f.name, depth+1); + self.emit("for(int i%(name)s=0;i%(name)s<%(name)s.length;i%(name)s++) {" % {"name":f.name}, depth+2) + self.emit("addChild(%s[i%s]);" % (f.name, f.name), depth+3) + self.emit("}", depth+2) + self.emit("}", depth+1) + elif str(f.type) == "expr": + self.emit("addChild(%s);" % (f.name), depth+1) def javaMethods(self, type, clsname, ctorname, fields, depth): # The java ctors Modified: branches/nowalker/src/org/python/antlr/GrammarActions.java =================================================================== --- branches/nowalker/src/org/python/antlr/GrammarActions.java 2008-08-22 23:03:45 UTC (rev 5236) +++ branches/nowalker/src/org/python/antlr/GrammarActions.java 2008-08-23 02:33:48 UTC (rev 5237) @@ -303,7 +303,7 @@ ((Context)tree).setContext(context); } for (int i=0; i<tree.getChildCount(); i++) { - recurseSetContext(tree.getChild(i), context); + recurseSetContext(tree.getChild(i), context); } } Modified: branches/nowalker/src/org/python/antlr/ast/Assert.java =================================================================== --- branches/nowalker/src/org/python/antlr/ast/Assert.java 2008-08-22 23:03:45 UTC (rev 5236) +++ branches/nowalker/src/org/python/antlr/ast/Assert.java 2008-08-23 02:33:48 UTC (rev 5237) @@ -15,19 +15,25 @@ public Assert(Token token, exprType test, exprType msg) { super(token); this.test = test; + addChild(test); this.msg = msg; + addChild(msg); } public Assert(int ttype, Token token, exprType test, exprType msg) { super(ttype, token); this.test = test; + addChild(test); this.msg = msg; + addChild(msg); } public Assert(PythonTree tree, exprType test, exprType msg) { super(tree); this.test = test; + addChild(test); this.msg = msg; + addChild(msg); } public String toString() { Modified: branches/nowalker/src/org/python/antlr/ast/Assign.java =================================================================== --- branches/nowalker/src/org/python/antlr/ast/Assign.java 2008-08-22 23:03:45 UTC (rev 5236) +++ branches/nowalker/src/org/python/antlr/ast/Assign.java 2008-08-23 02:33:48 UTC (rev 5237) @@ -21,6 +21,7 @@ } } this.value = value; + addChild(value); } public Assign(int ttype, Token token, exprType[] targets, exprType value) { @@ -32,6 +33,7 @@ } } this.value = value; + addChild(value); } public Assign(PythonTree tree, exprType[] targets, exprType value) { @@ -43,6 +45,7 @@ } } this.value = value; + addChild(value); } public String toString() { Modified: branches/nowalker/src/org/python/antlr/ast/Attribute.java =================================================================== --- branches/nowalker/src/org/python/antlr/ast/Attribute.java 2008-08-22 23:03:45 UTC (rev 5236) +++ branches/nowalker/src/org/python/antlr/ast/Attribute.java 2008-08-23 02:33:48 UTC (rev 5237) @@ -17,6 +17,7 @@ ctx) { super(token); this.value = value; + addChild(value); this.attr = attr; this.ctx = ctx; } @@ -25,6 +26,7 @@ expr_contextType ctx) { super(ttype, token); this.value = value; + addChild(value); this.attr = attr; this.ctx = ctx; } @@ -33,6 +35,7 @@ expr_contextType ctx) { super(tree); this.value = value; + addChild(value); this.attr = attr; this.ctx = ctx; } Modified: branches/nowalker/src/org/python/antlr/ast/AugAssign.java =================================================================== --- branches/nowalker/src/org/python/antlr/ast/AugAssign.java 2008-08-22 23:03:45 UTC (rev 5236) +++ branches/nowalker/src/org/python/antlr/ast/AugAssign.java 2008-08-23 02:33:48 UTC (rev 5237) @@ -17,24 +17,30 @@ value) { super(token); this.target = target; + addChild(target); this.op = op; this.value = value; + addChild(value); } public AugAssign(int ttype, Token token, exprType target, operatorType op, exprType value) { super(ttype, token); this.target = target; + addChild(target); this.op = op; this.value = value; + addChild(value); } public AugAssign(PythonTree tree, exprType target, operatorType op, exprType value) { super(tree); this.target = target; + addChild(target); this.op = op; this.value = value; + addChild(value); } public String toString() { Modified: branches/nowalker/src/org/python/antlr/ast/BinOp.java =================================================================== --- branches/nowalker/src/org/python/antlr/ast/BinOp.java 2008-08-22 23:03:45 UTC (rev 5236) +++ branches/nowalker/src/org/python/antlr/ast/BinOp.java 2008-08-23 02:33:48 UTC (rev 5237) @@ -17,28 +17,33 @@ super(token); } - public BinOp(Token token, exprType left, operatorType op, exprType right) { super(token); this.left = left; + addChild(left); this.op = op; this.right = right; + addChild(right); } public BinOp(int ttype, Token token, exprType left, operatorType op, exprType right) { super(ttype, token); this.left = left; + addChild(left); this.op = op; this.right = right; + addChild(right); } public BinOp(PythonTree tree, exprType left, operatorType op, exprType right) { super(tree); this.left = left; + addChild(left); this.op = op; this.right = right; + addChild(right); } public String toString() { Modified: branches/nowalker/src/org/python/antlr/ast/Call.java =================================================================== --- branches/nowalker/src/org/python/antlr/ast/Call.java 2008-08-22 23:03:45 UTC (rev 5236) +++ branches/nowalker/src/org/python/antlr/ast/Call.java 2008-08-23 02:33:48 UTC (rev 5237) @@ -20,6 +20,7 @@ keywords, exprType starargs, exprType kwargs) { super(token); this.func = func; + addChild(func); this.args = args; if (args != null) { for(int iargs=0;iargs<args.length;iargs++) { @@ -33,13 +34,16 @@ } } this.starargs = starargs; + addChild(starargs); this.kwargs = kwargs; + addChild(kwargs); } public Call(int ttype, Token token, exprType func, exprType[] args, keywordType[] keywords, exprType starargs, exprType kwargs) { super(ttype, token); this.func = func; + addChild(func); this.args = args; if (args != null) { for(int iargs=0;iargs<args.length;iargs++) { @@ -53,13 +57,16 @@ } } this.starargs = starargs; + addChild(starargs); this.kwargs = kwargs; + addChild(kwargs); } public Call(PythonTree tree, exprType func, exprType[] args, keywordType[] keywords, exprType starargs, exprType kwargs) { super(tree); this.func = func; + addChild(func); this.args = args; if (args != null) { for(int iargs=0;iargs<args.length;iargs++) { @@ -73,7 +80,9 @@ } } this.starargs = starargs; + addChild(starargs); this.kwargs = kwargs; + addChild(kwargs); } public String toString() { Modified: branches/nowalker/src/org/python/antlr/ast/Compare.java =================================================================== --- branches/nowalker/src/org/python/antlr/ast/Compare.java 2008-08-22 23:03:45 UTC (rev 5236) +++ branches/nowalker/src/org/python/antlr/ast/Compare.java 2008-08-23 02:33:48 UTC (rev 5237) @@ -18,6 +18,7 @@ comparators) { super(token); this.left = left; + addChild(left); this.ops = ops; this.comparators = comparators; if (comparators != null) { @@ -32,6 +33,7 @@ exprType[] comparators) { super(ttype, token); this.left = left; + addChild(left); this.ops = ops; this.comparators = comparators; if (comparators != null) { @@ -46,6 +48,7 @@ comparators) { super(tree); this.left = left; + addChild(left); this.ops = ops; this.comparators = comparators; if (comparators != null) { Modified: branches/nowalker/src/org/python/antlr/ast/Exec.java =================================================================== --- branches/nowalker/src/org/python/antlr/ast/Exec.java 2008-08-22 23:03:45 UTC (rev 5236) +++ branches/nowalker/src/org/python/antlr/ast/Exec.java 2008-08-23 02:33:48 UTC (rev 5237) @@ -17,24 +17,33 @@ public Exec(Token token, exprType body, exprType globals, exprType locals) { super(token); this.body = body; + addChild(body); this.globals = globals; + addChild(globals); this.locals = locals; + addChild(locals); } public Exec(int ttype, Token token, exprType body, exprType globals, exprType locals) { super(ttype, token); this.body = body; + addChild(body); this.globals = globals; + addChild(globals); this.locals = locals; + addChild(locals); } public Exec(PythonTree tree, exprType body, exprType globals, exprType locals) { super(tree); this.body = body; + addChild(body); this.globals = globals; + addChild(globals); this.locals = locals; + addChild(locals); } public String toString() { Modified: branches/nowalker/src/org/python/antlr/ast/Expr.java =================================================================== --- branches/nowalker/src/org/python/antlr/ast/Expr.java 2008-08-22 23:03:45 UTC (rev 5236) +++ branches/nowalker/src/org/python/antlr/ast/Expr.java 2008-08-23 02:33:48 UTC (rev 5237) @@ -14,16 +14,19 @@ public Expr(Token token, exprType value) { super(token); this.value = value; + addChild(value); } public Expr(int ttype, Token token, exprType value) { super(ttype, token); this.value = value; + addChild(value); } public Expr(PythonTree tree, exprType value) { super(tree); this.value = value; + addChild(value); } public String toString() { Modified: branches/nowalker/src/org/python/antlr/ast/Expression.java =================================================================== --- branches/nowalker/src/org/python/antlr/ast/Expression.java 2008-08-22 23:03:45 UTC (rev 5236) +++ branches/nowalker/src/org/python/antlr/ast/Expression.java 2008-08-23 02:33:48 UTC (rev 5237) @@ -14,16 +14,19 @@ public Expression(Token token, exprType body) { super(token); this.body = body; + addChild(body); } public Expression(int ttype, Token token, exprType body) { super(ttype, token); this.body = body; + addChild(body); } public Expression(PythonTree tree, exprType body) { super(tree); this.body = body; + addChild(body); } public String toString() { Modified: branches/nowalker/src/org/python/antlr/ast/For.java =================================================================== --- branches/nowalker/src/org/python/antlr/ast/For.java 2008-08-22 23:03:45 UTC (rev 5236) +++ branches/nowalker/src/org/python/antlr/ast/For.java 2008-08-23 02:33:48 UTC (rev 5237) @@ -19,7 +19,9 @@ stmtType[] orelse) { super(token); this.target = target; + addChild(target); this.iter = iter; + addChild(iter); this.body = body; if (body != null) { for(int ibody=0;ibody<body.length;ibody++) { @@ -38,7 +40,9 @@ stmtType[] body, stmtType[] orelse) { super(ttype, token); this.target = target; + addChild(target); this.iter = iter; + addChild(iter); this.body = body; if (body != null) { for(int ibody=0;ibody<body.length;ibody++) { @@ -57,7 +61,9 @@ body, stmtType[] orelse) { super(tree); this.target = target; + addChild(target); this.iter = iter; + addChild(iter); this.body = body; if (body != null) { for(int ibody=0;ibody<body.length;ibody++) { Modified: branches/nowalker/src/org/python/antlr/ast/GeneratorExp.java =================================================================== --- branches/nowalker/src/org/python/antlr/ast/GeneratorExp.java 2008-08-22 23:03:45 UTC (rev 5236) +++ branches/nowalker/src/org/python/antlr/ast/GeneratorExp.java 2008-08-23 02:33:48 UTC (rev 5237) @@ -16,6 +16,7 @@ generators) { super(token); this.elt = elt; + addChild(elt); this.generators = generators; if (generators != null) { for(int igenerators=0;igenerators<generators.length;igenerators++) { @@ -28,6 +29,7 @@ comprehensionType[] generators) { super(ttype, token); this.elt = elt; + addChild(elt); this.generators = generators; if (generators != null) { for(int igenerators=0;igenerators<generators.length;igenerators++) { @@ -40,6 +42,7 @@ generators) { super(tree); this.elt = elt; + addChild(elt); this.generators = generators; if (generators != null) { for(int igenerators=0;igenerators<generators.length;igenerators++) { Modified: branches/nowalker/src/org/python/antlr/ast/If.java =================================================================== --- branches/nowalker/src/org/python/antlr/ast/If.java 2008-08-22 23:03:45 UTC (rev 5236) +++ branches/nowalker/src/org/python/antlr/ast/If.java 2008-08-23 02:33:48 UTC (rev 5237) @@ -17,6 +17,7 @@ public If(Token token, exprType test, stmtType[] body, stmtType[] orelse) { super(token); this.test = test; + addChild(test); this.body = body; if (body != null) { for(int ibody=0;ibody<body.length;ibody++) { @@ -35,6 +36,7 @@ stmtType[] orelse) { super(ttype, token); this.test = test; + addChild(test); this.body = body; if (body != null) { for(int ibody=0;ibody<body.length;ibody++) { @@ -53,6 +55,7 @@ orelse) { super(tree); this.test = test; + addChild(test); this.body = body; if (body != null) { for(int ibody=0;ibody<body.length;ibody++) { Modified: branches/nowalker/src/org/python/antlr/ast/IfExp.java =================================================================== --- branches/nowalker/src/org/python/antlr/ast/IfExp.java 2008-08-22 23:03:45 UTC (rev 5236) +++ branches/nowalker/src/org/python/antlr/ast/IfExp.java 2008-08-23 02:33:48 UTC (rev 5237) @@ -17,24 +17,33 @@ public IfExp(Token token, exprType test, exprType body, exprType orelse) { super(token); this.test = test; + addChild(test); this.body = body; + addChild(body); this.orelse = orelse; + addChild(orelse); } public IfExp(int ttype, Token token, exprType test, exprType body, exprType orelse) { super(ttype, token); this.test = test; + addChild(test); this.body = body; + addChild(body); this.orelse = orelse; + addChild(orelse); } public IfExp(PythonTree tree, exprType test, exprType body, exprType orelse) { super(tree); this.test = test; + addChild(test); this.body = body; + addChild(body); this.orelse = orelse; + addChild(orelse); } public String toString() { Modified: branches/nowalker/src/org/python/antlr/ast/Index.java =================================================================== --- branches/nowalker/src/org/python/antlr/ast/Index.java 2008-08-22 23:03:45 UTC (rev 5236) +++ branches/nowalker/src/org/python/antlr/ast/Index.java 2008-08-23 02:33:48 UTC (rev 5237) @@ -14,16 +14,19 @@ public Index(Token token, exprType value) { super(token); this.value = value; + addChild(value); } public Index(int ttype, Token token, exprType value) { super(ttype, token); this.value = value; + addChild(value); } public Index(PythonTree tree, exprType value) { super(tree); this.value = value; + addChild(value); } public String toString() { Modified: branches/nowalker/src/org/python/antlr/ast/Lambda.java =================================================================== --- branches/nowalker/src/org/python/antlr/ast/Lambda.java 2008-08-22 23:03:45 UTC (rev 5236) +++ branches/nowalker/src/org/python/antlr/ast/Lambda.java 2008-08-23 02:33:48 UTC (rev 5237) @@ -16,18 +16,21 @@ super(token); this.args = args; this.body = body; + addChild(body); } public Lambda(int ttype, Token token, argumentsType args, exprType body) { super(ttype, token); this.args = args; this.body = body; + addChild(body); } public Lambda(PythonTree tree, argumentsType args, exprType body) { super(tree); this.args = args; this.body = body; + addChild(body); } public String toString() { Modified: branches/nowalker/src/org/python/antlr/ast/ListComp.java =================================================================== --- branches/nowalker/src/org/python/antlr/ast/ListComp.java 2008-08-22 23:03:45 UTC (rev 5236) +++ branches/nowalker/src/org/python/antlr/ast/ListComp.java 2008-08-23 02:33:48 UTC (rev 5237) @@ -15,6 +15,7 @@ public ListComp(Token token, exprType elt, comprehensionType[] generators) { super(token); this.elt = elt; + addChild(elt); this.generators = generators; if (generators != null) { for(int igenerators=0;igenerators<generators.length;igenerators++) { @@ -27,6 +28,7 @@ generators) { super(ttype, token); this.elt = elt; + addChild(elt); this.generators = generators; if (generators != null) { for(int igenerators=0;igenerators<generators.length;igenerators++) { @@ -39,6 +41,7 @@ generators) { super(tree); this.elt = elt; + addChild(elt); this.generators = generators; if (generators != null) { for(int igenerators=0;igenerators<generators.length;igenerators++) { Modified: branches/nowalker/src/org/python/antlr/ast/Print.java =================================================================== --- branches/nowalker/src/org/python/antlr/ast/Print.java 2008-08-22 23:03:45 UTC (rev 5236) +++ branches/nowalker/src/org/python/antlr/ast/Print.java 2008-08-23 02:33:48 UTC (rev 5237) @@ -16,6 +16,7 @@ public Print(Token token, exprType dest, exprType[] values, boolean nl) { super(token); this.dest = dest; + addChild(dest); this.values = values; if (values != null) { for(int ivalues=0;ivalues<values.length;ivalues++) { @@ -29,6 +30,7 @@ boolean nl) { super(ttype, token); this.dest = dest; + addChild(dest); this.values = values; if (values != null) { for(int ivalues=0;ivalues<values.length;ivalues++) { @@ -42,6 +44,7 @@ { super(tree); this.dest = dest; + addChild(dest); this.values = values; if (values != null) { for(int ivalues=0;ivalues<values.length;ivalues++) { Modified: branches/nowalker/src/org/python/antlr/ast/Raise.java =================================================================== --- branches/nowalker/src/org/python/antlr/ast/Raise.java 2008-08-22 23:03:45 UTC (rev 5236) +++ branches/nowalker/src/org/python/antlr/ast/Raise.java 2008-08-23 02:33:48 UTC (rev 5237) @@ -16,24 +16,33 @@ public Raise(Token token, exprType type, exprType inst, exprType tback) { super(token); this.type = type; + addChild(type); this.inst = inst; + addChild(inst); this.tback = tback; + addChild(tback); } public Raise(int ttype, Token token, exprType type, exprType inst, exprType tback) { super(ttype, token); this.type = type; + addChild(type); this.inst = inst; + addChild(inst); this.tback = tback; + addChild(tback); } public Raise(PythonTree tree, exprType type, exprType inst, exprType tback) { super(tree); this.type = type; + addChild(type); this.inst = inst; + addChild(inst); this.tback = tback; + addChild(tback); } public String toString() { Modified: branches/nowalker/src/org/python/antlr/ast/Repr.java =================================================================== --- branches/nowalker/src/org/python/antlr/ast/Repr.java 2008-08-22 23:03:45 UTC (rev 5236) +++ branches/nowalker/src/org/python/antlr/ast/Repr.java 2008-08-23 02:33:48 UTC (rev 5237) @@ -14,16 +14,19 @@ public Repr(Token token, exprType value) { super(token); this.value = value; + addChild(value); } public Repr(int ttype, Token token, exprType value) { super(ttype, token); this.value = value; + addChild(value); } public Repr(PythonTree tree, exprType value) { super(tree); this.value = value; + addChild(value); } public String toString() { Modified: branches/nowalker/src/org/python/antlr/ast/Return.java =================================================================== --- branches/nowalker/src/org/python/antlr/ast/Return.java 2008-08-22 23:03:45 UTC (rev 5236) +++ branches/nowalker/src/org/python/antlr/ast/Return.java 2008-08-23 02:33:48 UTC (rev 5237) @@ -14,16 +14,19 @@ public Return(Token token, exprType value) { super(token); this.value = value; + addChild(value); } public Return(int ttype, Token token, exprType value) { super(ttype, token); this.value = value; + addChild(value); } public Return(PythonTree tree, exprType value) { super(tree); this.value = value; + addChild(value); } public String toString() { Modified: branches/nowalker/src/org/python/antlr/ast/Slice.java =================================================================== --- branches/nowalker/src/org/python/antlr/ast/Slice.java 2008-08-22 23:03:45 UTC (rev 5236) +++ branches/nowalker/src/org/python/antlr/ast/Slice.java 2008-08-23 02:33:48 UTC (rev 5237) @@ -17,24 +17,33 @@ public Slice(Token token, exprType lower, exprType upper, exprType step) { super(token); this.lower = lower; + addChild(lower); this.upper = upper; + addChild(upper); this.step = step; + addChild(step); } public Slice(int ttype, Token token, exprType lower, exprType upper, exprType step) { super(ttype, token); this.lower = lower; + addChild(lower); this.upper = upper; + addChild(upper); this.step = step; + addChild(step); } public Slice(PythonTree tree, exprType lower, exprType upper, exprType step) { super(tree); this.lower = lower; + addChild(lower); this.upper = upper; + addChild(upper); this.step = step; + addChild(step); } public String toString() { Modified: branches/nowalker/src/org/python/antlr/ast/Subscript.java =================================================================== --- branches/nowalker/src/org/python/antlr/ast/Subscript.java 2008-08-22 23:03:45 UTC (rev 5236) +++ branches/nowalker/src/org/python/antlr/ast/Subscript.java 2008-08-23 02:33:48 UTC (rev 5237) @@ -17,6 +17,7 @@ expr_contextType ctx) { super(token); this.value = value; + addChild(value); this.slice = slice; this.ctx = ctx; } @@ -25,6 +26,7 @@ expr_contextType ctx) { super(ttype, token); this.value = value; + addChild(value); this.slice = slice; this.ctx = ctx; } @@ -33,6 +35,7 @@ expr_contextType ctx) { super(tree); this.value = value; + addChild(value); this.slice = slice; this.ctx = ctx; } Modified: branches/nowalker/src/org/python/antlr/ast/UnaryOp.java =================================================================== --- branches/nowalker/src/org/python/antlr/ast/UnaryOp.java 2008-08-22 23:03:45 UTC (rev 5236) +++ branches/nowalker/src/org/python/antlr/ast/UnaryOp.java 2008-08-23 02:33:48 UTC (rev 5237) @@ -16,18 +16,21 @@ super(token); this.op = op; this.operand = operand; + addChild(operand); } public UnaryOp(int ttype, Token token, unaryopType op, exprType operand) { super(ttype, token); this.op = op; this.operand = operand; + addChild(operand); } public UnaryOp(PythonTree tree, unaryopType op, exprType operand) { super(tree); this.op = op; this.operand = operand; + addChild(operand); } public String toString() { Modified: branches/nowalker/src/org/python/antlr/ast/While.java =================================================================== --- branches/nowalker/src/org/python/antlr/ast/While.java 2008-08-22 23:03:45 UTC (rev 5236) +++ branches/nowalker/src/org/python/antlr/ast/While.java 2008-08-23 02:33:48 UTC (rev 5237) @@ -18,6 +18,7 @@ orelse) { super(token); this.test = test; + addChild(test); this.body = body; if (body != null) { for(int ibody=0;ibody<body.length;ibody++) { @@ -36,6 +37,7 @@ stmtType[] orelse) { super(ttype, token); this.test = test; + addChild(test); this.body = body; if (body != null) { for(int ibody=0;ibody<body.length;ibody++) { @@ -54,6 +56,7 @@ orelse) { super(tree); this.test = test; + addChild(test); this.body = body; if (body != null) { for(int ibody=0;ibody<body.length;ibody++) { Modified: branches/nowalker/src/org/python/antlr/ast/With.java =================================================================== --- branches/nowalker/src/org/python/antlr/ast/With.java 2008-08-22 23:03:45 UTC (rev 5236) +++ branches/nowalker/src/org/python/antlr/ast/With.java 2008-08-23 02:33:48 UTC (rev 5237) @@ -18,7 +18,9 @@ stmtType[] body) { super(token); this.context_expr = context_expr; + addChild(context_expr); this.optional_vars = optional_vars; + addChild(optional_vars); this.body = body; if (body != null) { for(int ibody=0;ibody<body.length;ibody++) { @@ -31,7 +33,9 @@ optional_vars, stmtType[] body) { super(ttype, token); this.context_expr = context_expr; + addChild(context_expr); this.optional_vars = optional_vars; + addChild(optional_vars); this.body = body; if (body != null) { for(int ibody=0;ibody<body.length;ibody++) { @@ -44,7 +48,9 @@ stmtType[] body) { super(tree); this.context_expr = context_expr; + addChild(context_expr); this.optional_vars = optional_vars; + addChild(optional_vars); this.body = body; if (body != null) { for(int ibody=0;ibody<body.length;ibody++) { Modified: branches/nowalker/src/org/python/antlr/ast/Yield.java =================================================================== --- branches/nowalker/src/org/python/antlr/ast/Yield.java 2008-08-22 23:03:45 UTC (rev 5236) +++ branches/nowalker/src/org/python/antlr/ast/Yield.java 2008-08-23 02:33:48 UTC (rev 5237) @@ -14,16 +14,19 @@ public Yield(Token token, exprType value) { super(token); this.value = value; + addChild(value); } public Yield(int ttype, Token token, exprType value) { super(ttype, token); this.value = value; + addChild(value); } public Yield(PythonTree tree, exprType value) { super(tree); this.value = value; + addChild(value); } public String toString() { Modified: branches/nowalker/src/org/python/antlr/ast/comprehensionType.java =================================================================== --- branches/nowalker/src/org/python/antlr/ast/comprehensionType.java 2008-08-22 23:03:45 UTC (rev 5236) +++ branches/nowalker/src/org/python/antlr/ast/comprehensionType.java 2008-08-23 02:33:48 UTC (rev 5237) @@ -17,7 +17,9 @@ exprType[] ifs) { super(token); this.target = target; + addChild(target); this.iter = iter; + addChild(iter); this.ifs = ifs; if (ifs != null) { for(int iifs=0;iifs<ifs.length;iifs++) { @@ -30,7 +32,9 @@ iter, exprType[] ifs) { super(ttype, token); this.target = target; + addChild(target); this.iter = iter; + addChild(iter); this.ifs = ifs; if (ifs != null) { for(int iifs=0;iifs<ifs.length;iifs++) { @@ -43,7 +47,9 @@ exprType[] ifs) { super(tree); this.target = target; + addChild(target); this.iter = iter; + addChild(iter); this.ifs = ifs; if (ifs != null) { for(int iifs=0;iifs<ifs.length;iifs++) { Modified: branches/nowalker/src/org/python/antlr/ast/excepthandlerType.java =================================================================== --- branches/nowalker/src/org/python/antlr/ast/excepthandlerType.java 2008-08-22 23:03:45 UTC (rev 5236) +++ branches/nowalker/src/org/python/antlr/ast/excepthandlerType.java 2008-08-23 02:33:48 UTC (rev 5237) @@ -20,7 +20,9 @@ stmtType[] body, int lineno, int col_offset) { super(token); this.type = type; + addChild(type); this.name = name; + addChild(name); this.body = body; if (body != null) { for(int ibody=0;ibody<body.length;ibody++) { @@ -35,7 +37,9 @@ name, stmtType[] body, int lineno, int col_offset) { super(ttype, token); this.type = type; + addChild(type); this.name = name; + addChild(name); this.body = body; if (body != null) { for(int ibody=0;ibody<body.length;ibody++) { @@ -50,7 +54,9 @@ stmtType[] body, int lineno, int col_offset) { super(tree); this.type = type; + addChild(type); this.name = name; + addChild(name); this.body = body; if (body != null) { for(int ibody=0;ibody<body.length;ibody++) { Modified: branches/nowalker/src/org/python/antlr/ast/keywordType.java =================================================================== --- branches/nowalker/src/org/python/antlr/ast/keywordType.java 2008-08-22 23:03:45 UTC (rev 5236) +++ branches/nowalker/src/org/python/antlr/ast/keywordType.java 2008-08-23 02:33:48 UTC (rev 5237) @@ -16,18 +16,21 @@ super(token); this.arg = arg; this.value = value; + addChild(value); } public keywordType(int ttype, Token token, String arg, exprType value) { super(ttype, token); this.arg = arg; this.value = value; + addChild(value); } public keywordType(PythonTree tree, String arg, exprType value) { super(tree); this.arg = arg; this.value = value; + addChild(value); } public String toString() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-08-22 23:03:47
|
Revision: 5236 http://jython.svn.sourceforge.net/jython/?rev=5236&view=rev Author: fwierzbicki Date: 2008-08-22 23:03:45 +0000 (Fri, 22 Aug 2008) Log Message: ----------- Bugfix for expr_contextType on assign values. Modified Paths: -------------- branches/nowalker/src/org/python/antlr/GrammarActions.java Modified: branches/nowalker/src/org/python/antlr/GrammarActions.java =================================================================== --- branches/nowalker/src/org/python/antlr/GrammarActions.java 2008-08-22 23:02:32 UTC (rev 5235) +++ branches/nowalker/src/org/python/antlr/GrammarActions.java 2008-08-22 23:03:45 UTC (rev 5236) @@ -284,9 +284,9 @@ if (o instanceof PythonParser.testlist_return) { //XXX: Check to see if this is really happening anymore PythonParser.testlist_return r = (PythonParser.testlist_return)o; - e[i] = (exprType)r.getTree(); + e[i + 1] = (exprType)r.getTree(); } else { - e[i] = (exprType)o; + e[i + 1] = (exprType)o; } } return e; @@ -300,7 +300,6 @@ void recurseSetContext(Tree tree, expr_contextType context) { if (tree instanceof Context) { - //XXX: for Tuples, etc -- will need to recursively set to expr_contextType.Load. ((Context)tree).setContext(context); } for (int i=0; i<tree.getChildCount(); i++) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-08-22 23:02:37
|
Revision: 5235 http://jython.svn.sourceforge.net/jython/?rev=5235&view=rev Author: fwierzbicki Date: 2008-08-22 23:02:32 +0000 (Fri, 22 Aug 2008) Log Message: ----------- Merged revisions 5227,5229,5231-5234 via svnmerge from https://jython.svn.sourceforge.net/svnroot/jython/trunk/jython ........ r5227 | pjenvey | 2008-08-20 19:01:42 -0400 (Wed, 20 Aug 2008) | 3 lines rewrite the subx joiner yet again: this time exactly as CPython does it, with __getslice__ and join. fixes a string subclass corner case ........ r5229 | leosoto | 2008-08-20 23:23:28 -0400 (Wed, 20 Aug 2008) | 1 line Fixing #1095 for old-style classes. Thanks to Anselm Kruls for the patch. ........ r5231 | pjenvey | 2008-08-21 15:44:29 -0400 (Thu, 21 Aug 2008) | 3 lines make cStringIO thread safe as unfortunately the CPython GIL guarantees it, as does the pure python version. add cStringIO.In/OutputType ........ r5232 | pjenvey | 2008-08-21 19:59:46 -0400 (Thu, 21 Aug 2008) | 1 line document TypeError vs AttributeError here ........ r5233 | fwierzbicki | 2008-08-22 11:31:56 -0400 (Fri, 22 Aug 2008) | 2 lines Switch "type"->"kind" for the compile parameter value which specifies the kind of parse/compile "exec", "eval", or "single". CPython's source uses "kind" and other parts of Jython use this term as well. ........ r5234 | pjenvey | 2008-08-22 16:16:59 -0400 (Fri, 22 Aug 2008) | 3 lines fix unicode __add__ and repeat always forcing the basic plane on the result -- can't optimize for strs when unicode also uses these methods ........ Modified Paths: -------------- branches/nowalker/Lib/test/test_descr_jy.py branches/nowalker/Lib/test/test_re_jy.py branches/nowalker/src/org/python/core/Py.java branches/nowalker/src/org/python/core/PyInstance.java branches/nowalker/src/org/python/core/PyObject.java branches/nowalker/src/org/python/core/PyString.java branches/nowalker/src/org/python/core/__builtin__.java branches/nowalker/src/org/python/modules/cStringIO.java branches/nowalker/src/org/python/modules/sre/PatternObject.java Added Paths: ----------- branches/nowalker/Lib/test/test_unicode_jy.py Property Changed: ---------------- branches/nowalker/ Property changes on: branches/nowalker ___________________________________________________________________ Modified: svnmerge-integrated - /trunk/jython:1-5221 + /trunk/jython:1-5234 Modified: branches/nowalker/Lib/test/test_descr_jy.py =================================================================== --- branches/nowalker/Lib/test/test_descr_jy.py 2008-08-22 20:16:59 UTC (rev 5234) +++ branches/nowalker/Lib/test/test_descr_jy.py 2008-08-22 23:02:32 UTC (rev 5235) @@ -326,16 +326,34 @@ def __getattr__(self, name): raise BarAttributeError + class BarClassic: + def __getattr__(self, name): + raise BarAttributeError + class Foo(object): def __getattr__(self, name): raise AttributeError("Custom message") + + class FooClassic: + def __getattr__(self, name): + raise AttributeError("Custom message") + self.assertRaises(BarAttributeError, lambda: Bar().x) + self.assertRaises(BarAttributeError, lambda: BarClassic().x) + try: Foo().x self.assert_(False) # Previous line should raise AttributteError except AttributeError, e: self.assertEquals("Custom message", str(e)) + try: + FooClassic().x + self.assert_(False) # Previous line should raise AttributteError + except AttributeError, e: + self.assertEquals("Custom message", str(e)) + + def test_main(): test_support.run_unittest(TestDescrTestCase, SubclassDescrTestCase, Modified: branches/nowalker/Lib/test/test_re_jy.py =================================================================== --- branches/nowalker/Lib/test/test_re_jy.py 2008-08-22 20:16:59 UTC (rev 5234) +++ branches/nowalker/Lib/test/test_re_jy.py 2008-08-22 23:02:32 UTC (rev 5235) @@ -8,6 +8,23 @@ result = re.sub('', lambda match : None, 'foo') self.assertEqual(result, 'foo') self.assert_(isinstance(result, str)) + + def test_sub_with_subclasses(self): + class Foo(unicode): + def join(self, items): + return Foo(unicode.join(self, items)) + result = re.sub('bar', 'baz', Foo('bar')) + self.assertEqual(result, u'baz') + self.assertEqual(type(result), unicode) + + class Foo2(unicode): + def join(self, items): + return Foo2(unicode.join(self, items)) + def __getslice__(self, start, stop): + return Foo2(unicode.__getslice__(self, start, stop)) + result = re.sub('bar', 'baz', Foo2('bar')) + self.assertEqual(result, Foo2('baz')) + self.assert_(isinstance(result, Foo2)) def test_unkown_groupname(self): self.assertRaises(IndexError, Copied: branches/nowalker/Lib/test/test_unicode_jy.py (from rev 5234, trunk/jython/Lib/test/test_unicode_jy.py) =================================================================== --- branches/nowalker/Lib/test/test_unicode_jy.py (rev 0) +++ branches/nowalker/Lib/test/test_unicode_jy.py 2008-08-22 23:02:32 UTC (rev 5235) @@ -0,0 +1,28 @@ +"""Misc unicode tests + +Made for Jython. +""" +import re +import unittest +from test import test_support + +class UnicodeTestCase(unittest.TestCase): + + def test_simplejson_plane_bug(self): + # a bug exposed by simplejson: unicode __add__ was always + # forcing the basic plane + chunker = re.compile(r'(.*?)(["\\\x00-\x1f])', re.VERBOSE | re.MULTILINE | re.DOTALL) + orig = u'z\U0001d120x' + quoted1 = u'"z\U0001d120x"' + quoted2 = '"' + orig + '"' + # chunker re gives different results depending on the plane + self.assertEqual(chunker.match(quoted1, 1).groups(), (orig, u'"')) + self.assertEqual(chunker.match(quoted2, 1).groups(), (orig, u'"')) + + +def test_main(): + test_support.run_unittest(UnicodeTestCase) + + +if __name__ == "__main__": + test_main() Modified: branches/nowalker/src/org/python/core/Py.java =================================================================== --- branches/nowalker/src/org/python/core/Py.java 2008-08-22 20:16:59 UTC (rev 5234) +++ branches/nowalker/src/org/python/core/Py.java 2008-08-22 23:02:32 UTC (rev 5235) @@ -1641,8 +1641,8 @@ } public static PyObject compile(InputStream istream, String filename, - String type) { - return compile_flags(istream, filename, type, null); + String kind) { + return compile_flags(istream, filename, kind, null); } // with compiler-flags @@ -1664,15 +1664,15 @@ } public static PyObject compile_flags(InputStream istream, String filename, - String type,CompilerFlags cflags) + String kind,CompilerFlags cflags) { - modType node = ParserFacade.parse(istream, type, filename, cflags); + modType node = ParserFacade.parse(istream, kind, filename, cflags); if (cflags != null && cflags.only_ast) { return Py.java2py(node); } boolean printResults = false; - if (type.equals("single")) { + if (kind.equals("single")) { printResults = true; } return Py.compile_flags(node, getName(), filename, true, printResults, cflags); @@ -1680,7 +1680,7 @@ public static PyObject compile_flags(String data, String filename, - String type, + String kind, CompilerFlags cflags) { if (data.contains("\0")) { @@ -1695,7 +1695,7 @@ } return Py.compile_flags(new ByteArrayInputStream(bytes), filename, - type, + kind, cflags); } Modified: branches/nowalker/src/org/python/core/PyInstance.java =================================================================== --- branches/nowalker/src/org/python/core/PyInstance.java 2008-08-22 20:16:59 UTC (rev 5234) +++ branches/nowalker/src/org/python/core/PyInstance.java 2008-08-22 23:02:32 UTC (rev 5235) @@ -201,10 +201,19 @@ } public PyObject __findattr_ex__(String name) { - return __findattr__(name, false); + return __findattr_ex__(name, false); } public PyObject __findattr__(String name, boolean stopAtJava) { + try { + return __findattr_ex__(name, stopAtJava); + } catch (PyException exc) { + if (Py.matchException(exc, Py.AttributeError)) return null; + throw exc; + } + } + + protected PyObject __findattr_ex__(String name, boolean stopAtJava) { PyObject result = ifindlocal(name); if (result != null) return result; @@ -234,12 +243,7 @@ if (getter == null) return null; - try { - return getter.__call__(this, new PyString(name)); - } catch (PyException exc) { - if (Py.matchException(exc, Py.AttributeError)) return null; - throw exc; - } + return getter.__call__(this, new PyString(name)); } public boolean isCallable() { Modified: branches/nowalker/src/org/python/core/PyObject.java =================================================================== --- branches/nowalker/src/org/python/core/PyObject.java 2008-08-22 20:16:59 UTC (rev 5234) +++ branches/nowalker/src/org/python/core/PyObject.java 2008-08-22 23:02:32 UTC (rev 5235) @@ -829,6 +829,9 @@ } public void readonlyAttributeError(String name) { + // XXX: Should be an AttributeError but CPython throws TypeError for read only + // member descriptors (in structmember.c::PyMember_SetOne), which is expected by a + // few tests. fixed in py3k: http://bugs.python.org/issue1687163 throw Py.TypeError("readonly attribute"); } Modified: branches/nowalker/src/org/python/core/PyString.java =================================================================== --- branches/nowalker/src/org/python/core/PyString.java 2008-08-22 20:16:59 UTC (rev 5234) +++ branches/nowalker/src/org/python/core/PyString.java 2008-08-22 23:02:32 UTC (rev 5235) @@ -670,7 +670,7 @@ for(int i = 0; i < count; i++) { string.getChars(0, s, new_chars, i * s); } - return createInstance(new String(new_chars), true); + return createInstance(new String(new_chars)); } @Override @@ -711,7 +711,7 @@ if (generic_other instanceof PyUnicode) { return new PyUnicode(result); } - return createInstance(result, true); + return createInstance(result); } else return null; } Modified: branches/nowalker/src/org/python/core/__builtin__.java =================================================================== --- branches/nowalker/src/org/python/core/__builtin__.java 2008-08-22 20:16:59 UTC (rev 5234) +++ branches/nowalker/src/org/python/core/__builtin__.java 2008-08-22 23:02:32 UTC (rev 5235) @@ -455,15 +455,15 @@ throw Py.TypeError("number coercion failed"); } - public static PyObject compile(String data, String filename, String type) { - return Py.compile_flags(data, filename, type, Py.getCompilerFlags()); + public static PyObject compile(String data, String filename, String kind) { + return Py.compile_flags(data, filename, kind, Py.getCompilerFlags()); } - public static PyObject compile(String data, String filename, String type, int flags, boolean dont_inherit) { + public static PyObject compile(String data, String filename, String kind, int flags, boolean dont_inherit) { if ((flags & ~PyTableCode.CO_ALL_FEATURES) != 0) { throw Py.ValueError("compile(): unrecognised flags"); } - return Py.compile_flags(data, filename, type, Py.getCompilerFlags(flags, dont_inherit)); + return Py.compile_flags(data, filename, kind, Py.getCompilerFlags(flags, dont_inherit)); } public static void delattr(PyObject o, String n) { Modified: branches/nowalker/src/org/python/modules/cStringIO.java =================================================================== --- branches/nowalker/src/org/python/modules/cStringIO.java 2008-08-22 20:16:59 UTC (rev 5234) +++ branches/nowalker/src/org/python/modules/cStringIO.java 2008-08-22 23:02:32 UTC (rev 5235) @@ -16,6 +16,7 @@ import org.python.core.PyList; import org.python.core.PyObject; import org.python.core.PyString; +import org.python.core.PyType; /** * This module implements a file-like class, StringIO, that reads and @@ -37,6 +38,9 @@ public static final int SEEK_CUR = 1; public static final int SEEK_END = 2; } + + public static PyType InputType = PyType.fromClass(StringIO.class); + public static PyType OutputType = PyType.fromClass(StringIO.class); public static StringIO StringIO() { return new StringIO(); @@ -133,7 +137,7 @@ * @param pos the position in the file. * @param mode; 0=from the start, 1=relative, 2=from the end. */ - public void seek(long pos, int mode) { + public synchronized void seek(long pos, int mode) { _complain_ifclosed(); switch (mode) { case os.SEEK_CUR: @@ -152,7 +156,7 @@ /** * Reset the file position to the beginning of the file. */ - public void reset() { + public synchronized void reset() { pos = 0; } @@ -160,7 +164,7 @@ * Return the file position. * @returns the position in the file. */ - public int tell() { + public synchronized int tell() { _complain_ifclosed(); return pos; } @@ -186,7 +190,7 @@ * @returns A string containing the data read. */ - public String read(long size) { + public synchronized String read(long size) { _complain_ifclosed(); int size_int = _convert_to_int(size); int len = buf.length(); @@ -225,7 +229,7 @@ * returned. * @returns data from the file up to and including the newline. */ - public String readline(long size) { + public synchronized String readline(long size) { _complain_ifclosed(); int size_int = _convert_to_int(size); int len = buf.length(); @@ -247,7 +251,7 @@ * Read and return a line without the trailing newline. * Usind by cPickle as an optimization. */ - public String readlineNoNl() { + public synchronized String readlineNoNl() { _complain_ifclosed(); int len = buf.length(); int i = buf.indexOf("\n", pos); @@ -303,7 +307,7 @@ /** * truncate the file at the position pos. */ - public void truncate(long pos) { + public synchronized void truncate(long pos) { int pos_int = _convert_to_int(pos); if (pos_int < 0) pos_int = this.pos; @@ -320,7 +324,7 @@ write(obj.toString()); } - public void write(String s) { + public synchronized void write(String s) { _complain_ifclosed(); buf.setLength(pos); int newpos = pos + s.length(); @@ -332,7 +336,7 @@ * Write a char to the file. Used by cPickle as an optimization. * @param ch The data to write. */ - public void writeChar(char ch) { + public synchronized void writeChar(char ch) { int len = buf.length(); if (len <= pos) buf.setLength(pos + 1); @@ -363,7 +367,7 @@ * before the StringIO object's close() method is called. * @return the contents of the StringIO. */ - public String getvalue() { + public synchronized String getvalue() { return buf.toString(); } Modified: branches/nowalker/src/org/python/modules/sre/PatternObject.java =================================================================== --- branches/nowalker/src/org/python/modules/sre/PatternObject.java 2008-08-22 20:16:59 UTC (rev 5234) +++ branches/nowalker/src/org/python/modules/sre/PatternObject.java 2008-08-22 23:02:32 UTC (rev 5235) @@ -118,7 +118,7 @@ SRE_STATE state = new SRE_STATE(string, 0, Integer.MAX_VALUE, flags); - StringBuilder buf = new StringBuilder(); + PyList list = new PyList(); int n = 0; int i = 0; @@ -137,7 +137,7 @@ if (i < b) { /* get segment before this match */ - buf.append(string.substring(i, b)); + list.append(string.__getslice__(Py.newInteger(i), Py.newInteger(b))); } if (! (i == b && i == e && n > 0)) { PyObject item; @@ -150,7 +150,7 @@ } if (item != Py.None) { - buf.append(item.toString()); + list.append(item); } i = e; n++; @@ -163,25 +163,23 @@ state.start = state.ptr; } if (i < state.endpos) { - buf.append(string.substring(i, state.endpos)); + list.append(string.__getslice__(Py.newInteger(i), Py.newInteger(state.endpos))); } - // Follows rules enumerated in test_re.test_bug_1140 - PyString outstring; - if (buf.length() == 0) { - outstring = instring.createInstance(buf.toString()); - } else if (template instanceof PyUnicode || instring instanceof PyUnicode) { - outstring = Py.newUnicode(buf.toString()); - } else { - outstring = Py.newString(buf.toString()); - } - + PyObject outstring = join_list(list, string); if (subn) { return new PyTuple(outstring, Py.newInteger(n)); } return outstring; } + private PyObject join_list(PyList list, PyString string) { + PyObject joiner = string.__getslice__(Py.Zero, Py.Zero); + if (list.size() == 0) { + return joiner; + } + return joiner.__getattr__("join").__call__(list); + } public PyObject split(PyObject[] args, String[] kws) { ArgParser ap = new ArgParser("split", args, kws, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-08-22 20:17:02
|
Revision: 5234 http://jython.svn.sourceforge.net/jython/?rev=5234&view=rev Author: pjenvey Date: 2008-08-22 20:16:59 +0000 (Fri, 22 Aug 2008) Log Message: ----------- fix unicode __add__ and repeat always forcing the basic plane on the result -- can't optimize for strs when unicode also uses these methods Modified Paths: -------------- trunk/jython/src/org/python/core/PyString.java Added Paths: ----------- trunk/jython/Lib/test/test_unicode_jy.py Added: trunk/jython/Lib/test/test_unicode_jy.py =================================================================== --- trunk/jython/Lib/test/test_unicode_jy.py (rev 0) +++ trunk/jython/Lib/test/test_unicode_jy.py 2008-08-22 20:16:59 UTC (rev 5234) @@ -0,0 +1,28 @@ +"""Misc unicode tests + +Made for Jython. +""" +import re +import unittest +from test import test_support + +class UnicodeTestCase(unittest.TestCase): + + def test_simplejson_plane_bug(self): + # a bug exposed by simplejson: unicode __add__ was always + # forcing the basic plane + chunker = re.compile(r'(.*?)(["\\\x00-\x1f])', re.VERBOSE | re.MULTILINE | re.DOTALL) + orig = u'z\U0001d120x' + quoted1 = u'"z\U0001d120x"' + quoted2 = '"' + orig + '"' + # chunker re gives different results depending on the plane + self.assertEqual(chunker.match(quoted1, 1).groups(), (orig, u'"')) + self.assertEqual(chunker.match(quoted2, 1).groups(), (orig, u'"')) + + +def test_main(): + test_support.run_unittest(UnicodeTestCase) + + +if __name__ == "__main__": + test_main() Modified: trunk/jython/src/org/python/core/PyString.java =================================================================== --- trunk/jython/src/org/python/core/PyString.java 2008-08-22 15:31:56 UTC (rev 5233) +++ trunk/jython/src/org/python/core/PyString.java 2008-08-22 20:16:59 UTC (rev 5234) @@ -670,7 +670,7 @@ for(int i = 0; i < count; i++) { string.getChars(0, s, new_chars, i * s); } - return createInstance(new String(new_chars), true); + return createInstance(new String(new_chars)); } @Override @@ -711,7 +711,7 @@ if (generic_other instanceof PyUnicode) { return new PyUnicode(result); } - return createInstance(result, true); + return createInstance(result); } else return null; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-08-22 15:31:59
|
Revision: 5233 http://jython.svn.sourceforge.net/jython/?rev=5233&view=rev Author: fwierzbicki Date: 2008-08-22 15:31:56 +0000 (Fri, 22 Aug 2008) Log Message: ----------- Switch "type"->"kind" for the compile parameter value which specifies the kind of parse/compile "exec", "eval", or "single". CPython's source uses "kind" and other parts of Jython use this term as well. Modified Paths: -------------- trunk/jython/src/org/python/core/Py.java trunk/jython/src/org/python/core/__builtin__.java Modified: trunk/jython/src/org/python/core/Py.java =================================================================== --- trunk/jython/src/org/python/core/Py.java 2008-08-21 23:59:46 UTC (rev 5232) +++ trunk/jython/src/org/python/core/Py.java 2008-08-22 15:31:56 UTC (rev 5233) @@ -1641,8 +1641,8 @@ } public static PyObject compile(InputStream istream, String filename, - String type) { - return compile_flags(istream, filename, type, null); + String kind) { + return compile_flags(istream, filename, kind, null); } // with compiler-flags @@ -1664,15 +1664,15 @@ } public static PyObject compile_flags(InputStream istream, String filename, - String type,CompilerFlags cflags) + String kind,CompilerFlags cflags) { - modType node = ParserFacade.parse(istream, type, filename, cflags); + modType node = ParserFacade.parse(istream, kind, filename, cflags); if (cflags != null && cflags.only_ast) { return Py.java2py(node); } boolean printResults = false; - if (type.equals("single")) { + if (kind.equals("single")) { printResults = true; } return Py.compile_flags(node, getName(), filename, true, printResults, cflags); @@ -1680,7 +1680,7 @@ public static PyObject compile_flags(String data, String filename, - String type, + String kind, CompilerFlags cflags) { if (data.contains("\0")) { @@ -1695,7 +1695,7 @@ } return Py.compile_flags(new ByteArrayInputStream(bytes), filename, - type, + kind, cflags); } Modified: trunk/jython/src/org/python/core/__builtin__.java =================================================================== --- trunk/jython/src/org/python/core/__builtin__.java 2008-08-21 23:59:46 UTC (rev 5232) +++ trunk/jython/src/org/python/core/__builtin__.java 2008-08-22 15:31:56 UTC (rev 5233) @@ -455,15 +455,15 @@ throw Py.TypeError("number coercion failed"); } - public static PyObject compile(String data, String filename, String type) { - return Py.compile_flags(data, filename, type, Py.getCompilerFlags()); + public static PyObject compile(String data, String filename, String kind) { + return Py.compile_flags(data, filename, kind, Py.getCompilerFlags()); } - public static PyObject compile(String data, String filename, String type, int flags, boolean dont_inherit) { + public static PyObject compile(String data, String filename, String kind, int flags, boolean dont_inherit) { if ((flags & ~PyTableCode.CO_ALL_FEATURES) != 0) { throw Py.ValueError("compile(): unrecognised flags"); } - return Py.compile_flags(data, filename, type, Py.getCompilerFlags(flags, dont_inherit)); + return Py.compile_flags(data, filename, kind, Py.getCompilerFlags(flags, dont_inherit)); } public static void delattr(PyObject o, String n) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-08-21 23:59:49
|
Revision: 5232 http://jython.svn.sourceforge.net/jython/?rev=5232&view=rev Author: pjenvey Date: 2008-08-21 23:59:46 +0000 (Thu, 21 Aug 2008) Log Message: ----------- document TypeError vs AttributeError here Modified Paths: -------------- trunk/jython/src/org/python/core/PyObject.java Modified: trunk/jython/src/org/python/core/PyObject.java =================================================================== --- trunk/jython/src/org/python/core/PyObject.java 2008-08-21 19:44:29 UTC (rev 5231) +++ trunk/jython/src/org/python/core/PyObject.java 2008-08-21 23:59:46 UTC (rev 5232) @@ -829,6 +829,9 @@ } public void readonlyAttributeError(String name) { + // XXX: Should be an AttributeError but CPython throws TypeError for read only + // member descriptors (in structmember.c::PyMember_SetOne), which is expected by a + // few tests. fixed in py3k: http://bugs.python.org/issue1687163 throw Py.TypeError("readonly attribute"); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-08-21 19:44:31
|
Revision: 5231 http://jython.svn.sourceforge.net/jython/?rev=5231&view=rev Author: pjenvey Date: 2008-08-21 19:44:29 +0000 (Thu, 21 Aug 2008) Log Message: ----------- make cStringIO thread safe as unfortunately the CPython GIL guarantees it, as does the pure python version. add cStringIO.In/OutputType Modified Paths: -------------- trunk/jython/src/org/python/modules/cStringIO.java Modified: trunk/jython/src/org/python/modules/cStringIO.java =================================================================== --- trunk/jython/src/org/python/modules/cStringIO.java 2008-08-21 03:47:32 UTC (rev 5230) +++ trunk/jython/src/org/python/modules/cStringIO.java 2008-08-21 19:44:29 UTC (rev 5231) @@ -16,6 +16,7 @@ import org.python.core.PyList; import org.python.core.PyObject; import org.python.core.PyString; +import org.python.core.PyType; /** * This module implements a file-like class, StringIO, that reads and @@ -37,6 +38,9 @@ public static final int SEEK_CUR = 1; public static final int SEEK_END = 2; } + + public static PyType InputType = PyType.fromClass(StringIO.class); + public static PyType OutputType = PyType.fromClass(StringIO.class); public static StringIO StringIO() { return new StringIO(); @@ -133,7 +137,7 @@ * @param pos the position in the file. * @param mode; 0=from the start, 1=relative, 2=from the end. */ - public void seek(long pos, int mode) { + public synchronized void seek(long pos, int mode) { _complain_ifclosed(); switch (mode) { case os.SEEK_CUR: @@ -152,7 +156,7 @@ /** * Reset the file position to the beginning of the file. */ - public void reset() { + public synchronized void reset() { pos = 0; } @@ -160,7 +164,7 @@ * Return the file position. * @returns the position in the file. */ - public int tell() { + public synchronized int tell() { _complain_ifclosed(); return pos; } @@ -186,7 +190,7 @@ * @returns A string containing the data read. */ - public String read(long size) { + public synchronized String read(long size) { _complain_ifclosed(); int size_int = _convert_to_int(size); int len = buf.length(); @@ -225,7 +229,7 @@ * returned. * @returns data from the file up to and including the newline. */ - public String readline(long size) { + public synchronized String readline(long size) { _complain_ifclosed(); int size_int = _convert_to_int(size); int len = buf.length(); @@ -247,7 +251,7 @@ * Read and return a line without the trailing newline. * Usind by cPickle as an optimization. */ - public String readlineNoNl() { + public synchronized String readlineNoNl() { _complain_ifclosed(); int len = buf.length(); int i = buf.indexOf("\n", pos); @@ -303,7 +307,7 @@ /** * truncate the file at the position pos. */ - public void truncate(long pos) { + public synchronized void truncate(long pos) { int pos_int = _convert_to_int(pos); if (pos_int < 0) pos_int = this.pos; @@ -320,7 +324,7 @@ write(obj.toString()); } - public void write(String s) { + public synchronized void write(String s) { _complain_ifclosed(); buf.setLength(pos); int newpos = pos + s.length(); @@ -332,7 +336,7 @@ * Write a char to the file. Used by cPickle as an optimization. * @param ch The data to write. */ - public void writeChar(char ch) { + public synchronized void writeChar(char ch) { int len = buf.length(); if (len <= pos) buf.setLength(pos + 1); @@ -363,7 +367,7 @@ * before the StringIO object's close() method is called. * @return the contents of the StringIO. */ - public String getvalue() { + public synchronized String getvalue() { return buf.toString(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-08-21 03:47:34
|
Revision: 5230 http://jython.svn.sourceforge.net/jython/?rev=5230&view=rev Author: fwierzbicki Date: 2008-08-21 03:47:32 +0000 (Thu, 21 Aug 2008) Log Message: ----------- bugfix on exception and on assign value expr_contextType. Modified Paths: -------------- branches/nowalker/grammar/Python.g branches/nowalker/src/org/python/antlr/GrammarActions.java Modified: branches/nowalker/grammar/Python.g =================================================================== --- branches/nowalker/grammar/Python.g 2008-08-21 03:23:28 UTC (rev 5229) +++ branches/nowalker/grammar/Python.g 2008-08-21 03:47:32 UTC (rev 5230) @@ -754,7 +754,7 @@ ; //except_clause: 'except' [test [',' test]] -except_clause : EXCEPT (t1=test[expr_contextType.Load] (COMMA t2=test[expr_contextType.Load])?)? COLON suite +except_clause : EXCEPT (t1=test[expr_contextType.Load] (COMMA t2=test[expr_contextType.Store])?)? COLON suite -> ^(EXCEPT<excepthandlerType>[$EXCEPT, (exprType)$t1.tree, (exprType)$t2.tree, actions.makeStmts($suite.stmts), $EXCEPT.getLine(), $EXCEPT.getCharPositionInLine()]) ; Modified: branches/nowalker/src/org/python/antlr/GrammarActions.java =================================================================== --- branches/nowalker/src/org/python/antlr/GrammarActions.java 2008-08-21 03:23:28 UTC (rev 5229) +++ branches/nowalker/src/org/python/antlr/GrammarActions.java 2008-08-21 03:47:32 UTC (rev 5230) @@ -2,6 +2,7 @@ import org.antlr.runtime.CommonToken; import org.antlr.runtime.Token; +import org.antlr.runtime.tree.Tree; import org.python.core.Py; import org.python.core.PyComplex; @@ -293,21 +294,18 @@ exprType makeAssignValue(List rhs) { exprType value = (exprType)rhs.get(rhs.size() -1); - maybeSetContext(value, expr_contextType.Load); - if (value instanceof Tuple) { - exprType[] elts = ((Tuple)value).elts; - for (int i=0;i<elts.length;i++) { - maybeSetContext(elts[i], expr_contextType.Load); - } - } + recurseSetContext(value, expr_contextType.Load); return value; } - void maybeSetContext(PythonTree tree, expr_contextType context) { + void recurseSetContext(Tree tree, expr_contextType context) { if (tree instanceof Context) { //XXX: for Tuples, etc -- will need to recursively set to expr_contextType.Load. ((Context)tree).setContext(context); } + for (int i=0; i<tree.getChildCount(); i++) { + recurseSetContext(tree.getChild(i), context); + } } argumentsType makeArgumentsType(Token t, List params, Token snameToken, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <le...@us...> - 2008-08-21 03:23:30
|
Revision: 5229 http://jython.svn.sourceforge.net/jython/?rev=5229&view=rev Author: leosoto Date: 2008-08-21 03:23:28 +0000 (Thu, 21 Aug 2008) Log Message: ----------- Fixing #1095 for old-style classes. Thanks to Anselm Kruls for the patch. Modified Paths: -------------- trunk/jython/Lib/test/test_descr_jy.py trunk/jython/src/org/python/core/PyInstance.java Modified: trunk/jython/Lib/test/test_descr_jy.py =================================================================== --- trunk/jython/Lib/test/test_descr_jy.py 2008-08-21 02:58:24 UTC (rev 5228) +++ trunk/jython/Lib/test/test_descr_jy.py 2008-08-21 03:23:28 UTC (rev 5229) @@ -326,16 +326,34 @@ def __getattr__(self, name): raise BarAttributeError + class BarClassic: + def __getattr__(self, name): + raise BarAttributeError + class Foo(object): def __getattr__(self, name): raise AttributeError("Custom message") + + class FooClassic: + def __getattr__(self, name): + raise AttributeError("Custom message") + self.assertRaises(BarAttributeError, lambda: Bar().x) + self.assertRaises(BarAttributeError, lambda: BarClassic().x) + try: Foo().x self.assert_(False) # Previous line should raise AttributteError except AttributeError, e: self.assertEquals("Custom message", str(e)) + try: + FooClassic().x + self.assert_(False) # Previous line should raise AttributteError + except AttributeError, e: + self.assertEquals("Custom message", str(e)) + + def test_main(): test_support.run_unittest(TestDescrTestCase, SubclassDescrTestCase, Modified: trunk/jython/src/org/python/core/PyInstance.java =================================================================== --- trunk/jython/src/org/python/core/PyInstance.java 2008-08-21 02:58:24 UTC (rev 5228) +++ trunk/jython/src/org/python/core/PyInstance.java 2008-08-21 03:23:28 UTC (rev 5229) @@ -201,10 +201,19 @@ } public PyObject __findattr_ex__(String name) { - return __findattr__(name, false); + return __findattr_ex__(name, false); } public PyObject __findattr__(String name, boolean stopAtJava) { + try { + return __findattr_ex__(name, stopAtJava); + } catch (PyException exc) { + if (Py.matchException(exc, Py.AttributeError)) return null; + throw exc; + } + } + + protected PyObject __findattr_ex__(String name, boolean stopAtJava) { PyObject result = ifindlocal(name); if (result != null) return result; @@ -234,12 +243,7 @@ if (getter == null) return null; - try { - return getter.__call__(this, new PyString(name)); - } catch (PyException exc) { - if (Py.matchException(exc, Py.AttributeError)) return null; - throw exc; - } + return getter.__call__(this, new PyString(name)); } public boolean isCallable() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-08-21 02:58:26
|
Revision: 5228 http://jython.svn.sourceforge.net/jython/?rev=5228&view=rev Author: fwierzbicki Date: 2008-08-21 02:58:24 +0000 (Thu, 21 Aug 2008) Log Message: ----------- debugging of some expr_contextType values. Modified Paths: -------------- branches/nowalker/grammar/Python.g branches/nowalker/src/org/python/antlr/GrammarActions.java Modified: branches/nowalker/grammar/Python.g =================================================================== --- branches/nowalker/grammar/Python.g 2008-08-20 23:01:42 UTC (rev 5227) +++ branches/nowalker/grammar/Python.g 2008-08-21 02:58:24 UTC (rev 5228) @@ -411,7 +411,7 @@ //fpdef: NAME | '(' fplist ')' fpdef[expr_contextType ctype] : NAME -> ^(PYNODE<Name>[$NAME, $NAME.text, ctype]) - | (LPAREN fpdef[expr_contextType.Load] COMMA) => LPAREN fplist RPAREN + | (LPAREN fpdef[null] COMMA) => LPAREN fplist RPAREN -> fplist | LPAREN fplist RPAREN -> ^(LPAREN<Tuple>[$fplist.start, actions.makeExprs($fplist.etypes), expr_contextType.Store]) @@ -458,11 +458,11 @@ } : - ((testlist[expr_contextType.Load] augassign) => lhs=testlist[expr_contextType.AugStore] + ((testlist[null] augassign) => lhs=testlist[expr_contextType.AugStore] ( (aay=augassign y1=yield_expr {stype = new AugAssign($lhs.tree, (exprType)$lhs.tree, $aay.op, (exprType)$y1.tree);}) | (aat=augassign rhs=testlist[expr_contextType.Load] {stype = new AugAssign($lhs.tree, (exprType)$lhs.tree, $aat.op, (exprType)$rhs.tree);}) ) - |(testlist[expr_contextType.Load] ASSIGN) => lhs=testlist[expr_contextType.Store] + |(testlist[null] ASSIGN) => lhs=testlist[expr_contextType.Store] ( | ((at=ASSIGN t+=testlist[expr_contextType.Store])+ -> ^(PYNODE<Assign>[$at, actions.makeAssignTargets((exprType)$lhs.tree, $t), actions.makeAssignValue($t)])) | ((ay=ASSIGN y2+=yield_expr)+ -> ^(PYNODE<Assign>[$ay, actions.makeAssignTargets((exprType)$lhs.tree, $y2), actions.makeAssignValue($y2)])) @@ -502,7 +502,7 @@ //not in CPython's Grammar file printlist returns [boolean newline, List elts] - : (test[expr_contextType.Load] COMMA) => + : (test[null] COMMA) => t+=test[expr_contextType.Load] (options {k=2;}: COMMA t+=test[expr_contextType.Load])* (trailcomma=COMMA)? { $elts=$t; if ($trailcomma == null) { @@ -520,7 +520,7 @@ //XXX: would be nice if printlist and printlist2 could be merged. //not in CPython's Grammar file printlist2 returns [boolean newline, List elts] - : (test[expr_contextType.Load] COMMA test[expr_contextType.Load]) => + : (test[null] COMMA test[null]) => t+=test[expr_contextType.Load] (options {k=2;}: COMMA t+=test[expr_contextType.Load])* (trailcomma=COMMA)? { $elts=$t; if ($trailcomma == null) { @@ -767,7 +767,7 @@ //test: or_test ['if' or_test 'else' test] | lambdef test[expr_contextType ctype] :o1=or_test[ctype] - ( (IF or_test[expr_contextType.Load] ORELSE) => IF o2=or_test[ctype] ORELSE e=test[expr_contextType.Load] + ( (IF or_test[null] ORELSE) => IF o2=or_test[ctype] ORELSE e=test[expr_contextType.Load] -> ^(IF<IfExp>[$IF, (exprType)$o2.tree, (exprType)$o1.tree, (exprType)$e.tree]) | -> or_test ) @@ -1034,14 +1034,18 @@ $testlist_gexp.tree = etype; } } - : t+=test[expr_contextType.Load] - ( ((options {k=2;}: c1=COMMA t+=test[expr_contextType.Load])* (c2=COMMA)? + : t+=test[$expr::ctype] + ( ((options {k=2;}: c1=COMMA t+=test[$expr::ctype])* (c2=COMMA)? -> { $c1 != null || $c2 != null }? ^(PYNODE<Tuple>[$testlist_gexp.start, actions.makeExprs($t), $expr::ctype]) -> test ) | ( gen_for[gens] { Collections.reverse(gens); comprehensionType[] c = (comprehensionType[])gens.toArray(new comprehensionType[gens.size()]); + exprType e = (exprType)$t.get(0); + if (e instanceof Context) { + ((Context)e).setContext(expr_contextType.Load); + } etype = new GeneratorExp($gen_for.start, (exprType)$t.get(0), c); } ) @@ -1107,7 +1111,7 @@ } } : d1=DOT DOT DOT -> DOT<Ellipsis>[$d1] - | (test[expr_contextType.Load] COLON) => lower=test[expr_contextType.Load] (c1=COLON (upper1=test[expr_contextType.Load])? (sliceop)?)? { + | (test[null] COLON) => lower=test[expr_contextType.Load] (c1=COLON (upper1=test[expr_contextType.Load])? (sliceop)?)? { $sltype = actions.makeSubscript($lower.tree, $c1, $upper1.tree, $sliceop.tree); } | (COLON) => c2=COLON (upper2=test[expr_contextType.Load])? (sliceop)? { @@ -1122,8 +1126,8 @@ //exprlist: expr (',' expr)* [','] exprlist[expr_contextType ctype] returns [exprType etype] - : (expr[expr_contextType.Load] COMMA) => e+=expr[ctype] (options {k=2;}: COMMA e+=expr[ctype])* (COMMA)? { - $etype = new Tuple($exprlist.start, actions.makeExprs($e), ctype); + : (expr[null] COMMA) => e+=expr[ctype] (options {k=2;}: COMMA e+=expr[ctype])* (COMMA)? { + $etype = new Tuple($exprlist.start, actions.makeExprs($e), ctype); } | expr[ctype] { $etype = (exprType)$expr.tree; @@ -1145,7 +1149,7 @@ @after { $testlist.tree = etype; } - : (test[expr_contextType.Load] COMMA) => t+=test[ctype] (options {k=2;}: c1=COMMA t+=test[ctype])* (c2=COMMA)? { + : (test[null] COMMA) => t+=test[ctype] (options {k=2;}: c1=COMMA t+=test[ctype])* (c2=COMMA)? { etype = new Tuple($testlist.start, actions.makeExprs($t), ctype); } | test[ctype] { @@ -1214,7 +1218,11 @@ ( (ASSIGN t2=test[expr_contextType.Load]) { $kws.add(new exprType[]{(exprType)$t1.tree, (exprType)$t2.tree}); } - | gen_for[gens] //FIXME + | gen_for[gens] { + Collections.reverse(gens); + comprehensionType[] c = (comprehensionType[])gens.toArray(new comprehensionType[gens.size()]); + arguments.add(new GeneratorExp($gen_for.start, (exprType)$t1.tree, c)); + } | {$arguments.add($t1.tree);} ) ; Modified: branches/nowalker/src/org/python/antlr/GrammarActions.java =================================================================== --- branches/nowalker/src/org/python/antlr/GrammarActions.java 2008-08-20 23:01:42 UTC (rev 5227) +++ branches/nowalker/src/org/python/antlr/GrammarActions.java 2008-08-21 02:58:24 UTC (rev 5228) @@ -293,12 +293,21 @@ exprType makeAssignValue(List rhs) { exprType value = (exprType)rhs.get(rhs.size() -1); + maybeSetContext(value, expr_contextType.Load); + if (value instanceof Tuple) { + exprType[] elts = ((Tuple)value).elts; + for (int i=0;i<elts.length;i++) { + maybeSetContext(elts[i], expr_contextType.Load); + } + } + return value; + } - if (value instanceof Context) { + void maybeSetContext(PythonTree tree, expr_contextType context) { + if (tree instanceof Context) { //XXX: for Tuples, etc -- will need to recursively set to expr_contextType.Load. - ((Context)value).setContext(expr_contextType.Load); + ((Context)tree).setContext(context); } - return value; } argumentsType makeArgumentsType(Token t, List params, Token snameToken, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-08-20 23:01:44
|
Revision: 5227 http://jython.svn.sourceforge.net/jython/?rev=5227&view=rev Author: pjenvey Date: 2008-08-20 23:01:42 +0000 (Wed, 20 Aug 2008) Log Message: ----------- rewrite the subx joiner yet again: this time exactly as CPython does it, with __getslice__ and join. fixes a string subclass corner case Modified Paths: -------------- trunk/jython/Lib/test/test_re_jy.py trunk/jython/src/org/python/modules/sre/PatternObject.java Modified: trunk/jython/Lib/test/test_re_jy.py =================================================================== --- trunk/jython/Lib/test/test_re_jy.py 2008-08-20 20:59:44 UTC (rev 5226) +++ trunk/jython/Lib/test/test_re_jy.py 2008-08-20 23:01:42 UTC (rev 5227) @@ -8,6 +8,23 @@ result = re.sub('', lambda match : None, 'foo') self.assertEqual(result, 'foo') self.assert_(isinstance(result, str)) + + def test_sub_with_subclasses(self): + class Foo(unicode): + def join(self, items): + return Foo(unicode.join(self, items)) + result = re.sub('bar', 'baz', Foo('bar')) + self.assertEqual(result, u'baz') + self.assertEqual(type(result), unicode) + + class Foo2(unicode): + def join(self, items): + return Foo2(unicode.join(self, items)) + def __getslice__(self, start, stop): + return Foo2(unicode.__getslice__(self, start, stop)) + result = re.sub('bar', 'baz', Foo2('bar')) + self.assertEqual(result, Foo2('baz')) + self.assert_(isinstance(result, Foo2)) def test_unkown_groupname(self): self.assertRaises(IndexError, Modified: trunk/jython/src/org/python/modules/sre/PatternObject.java =================================================================== --- trunk/jython/src/org/python/modules/sre/PatternObject.java 2008-08-20 20:59:44 UTC (rev 5226) +++ trunk/jython/src/org/python/modules/sre/PatternObject.java 2008-08-20 23:01:42 UTC (rev 5227) @@ -118,7 +118,7 @@ SRE_STATE state = new SRE_STATE(string, 0, Integer.MAX_VALUE, flags); - StringBuilder buf = new StringBuilder(); + PyList list = new PyList(); int n = 0; int i = 0; @@ -137,7 +137,7 @@ if (i < b) { /* get segment before this match */ - buf.append(string.substring(i, b)); + list.append(string.__getslice__(Py.newInteger(i), Py.newInteger(b))); } if (! (i == b && i == e && n > 0)) { PyObject item; @@ -150,7 +150,7 @@ } if (item != Py.None) { - buf.append(item.toString()); + list.append(item); } i = e; n++; @@ -163,25 +163,23 @@ state.start = state.ptr; } if (i < state.endpos) { - buf.append(string.substring(i, state.endpos)); + list.append(string.__getslice__(Py.newInteger(i), Py.newInteger(state.endpos))); } - // Follows rules enumerated in test_re.test_bug_1140 - PyString outstring; - if (buf.length() == 0) { - outstring = instring.createInstance(buf.toString()); - } else if (template instanceof PyUnicode || instring instanceof PyUnicode) { - outstring = Py.newUnicode(buf.toString()); - } else { - outstring = Py.newString(buf.toString()); - } - + PyObject outstring = join_list(list, string); if (subn) { return new PyTuple(outstring, Py.newInteger(n)); } return outstring; } + private PyObject join_list(PyList list, PyString string) { + PyObject joiner = string.__getslice__(Py.Zero, Py.Zero); + if (list.size() == 0) { + return joiner; + } + return joiner.__getattr__("join").__call__(list); + } public PyObject split(PyObject[] args, String[] kws) { ArgParser ap = new ArgParser("split", args, kws, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-08-20 20:59:47
|
Revision: 5226 http://jython.svn.sourceforge.net/jython/?rev=5226&view=rev Author: fwierzbicki Date: 2008-08-20 20:59:44 +0000 (Wed, 20 Aug 2008) Log Message: ----------- gen expressions and list comps now actually work... Modified Paths: -------------- branches/nowalker/grammar/Python.g Modified: branches/nowalker/grammar/Python.g =================================================================== --- branches/nowalker/grammar/Python.g 2008-08-20 20:57:09 UTC (rev 5225) +++ branches/nowalker/grammar/Python.g 2008-08-20 20:59:44 UTC (rev 5226) @@ -78,7 +78,6 @@ PYNODE; Interactive; Expression; - GeneratorExp; } @header { @@ -116,6 +115,7 @@ import org.python.antlr.ast.ExtSlice; import org.python.antlr.ast.For; import org.python.antlr.ast.FunctionDef; +import org.python.antlr.ast.GeneratorExp; import org.python.antlr.ast.Global; import org.python.antlr.ast.If; import org.python.antlr.ast.IfExp; @@ -1026,14 +1026,24 @@ //testlist_gexp: test ( gen_for | (',' test)* [','] ) testlist_gexp @init { + exprType etype = null; List gens = new ArrayList(); } +@after { + if (etype != null) { + $testlist_gexp.tree = etype; + } +} : t+=test[expr_contextType.Load] ( ((options {k=2;}: c1=COMMA t+=test[expr_contextType.Load])* (c2=COMMA)? -> { $c1 != null || $c2 != null }? ^(PYNODE<Tuple>[$testlist_gexp.start, actions.makeExprs($t), $expr::ctype]) -> test ) - | ( gen_for[gens] -> ^(GeneratorExp test gen_for) + | ( gen_for[gens] { + Collections.reverse(gens); + comprehensionType[] c = (comprehensionType[])gens.toArray(new comprehensionType[gens.size()]); + etype = new GeneratorExp($gen_for.start, (exprType)$t.get(0), c); + } ) ) ; @@ -1219,7 +1229,7 @@ //list_for: 'for' exprlist 'in' testlist_safe [list_iter] list_for [List gens] - : FOR exprlist[expr_contextType.Load] IN testlist[expr_contextType.Load] (list_iter[gens])? { + : FOR exprlist[expr_contextType.Store] IN testlist[expr_contextType.Load] (list_iter[gens])? { exprType[] e; if ($list_iter.etype != null) { e = new exprType[]{$list_iter.etype}; @@ -1247,7 +1257,7 @@ //gen_for: 'for' exprlist 'in' or_test [gen_iter] gen_for [List gens] - :FOR exprlist[expr_contextType.Load] IN or_test[expr_contextType.Load] gen_iter[gens]? { + :FOR exprlist[expr_contextType.Store] IN or_test[expr_contextType.Load] gen_iter[gens]? { exprType[] e; if ($gen_iter.etype != null) { e = new exprType[]{$gen_iter.etype}; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-08-20 20:57:11
|
Revision: 5225 http://jython.svn.sourceforge.net/jython/?rev=5225&view=rev Author: fwierzbicki Date: 2008-08-20 20:57:09 +0000 (Wed, 20 Aug 2008) Log Message: ----------- re-remove PythonWalker.g from build Modified Paths: -------------- branches/nowalker/build.xml Modified: branches/nowalker/build.xml =================================================================== --- branches/nowalker/build.xml 2008-08-20 19:58:17 UTC (rev 5224) +++ branches/nowalker/build.xml 2008-08-20 20:57:09 UTC (rev 5225) @@ -434,7 +434,6 @@ <arg value="-lib"/> <arg path="${work.dir}/build/gensrc/org/python/antlr"/> <arg file="${jython.base.dir}/grammar/Python.g"/> - <arg file="${jython.base.dir}/grammar/PythonWalker.g"/> <arg file="${jython.base.dir}/grammar/PythonPartial.g"/> <classpath refid="main.classpath"/> </java> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-08-20 19:58:19
|
Revision: 5224 http://jython.svn.sourceforge.net/jython/?rev=5224&view=rev Author: fwierzbicki Date: 2008-08-20 19:58:17 +0000 (Wed, 20 Aug 2008) Log Message: ----------- oops revert build.xml Modified Paths: -------------- branches/nowalker/build.xml Modified: branches/nowalker/build.xml =================================================================== --- branches/nowalker/build.xml 2008-08-20 19:57:39 UTC (rev 5223) +++ branches/nowalker/build.xml 2008-08-20 19:58:17 UTC (rev 5224) @@ -318,7 +318,9 @@ change to grammar files. If you are working on the grammars you might want to comment this out, as a clean is really only needed if you change the tokens defined in Python.g (and cleans make the build slow) --> + <antcall target="clean"/> <!-- force jarjar build --> + <property name="jarjar.needed" value="true" /> </target> <target name ="prepare-output" depends="init,needed-check,clean-if-antlr-needed,make-output-dirs"/> @@ -432,6 +434,7 @@ <arg value="-lib"/> <arg path="${work.dir}/build/gensrc/org/python/antlr"/> <arg file="${jython.base.dir}/grammar/Python.g"/> + <arg file="${jython.base.dir}/grammar/PythonWalker.g"/> <arg file="${jython.base.dir}/grammar/PythonPartial.g"/> <classpath refid="main.classpath"/> </java> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-08-20 19:57:42
|
Revision: 5223 http://jython.svn.sourceforge.net/jython/?rev=5223&view=rev Author: fwierzbicki Date: 2008-08-20 19:57:39 +0000 (Wed, 20 Aug 2008) Log Message: ----------- Start of list comprehensions and generator expressions. Modified Paths: -------------- branches/nowalker/build.xml branches/nowalker/grammar/Python.g Modified: branches/nowalker/build.xml =================================================================== --- branches/nowalker/build.xml 2008-08-20 15:49:38 UTC (rev 5222) +++ branches/nowalker/build.xml 2008-08-20 19:57:39 UTC (rev 5223) @@ -318,9 +318,7 @@ change to grammar files. If you are working on the grammars you might want to comment this out, as a clean is really only needed if you change the tokens defined in Python.g (and cleans make the build slow) --> - <antcall target="clean"/> <!-- force jarjar build --> - <property name="jarjar.needed" value="true" /> </target> <target name ="prepare-output" depends="init,needed-check,clean-if-antlr-needed,make-output-dirs"/> Modified: branches/nowalker/grammar/Python.g =================================================================== --- branches/nowalker/grammar/Python.g 2008-08-20 15:49:38 UTC (rev 5222) +++ branches/nowalker/grammar/Python.g 2008-08-20 19:57:39 UTC (rev 5223) @@ -78,17 +78,7 @@ PYNODE; Interactive; Expression; - Ellipsis; - ListComp; - Target; GeneratorExp; - Ifs; - Elts; - - GenFor; - GenIf; - ListIf; - } @header { @@ -133,6 +123,7 @@ import org.python.antlr.ast.ImportFrom; import org.python.antlr.ast.Index; import org.python.antlr.ast.keywordType; +import org.python.antlr.ast.ListComp; import org.python.antlr.ast.Lambda; import org.python.antlr.ast.modType; import org.python.antlr.ast.Module; @@ -162,6 +153,7 @@ import org.python.core.PyUnicode; import java.math.BigInteger; +import java.util.Collections; import java.util.Iterator; import java.util.ListIterator; } @@ -1011,26 +1003,37 @@ ; //listmaker: test ( list_for | (',' test)* [','] ) -listmaker returns [exprType etype] +listmaker +@init { + List gens = new ArrayList(); + exprType etype = null; +} @after { - $listmaker.tree = $etype; + $listmaker.tree = etype; } : t+=test[expr_contextType.Load] - ( list_for -> ^(ListComp test list_for) + ( list_for[gens] { + Collections.reverse(gens); + comprehensionType[] c = (comprehensionType[])gens.toArray(new comprehensionType[gens.size()]); + etype = new ListComp($listmaker.start, (exprType)$t.get(0), c); + } | (options {greedy=true;}:COMMA t+=test[expr_contextType.Load])* { - $etype = new org.python.antlr.ast.List($listmaker.start, actions.makeExprs($t), $expr::ctype); + etype = new org.python.antlr.ast.List($listmaker.start, actions.makeExprs($t), $expr::ctype); } ) (COMMA)? ; //testlist_gexp: test ( gen_for | (',' test)* [','] ) testlist_gexp +@init { + List gens = new ArrayList(); +} : t+=test[expr_contextType.Load] ( ((options {k=2;}: c1=COMMA t+=test[expr_contextType.Load])* (c2=COMMA)? -> { $c1 != null || $c2 != null }? ^(PYNODE<Tuple>[$testlist_gexp.start, actions.makeExprs($t), $expr::ctype]) -> test ) - | ( gen_for -> ^(GeneratorExp test gen_for) + | ( gen_for[gens] -> ^(GeneratorExp test gen_for) ) ) ; @@ -1194,44 +1197,73 @@ //argument: test [gen_for] | test '=' test # Really [keyword '='] test argument[List arguments, List kws] +@init { + List gens = new ArrayList(); +} : t1=test[expr_contextType.Load] ( (ASSIGN t2=test[expr_contextType.Load]) { $kws.add(new exprType[]{(exprType)$t1.tree, (exprType)$t2.tree}); } - | gen_for //FIXME + | gen_for[gens] //FIXME | {$arguments.add($t1.tree);} ) ; //list_iter: list_for | list_if -list_iter : list_for - | list_if - ; +list_iter [List gens] returns [exprType etype] + : list_for[gens] + | list_if[gens] { + $etype = $list_if.etype; + } + ; //list_for: 'for' exprlist 'in' testlist_safe [list_iter] -list_for : FOR exprlist[expr_contextType.Load] IN testlist[expr_contextType.Load] (list_iter)? - -> ^(FOR<comprehensionType>[$FOR, $exprlist.etype, (exprType)$testlist.tree, null]) - ; +list_for [List gens] + : FOR exprlist[expr_contextType.Load] IN testlist[expr_contextType.Load] (list_iter[gens])? { + exprType[] e; + if ($list_iter.etype != null) { + e = new exprType[]{$list_iter.etype}; + } else { + e = new exprType[0]; + } + gens.add(new comprehensionType($FOR, $exprlist.etype, (exprType)$testlist.tree, e)); + } + ; //list_if: 'if' test [list_iter] -list_if : IF test[expr_contextType.Load] (list_iter)? - -> ^(ListIf ^(Target test) (Ifs list_iter)?) - ; +list_if[List gens] returns [exprType etype] + : IF test[expr_contextType.Load] (list_iter[gens])? { + $etype = (exprType)$test.tree; + } + ; //gen_iter: gen_for | gen_if -gen_iter: gen_for - | gen_if - ; +gen_iter [List gens] returns [exprType etype] + : gen_for[gens] + | gen_if[gens] { + $etype = $gen_if.etype; + } + ; //gen_for: 'for' exprlist 'in' or_test [gen_iter] -gen_for: FOR exprlist[expr_contextType.Load] IN or_test[expr_contextType.Load] gen_iter? - -> ^(GenFor ^(Target exprlist) ^(IN or_test) ^(Ifs gen_iter)?) +gen_for [List gens] + :FOR exprlist[expr_contextType.Load] IN or_test[expr_contextType.Load] gen_iter[gens]? { + exprType[] e; + if ($gen_iter.etype != null) { + e = new exprType[]{$gen_iter.etype}; + } else { + e = new exprType[0]; + } + gens.add(new comprehensionType($FOR, $exprlist.etype, (exprType)$or_test.tree, e)); + } ; //gen_if: 'if' old_test [gen_iter] -gen_if: IF test[expr_contextType.Load] gen_iter? - -> ^(GenIf ^(Target test) ^(Ifs gen_iter)?) - ; +gen_if[List gens] returns [exprType etype] + : IF test[expr_contextType.Load] gen_iter[gens]? { + $etype = (exprType)$test.tree; + } + ; //yield_expr: 'yield' [testlist] yield_expr : YIELD testlist[expr_contextType.Load]? This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-08-20 15:56:39
|
Revision: 5221 http://jython.svn.sourceforge.net/jython/?rev=5221&view=rev Author: fwierzbicki Date: 2008-08-20 15:39:29 +0000 (Wed, 20 Aug 2008) Log Message: ----------- Initialized merge tracking via "svnmerge" with revisions "1-5208" from https://jython.svn.sourceforge.net/svnroot/jython/trunk/jython Property Changed: ---------------- branches/nowalker/ Property changes on: branches/nowalker ___________________________________________________________________ Added: svnmerge-integrated + /trunk/jython:1-5208 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |