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

santagada at codespeak.net santagada at codespeak.net
Tue May 15 03:27:37 CEST 2007


Author: santagada
Date: Tue May 15 03:27:36 2007
New Revision: 43396

Added:
   pypy/dist/pypy/lang/js/jsparser.py
   pypy/dist/pypy/lang/js/test/test_parser.py
      - copied, changed from r43392, pypy/dist/pypy/lang/js/test/test_new_parser.py
Modified:
   pypy/dist/pypy/lang/js/astbuilder.py
   pypy/dist/pypy/lang/js/interpreter.py
   pypy/dist/pypy/lang/js/test/test_interp.py
   pypy/dist/pypy/lang/js/test/test_new_parser.py
Log:
making the transition to the new parser... it is not ready for production yet, but I will not be mantaining the old one... so it is better to work on things as they are going to be (file names, apis, etc)

Modified: pypy/dist/pypy/lang/js/astbuilder.py
==============================================================================
--- pypy/dist/pypy/lang/js/astbuilder.py	(original)
+++ pypy/dist/pypy/lang/js/astbuilder.py	Tue May 15 03:27:36 2007
@@ -46,7 +46,7 @@
 
     def visit_DECIMALLITERAL(self, node):
         result = self.get_instance(node, operations.Number)
-        result.num = float(node.additional_info)
+        result.num = float(result.value)
         return result
 
     def string(self,node):

Modified: pypy/dist/pypy/lang/js/interpreter.py
==============================================================================
--- pypy/dist/pypy/lang/js/interpreter.py	(original)
+++ pypy/dist/pypy/lang/js/interpreter.py	Tue May 15 03:27:36 2007
@@ -1,6 +1,7 @@
 
 import math
-from pypy.lang.js.jsparser import parse, parse_bytecode
+from pypy.lang.js.jsparser import parse
+from pypy.lang.js.astbuilder import ASTBuilder
 from pypy.lang.js.operations import *
 from pypy.rlib.objectmodel import we_are_translated
 
@@ -9,12 +10,9 @@
     print x
 
 def load_source(script_source):
+    astb = ASTBuilder()
     temp_tree = parse(script_source)
-    return from_tree(temp_tree)
-
-def load_bytecode(bytecode):
-    temp_tree = parse_bytecode(bytecode)
-    return from_tree(temp_tree)
+    return astb.dispatch(temp_tree)
 
 import cPickle as pickle
 import os.path

Added: pypy/dist/pypy/lang/js/jsparser.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/lang/js/jsparser.py	Tue May 15 03:27:36 2007
@@ -0,0 +1,17 @@
+from pypy.rlib.parsing.ebnfparse import parse_ebnf, make_parse_function
+from pypy.rlib.parsing.parsing import ParseError, Rule
+import py
+
+GFILE = py.magic.autopath().dirpath().join("jsgrammar.txt")
+
+try:
+    t = GFILE.read()
+    regexs, rules, ToAST = parse_ebnf(t)
+except ParseError,e:
+    print e.nice_error_message(filename=str(GFILE),source=t)
+    raise
+
+parsef = make_parse_function(regexs, rules, eof=True)
+
+def parse(code):
+    parsef(code).visit(ToAST())

Modified: pypy/dist/pypy/lang/js/test/test_interp.py
==============================================================================
--- pypy/dist/pypy/lang/js/test/test_interp.py	(original)
+++ pypy/dist/pypy/lang/js/test/test_interp.py	Tue May 15 03:27:36 2007
@@ -15,6 +15,7 @@
         py.test.skip("js binary not found")
 
 js_is_on_path()
+py.test.skip("making the transition to the new parser")
 
 class TestInterp(object):
     def test_simple(self):

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	Tue May 15 03:27:36 2007
@@ -279,7 +279,7 @@
         self.parse('function z (a,b,c,d,e) {;}')
     
 
-class TestToEvalTree(BaseGrammarTest):
+class TestToAST(BaseGrammarTest):
     def setup_class(cls):
         cls.parse = parse_func('expression')
 



More information about the Pypy-commit mailing list