| CODENOTIFIER | HelpYou are not signed inSign in |
Project: Jython
Revision: 5226
Author: fwierzbicki
Date: 20 Aug 2008 16:59:44
Changes:gen expressions and list comps now actually work...
Files:| ... | ...@@ -78,7 +78,6 @@ | |
| 78 | 78 | PYNODE; |
| 79 | 79 | Interactive; |
| 80 | 80 | Expression; |
| 81 | GeneratorExp; | |
| 82 | 81 | } |
| 83 | 82 | |
| 84 | 83 | @header { |
| ... | ...@@ -116,6 +115,7 @@ | |
| 116 | 115 | import org.python.antlr.ast.ExtSlice; |
| 117 | 116 | import org.python.antlr.ast.For; |
| 118 | 117 | import org.python.antlr.ast.FunctionDef; |
| 118 | import org.python.antlr.ast.GeneratorExp; | |
| 119 | 119 | import org.python.antlr.ast.Global; |
| 120 | 120 | import org.python.antlr.ast.If; |
| 121 | 121 | import org.python.antlr.ast.IfExp; |
| ... | ...@@ -1026,14 +1026,24 @@ | |
| 1026 | 1026 | //testlist_gexp: test ( gen_for | (',' test)* [','] ) |
| 1027 | 1027 | testlist_gexp |
| 1028 | 1028 | @init { |
| 1029 | exprType etype = null; | |
| 1029 | 1030 | List gens = new ArrayList(); |
| 1030 | 1031 | } |
| 1032 | @after { | |
| 1033 | if (etype != null) { | |
| 1034 | $testlist_gexp.tree = etype; | |
| 1035 | } | |
| 1036 | } | |
| 1031 | 1037 | : t+=test[expr_contextType.Load] |
| 1032 | 1038 | ( ((options {k=2;}: c1=COMMA t+=test[expr_contextType.Load])* (c2=COMMA)? |
| 1033 | 1039 | -> { $c1 != null || $c2 != null }? ^(PYNODE<Tuple>[$testlist_gexp.start, actions.makeExprs($t), $expr::ctype]) |
| 1034 | 1040 | -> test |
| 1035 | 1041 | ) |
| 1036 | | ( gen_for[gens] -> ^(GeneratorExp test gen_for) | |
| 1042 | | ( gen_for[gens] { | |
| 1043 | Collections.reverse(gens); | |
| 1044 | comprehensionType[] c = (comprehensionType[])gens.toArray(new comprehensionType[gens.size()]); | |
| 1045 | etype = new GeneratorExp($gen_for.start, (exprType)$t.get(0), c); | |
| 1046 | } | |
| 1037 | 1047 | ) |
| 1038 | 1048 | ) |
| 1039 | 1049 | ; |
| ... | ...@@ -1219,7 +1229,7 @@ | |
| 1219 | 1229 | |
| 1220 | 1230 | //list_for: 'for' exprlist 'in' testlist_safe [list_iter] |
| 1221 | 1231 | list_for [List gens] |
| 1222 | : FOR exprlist[expr_contextType.Load] IN testlist[expr_contextType.Load] (list_iter[gens])? { | |
| 1232 | : FOR exprlist[expr_contextType.Store] IN testlist[expr_contextType.Load] (list_iter[gens])? { | |
| 1223 | 1233 | exprType[] e; |
| 1224 | 1234 | if ($list_iter.etype != null) { |
| 1225 | 1235 | e = new exprType[]{$list_iter.etype}; |
| ... | ...@@ -1247,7 +1257,7 @@ | |
| 1247 | 1257 | |
| 1248 | 1258 | //gen_for: 'for' exprlist 'in' or_test [gen_iter] |
| 1249 | 1259 | gen_for [List gens] |
| 1250 | :FOR exprlist[expr_contextType.Load] IN or_test[expr_contextType.Load] gen_iter[gens]? { | |
| 1260 | :FOR exprlist[expr_contextType.Store] IN or_test[expr_contextType.Load] gen_iter[gens]? { | |
| 1251 | 1261 | exprType[] e; |
| 1252 | 1262 | if ($gen_iter.etype != null) { |
| 1253 | 1263 | e = new exprType[]{$gen_iter.etype}; |