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

santagada at codespeak.net santagada at codespeak.net
Tue May 15 04:45:00 CEST 2007


Author: santagada
Date: Tue May 15 04:44:59 2007
New Revision: 43398

Modified:
   pypy/dist/pypy/lang/js/astbuilder.py
   pypy/dist/pypy/lang/js/jsgrammar.txt
   pypy/dist/pypy/lang/js/operations.py
   pypy/dist/pypy/lang/js/test/test_parser.py
Log:
some preliminar suport for javascript programs.

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 04:44:59 2007
@@ -104,3 +104,19 @@
         result.initializer = operations.astundef #XXX this is uneded now
         print result
         return result
+
+    def visit_program(self, node):
+        result = self.get_instance(node, operations.Program)
+        result.body = self.dispatch(node.children[0])
+        return result
+        
+    def visit_sourceelements(self, node):
+        result = self.get_instance(node, operations.Script)
+        result.var_decl = None #XXX TODO
+        result.func_decl = None #XXX TODO
+        result.nodes = [self.dispatch(child) for child in node.children]
+        return result
+    
+    def visit_expressionstatement(self, node):
+        return self.dispatch(node.children[0])
+        
\ No newline at end of file

Modified: pypy/dist/pypy/lang/js/jsgrammar.txt
==============================================================================
--- pypy/dist/pypy/lang/js/jsgrammar.txt	(original)
+++ pypy/dist/pypy/lang/js/jsgrammar.txt	Tue May 15 04:44:59 2007
@@ -188,17 +188,17 @@
                 | <numericliteral>
                 ; 
 
-functiondeclaration : ["function"] identifier ["("] formalparameterlist? [")"] ["{"] functionbody ["}"]
+functiondeclaration : ["function"] identifier ["("] formalparameterlist? [")"] ["{"] >functionbody< ["}"]
                     ;
 
-functionexpression  : ["function"] identifier? ["("] formalparameterlist? [")"] ["{"] functionbody ["}"]
+functionexpression  : ["function"] identifier? ["("] formalparameterlist? [")"] ["{"] >functionbody< ["}"]
                     ;
 
 formalparameterlist : identifier [","] >formalparameterlist<
                     | identifier
                     ;
 
-functionbody    : <sourceelements>
+functionbody    : sourceelements
                 ;
 
 begmemberexpression : <primaryexpression>

Modified: pypy/dist/pypy/lang/js/operations.py
==============================================================================
--- pypy/dist/pypy/lang/js/operations.py	(original)
+++ pypy/dist/pypy/lang/js/operations.py	Tue May 15 04:44:59 2007
@@ -868,6 +868,11 @@
                 print "exception in line: %s, on: %s"%(node.lineno, node.value)
                 raise
 
+class Program(Statement):
+
+    def execute(self, ctx):
+        return self.body.execute(self, ctx)
+
 class Semicolon(Statement):
     opcode = 'SEMICOLON'
 

Modified: pypy/dist/pypy/lang/js/test/test_parser.py
==============================================================================
--- pypy/dist/pypy/lang/js/test/test_parser.py	(original)
+++ pypy/dist/pypy/lang/js/test/test_parser.py	Tue May 15 04:44:59 2007
@@ -279,7 +279,7 @@
         self.parse('function z (a,b,c,d,e) {;}')
     
 
-class TestToAST(BaseGrammarTest):
+class TestToASTExpr(BaseGrammarTest):
     def setup_class(cls):
         cls.parse = parse_func('expression')
 
@@ -328,5 +328,16 @@
         assert w_num.ToNumber() == 4
         w_str = self.eval_expr('"hello "+\'world\'')
         assert w_str.ToString() == 'hello world'
-        
-    
\ No newline at end of file
+    
+
+class TestToAST(BaseGrammarTest):
+    def setup_class(cls):
+        cls.parse = parse_func()
+
+    def to_ast(self, s):
+        ASTBuilder().dispatch(self.parse(s))
+    
+    def test_simple(self):
+        self.to_ast("1;")
+        #self.to_ast("print(1+1);")
+    



More information about the Pypy-commit mailing list