[pypy-svn] r10103 - in pypy/dist/pypy: interpreter module/parser module/sys2
hpk at codespeak.net
hpk at codespeak.net
Wed Mar 23 01:41:51 CET 2005
Author: hpk
Date: Wed Mar 23 01:41:51 2005
New Revision: 10103
Modified:
pypy/dist/pypy/interpreter/baseobjspace.py
pypy/dist/pypy/module/parser/__init__.py
pypy/dist/pypy/module/parser/pyparser.py
pypy/dist/pypy/module/sys2/state.py
Log:
- make jonathan's parser replace the cpython parser module
- passes regrtests (but they don't really test that much)
- various fixes, especially regarding exception handling
parser/pyparser.py is slightly messy (but it works and
is fast)
(Jonathan and holger)
Modified: pypy/dist/pypy/interpreter/baseobjspace.py
==============================================================================
--- pypy/dist/pypy/interpreter/baseobjspace.py (original)
+++ pypy/dist/pypy/interpreter/baseobjspace.py Wed Mar 23 01:41:51 2005
@@ -55,6 +55,17 @@
def __repr__(self):
return self.__class__.__name__
+ def setbuiltinmodule(self, name, importname=None):
+ """ load a lazy pypy/module and put it into sys.modules"""
+ if importname is None:
+ importname = name
+ Module = __import__("pypy.module.%s" % importname,
+ None, None, ["Module"]).Module
+ w_name = self.wrap(name)
+ w_mod = self.wrap(Module(self, w_name))
+ w_modules = self.sys.get('modules')
+ self.setitem(w_modules, w_name, w_mod)
+
def make_builtins(self):
"NOT_RPYTHON: only for initializing the space."
@@ -71,6 +82,8 @@
self.setitem(w_modules, w_name, w_builtin)
self.setitem(self.builtin.w_dict, self.wrap('__builtins__'), w_builtin)
+ self.setbuiltinmodule('parser')
+
# initialize with "bootstrap types" from objspace (e.g. w_None)
for name, value in self.__dict__.items():
if name.startswith('w_') and not name.endswith('Type'):
Modified: pypy/dist/pypy/module/parser/__init__.py
==============================================================================
--- pypy/dist/pypy/module/parser/__init__.py (original)
+++ pypy/dist/pypy/module/parser/__init__.py Wed Mar 23 01:41:51 2005
@@ -14,26 +14,23 @@
'__doc__' : '(space.wrap("parser module"))',
'suite' : 'pyparser.suite',
+ 'expr' : 'pyparser.expr',
'STType' : 'pyparser.STType',
'ASTType' : 'pyparser.STType',
- 'eval_input' : 'pyparser.eval_input',
- 'file_input' : 'pyparser.file_input',
- 'compileast' : 'pyparser.compileast',
- 'st2tuple' : 'pyparser.st2tuple',
- 'st2list' : 'pyparser.st2list',
- 'issuite' : 'pyparser.issuite',
- 'ast2tuple' : 'pyparser.ast2tuple',
- 'tuple2st' : 'pyparser.tuple2st',
- 'isexpr' : 'pyparser.isexpr',
- 'expr' : 'pyparser.expr',
- 'ast2list' : 'pyparser.ast2list',
- 'sequence2ast' : 'pyparser.sequence2ast',
- 'tuple2ast' : 'pyparser.tuple2ast',
'sequence2st' : 'pyparser.sequence2st',
- '_pickler' : 'pyparser._pickler',
- 'compilest' : 'pyparser.compilest',
+ #'eval_input' : 'pyparser.eval_input',
+ #'file_input' : 'pyparser.file_input',
+ #'compileast' : 'pyparser.compileast',
+ #'st2tuple' : 'pyparser.st2tuple',
+ #'st2list' : 'pyparser.st2list',
+ #'issuite' : 'pyparser.issuite',
+ #'ast2tuple' : 'pyparser.ast2tuple',
+ #'tuple2st' : 'pyparser.tuple2st',
+ #'isexpr' : 'pyparser.isexpr',
+ #'ast2list' : 'pyparser.ast2list',
+ #'sequence2ast' : 'pyparser.sequence2ast',
+ #'tuple2ast' : 'pyparser.tuple2ast',
+ #'_pickler' : 'pyparser._pickler',
+ #'compilest' : 'pyparser.compilest',
}
- appleveldefs = {
-
- }
Modified: pypy/dist/pypy/module/parser/pyparser.py
==============================================================================
--- pypy/dist/pypy/module/parser/pyparser.py (original)
+++ pypy/dist/pypy/module/parser/pyparser.py Wed Mar 23 01:41:51 2005
@@ -9,7 +9,7 @@
# ______________________________________________________________________
# Module imports
-from pypy.interpreter.baseobjspace import ObjSpace, Wrappable
+from pypy.interpreter.baseobjspace import ObjSpace, Wrappable, W_Root
from pypy.interpreter.gateway import interp2app, applevel
from pypy.interpreter.error import OperationError
from pypy.interpreter.typedef import TypeDef
@@ -27,10 +27,10 @@
pygrammar = DFAParser.addAccelerators(PyGrammar.grammarObj)
# ______________________________________________________________________
-# ParserError exception
+# InternalParserError exception
-class ParserError (Exception):
- """Class ParserError
+class InternalParserError (Exception):
+ """Class InternalParserError
Exception class for parser errors (I assume).
"""
@@ -58,6 +58,11 @@
"""
return _st2tuple(self.tup, line_info)
+ def descr_totuple(self, line_info = 0):
+ return self.space.wrap(self.totuple(line_info))
+
+ descr_totuple.unwrap_spec=['self', int]
+
# ____________________________________________________________
def tolist (self, line_info = 0):
"""STType.tolist()
@@ -119,6 +124,7 @@
STType.typedef = TypeDef("parser.st",
compile = interp2app(STType.descr_compile),
+ totuple = interp2app(STType.descr_totuple),
)
# ______________________________________________________________________
@@ -144,12 +150,12 @@
next_state = states[arc_state]
break
if next_state == None:
- raise ParserError("symbol %d should be in %s" %
+ raise InternalParserError("symbol %d should be in %s" %
(ilabel, str(arcs)))
else:
crnt_state = next_state
if crnt_state[2] != 1:
- raise ParserError("incomplete sequence of children (ended with %s)" %
+ raise InternalParserError("incomplete sequence of children (ended with %s)" %
str(child[0]))
# ______________________________________________________________________
@@ -184,19 +190,23 @@
node = ((symbol_no, seqobj[1], 0), [])
line_no = 0
else:
- raise ParserError("terminal nodes must have 2 or 3 entries")
+ raise InternalParserError("terminal nodes must have 2 or 3 entries")
return node, line_no
# ______________________________________________________________________
-def sequence2st (seqObj):
+def sequence2st (space, w_seqObj):
"""sequence2st()
Do some basic checking on the input sequence and wrap in a STType.
"""
- tup = _seq2st(seqObj)[0]
- if tup[0][0] not in (file_input, eval_input):
- raise ParserError("parse tree does not use a valid start symbol")
- return STType(space, tup)
+ try:
+ seqObj = space.unwrap(w_seqObj)
+ tup = _seq2st(seqObj)[0]
+ if tup[0][0] not in (file_input, eval_input):
+ raise InternalParserError("parse tree does not use a valid start symbol")
+ return STType(space, tup)
+ except InternalParserError, e:
+ reraise(space, e)
sequence2ast = sequence2st
tuple2ast = sequence2st
@@ -321,8 +331,16 @@
return STType(space, DFAParser.parsetok(tokenizer, pygrammar, start))
except SyntaxError:
raise OperationError(space.w_SyntaxError)
- except ParserError:
- raise OperationError(space.w_RuntimeError)
+ except InternalParserError, e:
+ reraise(space, e)
+
+def reraise(space, e):
+ w_ParserError = space.sys.getmodule('parser').get('ParserError')
+ if e.args:
+ w_msg = space.wrap(e.args[0])
+ else:
+ w_msg = space.wrap("unknown")
+ raise OperationError(w_ParserError, w_msg)
# ______________________________________________________________________
Modified: pypy/dist/pypy/module/sys2/state.py
==============================================================================
--- pypy/dist/pypy/module/sys2/state.py (original)
+++ pypy/dist/pypy/module/sys2/state.py Wed Mar 23 01:41:51 2005
@@ -27,7 +27,8 @@
for fn in ['posix', 'nt', 'os2', 'mac', 'ce', 'riscos',
'math', '_codecs', 'array', 'select',
'_random', '_sre', 'time', '_socket', 'errno',
- 'parser']:
+ #'parser'
+ ]:
if fn not in builtin_modules:
try:
builtin_modules[fn] = hack_cpython_module(fn)
More information about the Pypy-commit
mailing list