[pypy-svn] r11458 - in pypy/dist/pypy/module/recparser: . tool tools

ludal at codespeak.net ludal at codespeak.net
Tue Apr 26 12:44:08 CEST 2005


Author: ludal
Date: Tue Apr 26 12:44:08 2005
New Revision: 11458

Added:
   pypy/dist/pypy/module/recparser/pythonutil.py
      - copied, changed from r11454, pypy/dist/pypy/module/recparser/pythonutils.py
   pypy/dist/pypy/module/recparser/tool/
      - copied from r11450, pypy/dist/pypy/module/recparser/tools/
Removed:
   pypy/dist/pypy/module/recparser/pythonutils.py
   pypy/dist/pypy/module/recparser/tools/
Modified:
   pypy/dist/pypy/module/recparser/ebnfparse.py
   pypy/dist/pypy/module/recparser/pythonparse.py
Log:
 * rename more files to match coding style
 * fixup some imports (still incomplete)


Modified: pypy/dist/pypy/module/recparser/ebnfparse.py
==============================================================================
--- pypy/dist/pypy/module/recparser/ebnfparse.py	(original)
+++ pypy/dist/pypy/module/recparser/ebnfparse.py	Tue Apr 26 12:44:08 2005
@@ -1,7 +1,7 @@
 #!/usr/bin/env python
 from grammar import BaseGrammarBuilder, Alternative, Sequence, Token, \
      KleenStar, GrammarElement
-from lexer import GrammarSource
+from ebnflexer import GrammarSource
 
 import re
 py_name = re.compile(r"[a-zA-Z_][a-zA-Z0-9_]*", re.M)

Modified: pypy/dist/pypy/module/recparser/pythonparse.py
==============================================================================
--- pypy/dist/pypy/module/recparser/pythonparse.py	(original)
+++ pypy/dist/pypy/module/recparser/pythonparse.py	Tue Apr 26 12:44:08 2005
@@ -1,10 +1,9 @@
 #!/usr/bin/env python
 from grammar import BaseGrammarBuilder
-from lexer import PythonSource
-from ebnf import parse_grammar
-from pprint import pprint
+from pythonlexer import PythonSource
+from ebnfparse import parse_grammar
 import sys
-import python
+import pythonutil
 
 
 def parse_python_source( textsrc, gram, goal ):
@@ -45,6 +44,6 @@
         test_file = sys.argv[1]
     print "-"*20
     print
-    print "pyparse \n", python.pypy_parse(test_file)
-    print "parser  \n", python.python_parse(test_file)
+    print "pyparse \n", pythonutil.pypy_parse(test_file)
+    print "parser  \n", pythonutil.python_parse(test_file)
 

Copied: pypy/dist/pypy/module/recparser/pythonutil.py (from r11454, pypy/dist/pypy/module/recparser/pythonutils.py)
==============================================================================
--- pypy/dist/pypy/module/recparser/pythonutils.py	(original)
+++ pypy/dist/pypy/module/recparser/pythonutil.py	Tue Apr 26 12:44:08 2005
@@ -1,7 +1,7 @@
 __all__ = [ "parse_file_input", "parse_single_input", "parse_eval_input",
             "python_grammar", "PYTHON_GRAMMAR" ]
 
-from parse import parse_file_input, parse_single_input, parse_eval_input
+from pythonparse import parse_file_input, parse_single_input, parse_eval_input
 import os
 import sys
 

Deleted: /pypy/dist/pypy/module/recparser/pythonutils.py
==============================================================================
--- /pypy/dist/pypy/module/recparser/pythonutils.py	Tue Apr 26 12:44:08 2005
+++ (empty file)
@@ -1,60 +0,0 @@
-__all__ = [ "parse_file_input", "parse_single_input", "parse_eval_input",
-            "python_grammar", "PYTHON_GRAMMAR" ]
-
-from parse import parse_file_input, parse_single_input, parse_eval_input
-import os
-import sys
-
-_ver = ".".join([str(i) for i in sys.version_info[:2]])
-PYTHON_GRAMMAR = os.path.join( os.path.dirname(__file__), "Grammar" + _ver )
-
-def python_grammar():
-    """returns a """
-    from ebnf import parse_grammar
-    level = get_debug()
-    set_debug( 0 )
-    gram = parse_grammar( file(PYTHON_GRAMMAR) )
-    set_debug( level )
-    return gram
-
-def get_debug():
-    """Return debug level"""
-    import grammar
-    return grammar.DEBUG
-
-def set_debug( level ):
-    """sets debug mode to <level>"""
-    import grammar
-    grammar.DEBUG = level
-
-
-def python_parse(filename):
-    """parse <filename> using CPython's parser module and return nested tuples
-    """
-    pyf = file(filename)
-    import parser
-    tp2 = parser.suite(pyf.read())
-    return tp2.totuple()
-
-
-def _get_encoding(builder):
-    if hasattr(builder, '_source_encoding'):
-        return builder._source_encoding
-    return None
-
-def pypy_parse(filename):
-    """parse <filename> using PyPy's parser module and return nested tuples
-    """
-    pyf = file(filename)
-    builder = parse_file_input(pyf, python_grammar())
-    pyf.close()
-    if builder.stack:
-        # print builder.stack[-1]
-        root_node = builder.stack[-1]
-        nested_tuples = root_node.totuple()
-        source_encoding = _get_encoding(builder)
-        if source_encoding is None:
-            return nested_tuples
-        else:
-            return (323, nested_tuples, source_encoding)
-    return None # XXX raise an exception instead



More information about the Pypy-commit mailing list