[pypy-svn] r50303 - in pypy/branch/parser-playground/pypy: interpreter interpreter/pyparser module/dyngram module/recparser/test

cfbolz at codespeak.net cfbolz at codespeak.net
Fri Jan 4 00:18:41 CET 2008


Author: cfbolz
Date: Fri Jan  4 00:18:40 2008
New Revision: 50303

Removed:
   pypy/branch/parser-playground/pypy/module/dyngram/
   pypy/branch/parser-playground/pypy/module/recparser/test/test_dyn_grammarrules.py
Modified:
   pypy/branch/parser-playground/pypy/interpreter/baseobjspace.py
   pypy/branch/parser-playground/pypy/interpreter/pycompiler.py
   pypy/branch/parser-playground/pypy/interpreter/pyparser/pythonparse.py
Log:
kill support for dynamic grammar modifications


Modified: pypy/branch/parser-playground/pypy/interpreter/baseobjspace.py
==============================================================================
--- pypy/branch/parser-playground/pypy/interpreter/baseobjspace.py	(original)
+++ pypy/branch/parser-playground/pypy/interpreter/baseobjspace.py	Fri Jan  4 00:18:40 2008
@@ -433,11 +433,9 @@
         except AttributeError:
             if self.config.objspace.compiler == 'cpython':
                 compiler = CPythonCompiler(self)
-            elif self.config.objspace.compiler == 'ast':
-                compiler = PythonAstCompiler(self)
             else:
-                raise ValueError('unknown --compiler option value: %r' % (
-                    self.config.objspace.compiler,))
+                assert self.config.objspace.compiler == 'ast'
+                compiler = PythonAstCompiler(self)
             self.default_compiler = compiler
             return compiler
 

Modified: pypy/branch/parser-playground/pypy/interpreter/pycompiler.py
==============================================================================
--- pypy/branch/parser-playground/pypy/interpreter/pycompiler.py	(original)
+++ pypy/branch/parser-playground/pypy/interpreter/pycompiler.py	Fri Jan  4 00:18:40 2008
@@ -219,7 +219,6 @@
         PyCodeCompiler.__init__(self, space)
         self.grammar_version = override_version or space.config.objspace.pyversion
         self.parser = make_pyparser(self.grammar_version)
-        self.additional_rules = {}
         if self.grammar_version >= '2.5':
             self.futureFlags = future.futureFlags_2_5
         else:
@@ -244,9 +243,6 @@
         space = self.space
         try:
             builder = AstBuilder(self.parser, self.grammar_version, space=space)
-            for rulename, buildfunc in self.additional_rules.iteritems():
-                assert isinstance(buildfunc, Function)
-                builder.user_build_rules[rulename] = buildfunc
             flags |= getFutures(self.futureFlags, source)
             self.parser.parse_source(source, mode, builder, flags)
             ast_tree = builder.rule_stack[-1]
@@ -291,27 +287,3 @@
 #           raise OperationError( space.w_TypeError( space.wrap( "must have a callable" ) )
     space.default_compiler.w_compile_hook = w_callable
 
-def insert_grammar_rule(space, w_rule, w_buildfuncs):
-    """inserts new grammar rules to the default compiler"""
-    from pypy.interpreter import function
-    rule = space.str_w(w_rule)
-    #buildfuncs_w = w_buildfuncs.content
-    buildfuncs = {}
-    #for w_name, w_func in buildfuncs_w.iteritems():
-    #    buildfuncs[space.str_w(w_name)] = space.unwrap(w_func)
-    w_iter = space.iter(w_buildfuncs)
-    while 1:
-        try:
-            w_key = space.next(w_iter)
-            w_func = space.getitem(w_buildfuncs, w_key)
-            buildfuncs[space.str_w(w_key)] = space.interp_w(function.Function, w_func)
-        except OperationError, e:
-            if not e.match(space, space.w_StopIteration):
-                raise
-            break
-    space.default_compiler.additional_rules = buildfuncs
-    space.default_compiler.parser.insert_rule(rule)
-
-# XXX cyclic import
-#from pypy.interpreter.baseobjspace import ObjSpace
-#insert_grammar_rule.unwrap_spec = [ObjSpace, str, dict]

Modified: pypy/branch/parser-playground/pypy/interpreter/pyparser/pythonparse.py
==============================================================================
--- pypy/branch/parser-playground/pypy/interpreter/pyparser/pythonparse.py	(original)
+++ pypy/branch/parser-playground/pypy/interpreter/pyparser/pythonparse.py	Fri Jan  4 00:18:40 2008
@@ -131,33 +131,9 @@
             # return None
         return builder
 
-    def update_rules_references(self):
-        """update references to old rules"""
-        # brute force algorithm
-        for rule in self.all_rules:
-            for i in range(len(rule.args)):
-                arg = rule.args[i]
-                if arg.codename in self.root_rules:
-                    real_rule = self.root_rules[arg.codename]
-                    # This rule has been updated
-                    if real_rule is not rule.args[i]:
-                        rule.args[i] = real_rule
-
-
-    def insert_rule(self, ruledef):
-        """parses <ruledef> and inserts corresponding rules in the parser"""
-        # parse the ruledef(s)
-        source = GrammarSource(GRAMMAR_GRAMMAR, ruledef)
-        builder = ebnfparse.EBNFBuilder(GRAMMAR_GRAMMAR, dest_parser=self)
-        GRAMMAR_GRAMMAR.root_rules['grammar'].match(source, builder)
-        # remove proxy objects if any
-        builder.resolve_rules()
-        # update keywords
-        self.keywords.extend(builder.keywords)
-        # update old references in case an existing rule was modified
-        self.update_rules_references()
-        # recompute first sets
-        self.build_first_sets()
+# XXX kill?
+# GrammarProxy
+# resolve_rules
 
 
 def make_pyparser(version):



More information about the Pypy-commit mailing list