[Jython-checkins] jython: Cleanup dictorsetmaker.

frank.wierzbicki jython-checkins at python.org
Fri Mar 9 06:27:09 CET 2012


http://hg.python.org/jython/rev/25e8eff398f2
changeset:   6316:25e8eff398f2
user:        Frank Wierzbicki <fwierzbicki at gmail.com>
date:        Thu Mar 08 21:27:00 2012 -0800
summary:
  Cleanup dictorsetmaker.

files:
  grammar/Python.g |  31 ++++++++++++-------------------
  1 files changed, 12 insertions(+), 19 deletions(-)


diff --git a/grammar/Python.g b/grammar/Python.g
--- a/grammar/Python.g
+++ b/grammar/Python.g
@@ -1716,18 +1716,8 @@
       )
       RBRACK
     | LCURLY
-       (dictorsetmaker
-        {
-            if ($dictorsetmaker.etype != null) {
-                etype = $dictorsetmaker.etype;
-            }
-            else if ($dictorsetmaker.keys != null && $dictorsetmaker.values == null) {
-                etype = new Set($LCURLY, actions.castExprs($dictorsetmaker.keys));
-            } else {
-                etype = new Dict($LCURLY, actions.castExprs($dictorsetmaker.keys),
-                  actions.castExprs($dictorsetmaker.values));
-            }
-        }
+       (dictorsetmaker[$LCURLY]
+      -> dictorsetmaker
        |
         {
             etype = new Dict($LCURLY, new ArrayList<expr>(), new ArrayList<expr>());
@@ -1974,23 +1964,26 @@
 //                  (test (comp_for | (',' test)* [','])) )
 
 //dictmaker: test ':' test (',' test ':' test)* [',']
-dictorsetmaker
-    returns [List keys, List values, expr etype]
+dictorsetmaker[Token lcurly]
 @init {
     List gens = new ArrayList();
+    expr etype = null;
+}
+ at after {
+    if (etype != null) {
+        $dictorsetmaker.tree = etype;
+    }
 }
     : k+=test[expr_contextType.Load]
          (
              (COLON v+=test[expr_contextType.Load]
                (options {k=2;}:COMMA k+=test[expr_contextType.Load] COLON v+=test[expr_contextType.Load])*
                {
-                   $keys = $k;
-                   $values= $v;
+                   etype = new Dict($lcurly, actions.castExprs($k), actions.castExprs($v));
                }
              |(COMMA k+=test[expr_contextType.Load])*
               {
-                  $keys = $k;
-                  $values = null;
+                  etype = new Set($lcurly, actions.castExprs($k));
               }
              )
              (COMMA)?
@@ -2002,7 +1995,7 @@
                if (e instanceof Context) {
                    ((Context)e).setContext(expr_contextType.Load);
                }
-               $etype = new SetComp($dictorsetmaker.start, actions.castExpr($k.get(0)), c);
+               etype = new SetComp($lcurly, actions.castExpr($k.get(0)), c);
            }
          )
     ;

-- 
Repository URL: http://hg.python.org/jython


More information about the Jython-checkins mailing list