From: <fwi...@us...> - 2007-12-08 20:39:50
|
Revision: 3777 http://jython.svn.sourceforge.net/jython/?rev=3777&view=rev Author: fwierzbicki Date: 2007-12-08 12:39:48 -0800 (Sat, 08 Dec 2007) Log Message: ----------- Start of ClassDef -- still needs some work, especially if multiple bases or bases with dotted names. Modified Paths: -------------- trunk/sandbox/ast/grammar/Python.g trunk/sandbox/ast/grammar/PythonWalker.g Modified: trunk/sandbox/ast/grammar/Python.g =================================================================== --- trunk/sandbox/ast/grammar/Python.g 2007-12-08 18:10:06 UTC (rev 3776) +++ trunk/sandbox/ast/grammar/Python.g 2007-12-08 20:39:48 UTC (rev 3777) @@ -643,7 +643,7 @@ //classdef: 'class' NAME ['(' testlist ')'] ':' suite classdef: 'class' NAME (LPAREN testlist RPAREN)? COLON suite - -> ^(ClassDef ^(Name NAME) ^(Bases testlist)? ^(Body suite)) + -> ^(ClassDef ^(Name NAME) ^(Bases testlist?) ^(Body suite)) ; //arglist: (argument ',')* (argument [',']| '*' test [',' '**' test] | '**' test) Modified: trunk/sandbox/ast/grammar/PythonWalker.g =================================================================== --- trunk/sandbox/ast/grammar/PythonWalker.g 2007-12-08 18:10:06 UTC (rev 3776) +++ trunk/sandbox/ast/grammar/PythonWalker.g 2007-12-08 20:39:48 UTC (rev 3777) @@ -69,6 +69,12 @@ return new Module(t, s); } + private ClassDef makeClassDef(PythonTree t, PythonTree nameToken, List bases, List body) { + exprType[] b = (exprType[])bases.toArray(new exprType[bases.size()]); + stmtType[] s = (stmtType[])body.toArray(new stmtType[body.size()]); + return new ClassDef(t, nameToken.getText(), b, s); + } + private FunctionDef makeFunctionDef(PythonTree t, PythonTree nameToken, argumentsType args, List funcStatements, List decorators) { argumentsType a; debug("Matched FunctionDef"); @@ -285,7 +291,7 @@ } | ^(augassign targ=test[expr_contextType.Load] value=test[expr_contextType.Load]) { } - | ^(Assign targets ^(Value value=test[expr_contextType.Store])) { + | ^(Assign targets ^(Value value=test[expr_contextType.Load])) { debug("Matched Assign"); exprType[] e = new exprType[$targets.etypes.size()]; for(int i=0;i<$targets.etypes.size();i++) { @@ -307,7 +313,7 @@ ; target[List etypes] - : ^(Target test[expr_contextType.Load]) { + : ^(Target test[expr_contextType.Store]) { etypes.add($test.etype); } ; @@ -548,11 +554,24 @@ ; classdef - : ^(ClassDef ^(Name NAME) (^(Bases test[expr_contextType.Load]))? ^(Body suite)) { - debug("class matched"); + : ^(ClassDef ^(Name classname=NAME) bases ^(Body stmts)) { + $stmts::statements.add(makeClassDef($ClassDef, $classname, $bases.names, $stmts.stypes)); } ; +bases returns [List names] +@init { + List nms = new ArrayList(); +} + :^(Bases base[nms]*) { + $names = nms; + } + ; + +base[List names] + : test[expr_contextType.Store] {names.add($test.etype);} + ; + arglist : ^(Arguments argument+) (^(StarArgs test[expr_contextType.Load]))? (^(KWArgs test[expr_contextType.Load]))? | ^(StarArgs test[expr_contextType.Load]) (^(KWArgs test[expr_contextType.Load]))? This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2007-12-09 00:16:29
|
Revision: 3780 http://jython.svn.sourceforge.net/jython/?rev=3780&view=rev Author: fwierzbicki Date: 2007-12-08 16:16:26 -0800 (Sat, 08 Dec 2007) Log Message: ----------- Start of try/except/finally matcing for 2.5. Some reformatting. Modified Paths: -------------- trunk/sandbox/ast/grammar/Python.g trunk/sandbox/ast/grammar/PythonWalker.g Modified: trunk/sandbox/ast/grammar/Python.g =================================================================== --- trunk/sandbox/ast/grammar/Python.g 2007-12-08 23:27:20 UTC (rev 3779) +++ trunk/sandbox/ast/grammar/Python.g 2007-12-09 00:16:26 UTC (rev 3780) @@ -110,7 +110,7 @@ Print; TryExcept; TryFinally; - Except; + ExceptHandler; For; Return; Yield; @@ -166,6 +166,7 @@ GenIf; ListFor; ListIf; + FinalBody; } @header { @@ -448,13 +449,16 @@ -> ^(For ^(Target exprlist) ^(Iter testlist) ^(Body $s1) ^(OrElse $s2)?) ; -//try_stmt: ('try' ':' suite (except_clause ':' suite)+ #diagram:break -// ['else' ':' suite] | 'try' ':' suite 'finally' ':' suite) +//try_stmt: ('try' ':' suite +// ((except_clause ':' suite)+ +// ['else' ':' suite] +// ['finally' ':' suite] | +// 'finally' ':' suite)) try_stmt : 'try' COLON trysuite=suite - ( (except_clause+ ('else' COLON elsesuite=suite)? - -> ^(TryExcept ^(Body $trysuite) except_clause+ ^(OrElse $elsesuite)?)) - | ('finally' COLON suite - -> ^(TryFinally suite)) + ( (except_clause+ ('else' COLON elsesuite=suite)? ('finally' COLON finalsuite=suite)? + -> ^(TryExcept ^(Body $trysuite) except_clause+ ^(OrElse $elsesuite)? ^(FinalBody 'finally' $finalsuite)?)) + | ('finally' COLON finalsuite=suite + -> ^(TryFinally ^(Body $trysuite) ^(FinalBody $finalsuite))) ) ; @@ -469,7 +473,7 @@ //except_clause: 'except' [test [',' test]] except_clause : 'except' (t1=test (COMMA t2=test)?)? COLON suite - -> ^(Except ^(Type $t1)? ^(Name $t2)? ^(Body suite)) + -> ^(ExceptHandler ^(Type $t1)? ^(Name $t2)? ^(Body suite)) ; //suite: simple_stmt | NEWLINE INDENT stmt+ DEDENT Modified: trunk/sandbox/ast/grammar/PythonWalker.g =================================================================== --- trunk/sandbox/ast/grammar/PythonWalker.g 2007-12-08 23:27:20 UTC (rev 3779) +++ trunk/sandbox/ast/grammar/PythonWalker.g 2007-12-09 00:16:26 UTC (rev 3780) @@ -384,51 +384,64 @@ | ^(ImportFrom dotted_name ^(Import import_as_name+)) ; -import_as_name : ^(Alias NAME (^(Asname NAME))?) - ; +import_as_name + : ^(Alias NAME (^(Asname NAME))?) + ; -dotted_as_name : ^(Alias dotted_name (^(Asname NAME))?) - ; +dotted_as_name + : ^(Alias dotted_name (^(Asname NAME))?) + ; dotted_name : start=NAME (DOT NAME)* { } ; -global_stmt : ^(Global NAME+) - ; +global_stmt + : ^(Global NAME+) + ; -exec_stmt : ^(Exec test[expr_contextType.Load] (^(Globals test[expr_contextType.Load]))? (^(Locals test[expr_contextType.Load]))?) - ; +exec_stmt + : ^(Exec test[expr_contextType.Load] (^(Globals test[expr_contextType.Load]))? (^(Locals test[expr_contextType.Load]))?) + ; -assert_stmt : ^(Assert ^(Test test[expr_contextType.Load]) (^(Msg test[expr_contextType.Load]))?) - ; +assert_stmt + : ^(Assert ^(Test test[expr_contextType.Load]) (^(Msg test[expr_contextType.Load]))?) + ; -if_stmt: ^(If test[expr_contextType.Load] suite elif_clause* (^(OrElse suite))?) - ; +if_stmt + : ^(If test[expr_contextType.Load] suite elif_clause* (^(OrElse suite))?) + ; -elif_clause : ^(Elif test[expr_contextType.Load] suite) - ; +elif_clause + : ^(Elif test[expr_contextType.Load] suite) + ; -while_stmt : ^(While test[expr_contextType.Load] ^(Body suite) (^(OrElse suite))?) - ; +while_stmt + : ^(While test[expr_contextType.Load] ^(Body suite) (^(OrElse suite))?) + ; -for_stmt : ^(For ^(Target test[expr_contextType.Load]+) ^(Iter test[expr_contextType.Load]) ^(Body suite) (^(OrElse suite))?) - ; +for_stmt + : ^(For ^(Target test[expr_contextType.Load]+) ^(Iter test[expr_contextType.Load]) ^(Body suite) (^(OrElse suite))?) + ; -try_stmt : ^(TryExcept ^(Body suite) except_clause+ (^(OrElse suite))?) - | ^(TryFinally suite) - ; +try_stmt + : ^(TryExcept ^(Body suite) except_clause+ (^(OrElse suite))? (^(FinalBody 'finally' suite))?) + | ^(TryFinally ^(Body suite) ^(FinalBody suite)) + ; -except_clause : ^(Except (^(Type test[expr_contextType.Load]))? (^(Name test[expr_contextType.Load]))? ^(Body suite)) - ; +except_clause + : ^(ExceptHandler (^(Type test[expr_contextType.Load]))? (^(Name test[expr_contextType.Load]))? ^(Body suite)) + ; -with_stmt: ^(With test[expr_contextType.Load] with_var? ^(Body suite)) - ; +with_stmt + : ^(With test[expr_contextType.Load] with_var? ^(Body suite)) + ; -with_var: ('as' | NAME) test[expr_contextType.Load] - ; +with_var + : ('as' | NAME) test[expr_contextType.Load] + ; suite This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2007-12-12 02:45:11
|
Revision: 3798 http://jython.svn.sourceforge.net/jython/?rev=3798&view=rev Author: fwierzbicki Date: 2007-12-11 18:45:07 -0800 (Tue, 11 Dec 2007) Log Message: ----------- added delete ast. Modified Paths: -------------- trunk/sandbox/ast/grammar/Python.g trunk/sandbox/ast/grammar/PythonWalker.g Modified: trunk/sandbox/ast/grammar/Python.g =================================================================== --- trunk/sandbox/ast/grammar/Python.g 2007-12-12 01:19:18 UTC (rev 3797) +++ trunk/sandbox/ast/grammar/Python.g 2007-12-12 02:45:07 UTC (rev 3798) @@ -339,7 +339,7 @@ //del_stmt: 'del' exprlist del_stmt : 'del' exprlist - -> ^(Delete ^(Targets exprlist)) + -> ^(Delete exprlist) ; //pass_stmt: 'pass' Modified: trunk/sandbox/ast/grammar/PythonWalker.g =================================================================== --- trunk/sandbox/ast/grammar/PythonWalker.g 2007-12-12 01:19:18 UTC (rev 3797) +++ trunk/sandbox/ast/grammar/PythonWalker.g 2007-12-12 02:45:07 UTC (rev 3798) @@ -27,6 +27,7 @@ import org.python.antlr.ast.Call; import org.python.antlr.ast.ClassDef; import org.python.antlr.ast.Compare; +import org.python.antlr.ast.Delete; import org.python.antlr.ast.Dict; import org.python.antlr.ast.Expr; import org.python.antlr.ast.FunctionDef; @@ -383,19 +384,21 @@ ; print_stmt - : ^(Print RIGHTSHIFT? test[expr_contextType.Load]?) - { + : ^(Print RIGHTSHIFT? test[expr_contextType.Load]?) { } ; del_stmt - : ^(Delete ^(Targets test[expr_contextType.Load]+)) + : ^(Delete elts[expr_contextType.Del]) { + exprType[] t = (exprType[])$elts.etypes.toArray(new exprType[$elts.etypes.size()]); + $stmts::statements.add(new Delete($Delete, t)); + } ; pass_stmt : Pass { - debug("Matched Pass"); - $stmts::statements.add(new Pass($Pass)); + debug("Matched Pass"); + $stmts::statements.add(new Pass($Pass)); } ; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2007-12-12 03:47:56
|
Revision: 3799 http://jython.svn.sourceforge.net/jython/?rev=3799&view=rev Author: fwierzbicki Date: 2007-12-11 19:47:54 -0800 (Tue, 11 Dec 2007) Log Message: ----------- Break, Return, Continue, start of Yield. Modified Paths: -------------- trunk/sandbox/ast/grammar/Python.g trunk/sandbox/ast/grammar/PythonWalker.g Modified: trunk/sandbox/ast/grammar/Python.g =================================================================== --- trunk/sandbox/ast/grammar/Python.g 2007-12-12 02:45:07 UTC (rev 3798) +++ trunk/sandbox/ast/grammar/Python.g 2007-12-12 03:47:54 UTC (rev 3799) @@ -357,15 +357,17 @@ //break_stmt: 'break' break_stmt : 'break' + -> Break ; //continue_stmt: 'continue' continue_stmt : 'continue' + -> Continue ; //return_stmt: 'return' [testlist] return_stmt : 'return' (testlist)? - -> ^(Return testlist?) + -> ^(Return ^(Value testlist)?) ; //yield_stmt: yield_expr @@ -722,7 +724,7 @@ //yield_expr: 'yield' [testlist] yield_expr : 'yield' testlist? - -> ^(Yield testlist?) + -> ^(Yield ^(Value testlist)?) ; //XXX: Modified: trunk/sandbox/ast/grammar/PythonWalker.g =================================================================== --- trunk/sandbox/ast/grammar/PythonWalker.g 2007-12-12 02:45:07 UTC (rev 3798) +++ trunk/sandbox/ast/grammar/PythonWalker.g 2007-12-12 03:47:54 UTC (rev 3799) @@ -24,9 +24,11 @@ import org.python.antlr.ast.Assign; import org.python.antlr.ast.Attribute; import org.python.antlr.ast.AugAssign; +import org.python.antlr.ast.Break; import org.python.antlr.ast.Call; import org.python.antlr.ast.ClassDef; import org.python.antlr.ast.Compare; +import org.python.antlr.ast.Continue; import org.python.antlr.ast.Delete; import org.python.antlr.ast.Dict; import org.python.antlr.ast.Expr; @@ -40,7 +42,9 @@ import org.python.antlr.ast.Tuple; import org.python.antlr.ast.Pass; import org.python.antlr.ast.Print; +import org.python.antlr.ast.Return; import org.python.antlr.ast.Str; +import org.python.antlr.ast.Yield; import java.util.HashMap; import java.util.Iterator; @@ -411,19 +415,35 @@ ; break_stmt - : 'break' + : Break { + $stmts::statements.add(new Break($Break)); + } ; continue_stmt - : 'continue' + : Continue { + $stmts::statements.add(new Continue($Continue)); + } ; return_stmt - : ^(Return (test[expr_contextType.Load])?) + : ^(Return (^(Value test[expr_contextType.Load]))?) { + exprType v = null; + if ($Value != null) { + v = $test.etype; + } + $stmts::statements.add(new Return($Return, v)); + } ; yield_stmt - : ^(Yield test[expr_contextType.Load]?) + : ^(Yield (^(Value test[expr_contextType.Load]))?) { + exprType v = null; + if ($Value != null) { + v = $test.etype; + } + //$stmts::statements.add(new Yield($Yield, v)); + } ; raise_stmt This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2007-12-15 21:04:28
|
Revision: 3808 http://jython.svn.sourceforge.net/jython/?rev=3808&view=rev Author: fwierzbicki Date: 2007-12-15 13:04:26 -0800 (Sat, 15 Dec 2007) Log Message: ----------- somewhat better Bases handling for ClassDef -- though I want a better solution at some point (see comments in PythonWalker.g) Modified Paths: -------------- trunk/sandbox/ast/grammar/Python.g trunk/sandbox/ast/grammar/PythonWalker.g Modified: trunk/sandbox/ast/grammar/Python.g =================================================================== --- trunk/sandbox/ast/grammar/Python.g 2007-12-15 15:29:32 UTC (rev 3807) +++ trunk/sandbox/ast/grammar/Python.g 2007-12-15 21:04:26 UTC (rev 3808) @@ -667,7 +667,7 @@ //classdef: 'class' NAME ['(' testlist ')'] ':' suite classdef: 'class' NAME (LPAREN testlist RPAREN)? COLON suite - -> ^(ClassDef ^(Name NAME) ^(Bases testlist?) ^(Body suite)) + -> ^(ClassDef ^(Name NAME) ^(Bases testlist)? ^(Body suite)) ; //arglist: (argument ',')* (argument [',']| '*' test [',' '**' test] | '**' test) Modified: trunk/sandbox/ast/grammar/PythonWalker.g =================================================================== --- trunk/sandbox/ast/grammar/PythonWalker.g 2007-12-15 15:29:32 UTC (rev 3807) +++ trunk/sandbox/ast/grammar/PythonWalker.g 2007-12-15 21:04:26 UTC (rev 3808) @@ -47,6 +47,7 @@ import org.python.antlr.ast.Str; import org.python.antlr.ast.Yield; +import java.util.Arrays; import java.util.HashMap; import java.util.Iterator; import java.util.Map; @@ -683,7 +684,8 @@ $etype = new Name($NAME, $NAME.text, ctype); } | ^(DOT NAME test[ctype]) { - $etype = new Attribute($DOT, $atom.etype, $NAME.text, expr_contextType.Load); + debug("matched DOT in atom: " + $test.etype + "###" + $NAME.text); + $etype = new Attribute($DOT, $test.etype, $NAME.text, expr_contextType.Load); } | ^(SubscriptList subscriptlist test[ctype]) | ^(Num INT) {$etype = makeNum($INT);} @@ -718,8 +720,14 @@ ; classdef - : ^(ClassDef ^(Name classname=NAME) bases ^(Body stmts)) { - $stmts::statements.add(makeClassDef($ClassDef, $classname, $bases.names, $stmts.stypes)); + : ^(ClassDef ^(Name classname=NAME) (^(Bases bases))? ^(Body stmts)) { + List b; + if ($Bases != null) { + b = $bases.names; + } else { + b = new ArrayList(); + } + $stmts::statements.add(makeClassDef($ClassDef, $classname, b, $stmts.stypes)); } ; @@ -727,13 +735,29 @@ @init { List nms = new ArrayList(); } - :^(Bases base[nms]*) { - $names = nms; + : base[nms] { + //The instanceof and tuple unpack here is gross. I *should* be able to detect + //"Tuple or Tuple DOWN or some such in a syntactic predicate in the "base" rule + //instead, but I haven't been able to get it to work. + if (nms.get(0) instanceof Tuple) { + debug("TUPLE"); + Tuple t = (Tuple)nms.get(0); + $names = Arrays.asList(t.elts); + } else { + debug("NOT TUPLE"); + $names = nms; + } } ; +//FIXME: right now test matches a Tuple from Python.g output -- I'd rather +// unpack the tuple here instead of in bases, otherwise this rule +// should just get absorbed back into bases, since it is never matched +// more than once as it is now. base[List names] - : test[expr_contextType.Store] {names.add($test.etype);} + : test[expr_contextType.Load] { + names.add($test.etype); + } ; arglist returns [List args, List keywords, exprType starargs, exprType kwargs] This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2007-12-16 02:27:34
|
Revision: 3812 http://jython.svn.sourceforge.net/jython/?rev=3812&view=rev Author: fwierzbicki Date: 2007-12-15 18:27:33 -0800 (Sat, 15 Dec 2007) Log Message: ----------- makeFor for For support. Modified Paths: -------------- trunk/sandbox/ast/grammar/Python.g trunk/sandbox/ast/grammar/PythonWalker.g Modified: trunk/sandbox/ast/grammar/Python.g =================================================================== --- trunk/sandbox/ast/grammar/Python.g 2007-12-16 00:26:15 UTC (rev 3811) +++ trunk/sandbox/ast/grammar/Python.g 2007-12-16 02:27:33 UTC (rev 3812) @@ -647,8 +647,8 @@ ; //exprlist: expr (',' expr)* [','] -exprlist : expr (options {k=2;}: COMMA expr)* (COMMA)? - -> expr+ +exprlist : (expr COMMA) => expr (options {k=2;}: COMMA expr)* (COMMA)? -> ^(Tuple expr+) + | expr ; //testlist: test (',' test)* [','] Modified: trunk/sandbox/ast/grammar/PythonWalker.g =================================================================== --- trunk/sandbox/ast/grammar/PythonWalker.g 2007-12-16 00:26:15 UTC (rev 3811) +++ trunk/sandbox/ast/grammar/PythonWalker.g 2007-12-16 02:27:33 UTC (rev 3812) @@ -32,6 +32,7 @@ import org.python.antlr.ast.Delete; import org.python.antlr.ast.Dict; import org.python.antlr.ast.Expr; +import org.python.antlr.ast.For; import org.python.antlr.ast.FunctionDef; import org.python.antlr.ast.Import; import org.python.antlr.ast.Module; @@ -245,6 +246,17 @@ stmtType[] b = (stmtType[])body.toArray(new stmtType[body.size()]); return new While(t, test, b, o); } + + private For makeFor(PythonTree t, exprType target, exprType iter, List body, List orelse) { + 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()]); + return new For(t, target, iter, b, o); + } } module returns [modType mod] @@ -550,7 +562,14 @@ ; for_stmt - : ^(For ^(Target test[expr_contextType.Load]+) ^(Iter test[expr_contextType.Load]) ^(Body suite) (^(OrElse suite))?) + : ^(For ^(Target targ=test[expr_contextType.Store]) ^(Iter iter=test[expr_contextType.Load]) ^(Body body=stmts) (^(OrElse orelse=stmts))?) { + List o = null; + if ($OrElse != null) { + o = $orelse.stypes; + } + For f = makeFor($For, $targ.etype, $iter.etype, $body.stypes, o); + $stmts::statements.add(f); + } ; try_stmt @@ -693,7 +712,6 @@ | ^(List test[ctype]*) {} | ^(ListComp list_for) {} | ^(GenExpFor gen_for) {} -// | ^(Tuple test[ctype]*) {} | ^(Parens test[ctype]*) {} | ^(Dict test[ctype]*) {} | ^(Repr test[ctype]*) {} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2007-12-16 02:49:17
|
Revision: 3813 http://jython.svn.sourceforge.net/jython/?rev=3813&view=rev Author: fwierzbicki Date: 2007-12-15 18:49:16 -0800 (Sat, 15 Dec 2007) Log Message: ----------- Slightly better Tuple. Modified Paths: -------------- trunk/sandbox/ast/grammar/Python.g trunk/sandbox/ast/grammar/PythonWalker.g Modified: trunk/sandbox/ast/grammar/Python.g =================================================================== --- trunk/sandbox/ast/grammar/Python.g 2007-12-16 02:27:33 UTC (rev 3812) +++ trunk/sandbox/ast/grammar/Python.g 2007-12-16 02:49:16 UTC (rev 3813) @@ -588,9 +588,10 @@ //atom: '(' [testlist] ')' | '[' [listmaker] ']' | '{' [dictmaker] '}' | '`' testlist1 '`' | NAME | NUMBER | STRING+ atom : LPAREN - ( yield_expr -> ^(Parens yield_expr) - | testlist_gexp -> ^(Parens testlist_gexp?) - | -> ^(Parens) + //XXX: calling all of these "Tuple" is almost certainly incorrect. + ( yield_expr -> ^(Tuple ^(Elts yield_expr)) + | testlist_gexp -> ^(Tuple ^(Elts testlist_gexp)) + | -> ^(Tuple) ) RPAREN | LBRACK (listmaker)? RBRACK -> ^(List listmaker?) @@ -647,12 +648,12 @@ ; //exprlist: expr (',' expr)* [','] -exprlist : (expr COMMA) => expr (options {k=2;}: COMMA expr)* (COMMA)? -> ^(Tuple expr+) +exprlist : (expr COMMA) => expr (options {k=2;}: COMMA expr)* (COMMA)? -> ^(Tuple ^(Elts expr+)) | expr ; //testlist: test (',' test)* [','] -testlist : (test COMMA) => test (options {k=2;}: COMMA test)* (COMMA)? -> ^(Tuple test+) +testlist : (test COMMA) => test (options {k=2;}: COMMA test)* (COMMA)? -> ^(Tuple ^(Elts test+)) | test ; Modified: trunk/sandbox/ast/grammar/PythonWalker.g =================================================================== --- trunk/sandbox/ast/grammar/PythonWalker.g 2007-12-16 02:27:33 UTC (rev 3812) +++ trunk/sandbox/ast/grammar/PythonWalker.g 2007-12-16 02:49:16 UTC (rev 3813) @@ -702,10 +702,13 @@ //FIXME: lots of placeholders atom[int ctype] returns [exprType etype] - : ^(Tuple elts[ctype]) { - exprType[] e = new exprType[$elts.etypes.size()]; - for(int i=0;i<$elts.etypes.size();i++) { - e[i] = (exprType)$elts.etypes.get(i); + : ^(Tuple (^(Elts elts[ctype]))?) { + debug("matched Tuple"); + exprType[] e; + if ($Elts != null) { + e = (exprType[])$elts.etypes.toArray(new exprType[$elts.etypes.size()]); + } else { + e = new exprType[0]; } $etype = new Tuple($Tuple, e, ctype); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2007-12-16 02:55:07
|
Revision: 3814 http://jython.svn.sourceforge.net/jython/?rev=3814&view=rev Author: fwierzbicki Date: 2007-12-15 18:55:01 -0800 (Sat, 15 Dec 2007) Log Message: ----------- List support. Modified Paths: -------------- trunk/sandbox/ast/grammar/Python.g trunk/sandbox/ast/grammar/PythonWalker.g Modified: trunk/sandbox/ast/grammar/Python.g =================================================================== --- trunk/sandbox/ast/grammar/Python.g 2007-12-16 02:49:16 UTC (rev 3813) +++ trunk/sandbox/ast/grammar/Python.g 2007-12-16 02:55:01 UTC (rev 3814) @@ -594,7 +594,7 @@ | -> ^(Tuple) ) RPAREN - | LBRACK (listmaker)? RBRACK -> ^(List listmaker?) + | LBRACK (listmaker)? RBRACK -> ^(List ^(Elts listmaker)?) | LCURLY (dictmaker)? RCURLY -> ^(Dict dictmaker?) | BACKQUOTE testlist BACKQUOTE -> ^(Repr testlist) | NAME {debug("parsed NAME");} -> ^(Name NAME) Modified: trunk/sandbox/ast/grammar/PythonWalker.g =================================================================== --- trunk/sandbox/ast/grammar/PythonWalker.g 2007-12-16 02:49:16 UTC (rev 3813) +++ trunk/sandbox/ast/grammar/PythonWalker.g 2007-12-16 02:55:01 UTC (rev 3814) @@ -712,7 +712,17 @@ } $etype = new Tuple($Tuple, e, ctype); } - | ^(List test[ctype]*) {} + | ^(List (^(Elts elts[ctype]))?) { + debug("matched List"); + exprType[] e; + if ($Elts != null) { + e = (exprType[])$elts.etypes.toArray(new exprType[$elts.etypes.size()]); + } else { + e = new exprType[0]; + } + $etype = new org.python.antlr.ast.List($List, e, ctype); + } + | ^(ListComp list_for) {} | ^(GenExpFor gen_for) {} | ^(Parens test[ctype]*) {} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2007-12-16 02:59:38
|
Revision: 3815 http://jython.svn.sourceforge.net/jython/?rev=3815&view=rev Author: fwierzbicki Date: 2007-12-15 18:59:37 -0800 (Sat, 15 Dec 2007) Log Message: ----------- some cleanup. Modified Paths: -------------- trunk/sandbox/ast/grammar/Python.g trunk/sandbox/ast/grammar/PythonWalker.g Modified: trunk/sandbox/ast/grammar/Python.g =================================================================== --- trunk/sandbox/ast/grammar/Python.g 2007-12-16 02:55:01 UTC (rev 3814) +++ trunk/sandbox/ast/grammar/Python.g 2007-12-16 02:59:37 UTC (rev 3815) @@ -149,7 +149,6 @@ Invert; Delete; Default; - Parens; Alias; Asname; Decorator; Modified: trunk/sandbox/ast/grammar/PythonWalker.g =================================================================== --- trunk/sandbox/ast/grammar/PythonWalker.g 2007-12-16 02:55:01 UTC (rev 3814) +++ trunk/sandbox/ast/grammar/PythonWalker.g 2007-12-16 02:59:37 UTC (rev 3815) @@ -543,11 +543,11 @@ if_stmt - : ^(If test[expr_contextType.Load] suite elif_clause* (^(OrElse suite))?) + : ^(If test[expr_contextType.Load] stmts elif_clause* (^(OrElse stmts))?) ; elif_clause - : ^(Elif test[expr_contextType.Load] suite) + : ^(Elif test[expr_contextType.Load] stmts) ; while_stmt @@ -615,19 +615,13 @@ ; with_stmt - : ^(With test[expr_contextType.Load] with_var? ^(Body suite)) + : ^(With test[expr_contextType.Load] with_var? ^(Body stmts)) ; with_var : ('as' | NAME) test[expr_contextType.Load] ; - -suite - : INDENT stmt+ DEDENT - | stmt+ - ; - //FIXME: lots of placeholders test[int ctype] returns [exprType etype] : ^('and' test[ctype] test[ctype]) @@ -722,10 +716,8 @@ } $etype = new org.python.antlr.ast.List($List, e, ctype); } - | ^(ListComp list_for) {} | ^(GenExpFor gen_for) {} - | ^(Parens test[ctype]*) {} | ^(Dict test[ctype]*) {} | ^(Repr test[ctype]*) {} | ^(Name NAME) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2007-12-16 14:44:47
|
Revision: 3817 http://jython.svn.sourceforge.net/jython/?rev=3817&view=rev Author: fwierzbicki Date: 2007-12-16 06:44:45 -0800 (Sun, 16 Dec 2007) Log Message: ----------- assert and exec support Modified Paths: -------------- trunk/sandbox/ast/grammar/Python.g trunk/sandbox/ast/grammar/PythonWalker.g Modified: trunk/sandbox/ast/grammar/Python.g =================================================================== --- trunk/sandbox/ast/grammar/Python.g 2007-12-16 14:02:08 UTC (rev 3816) +++ trunk/sandbox/ast/grammar/Python.g 2007-12-16 14:44:45 UTC (rev 3817) @@ -589,7 +589,7 @@ atom : LPAREN //XXX: calling all of these "Tuple" is almost certainly incorrect. ( yield_expr -> ^(Tuple ^(Elts yield_expr)) - | testlist_gexp -> ^(Tuple ^(Elts testlist_gexp)) + | testlist_gexp {debug("parsed testlist_gexp");} -> ^(Tuple ^(Elts testlist_gexp)) | -> ^(Tuple) ) RPAREN Modified: trunk/sandbox/ast/grammar/PythonWalker.g =================================================================== --- trunk/sandbox/ast/grammar/PythonWalker.g 2007-12-16 14:02:08 UTC (rev 3816) +++ trunk/sandbox/ast/grammar/PythonWalker.g 2007-12-16 14:44:45 UTC (rev 3817) @@ -21,6 +21,7 @@ import org.python.antlr.ast.modType; import org.python.antlr.ast.operatorType; import org.python.antlr.ast.stmtType; +import org.python.antlr.ast.Assert; import org.python.antlr.ast.Assign; import org.python.antlr.ast.Attribute; import org.python.antlr.ast.AugAssign; @@ -31,6 +32,7 @@ import org.python.antlr.ast.Continue; import org.python.antlr.ast.Delete; import org.python.antlr.ast.Dict; +import org.python.antlr.ast.Exec; import org.python.antlr.ast.Expr; import org.python.antlr.ast.For; import org.python.antlr.ast.FunctionDef; @@ -547,14 +549,29 @@ ; exec_stmt - : ^(Exec test[expr_contextType.Load] (^(Globals test[expr_contextType.Load]))? (^(Locals test[expr_contextType.Load]))?) + : ^(Exec exec=test[expr_contextType.Load] (^(Globals globals=test[expr_contextType.Load]))? (^(Locals locals=test[expr_contextType.Load]))?) { + exprType g = null; + if ($Globals != null) { + g = $globals.etype; + } + exprType loc = null; + if ($Locals != null) { + loc = $locals.etype; + } + $stmts::statements.add(new Exec($Exec, $exec.etype, g, loc)); + } ; assert_stmt - : ^(Assert ^(Test test[expr_contextType.Load]) (^(Msg test[expr_contextType.Load]))?) + : ^(Assert ^(Test tst=test[expr_contextType.Load]) (^(Msg msg=test[expr_contextType.Load]))?) { + exprType m = null; + if ($Msg != null) { + m = $msg.etype; + } + $stmts::statements.add(new Assert($Assert, $tst.etype, m)); + } ; - if_stmt : ^(If test[expr_contextType.Load] stmts elif_clause* (^(OrElse stmts))?) ; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2007-12-19 16:49:03
|
Revision: 3841 http://jython.svn.sourceforge.net/jython/?rev=3841&view=rev Author: fwierzbicki Date: 2007-12-19 08:48:40 -0800 (Wed, 19 Dec 2007) Log Message: ----------- Finished Print (including trailing newline) bugfix on Call. Modified Paths: -------------- trunk/sandbox/ast/grammar/Python.g trunk/sandbox/ast/grammar/PythonWalker.g Modified: trunk/sandbox/ast/grammar/Python.g =================================================================== --- trunk/sandbox/ast/grammar/Python.g 2007-12-19 00:10:18 UTC (rev 3840) +++ trunk/sandbox/ast/grammar/Python.g 2007-12-19 16:48:40 UTC (rev 3841) @@ -362,12 +362,13 @@ ; //print_stmt: 'print' ( [ test (',' test)* [','] ] | '>>' test [ (',' test)+ [','] ] ) -//XXX: we need to capture the presence/absence of a trailing comma for print (yuck) print_stmt : 'print' - ( testlist - | RIGHTSHIFT testlist - )? - -> ^(Print ^(Dest RIGHTSHIFT)? ^(Values testlist)?) + ( t1=testlist -> {$t1.newline}? ^(Print ^(Values $t1) ^(Newline)) + -> ^(Print ^(Values $t1)) + | RIGHTSHIFT t2=testlist -> {$t2.newline}? ^(Print ^(Dest RIGHTSHIFT) ^(Values testlist) ^(Newline)) + -> ^(Print ^(Dest RIGHTSHIFT) ^(Values testlist)) + | -> Print + ) ; //del_stmt: 'del' exprlist @@ -687,11 +688,16 @@ //testlist: test (',' test)* [','] //XXX: newline is only used by print - is there a better way? -testlist returns [Token newline] - : (test COMMA) => test (options {k=2;}: COMMA test)* (trailcomma=COMMA)? { - $newline=$trailcomma; - } -> ^(Tuple ^(Elts test+)) - | test {$newline = null;} +testlist returns [boolean newline] + : (test COMMA) => test (options {k=2;}: COMMA test)* (trailcomma=COMMA)? + { if ($trailcomma == null) { + $newline = true; + } else { + $newline = false; + } + } + -> ^(Tuple ^(Elts test+)) + | test {$newline = true;} ; //XXX: Modified: trunk/sandbox/ast/grammar/PythonWalker.g =================================================================== --- trunk/sandbox/ast/grammar/PythonWalker.g 2007-12-19 00:10:18 UTC (rev 3840) +++ trunk/sandbox/ast/grammar/PythonWalker.g 2007-12-19 16:48:40 UTC (rev 3841) @@ -407,7 +407,7 @@ } ; -call_expr +call_expr returns [exprType etype] : ^(Call (^(Args arglist))? test[expr_contextType.Load]) { Call c; if ($Args == null) { @@ -420,7 +420,7 @@ keywordType[] keywords = (keywordType[])$arglist.keywords.toArray(new keywordType[$arglist.keywords.size()]); c = new Call($Call, $test.etype, args, keywords, $arglist.starargs, $arglist.kwargs); } - $stmts::statements.add(new Expr($Call, c)); + $etype = c; } ; @@ -455,15 +455,17 @@ ; print_stmt - : ^(Print (^(Dest RIGHTSHIFT))? (^(Values test[expr_contextType.Load]))?) { + : ^(Print (^(Dest RIGHTSHIFT))? (^(Values test[expr_contextType.Load]))? (Newline)?) { Print p; exprType[] values; exprType dest = null; boolean hasdest = false; - //FIXME: just assuming newline for now. - boolean newline = true; + boolean newline = false; + if ($Newline != null) { + newline = true; + } if ($Dest != null) { hasdest = true; @@ -783,8 +785,8 @@ | ^(UAdd test[ctype]) | ^(USub test[ctype]) | ^(Invert test[ctype]) + | call_expr {$etype = $call_expr.etype;} | lambdef - | call_expr ; comp_op returns [int op] This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2007-12-26 16:35:24
|
Revision: 3869 http://jython.svn.sourceforge.net/jython/?rev=3869&view=rev Author: fwierzbicki Date: 2007-12-26 08:32:29 -0800 (Wed, 26 Dec 2007) Log Message: ----------- BoolOp support -- including the way CPython "rolls up" AND and OR so: a and b and c and d creates *one* and node with 4 tests (a,b,c,d). Modified Paths: -------------- trunk/sandbox/ast/grammar/Python.g trunk/sandbox/ast/grammar/PythonWalker.g Modified: trunk/sandbox/ast/grammar/Python.g =================================================================== --- trunk/sandbox/ast/grammar/Python.g 2007-12-26 00:51:37 UTC (rev 3868) +++ trunk/sandbox/ast/grammar/Python.g 2007-12-26 16:32:29 UTC (rev 3869) @@ -543,11 +543,11 @@ ; //or_test: and_test ('or' and_test)* -or_test : and_test ('or'^ and_test)* +or_test : and_test (OR^ and_test)* ; //and_test: not_test ('and' not_test)* -and_test : not_test ('and'^ not_test)* +and_test : not_test (AND^ not_test)* ; //not_test: 'not' not_test | comparison @@ -867,6 +867,10 @@ AT : '@' ; +AND : 'and' ; + +OR : 'or' ; + FLOAT : '.' DIGITS (Exponent)? | DIGITS ('.' (DIGITS (Exponent)?)? | Exponent) Modified: trunk/sandbox/ast/grammar/PythonWalker.g =================================================================== --- trunk/sandbox/ast/grammar/PythonWalker.g 2007-12-26 00:51:37 UTC (rev 3868) +++ trunk/sandbox/ast/grammar/PythonWalker.g 2007-12-26 16:32:29 UTC (rev 3869) @@ -13,6 +13,7 @@ //import org.python.core.CompilerFlags; import org.python.antlr.ast.aliasType; import org.python.antlr.ast.argumentsType; +import org.python.antlr.ast.boolopType; import org.python.antlr.ast.cmpopType; import org.python.antlr.ast.excepthandlerType; import org.python.antlr.ast.exprType; @@ -26,6 +27,7 @@ import org.python.antlr.ast.Attribute; import org.python.antlr.ast.AugAssign; import org.python.antlr.ast.BinOp; +import org.python.antlr.ast.BoolOp; import org.python.antlr.ast.Break; import org.python.antlr.ast.Call; import org.python.antlr.ast.ClassDef; @@ -791,8 +793,89 @@ //FIXME: lots of placeholders test[expr_contextType ctype] returns [exprType etype] - : ^('and' test[ctype] test[ctype]) - | ^('or' test[ctype] test[ctype]) + : ^(AND left=test[ctype] right=test[ctype]) { + List values = new ArrayList(); + boolean leftIsAnd = false; + boolean rightIsAnd = false; + BoolOp leftB = null; + BoolOp rightB = null; + if ($left.start.getType() == AND) { + leftIsAnd = true; + leftB = (BoolOp)$left.etype; + } + if ($right.start.getType() == AND) { + rightIsAnd = true; + rightB = (BoolOp)$right.etype; + } + exprType[] e; + if (leftIsAnd && rightIsAnd) { + debug("matched And + L + R"); + int lenL = leftB.values.length; + int lenR = rightB.values.length; + e = new exprType[lenL + lenR]; + System.arraycopy(leftB.values, 0, e, 0, lenL - 1); + System.arraycopy(rightB.values, 0, e, lenL - 1, lenL + lenR); + } else if (leftIsAnd) { + debug("matched And + L"); + e = new exprType[leftB.values.length + 1]; + System.arraycopy(leftB.values, 0, e, 0, leftB.values.length); + e[e.length - 1] = $right.etype; + } else if (rightIsAnd) { + debug("matched And + R"); + e = new exprType[rightB.values.length + 1]; + System.arraycopy(rightB.values, 0, e, 0, rightB.values.length); + e[e.length - 1] = $left.etype; + } else { + debug("matched And"); + e = new exprType[2]; + e[0] = $left.etype; + e[1] = $right.etype; + } + //XXX: could re-use BoolOps discarded above in many cases. + $etype = new BoolOp($AND, boolopType.And, e); + } + | ^(OR left=test[ctype] right=test[ctype]) { + //XXX: AND and OR could be factored into one method. + List values = new ArrayList(); + boolean leftIsOr = false; + boolean rightIsOr = false; + BoolOp leftB = null; + BoolOp rightB = null; + if ($left.start.getType() == OR) { + leftIsOr = true; + leftB = (BoolOp)$left.etype; + } + if ($right.start.getType() == OR) { + rightIsOr = true; + rightB = (BoolOp)$right.etype; + } + exprType[] e; + if (leftIsOr && rightIsOr) { + debug("matched Or + L + R"); + int lenL = leftB.values.length; + int lenR = rightB.values.length; + e = new exprType[lenL + lenR]; + System.arraycopy(leftB.values, 0, e, 0, lenL - 1); + System.arraycopy(rightB.values, 0, e, lenL - 1, lenL + lenR); + } else if (leftIsOr) { + debug("matched Or + L"); + e = new exprType[leftB.values.length + 1]; + System.arraycopy(leftB.values, 0, e, 0, leftB.values.length); + e[e.length - 1] = $right.etype; + } else if (rightIsOr) { + debug("matched Or + R"); + e = new exprType[rightB.values.length + 1]; + System.arraycopy(rightB.values, 0, e, 0, rightB.values.length); + e[e.length - 1] = $left.etype; + } else { + debug("matched Or"); + e = new exprType[2]; + e[0] = $left.etype; + e[1] = $right.etype; + } + //XXX: could re-use BoolOps discarded above in many cases. + $etype = new BoolOp($OR, boolopType.Or, e); + } | ^('not' test[ctype]) | ^(comp_op left=test[ctype] targs=test[ctype]) { exprType[] targets = new exprType[1]; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2007-12-26 17:52:04
|
Revision: 3870 http://jython.svn.sourceforge.net/jython/?rev=3870&view=rev Author: fwierzbicki Date: 2007-12-26 09:52:00 -0800 (Wed, 26 Dec 2007) Log Message: ----------- simple list comp support (no ifs processing yet). Modified Paths: -------------- trunk/sandbox/ast/grammar/Python.g trunk/sandbox/ast/grammar/PythonWalker.g Modified: trunk/sandbox/ast/grammar/Python.g =================================================================== --- trunk/sandbox/ast/grammar/Python.g 2007-12-26 16:32:29 UTC (rev 3869) +++ trunk/sandbox/ast/grammar/Python.g 2007-12-26 17:52:00 UTC (rev 3870) @@ -630,7 +630,11 @@ | -> ^(Tuple) ) RPAREN - | LBRACK (listmaker)? RBRACK -> ^(List ^(Elts listmaker)?) + | LBRACK + (listmaker -> listmaker + | -> ^(List) + ) + RBRACK | LCURLY (dictmaker)? RCURLY -> ^(Dict dictmaker?) | BACKQUOTE testlist BACKQUOTE -> ^(Repr testlist) | NAME {debug("parsed NAME");} -> ^(Name NAME) @@ -643,8 +647,8 @@ //listmaker: test ( list_for | (',' test)* [','] ) listmaker : test - ( list_for -> ^(ListComp list_for) - | (options {greedy=true;}:COMMA test)* -> test+ + ( list_for -> ^(ListComp test list_for) + | (options {greedy=true;}:COMMA test)* -> ^(List ^(Elts test+)) ) (COMMA)? ; Modified: trunk/sandbox/ast/grammar/PythonWalker.g =================================================================== --- trunk/sandbox/ast/grammar/PythonWalker.g 2007-12-26 16:32:29 UTC (rev 3869) +++ trunk/sandbox/ast/grammar/PythonWalker.g 2007-12-26 17:52:00 UTC (rev 3870) @@ -14,6 +14,7 @@ import org.python.antlr.ast.aliasType; import org.python.antlr.ast.argumentsType; import org.python.antlr.ast.boolopType; +import org.python.antlr.ast.comprehensionType; import org.python.antlr.ast.cmpopType; import org.python.antlr.ast.excepthandlerType; import org.python.antlr.ast.exprType; @@ -43,6 +44,7 @@ import org.python.antlr.ast.If; import org.python.antlr.ast.Import; import org.python.antlr.ast.ImportFrom; +import org.python.antlr.ast.ListComp; import org.python.antlr.ast.Module; import org.python.antlr.ast.Name; import org.python.antlr.ast.Num; @@ -958,7 +960,10 @@ } $etype = new org.python.antlr.ast.List($List, e, ctype); } - | ^(ListComp list_for) {} + | ^(ListComp test[ctype] list_for) { + debug("matched ListComp"); + $etype = new ListComp($ListComp, $test.etype, new comprehensionType[]{$list_for.gen}); + } | ^(GenExpFor gen_for) {} | ^(Dict test[ctype]*) {} | ^(Repr test[ctype]*) {} @@ -1091,7 +1096,13 @@ | list_if ; -list_for: ^(ListFor ^(Target test[expr_contextType.Load]+) ^(Iter test[expr_contextType.Load]+) (^(Ifs list_iter))?) +list_for returns [comprehensionType gen] + : + ^(ListFor ^(Target targ=test[expr_contextType.Store]) ^(Iter iter=test[expr_contextType.Store]) (^(Ifs list_iter))?) { + debug("matched list_for"); + //XXX: Not collecting from Ifs yet. + $gen = new comprehensionType($ListFor, $targ.etype, $iter.etype, new exprType[0]); + } ; list_if: ^(ListIf ^(Target test[expr_contextType.Load]) (Ifs list_iter)?) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2007-12-30 19:41:37
|
Revision: 3911 http://jython.svn.sourceforge.net/jython/?rev=3911&view=rev Author: fwierzbicki Date: 2007-12-30 11:41:35 -0800 (Sun, 30 Dec 2007) Log Message: ----------- Dict support. Modified Paths: -------------- trunk/sandbox/ast/grammar/Python.g trunk/sandbox/ast/grammar/PythonWalker.g Modified: trunk/sandbox/ast/grammar/Python.g =================================================================== --- trunk/sandbox/ast/grammar/Python.g 2007-12-30 19:34:40 UTC (rev 3910) +++ trunk/sandbox/ast/grammar/Python.g 2007-12-30 19:41:35 UTC (rev 3911) @@ -622,7 +622,11 @@ power : atom (trailer^)* (options {greedy=true;}:DOUBLESTAR^ factor)? ; -//atom: '(' [testlist] ')' | '[' [listmaker] ']' | '{' [dictmaker] '}' | '`' testlist1 '`' | NAME | NUMBER | STRING+ +//atom: ('(' [yield_expr|testlist_gexp] ')' | +// '[' [listmaker] ']' | +// '{' [dictmaker] '}' | +// '`' testlist1 '`' | +// NAME | NUMBER | STRING+) atom : LPAREN //XXX: calling all of these "Tuple" is almost certainly incorrect. ( yield_expr -> ^(Tuple ^(Elts yield_expr)) @@ -635,7 +639,7 @@ | -> ^(List) ) RBRACK - | LCURLY (dictmaker)? RCURLY -> ^(Dict dictmaker?) + | LCURLY (dictmaker)? RCURLY -> ^(Dict ^(Elts dictmaker)?) | BACKQUOTE testlist BACKQUOTE -> ^(Repr testlist) | NAME {debug("parsed NAME");} -> ^(Name NAME) | INT -> ^(Num INT) Modified: trunk/sandbox/ast/grammar/PythonWalker.g =================================================================== --- trunk/sandbox/ast/grammar/PythonWalker.g 2007-12-30 19:34:40 UTC (rev 3910) +++ trunk/sandbox/ast/grammar/PythonWalker.g 2007-12-30 19:41:35 UTC (rev 3911) @@ -965,7 +965,24 @@ $etype = new ListComp($ListComp, $test.etype, new comprehensionType[]{$list_for.gen}); } | ^(GenExpFor gen_for) {} - | ^(Dict test[ctype]*) {} + | ^(Dict (^(Elts elts[ctype]))?) { + exprType[] keys; + exprType[] values; + if ($Elts != null) { + int size = $elts.etypes.size() / 2; + keys = new exprType[size]; + values = new exprType[size]; + for(int i=0;i<size;i++) { + keys[i] = (exprType)$elts.etypes.get(i*2); + values[i] = (exprType)$elts.etypes.get(i*2+1); + } + } else { + keys = new exprType[0]; + values = new exprType[0]; + } + $etype = new Dict($Dict, keys, values); + + } | ^(Repr test[ctype]*) {} | ^(Name NAME) { debug("matched Name " + $NAME.text); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-01-01 17:07:58
|
Revision: 3939 http://jython.svn.sourceforge.net/jython/?rev=3939&view=rev Author: fwierzbicki Date: 2008-01-01 09:07:57 -0800 (Tue, 01 Jan 2008) Log Message: ----------- Work on slices, delete and lambda support. Modified Paths: -------------- trunk/sandbox/ast/grammar/Python.g trunk/sandbox/ast/grammar/PythonWalker.g Modified: trunk/sandbox/ast/grammar/Python.g =================================================================== --- trunk/sandbox/ast/grammar/Python.g 2008-01-01 06:20:20 UTC (rev 3938) +++ trunk/sandbox/ast/grammar/Python.g 2008-01-01 17:07:57 UTC (rev 3939) @@ -143,7 +143,6 @@ Lower; Upper; Step; - SliceOp; UnaryOp; UAdd; USub; @@ -167,6 +166,9 @@ Values; Newline; //The tokens below are not represented in the 2.5 Python.asdl + StepOp; + UpperOp; + GenFor; GenIf; ListFor; @@ -373,8 +375,8 @@ ; //del_stmt: 'del' exprlist -del_stmt : 'del' exprlist - -> ^(Delete exprlist) +del_stmt : 'del' exprlist2 + -> ^(Delete exprlist2) ; //pass_stmt: 'pass' @@ -684,12 +686,12 @@ //subscript: '.' '.' '.' | test | [test] ':' [test] [sliceop] subscript : DOT DOT DOT -> Ellipsis - | t1=test (COLON (t2=test)? (sliceop)?)? -> ^(Subscript ^(Lower $t1) ^(Upper $t2)? ^(Step sliceop)?) - | COLON (test)? (sliceop)? -> ^(Subscript ^(Upper test)? ^(Step sliceop)?) + | t1=test (COLON (t2=test)? (sliceop)?)? -> ^(Subscript ^(Lower $t1) ^(Upper COLON ^(UpperOp $t2)?)? ^(Step sliceop)?) + | COLON (test)? (sliceop)? -> ^(Subscript ^(Upper COLON ^(UpperOp test)?)? ^(Step sliceop)?) ; //sliceop: ':' [test] -sliceop : COLON (test)? -> ^(SliceOp test)? +sliceop : COLON (test)? -> ^(StepOp test)? ; //exprlist: expr (',' expr)* [','] @@ -697,6 +699,12 @@ | expr ; +//XXX: I'm hoping I can get rid of this -- but for now I need an exprlist that does not produce tuples +// at least for del_stmt +exprlist2 : expr (options {k=2;}: COMMA expr)* (COMMA)? + -> expr+ + ; + //testlist: test (',' test)* [','] //XXX: newline is only used by print - is there a better way? testlist returns [boolean newline] Modified: trunk/sandbox/ast/grammar/PythonWalker.g =================================================================== --- trunk/sandbox/ast/grammar/PythonWalker.g 2008-01-01 06:20:20 UTC (rev 3938) +++ trunk/sandbox/ast/grammar/PythonWalker.g 2008-01-01 17:07:57 UTC (rev 3939) @@ -47,6 +47,7 @@ import org.python.antlr.ast.Index; import org.python.antlr.ast.Import; import org.python.antlr.ast.ImportFrom; +import org.python.antlr.ast.Lambda; import org.python.antlr.ast.ListComp; import org.python.antlr.ast.Module; import org.python.antlr.ast.Name; @@ -178,7 +179,7 @@ } if (raw) { - return s.substring(quotes+start+1, s.length()-quotes); + return s.substring(quotes+start, s.length()-quotes); } else { StringBuffer sb = new StringBuffer(s.length()); char[] ca = s.toCharArray(); @@ -917,7 +918,9 @@ | call_expr { $etype = $call_expr.etype; } - | lambdef + | lambdef { + $etype = $lambdef.etype; + } ; comp_op returns [cmpopType op] @@ -1057,9 +1060,13 @@ : STRING {strs.add($STRING.text);} ; -lambdef: ^(Lambda varargslist? ^(Body test[expr_contextType.Load])) - ; +lambdef returns [exprType etype] + : ^(Lambda varargslist? ^(Body test[expr_contextType.Load])) { + $etype = new Lambda($Lambda, $varargslist.args, $test.etype); + } + ; + subscriptlist returns [List sltypes] @init { List subs = new ArrayList(); @@ -1072,7 +1079,8 @@ subscript [List subs] : Ellipsis | ^(Subscript (^(Lower start=test[expr_contextType.Load]))? - (^(Upper end=test[expr_contextType.Load]))? (^(Step (^(SliceOp op=test[expr_contextType.Load]))?))?) { + (^(Upper COLON (^(UpperOp end=test[expr_contextType.Load]))?))? (^(Step (^(StepOp op=test[expr_contextType.Load]))?))?) { + boolean isSlice = false; exprType s = null; exprType e = null; exprType o = null; @@ -1080,18 +1088,22 @@ s = $start.etype; } if ($Upper != null) { - e = $end.etype; + isSlice = true; + if ($UpperOp != null) { + e = $end.etype; + } } if ($Step != null) { - if ($SliceOp != null) { + isSlice = true; + if ($StepOp != null) { o = $op.etype; } } - if (o != null || e != null) { + if (isSlice) { subs.add(new Slice($Subscript, s, e, o)); } - else if (s != null) { + else { subs.add(new Index($Subscript, s)); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-01-03 23:20:28
|
Revision: 3960 http://jython.svn.sourceforge.net/jython/?rev=3960&view=rev Author: fwierzbicki Date: 2008-01-03 15:20:26 -0800 (Thu, 03 Jan 2008) Log Message: ----------- better list comps, USub, and better subscript. Modified Paths: -------------- trunk/sandbox/ast/grammar/Python.g trunk/sandbox/ast/grammar/PythonWalker.g Modified: trunk/sandbox/ast/grammar/Python.g =================================================================== --- trunk/sandbox/ast/grammar/Python.g 2008-01-03 19:02:53 UTC (rev 3959) +++ trunk/sandbox/ast/grammar/Python.g 2008-01-03 23:20:26 UTC (rev 3960) @@ -102,6 +102,7 @@ List; Dict; If; + IfExp; OrElse; Elif; While; @@ -137,6 +138,7 @@ BinOp; Subscript; SubscriptList; + Index; Target; Targets; Value; @@ -687,8 +689,9 @@ //subscript: '.' '.' '.' | test | [test] ':' [test] [sliceop] subscript : DOT DOT DOT -> Ellipsis - | t1=test (COLON (t2=test)? (sliceop)?)? -> ^(Subscript ^(Lower $t1) ^(Upper COLON ^(UpperOp $t2)?)? ^(Step sliceop)?) - | COLON (test)? (sliceop)? -> ^(Subscript ^(Upper COLON ^(UpperOp test)?)? ^(Step sliceop)?) + | (test COLON) => t1=test (COLON (t2=test)? (sliceop)?)? -> ^(Subscript ^(Lower $t1) ^(Upper COLON ^(UpperOp $t2)?)? ^(Step sliceop)?) + | (COLON) => COLON (test)? (sliceop)? -> ^(Subscript ^(Upper COLON ^(UpperOp test)?)? ^(Step sliceop)?) + | test -> ^(Index test) ; //sliceop: ':' [test] Modified: trunk/sandbox/ast/grammar/PythonWalker.g =================================================================== --- trunk/sandbox/ast/grammar/PythonWalker.g 2008-01-03 19:02:53 UTC (rev 3959) +++ trunk/sandbox/ast/grammar/PythonWalker.g 2008-01-03 23:20:26 UTC (rev 3960) @@ -296,7 +296,7 @@ } //FIXME: just calling __neg__ for now - can be more efficient. - private exprType negate(exprType o) { + private exprType negate(PythonTree t, exprType o) { if (o instanceof Num) { Num num = (Num)o; if (num.n instanceof PyObject) { @@ -304,7 +304,7 @@ } return num; } - return o; + return new UnaryOp(t, unaryopType.USub, o); } } @@ -1054,7 +1054,7 @@ | ^(USub test[ctype]) { debug("USub matched " + $test.etype); //FIXME: need to actually negate this - $etype = negate($test.etype); + $etype = negate($USub, $test.etype); } | ^(UAdd test[ctype]) { $etype = $test.etype; @@ -1093,8 +1093,25 @@ : subscript[subs]+ { $sltypes = subs; } + | index[subs]+ { + exprType e; + if (subs.size() > 1) { + exprType[] es = (exprType[])subs.toArray(new exprType[subs.size()]); + e = new Tuple($index.start, es, expr_contextType.Load); + } else { + e = (exprType)subs.get(0); + } + $sltypes = new ArrayList(); + $sltypes.add(new Index($index.start, e)); + } ; +index [List subs] + : ^(Index test[expr_contextType.Load]) { + subs.add($test.etype); + } + ; + subscript [List subs] : Ellipsis | ^(Subscript (^(Lower start=test[expr_contextType.Load]))? @@ -1213,8 +1230,11 @@ } ; -list_iter: list_for - | list_if +list_iter returns [exprType etype] + : list_for + | list_if { + $etype = $list_if.etype; + } ; list_for returns [comprehensionType gen] @@ -1222,11 +1242,20 @@ ^(ListFor ^(Target targ=test[expr_contextType.Store]) ^(Iter iter=test[expr_contextType.Load]) (^(Ifs list_iter))?) { debug("matched list_for"); //XXX: Not collecting from Ifs yet. - $gen = new comprehensionType($ListFor, $targ.etype, $iter.etype, new exprType[0]); + exprType[] e; + if ($Ifs != null && $list_iter.etype != null) { + e = new exprType[]{$list_iter.etype}; + } else { + e = new exprType[0]; + } + $gen = new comprehensionType($ListFor, $targ.etype, $iter.etype, e); } ; -list_if: ^(ListIf ^(Target test[expr_contextType.Load]) (Ifs list_iter)?) +list_if returns [exprType etype] + : ^(ListIf ^(Target test[expr_contextType.Load]) (Ifs list_iter)?) { + $etype = $test.etype; + } ; gen_iter: gen_for This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-01-04 01:25:32
|
Revision: 3964 http://jython.svn.sourceforge.net/jython/?rev=3964&view=rev Author: fwierzbicki Date: 2008-01-03 17:25:31 -0800 (Thu, 03 Jan 2008) Log Message: ----------- some fplist support Modified Paths: -------------- trunk/sandbox/ast/grammar/Python.g trunk/sandbox/ast/grammar/PythonWalker.g Modified: trunk/sandbox/ast/grammar/Python.g =================================================================== --- trunk/sandbox/ast/grammar/Python.g 2008-01-04 00:20:15 UTC (rev 3963) +++ trunk/sandbox/ast/grammar/Python.g 2008-01-04 01:25:31 UTC (rev 3964) @@ -168,6 +168,7 @@ Values; Newline; //The tokens below are not represented in the 2.5 Python.asdl + FpList; StepOp; UpperOp; @@ -297,7 +298,7 @@ //fpdef: NAME | '(' fplist ')' fpdef : NAME - | LPAREN! fplist RPAREN! + | LPAREN fplist RPAREN -> ^(FpList fplist) ; //fplist: fpdef (',' fpdef)* [','] Modified: trunk/sandbox/ast/grammar/PythonWalker.g =================================================================== --- trunk/sandbox/ast/grammar/PythonWalker.g 2008-01-04 00:20:15 UTC (rev 3963) +++ trunk/sandbox/ast/grammar/PythonWalker.g 2008-01-04 01:25:31 UTC (rev 3964) @@ -339,14 +339,28 @@ ; defparameter[List params, List defaults] +@init { + List nms = new ArrayList(); +} : NAME (ASSIGN test[expr_contextType.Load] )? { params.add(new Name($NAME, $NAME.text, expr_contextType.Param)); if ($ASSIGN != null) { defaults.add($test.etype); } } + | ^(FpList fplist_name[nms]+) { + Name[] n = (Name[])nms.toArray(new Name[nms.size()]); + params.add(new Tuple($fplist_name.start, n, expr_contextType.Store)); + } ; +fplist_name[List nms] + : NAME { + nms.add(new Name($NAME, $NAME.text, expr_contextType.Store)); + } + ; + + decorators returns [List etypes] @init { List decs = new ArrayList(); @@ -1081,8 +1095,11 @@ lambdef returns [exprType etype] : ^(Lambda varargslist? ^(Body test[expr_contextType.Load])) { - $etype = new Lambda($Lambda, $varargslist.args, $test.etype); - + argumentsType a = $varargslist.args; + if (a == null) { + a = new argumentsType($Lambda, new exprType[0], null, null, new exprType[0]); + } + $etype = new Lambda($Lambda, a, $test.etype); } ; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-01-04 18:32:11
|
Revision: 3965 http://jython.svn.sourceforge.net/jython/?rev=3965&view=rev Author: fwierzbicki Date: 2008-01-04 10:32:10 -0800 (Fri, 04 Jan 2008) Log Message: ----------- start of generator support. Modified Paths: -------------- trunk/sandbox/ast/grammar/Python.g trunk/sandbox/ast/grammar/PythonWalker.g Modified: trunk/sandbox/ast/grammar/Python.g =================================================================== --- trunk/sandbox/ast/grammar/Python.g 2008-01-04 01:25:31 UTC (rev 3964) +++ trunk/sandbox/ast/grammar/Python.g 2008-01-04 18:32:10 UTC (rev 3965) @@ -156,7 +156,7 @@ Decorator; Decorators; With; - GenExpFor; + GeneratorExp; Id; Iter; Ifs; @@ -369,14 +369,30 @@ //print_stmt: 'print' ( [ test (',' test)* [','] ] | '>>' test [ (',' test)+ [','] ] ) print_stmt : 'print' - ( t1=testlist -> {$t1.newline}? ^(Print ^(Values $t1) ^(Newline)) + ( t1=printlist -> {$t1.newline}? ^(Print ^(Values $t1) ^(Newline)) -> ^(Print ^(Values $t1)) - | RIGHTSHIFT t2=testlist -> {$t2.newline}? ^(Print ^(Dest RIGHTSHIFT) ^(Values testlist) ^(Newline)) - -> ^(Print ^(Dest RIGHTSHIFT) ^(Values testlist)) + | RIGHTSHIFT t2=printlist -> {$t2.newline}? ^(Print ^(Dest RIGHTSHIFT) ^(Values $t2) ^(Newline)) + -> ^(Print ^(Dest RIGHTSHIFT) ^(Values $t2)) | -> ^(Print ^(Newline)) ) ; +//testlist: test (',' test)* [','] +//XXX: newline is only used by print - is there a better way? +printlist returns [boolean newline] + : (test COMMA) => test (options {k=2;}: COMMA test)* (trailcomma=COMMA)? + { if ($trailcomma == null) { + $newline = true; + } else { + $newline = false; + } + } + -> ^(Elts test+) + | test {$newline = true;} + -> ^(Elts test) + ; + + //del_stmt: 'del' exprlist del_stmt : 'del' exprlist2 -> ^(Delete exprlist2) @@ -665,7 +681,7 @@ //testlist_gexp: test ( gen_for | (',' test)* [','] ) testlist_gexp : (test COMMA) => test (options {k=2;}: COMMA test)* (COMMA)? -> ^(Tuple ^(Elts test+)) - | test ( gen_for -> ^(GenExpFor gen_for) + | test ( gen_for -> ^(GeneratorExp test gen_for) | -> test ) ; @@ -782,12 +798,12 @@ //gen_for: 'for' exprlist 'in' or_test [gen_iter] gen_for: 'for' exprlist 'in' or_test gen_iter? - -> ^(GenFor ^(Target exprlist) ^(Iter gen_iter)?) + -> ^(GenFor ^(Target exprlist) ^(Iter or_test) ^(Ifs gen_iter)?) ; //gen_if: 'if' old_test [gen_iter] gen_if: 'if' test gen_iter? - -> ^(GenIf ^(Target test) ^(Iter gen_iter)?) + -> ^(GenIf ^(Target test) ^(Ifs gen_iter)?) ; //yield_expr: 'yield' [testlist] Modified: trunk/sandbox/ast/grammar/PythonWalker.g =================================================================== --- trunk/sandbox/ast/grammar/PythonWalker.g 2008-01-04 01:25:31 UTC (rev 3964) +++ trunk/sandbox/ast/grammar/PythonWalker.g 2008-01-04 18:32:10 UTC (rev 3965) @@ -42,6 +42,7 @@ import org.python.antlr.ast.Expr; 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.Index; @@ -60,6 +61,7 @@ import org.python.antlr.ast.Pass; import org.python.antlr.ast.Print; import org.python.antlr.ast.Raise; +import org.python.antlr.ast.Repr; import org.python.antlr.ast.Return; import org.python.antlr.ast.Str; import org.python.antlr.ast.UnaryOp; @@ -454,7 +456,6 @@ c = new Call($Call, $test.etype, new exprType[0], new keywordType[0], null, null); debug("Matched Call site no args"); } else { - debug($arglist.text + "!!!!" + $test.text); debug("Matched Call w/ args"); exprType[] args = (exprType[])$arglist.args.toArray(new exprType[$arglist.args.size()]); keywordType[] keywords = (keywordType[])$arglist.keywords.toArray(new keywordType[$arglist.keywords.size()]); @@ -511,7 +512,7 @@ print_stmt - : ^(Print (^(Dest RIGHTSHIFT))? (^(Values test[expr_contextType.Load]))? (Newline)?) { + : ^(Print (^(Dest RIGHTSHIFT))? (^(Values ^(Elts elts[expr_contextType.Load])))? (Newline)?) { Print p; exprType[] values; @@ -527,17 +528,13 @@ hasdest = true; } if ($Values != null) { - if ($test.etype instanceof Tuple) { - Tuple t = (Tuple)$test.etype; - if (hasdest) { - dest = t.elts[0]; - values = new exprType[t.elts.length - 1]; - System.arraycopy(t.elts, 1, values, 0, values.length); - } else { - values = t.elts; - } + exprType[] t = (exprType[])$elts.etypes.toArray(new exprType[$elts.etypes.size()]); + if (hasdest) { + dest = t[0]; + values = new exprType[t.length - 1]; + System.arraycopy(t, 1, values, 0, values.length); } else { - values = new exprType[]{$test.etype}; + values = t; } } else { values = new exprType[0]; @@ -1014,7 +1011,10 @@ debug("matched ListComp"); $etype = new ListComp($ListComp, $test.etype, new comprehensionType[]{$list_for.gen}); } - | ^(GenExpFor gen_for) {} + | ^(GeneratorExp test[ctype] gen_for) { + debug("matched GeneratorExp"); + $etype = new GeneratorExp($GeneratorExp, $test.etype, new comprehensionType[]{$gen_for.gen}); + } | ^(Dict (^(Elts elts[ctype]))?) { exprType[] keys; exprType[] values; @@ -1033,7 +1033,9 @@ $etype = new Dict($Dict, keys, values); } - | ^(Repr test[ctype]*) {} + | ^(Repr test[ctype]*) { + $etype = new Repr($Repr, $test.etype); + } | ^(Name NAME) { debug("matched Name " + $NAME.text); $etype = new Name($NAME, $NAME.text, ctype); @@ -1237,8 +1239,9 @@ : ^(Arg test[expr_contextType.Load]) { arguments.add($test.etype); } - | ^(GenFor test[expr_contextType.Load] gen_for) - //arguments.add($test.etype)); + | ^(GenFor test[expr_contextType.Load] gen_for) { + arguments.add(new GeneratorExp($GenFor, $test.etype, new comprehensionType[]{$gen_for.gen})); + } ; keyword[List kws] @@ -1258,7 +1261,6 @@ : ^(ListFor ^(Target targ=test[expr_contextType.Store]) ^(Iter iter=test[expr_contextType.Load]) (^(Ifs list_iter))?) { debug("matched list_for"); - //XXX: Not collecting from Ifs yet. exprType[] e; if ($Ifs != null && $list_iter.etype != null) { e = new exprType[]{$list_iter.etype}; @@ -1275,13 +1277,29 @@ } ; -gen_iter: gen_for - | gen_if - ; +gen_iter returns [exprType etype] + : gen_for + | gen_if { + $etype = $gen_if.etype; + } + ; -gen_for: ^(GenFor ^(Target test[expr_contextType.Load]+) (^(Iter gen_iter))?) - ; +gen_for returns [comprehensionType gen] + : ^(GenFor ^(Target targ=test[expr_contextType.Store]+) ^(Iter iter=test[expr_contextType.Load]) (^(Ifs gen_iter))?) { + debug("matched gen_for"); + exprType[] e; + if ($Ifs != null && $gen_iter.etype != null) { + e = new exprType[]{$gen_iter.etype}; + } else { + e = new exprType[0]; + } + $gen = new comprehensionType($GenFor, $targ.etype, $iter.etype, e); + } + ; -gen_if: ^(GenIf ^(Target test[expr_contextType.Load]) (^(Iter gen_iter))?) - ; +gen_if returns [exprType etype] + : ^(GenIf ^(Target test[expr_contextType.Load]) (^(Iter gen_iter))?) { + $etype = $test.etype; + } + ; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-01-12 16:08:23
|
Revision: 4016 http://jython.svn.sourceforge.net/jython/?rev=4016&view=rev Author: fwierzbicki Date: 2008-01-12 08:08:14 -0800 (Sat, 12 Jan 2008) Log Message: ----------- Properly handle nested AND with parens. Still need to work through the other BoolOps. Modified Paths: -------------- trunk/sandbox/ast/grammar/Python.g trunk/sandbox/ast/grammar/PythonWalker.g Modified: trunk/sandbox/ast/grammar/Python.g =================================================================== --- trunk/sandbox/ast/grammar/Python.g 2008-01-11 12:09:20 UTC (rev 4015) +++ trunk/sandbox/ast/grammar/Python.g 2008-01-12 16:08:14 UTC (rev 4016) @@ -178,6 +178,7 @@ ListFor; ListIf; FinalBody; + Parens; } @header { @@ -666,7 +667,7 @@ // NAME | NUMBER | STRING+) atom : LPAREN ( yield_expr -> ^(Tuple ^(Elts yield_expr)) - | testlist_gexp {debug("parsed testlist_gexp");} -> testlist_gexp + | testlist_gexp {debug("parsed testlist_gexp");} -> ^(Parens testlist_gexp) | -> ^(Tuple) ) RPAREN Modified: trunk/sandbox/ast/grammar/PythonWalker.g =================================================================== --- trunk/sandbox/ast/grammar/PythonWalker.g 2008-01-11 12:09:20 UTC (rev 4015) +++ trunk/sandbox/ast/grammar/PythonWalker.g 2008-01-12 16:08:14 UTC (rev 4016) @@ -881,18 +881,18 @@ ; //FIXME: lots of placeholders -test[expr_contextType ctype] returns [exprType etype] +test[expr_contextType ctype] returns [exprType etype, boolean parens] : ^(AND left=test[ctype] right=test[ctype]) { List values = new ArrayList(); boolean leftIsAnd = false; boolean rightIsAnd = false; BoolOp leftB = null; BoolOp rightB = null; - if ($left.start.getType() == AND) { + if (! $left.parens && $left.start.getType() == AND) { leftIsAnd = true; leftB = (BoolOp)$left.etype; } - if ($right.start.getType() == AND) { + if (! $right.parens && $right.start.getType() == AND) { rightIsAnd = true; rightB = (BoolOp)$right.etype; } @@ -986,8 +986,9 @@ comparators[0] = $targs.etype; val = $left.etype; } + $parens = $left.parens; $etype = new Compare($comp_op.start, val, ops, comparators); - debug("COMP_OP: " + $comp_op.start); + debug("COMP_OP: " + $comp_op.start + ":::" + $etype + ":::" + $parens); } | atom[ctype] { debug("matched atom"); @@ -1007,7 +1008,7 @@ | ^(IfExp ^(Test t1=test[ctype]) ^(Body t2=test[ctype]) ^(OrElse t3=test[ctype])) { $etype = new IfExp($IfExp, $t1.etype, $t2.etype, $t3.etype); } - ; +; comp_op returns [cmpopType op] : LESS {$op = cmpopType.Lt;} @@ -1045,7 +1046,7 @@ ; //FIXME: lots of placeholders -atom[expr_contextType ctype] returns [exprType etype] +atom[expr_contextType ctype] returns [exprType etype, boolean parens] : ^(Tuple (^(Elts elts[ctype]))?) { debug("matched Tuple"); exprType[] e; @@ -1154,6 +1155,11 @@ | ^(NOT test[ctype]) { $etype = new UnaryOp($NOT, unaryopType.Not, $test.etype); } + | ^(Parens test[ctype]) { + debug("PARENS! " + $test.etype); + $etype = $test.etype; + $parens = true; + } ; comprehension[expr_contextType ctype] returns [exprType etype] This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-01-14 23:11:34
|
Revision: 4029 http://jython.svn.sourceforge.net/jython/?rev=4029&view=rev Author: fwierzbicki Date: 2008-01-14 15:11:33 -0800 (Mon, 14 Jan 2008) Log Message: ----------- yield expr support. Modified Paths: -------------- trunk/sandbox/ast/grammar/Python.g trunk/sandbox/ast/grammar/PythonWalker.g Modified: trunk/sandbox/ast/grammar/Python.g =================================================================== --- trunk/sandbox/ast/grammar/Python.g 2008-01-14 19:52:12 UTC (rev 4028) +++ trunk/sandbox/ast/grammar/Python.g 2008-01-14 23:11:33 UTC (rev 4029) @@ -666,7 +666,7 @@ // '`' testlist1 '`' | // NAME | NUMBER | STRING+) atom : LPAREN - ( yield_expr -> ^(Tuple ^(Elts yield_expr)) + ( yield_expr -> ^(Parens yield_expr) | testlist_gexp {debug("parsed testlist_gexp");} -> ^(Parens testlist_gexp) | -> ^(Tuple) ) Modified: trunk/sandbox/ast/grammar/PythonWalker.g =================================================================== --- trunk/sandbox/ast/grammar/PythonWalker.g 2008-01-14 19:52:12 UTC (rev 4028) +++ trunk/sandbox/ast/grammar/PythonWalker.g 2008-01-14 23:11:33 UTC (rev 4029) @@ -606,7 +606,6 @@ | continue_stmt | return_stmt | raise_stmt - | yield_stmt ; break_stmt @@ -631,14 +630,13 @@ } ; -yield_stmt +yield_expr returns [exprType etype] : ^(Yield (^(Value test[expr_contextType.Load]))?) { exprType v = null; if ($Value != null) { v = $test.etype; } - Yield y = new Yield($Yield, v); - $stmts::statements.add(new Expr($Yield, y)); + $etype = new Yield($Yield, v); } ; @@ -1031,7 +1029,10 @@ | ^(IfExp ^(Test t1=test[ctype]) ^(Body t2=test[ctype]) ^(OrElse t3=test[ctype])) { $etype = new IfExp($IfExp, $t1.etype, $t2.etype, $t3.etype); } -; + | yield_expr { + $etype = $yield_expr.etype; + } + ; comp_op returns [cmpopType op] : LESS {$op = cmpopType.Lt;} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-01-16 02:46:36
|
Revision: 4039 http://jython.svn.sourceforge.net/jython/?rev=4039&view=rev Author: fwierzbicki Date: 2008-01-15 18:46:32 -0800 (Tue, 15 Jan 2008) Log Message: ----------- Empty decorator call, and bugfix on GenIf Modified Paths: -------------- trunk/sandbox/ast/grammar/Python.g trunk/sandbox/ast/grammar/PythonWalker.g Modified: trunk/sandbox/ast/grammar/Python.g =================================================================== --- trunk/sandbox/ast/grammar/Python.g 2008-01-16 00:12:20 UTC (rev 4038) +++ trunk/sandbox/ast/grammar/Python.g 2008-01-16 02:46:32 UTC (rev 4039) @@ -262,8 +262,10 @@ ; //decorator: '@' dotted_name [ '(' [arglist] ')' ] NEWLINE -decorator: AT dotted_attr (LPAREN arglist? RPAREN)? NEWLINE - -> ^(Decorator dotted_attr ^(Call arglist)?) +decorator: AT dotted_attr + ( (LPAREN arglist? RPAREN) -> ^(Decorator dotted_attr ^(Call ^(Args arglist)?)) + | -> ^(Decorator dotted_attr) + ) NEWLINE ; dotted_attr Modified: trunk/sandbox/ast/grammar/PythonWalker.g =================================================================== --- trunk/sandbox/ast/grammar/PythonWalker.g 2008-01-16 00:12:20 UTC (rev 4038) +++ trunk/sandbox/ast/grammar/PythonWalker.g 2008-01-16 02:46:32 UTC (rev 4039) @@ -325,7 +325,8 @@ return new For(t, target, iter, b, o); } - //FIXME: just calling __neg__ for now - can be more efficient. + //FIXME: just calling __neg__ for now - can be better. Also does not parse expressions like + // --2 correctly (should give ^(USub -2) but gives 2). private exprType negate(PythonTree t, exprType o) { if (o instanceof Num) { Num num = (Num)o; @@ -416,13 +417,24 @@ ; decorator [List decs] - : ^(Decorator dotted_attr (^(Call arglist))?) { + : ^(Decorator dotted_attr (^(Call (^(Args arglist))?))?) { if ($Call == null) { decs.add($dotted_attr.etype); } else { - exprType[] args = (exprType[])$arglist.args.toArray(new exprType[$arglist.args.size()]); - keywordType[] keywords = (keywordType[])$arglist.keywords.toArray(new keywordType[$arglist.keywords.size()]); - Call c = new Call($Call, $dotted_attr.etype, args, keywords, $arglist.starargs, $arglist.kwargs); + exprType[] args; + keywordType[] keywords; + exprType starargs = null; + exprType kwargs = null; + if ($Args != null) { + args = (exprType[])$arglist.args.toArray(new exprType[$arglist.args.size()]); + keywords = (keywordType[])$arglist.keywords.toArray(new keywordType[$arglist.keywords.size()]); + starargs = $arglist.starargs; + kwargs = $arglist.kwargs; + } else { + args = new exprType[0]; + keywords = new keywordType[0]; + } + Call c = new Call($Call, $dotted_attr.etype, args, keywords, starargs, kwargs); decs.add(c); } } @@ -1171,14 +1183,12 @@ } | ^(USub test[ctype]) { debug("USub matched " + $test.etype); - //FIXME: need to actually negate this $etype = negate($USub, $test.etype); } | ^(UAdd test[ctype]) { $etype = new UnaryOp($UAdd, unaryopType.UAdd, $test.etype); } | ^(Invert test[ctype]) { - //FIXME: need to actually invert this $etype = new UnaryOp($Invert, unaryopType.Invert, $test.etype); } | ^(NOT test[ctype]) { @@ -1418,7 +1428,7 @@ ; gen_if[List gens] returns [exprType etype] - : ^(GenIf ^(Target test[expr_contextType.Load]) (^(Iter gen_iter[gens]))?) { + : ^(GenIf ^(Target test[expr_contextType.Load]) (^(Ifs gen_iter[gens]))?) { $etype = $test.etype; } ; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |