[pypy-svn] r14203 - pypy/dist/pypy/interpreter/pyparser

adim at codespeak.net adim at codespeak.net
Mon Jul 4 13:02:46 CEST 2005


Author: adim
Date: Mon Jul  4 13:02:45 2005
New Revision: 14203

Modified:
   pypy/dist/pypy/interpreter/pyparser/pythonutil.py
Log:
cleanup the pythonutil's functions to use the new wrapper class

Modified: pypy/dist/pypy/interpreter/pyparser/pythonutil.py
==============================================================================
--- pypy/dist/pypy/interpreter/pyparser/pythonutil.py	(original)
+++ pypy/dist/pypy/interpreter/pyparser/pythonutil.py	Mon Jul  4 13:02:45 2005
@@ -1,7 +1,6 @@
 __all__ = ["python_parse", "pypy_parse", "ast_single_input", "ast_file_input",
-           "ast_eval_input" ]
+           "ast_eval_input"]
 
-from compiler.transformer import Transformer
 import parser
 import symbol
 
@@ -63,24 +62,11 @@
     nested tuples
     """
     builder = TupleBuilder(PYTHON_PARSER.rules, lineno=False)
-    # make the annotator life easier (don't use str.splitlines())
-    strings = [line + '\n' for line in source.split('\n')]
-    # finalize the last line 
-    if not source.endswith('\n'):
-        last_line = strings[-1]
-        strings[-1] = last_line[:-1]
-    else:
-        strings.pop()
     target_rule = TARGET_DICT[mode]
-    pythonparse.parse_python_source(strings, PYTHON_PARSER,
-                                    target_rule, builder)
-##     if builder.error_occured():
-##         line, lineno, offset, filename = builder.get_error()
-##         raise SyntaxError(line, lineno, offset, filename)
-##     # stack_element is a tuplerbuilder.StackElement's instance
+    PYTHON_PARSER.parse_source(source, target_rule, builder)
     stack_element = builder.stack[-1]
-    # convert the stack element into nested tuples
-    # XXX : the annotator can't follow this call
+    # convert the stack element into nested tuples (caution, the annotator
+    # can't follow this call)
     nested_tuples = stack_element.as_tuple(lineno)
     if builder.source_encoding is not None:
         return (symbol.encoding_decl, nested_tuples, builder.source_encoding)
@@ -88,14 +74,23 @@
         return nested_tuples
 
 ## convenience functions for computing AST objects using recparser
-def ast_from_input(input, mode):
+def ast_from_input(input, mode, transformer):
+    """converts a source input into an AST
+
+     - input : the source to be converted
+     - mode : 'exec', 'eval' or 'single'
+     - transformer : the transfomer instance to use to convert
+                     the nested tuples into the AST
+     XXX: transformer could be instantiated here but we don't want
+          here to explicitly import compiler or stablecompiler or
+          etc. This is to be fixed in a clean way
+    """
     tuples = pypy_parse(input, mode, True)
-    transformer = Transformer()
     ast = transformer.compile_node(tuples)
     return ast
 
 ## TARGET FOR ANNOTATORS #############################################
-def annotateme(strings):
+def annotateme(source):
     """This function has no other role than testing the parser's annotation
 
     annotateme() is basically the same code that pypy_parse(), but with the
@@ -108,7 +103,7 @@
 
     """
     builder = TupleBuilder(PYTHON_PARSER.rules, lineno=False)
-    pythonparse.parse_python_source(strings, PYTHON_PARSER, 'file_input', builder)
+    PYTHON_PARSER.parse_source(source, 'file_input', builder)
     nested_tuples = builder.stack[-1]
     if builder.source_encoding is not None:
         return (symbol.encoding_decl, nested_tuples, builder.source_encoding)



More information about the Pypy-commit mailing list