[pypy-svn] r14126 - in pypy/dist/pypy: interpreter interpreter/pyparser module/recparser tool translator/goal

ludal at codespeak.net ludal at codespeak.net
Sun Jul 3 13:09:15 CEST 2005


Author: ludal
Date: Sun Jul  3 13:09:12 2005
New Revision: 14126

Added:
   pypy/dist/pypy/module/recparser/astbuilder.py
      - copied unchanged from r14092, pypy/branch/pycompiler/module/recparser/astbuilder.py
   pypy/dist/pypy/module/recparser/codegen.py
      - copied unchanged from r14092, pypy/branch/pycompiler/module/recparser/codegen.py
   pypy/dist/pypy/translator/goal/targetparser.py
      - copied unchanged from r14092, pypy/branch/pycompiler/translator/goal/targetparser.py
Modified:
   pypy/dist/pypy/interpreter/baseobjspace.py
   pypy/dist/pypy/interpreter/pycompiler.py
   pypy/dist/pypy/interpreter/pyparser/pythonparse.py
   pypy/dist/pypy/module/recparser/__init__.py
   pypy/dist/pypy/tool/option.py
Log:
 * added option to use pyparser from command line
 * misc cleanup


Modified: pypy/dist/pypy/interpreter/baseobjspace.py
==============================================================================
--- pypy/dist/pypy/interpreter/baseobjspace.py	(original)
+++ pypy/dist/pypy/interpreter/baseobjspace.py	Sun Jul  3 13:09:12 2005
@@ -143,9 +143,9 @@
         # XXX we need to resolve unwrapping issues to 
         #     make this the default _sre module
         #self.setbuiltinmodule("_sre", "_sre_pypy")
-        if self.options.parser == "recparser":
-            self.setbuiltinmodule('parser', 'recparser')
-        elif self.options.parser == "parser":
+        if self.options.useparsermodule == "recparser":
+             self.setbuiltinmodule('parser', 'recparser')
+        elif self.options.parsermodule == "parser":
             self.setbuiltinmodule('parser')
 
         # initialize with "bootstrap types" from objspace  (e.g. w_None)
@@ -194,7 +194,7 @@
                 return PythonCompiler(self)
             else:
                 return PyPyCompiler(self)
-        elif self.options.compiler == 'recparser':
+        elif self.options.compiler == 'pyparse':
             # <=> options.parser == 'cpython'
             return PythonCompiler(self)
         else:

Modified: pypy/dist/pypy/interpreter/pycompiler.py
==============================================================================
--- pypy/dist/pypy/interpreter/pycompiler.py	(original)
+++ pypy/dist/pypy/interpreter/pycompiler.py	Sun Jul  3 13:09:12 2005
@@ -177,7 +177,7 @@
 from pyparser.pythonparse import parse_python_source, PYTHON_PARSER
 from pyparser.tuplebuilder import TupleBuilder
 
-def pycompile(source, mode):
+def _parse_source(source, mode):
     strings = [line+'\n' for line in source.split('\n')]
     builder = TupleBuilder(PYTHON_PARSER.rules, lineno=False)
     if mode == 'exec':
@@ -202,7 +202,7 @@
         space = self.space
         try:
             transformer = Transformer()
-            tuples = pycompile(source, mode)
+            tuples = _parse_source(source, mode)
             tree = transformer.compile_node(tuples)
             compiler.misc.set_filename(filename, tree)
             if mode == 'exec':

Modified: pypy/dist/pypy/interpreter/pyparser/pythonparse.py
==============================================================================
--- pypy/dist/pypy/interpreter/pyparser/pythonparse.py	(original)
+++ pypy/dist/pypy/interpreter/pyparser/pythonparse.py	Sun Jul  3 13:09:12 2005
@@ -1,9 +1,16 @@
 #!/usr/bin/env python
+"""This module loads the python Grammar (2.3 or 2.4) and builds
+the parser for this grammar in the global PYTHON_PARSER
+
+helper functions are provided that use the grammar to parse
+using file_input, single_input and eval_input targets
+"""
+from pypy.interpreter.error import OperationError, debug_print
+
 from pythonlexer import Source
-from ebnfparse import parse_grammar
+import ebnfparse
 import sys
 import os
-import symbol
 import grammar
 
 # parse the python grammar corresponding to our CPython version
@@ -14,12 +21,13 @@
     """returns a """
     level = grammar.DEBUG
     grammar.DEBUG = 0
-    gram = parse_grammar( file(PYTHON_GRAMMAR) )
+    gram = ebnfparse.parse_grammar( file(PYTHON_GRAMMAR) )
     grammar.DEBUG = level
     # Build first sets for each rule (including anonymous ones)
     grammar.build_first_sets(gram.items)
     return gram
 
+debug_print( "Loading grammar %s" % PYTHON_GRAMMAR )
 PYTHON_PARSER = python_grammar()
 
 

Modified: pypy/dist/pypy/module/recparser/__init__.py
==============================================================================
--- pypy/dist/pypy/module/recparser/__init__.py	(original)
+++ pypy/dist/pypy/module/recparser/__init__.py	Sun Jul  3 13:09:12 2005
@@ -4,8 +4,7 @@
 
 
 
-import pythonparse
-debug_print( "Loading grammar %s" % pythonparse.PYTHON_GRAMMAR )
+import pypy.interpreter.pyparser.pythonparse
 
 from pypy.interpreter.mixedmodule import MixedModule
 class Module(MixedModule):

Modified: pypy/dist/pypy/tool/option.py
==============================================================================
--- pypy/dist/pypy/tool/option.py	(original)
+++ pypy/dist/pypy/tool/option.py	Sun Jul  3 13:09:12 2005
@@ -10,8 +10,11 @@
     spaces = []
     oldstyle = 0
     uselibfile = 0
-    parser = "cpython"
-    compiler = "cpython"
+    useparsermodule = "recparser" # "cpython" / "recparser" / "parser"
+    parser = "cpython" # "cpython" / "pyparse"
+    compiler = "cpython" # "cpython"
+                         # "pyparse" pypy parser, cpython compiler
+                         # "pycomp" pypy parser and compiler (TBD)
 
 def run_tb_server(option, opt, value, parser):
     from pypy.tool import tb_server
@@ -41,6 +44,9 @@
         '-H', action="callback",
         callback=run_tb_server,
         help="use web browser for traceback info"))
+    options.append(make_option(
+        '--pyparse', action="store_const", dest="compiler", const="pyparse",
+        help="enable the internal pypy parser with CPython compiler"))
 
     return options
 



More information about the Pypy-commit mailing list