[pypy-svn] r14142 - in pypy/dist/pypy: interpreter module/recparser tool
ludal at codespeak.net
ludal at codespeak.net
Sun Jul 3 15:36:29 CEST 2005
Author: ludal
Date: Sun Jul 3 15:36:27 2005
New Revision: 14142
Added:
pypy/dist/pypy/module/recparser/app_class.py
Modified:
pypy/dist/pypy/interpreter/baseobjspace.py
pypy/dist/pypy/module/recparser/__init__.py
pypy/dist/pypy/module/recparser/pyparser.py
pypy/dist/pypy/tool/option.py
Log:
revived parser module (a bit), add option to select it
Modified: pypy/dist/pypy/interpreter/baseobjspace.py
==============================================================================
--- pypy/dist/pypy/interpreter/baseobjspace.py (original)
+++ pypy/dist/pypy/interpreter/baseobjspace.py Sun Jul 3 15:36:27 2005
@@ -145,7 +145,7 @@
#self.setbuiltinmodule("_sre", "_sre_pypy")
if self.options.useparsermodule == "recparser":
self.setbuiltinmodule('parser', 'recparser')
- elif self.options.parsermodule == "parser":
+ elif self.options.useparsermodule == "parser":
self.setbuiltinmodule('parser')
# initialize with "bootstrap types" from objspace (e.g. w_None)
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 15:36:27 2005
@@ -1,33 +1,29 @@
from pypy.interpreter.error import OperationError, debug_print
-from pypy.interpreter import module
-
-
+import pypy.interpreter.pyparser.pythonparse
+from pypy.interpreter.mixedmodule import MixedModule
+# Forward imports so they run at startup time
+import pyparser
+import pypy.interpreter.pyparser.pythonlexer
import pypy.interpreter.pyparser.pythonparse
-from pypy.interpreter.mixedmodule import MixedModule
class Module(MixedModule):
- interpleveldefs = {}
- appleveldefs = {}
+ """The builtin parser module.
+ """
+
-## from pypy.interpreter.mixedmodule import MixedModule
-## class Module(MixedModule):
-## """The builtin parser module.
-## """
-
-
-## appleveldefs = {
-## # 'ParserError' : 'app_class.ParserError',
-## }
-## interpleveldefs = {
-## '__name__' : '(space.wrap("parser"))',
-## '__doc__' : '(space.wrap("parser (recparser version) module"))',
-
-## 'suite' : 'pyparser.suite',
-## 'expr' : 'pyparser.expr',
-## 'STType' : 'pyparser.STType',
-## 'ast2tuple' : 'pyparser.ast2tuple',
+ appleveldefs = {
+ 'ParserError' : 'app_class.ParserError',
+ }
+ interpleveldefs = {
+ '__name__' : '(space.wrap("parser"))',
+ '__doc__' : '(space.wrap("parser (recparser version) module"))',
+
+ 'suite' : 'pyparser.suite',
+ 'expr' : 'pyparser.expr',
+ 'STType' : 'pyparser.STType',
+ 'ast2tuple' : 'pyparser.ast2tuple',
## # 'ASTType' : 'pyparser.STType',
## # 'sequence2st' : 'pyparser.sequence2st',
## #'eval_input' : 'pyparser.eval_input',
@@ -44,5 +40,5 @@
## #'tuple2ast' : 'pyparser.tuple2ast',
## #'_pickler' : 'pyparser._pickler',
## #'compilest' : 'pyparser.compilest',
-## }
+ }
Added: pypy/dist/pypy/module/recparser/app_class.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/module/recparser/app_class.py Sun Jul 3 15:36:27 2005
@@ -0,0 +1,8 @@
+
+# ______________________________________________________________________
+# ParserError exception
+
+class ParserError (Exception):
+ """Class ParserError
+ Exception class for parser errors (I assume).
+ """
Modified: pypy/dist/pypy/module/recparser/pyparser.py
==============================================================================
--- pypy/dist/pypy/module/recparser/pyparser.py (original)
+++ pypy/dist/pypy/module/recparser/pyparser.py Sun Jul 3 15:36:27 2005
@@ -7,9 +7,9 @@
from pypy.interpreter.typedef import TypeDef
from pypy.interpreter.typedef import interp_attrproperty, GetSetProperty
from pypy.interpreter.pycode import PyCode
-from syntaxtree import SyntaxNode
-from pythonparse import parse_python_source
-from pythonutil import PYTHON_PARSER
+from pypy.interpreter.pyparser.syntaxtree import SyntaxNode
+from pypy.interpreter.pyparser.pythonparse import parse_python_source
+from pypy.interpreter.pyparser.pythonutil import PYTHON_PARSER
__all__ = [ "ASTType", "STType", "suite", "expr" ]
@@ -100,20 +100,24 @@
)
def suite( space, source ):
- builder = parse_python_source( source, PYTHON_PARSER, "file_input" )
+ # make the annotator life easier (don't use str.splitlines())
+ strings = [line + '\n' for line in source.split('\n')]
+ builder = parse_python_source( strings, PYTHON_PARSER, "file_input" )
return space.wrap( STType(space, builder.stack[-1]) )
suite.unwrap_spec = [ObjSpace, str]
def expr( space, source ):
- builder = parse_python_source( source, PYTHON_PARSER, "eval_input" )
+ # make the annotator life easier (don't use str.splitlines())
+ strings = [line + '\n' for line in source.split('\n')]
+ builder = parse_python_source( strings, PYTHON_PARSER, "eval_input" )
return space.wrap( STType(space, builder.stack[-1]) )
expr.unwrap_spec = [ObjSpace, str]
-def ast2tuple(space, node, line_info=False):
+def ast2tuple(space, node, line_info=0):
"""Quick dummy implementation of parser.ast2tuple(tree) function"""
tuples = node.totuple(line_info)
return space.wrap(tuples)
-ast2tuple.unwrap_spec = [ObjSpace, STType, bool]
+ast2tuple.unwrap_spec = [ObjSpace, STType, int]
Modified: pypy/dist/pypy/tool/option.py
==============================================================================
--- pypy/dist/pypy/tool/option.py (original)
+++ pypy/dist/pypy/tool/option.py Sun Jul 3 15:36:27 2005
@@ -10,7 +10,7 @@
spaces = []
oldstyle = 0
uselibfile = 0
- useparsermodule = "recparser" # "cpython" / "recparser" / "parser"
+ useparsermodule = "cpython" # "cpython" / "recparser" / "parser"
parser = "cpython" # "cpython" / "pyparse"
compiler = "cpython" # "cpython"
# "pyparse" pypy parser, cpython compiler
@@ -33,7 +33,7 @@
options.append(make_option(
'--oldstyle', action="store_true",dest="oldstyle",
- help="enable oldstyle classes as default metaclass (std objspace only)"))
+ help="enable oldstyle classes as default metaclass (std objspace only)"))
options.append(make_option(
'--file', action="store_true",dest="uselibfile",
help="enable our custom file implementation"))
@@ -47,6 +47,10 @@
options.append(make_option(
'--pyparse', action="store_const", dest="compiler", const="pyparse",
help="enable the internal pypy parser with CPython compiler"))
+ options.append(make_option(
+ '--parsermodule', action="store",type="string", dest="useparsermodule",
+ help="select the parser module to use",
+ metavar="[cpython|recparser|parser]"))
return options
More information about the Pypy-commit
mailing list