[pypy-svn] r42763 - in pypy/dist/pypy/lang/js: . test

santagada at codespeak.net santagada at codespeak.net
Sun May 6 23:16:46 CEST 2007


Author: santagada
Date: Sun May  6 23:16:46 2007
New Revision: 42763

Modified:
   pypy/dist/pypy/lang/js/newparser.py
   pypy/dist/pypy/lang/js/test/test_new_parser.py
Log:
support for strings on newparser... now I think I fully understand how it works and I am planing to move it to another file, maybe concrete_tree_builder or something.

Modified: pypy/dist/pypy/lang/js/newparser.py
==============================================================================
--- pypy/dist/pypy/lang/js/newparser.py	(original)
+++ pypy/dist/pypy/lang/js/newparser.py	Sun May  6 23:16:46 2007
@@ -43,6 +43,7 @@
         '+': operations.UPlus,
         '-': operations.UMinus,
         '++': operations.Increment,
+        '--': operations.Decrement,
     }
     def get_instance(self, symbol, cls):
         assert isinstance(symbol, Symbol)
@@ -59,6 +60,15 @@
         result.num = float(node.additional_info)
         return result
 
+    def string(self,node):
+        print node.additional_info
+        result = self.get_instance(node, operations.String)
+        result.strval = node.additional_info[1:-1] #XXX should do unquoting
+        return result
+    
+    visit_DOUBLESTRING = string
+    visit_SINGLESTRING = string
+
     def binaryop(self, node):
         left = self.dispatch(node.children[0])
         for i in range((len(node.children) - 1) // 2):
@@ -79,7 +89,6 @@
         result = self.get_instance(
                 op, self.UNOP_TO_CLS[op.additional_info])
         child = self.dispatch(node.children[1])
-        print child
         result.expr = child
         result.postfix = False
         return result

Modified: pypy/dist/pypy/lang/js/test/test_new_parser.py
==============================================================================
--- pypy/dist/pypy/lang/js/test/test_new_parser.py	(original)
+++ pypy/dist/pypy/lang/js/test/test_new_parser.py	Sun May  6 23:16:46 2007
@@ -284,7 +284,11 @@
 
     def to_etree(self, s):
         return EvalTreeBuilder().dispatch(self.parse(s))
-
+    
+    def eval_expr(self, s):
+        etree = self.to_etree(s)
+        return etree.eval(None)
+    
     def test_primary(self):
         etree = self.to_etree('(6)')
         w_num = etree.eval(None)
@@ -301,4 +305,8 @@
         etree = self.to_etree('++5')
         w_num = etree.eval(None)
         assert w_num.ToNumber() == 6
+        w_num = self.eval_expr('--5')
+        assert w_num.ToNumber() == 4
+        w_str = self.eval_expr('"hello "+\'world\'')
+        assert w_str.ToString() == 'hello world'
     
\ No newline at end of file



More information about the Pypy-commit mailing list