[pypy-svn] r35247 - pypy/dist/pypy/lang/prolog/interpreter

cfbolz at codespeak.net cfbolz at codespeak.net
Mon Dec 4 12:03:42 CET 2006


Author: cfbolz
Date: Mon Dec  4 12:03:40 2006
New Revision: 35247

Modified:
   pypy/dist/pypy/lang/prolog/interpreter/parsing.py
Log:
small changes to keep up with the new things in the parser


Modified: pypy/dist/pypy/lang/prolog/interpreter/parsing.py
==============================================================================
--- pypy/dist/pypy/lang/prolog/interpreter/parsing.py	(original)
+++ pypy/dist/pypy/lang/prolog/interpreter/parsing.py	Mon Dec  4 12:03:40 2006
@@ -225,21 +225,24 @@
     def transform(self, node):
         if isinstance(node, Symbol):
             return node
+        children = [c for c in node.children
+                        if isinstance(c, Symbol) or (
+                            isinstance(c, Nonterminal) and len(c.children))]
         if isinstance(node, Nonterminal):
-            if len(node.children) == 1:
+            if len(children) == 1:
                 return Nonterminal(
-                    node.symbol, [self.transform(node.children[0])])
-            if len(node.children) == 2 or len(node.children) == 3:
-                left = node.children[-2]
-                right = node.children[-1]
+                    node.symbol, [self.transform(children[0])])
+            if len(children) == 2 or len(children) == 3:
+                left = children[-2]
+                right = children[-1]
                 if (isinstance(right, Nonterminal) and
                     right.symbol.startswith("extraexpr")):
-                    if len(node.children) == 2:
+                    if len(children) == 2:
                         leftreplacement = self.transform(left)
                     else:
                         leftreplacement = Nonterminal(
                             node.symbol,
-                            [self.transform(node.children[0]),
+                            [self.transform(children[0]),
                              self.transform(left)])
                     children = [leftreplacement,
                                 self.transform(right.children[0]),
@@ -247,14 +250,17 @@
 
                     newnode = Nonterminal(node.symbol, children)
                     return self.transform_extra(right, newnode)
-            children = [self.transform(child) for child in node.children]
+            children = [self.transform(child) for child in children]
             return Nonterminal(node.symbol, children)
 
     def transform_extra(self, extranode, child):
+        children = [c for c in extranode.children
+                        if isinstance(c, Symbol) or (
+                            isinstance(c, Nonterminal) and len(c.children))]
         symbol = extranode.symbol[5:]
-        if len(extranode.children) == 2:
+        if len(children) == 2:
             return child
-        right = extranode.children[2]
+        right = children[2]
         assert isinstance(right, Nonterminal)
         children = [child,
                     self.transform(right.children[0]),


More information about the pypy-svn mailing list