[pypy-svn] r14863 - in pypy/dist/pypy: interpreter/pyparser module/recparser

ludal at codespeak.net ludal at codespeak.net
Thu Jul 21 15:53:11 CEST 2005


Author: ludal
Date: Thu Jul 21 15:53:09 2005
New Revision: 14863

Modified:
   pypy/dist/pypy/interpreter/pyparser/pythonparse.py
   pypy/dist/pypy/module/recparser/pyparser.py
Log:
prevent callers of grammar to get AbstractBuilders, builder should always be provided by the caller that use it.
correct recparser/pyparse to make sure it does provide it's own builder


Modified: pypy/dist/pypy/interpreter/pyparser/pythonparse.py
==============================================================================
--- pypy/dist/pypy/interpreter/pyparser/pythonparse.py	(original)
+++ pypy/dist/pypy/interpreter/pyparser/pythonparse.py	Thu Jul 21 15:53:09 2005
@@ -25,7 +25,7 @@
         # Build first sets for each rule (including anonymous ones)
         grammar.build_first_sets(self.items)
 
-    def parse_source(self, textsrc, goal, builder=None, flags=0):
+    def parse_source(self, textsrc, goal, builder, flags=0):
         """Parse a python source according to goal"""
         lines = [line + '\n' for line in textsrc.split('\n')]
         if textsrc.endswith('\n'):
@@ -36,13 +36,11 @@
             lines[-1] = last_line[:-1]
         return self.parse_lines(lines, goal, builder, flags)
 
-    def parse_lines(self, lines, goal, builder=None, flags=0):
+    def parse_lines(self, lines, goal, builder, flags=0):
         goalnumber = pysymbol.sym_values[goal]
         target = self.rules[goalnumber]
         src = Source(lines, flags)
         
-#        if builder is None:
-#            builder = grammar.BaseGrammarBuilder(debug=False, rules=self.rules)
         result = target.match(src, builder)
         # <HACK> XXX find a clean way to process encoding declarations
         builder.source_encoding = src.encoding
@@ -85,14 +83,14 @@
     debug_print( "Reloading grammar %s" % PYTHON_GRAMMAR )
     PYTHON_PARSER = python_grammar( PYTHON_GRAMMAR )
 
-def parse_file_input(pyf, gram, builder=None):
+def parse_file_input(pyf, gram, builder ):
     """Parse a python file"""
     return gram.parse_source( pyf.read(), "file_input", builder )
     
-def parse_single_input(textsrc, gram, builder=None):
+def parse_single_input(textsrc, gram, builder ):
     """Parse a python single statement"""
     return gram.parse_source( textsrc, "single_input", builder )
 
-def parse_eval_input(textsrc, gram, builder=None):
+def parse_eval_input(textsrc, gram, builder):
     """Parse a python expression"""
     return gram.parse_source( textsrc, "eval_input", builder )

Modified: pypy/dist/pypy/module/recparser/pyparser.py
==============================================================================
--- pypy/dist/pypy/module/recparser/pyparser.py	(original)
+++ pypy/dist/pypy/module/recparser/pyparser.py	Thu Jul 21 15:53:09 2005
@@ -9,6 +9,7 @@
 from pypy.interpreter.pycode import PyCode 
 from pypy.interpreter.pyparser.syntaxtree import SyntaxNode
 from pypy.interpreter.pyparser.pythonutil import PYTHON_PARSER, ParseError
+from pypy.interpreter.pyparser import grammar
 
 __all__ = [ "ASTType", "STType", "suite", "expr" ]
 
@@ -55,18 +56,18 @@
         """
         return self.node.name == "file_input"
 
-    def descr_compile (self, w_filename = "<syntax_tree>"): 
+    def descr_compile (self, w_filename = "<syntax_tree>"):
         """STType.compile()
         """
         # We use the compiler module for that
-        space = self.space 
-        tup = self.totuple(line_info=1) 
-        w_tup = space.wrap(tup)   
-        w_compileAST = mycompile(space, w_tup, w_filename) 
+        space = self.space
+        tup = self.totuple(line_info=1)
+        w_tup = space.wrap(tup)
+        w_compileAST = mycompile(space, w_tup, w_filename)
         if self.isexpr(): 
-            return exprcompile(space, w_compileAST) 
+            return exprcompile(space, w_compileAST)
         else: 
-            return modcompile(space, w_compileAST) 
+            return modcompile(space, w_compileAST)
 
 ASTType = STType
 
@@ -99,23 +100,25 @@
 )
 
 def parse_python_source(space, source, goal):
+    builder = grammar.BaseGrammarBuilder(debug=False, rules=PYTHON_PARSER.rules)
     try:
-        return PYTHON_PARSER.parse_source(source, goal)
+        PYTHON_PARSER.parse_source(source, goal, builder )
+        return builder.stack[-1]
     except ParseError, e:
         raise OperationError(space.w_SyntaxError,
                              e.wrap_info(space, '<string>'))
 
 def suite( space, source ):
     # make the annotator life easier (don't use str.splitlines())
-    builder = parse_python_source( space, source, "file_input" )
-    return space.wrap( STType(space, builder.stack[-1]) )    
+    syntaxtree = parse_python_source( space, source, "file_input" )
+    return space.wrap( STType(space, syntaxtree) )    
 
 suite.unwrap_spec = [ObjSpace, str]
 
 def expr( space, source ):
     # make the annotator life easier (don't use str.splitlines())
-    builder = parse_python_source( space, source, "eval_input" )
-    return space.wrap( STType(space, builder.stack[-1]) )    
+    syntaxtree = parse_python_source( space, source, "eval_input" )
+    return space.wrap( STType(space, syntaxtree) )    
 
 expr.unwrap_spec = [ObjSpace, str]
 



More information about the Pypy-commit mailing list