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

adim at codespeak.net adim at codespeak.net
Sun Jul 3 18:39:12 CEST 2005


Author: adim
Date: Sun Jul  3 18:39:11 2005
New Revision: 14164

Modified:
   pypy/dist/pypy/interpreter/pyparser/pythonutil.py
Log:
added a lineno optional argument to be able to choose if linenos should
be included in the nested tuples (needed for the compiler)



Modified: pypy/dist/pypy/interpreter/pyparser/pythonutil.py
==============================================================================
--- pypy/dist/pypy/interpreter/pyparser/pythonutil.py	(original)
+++ pypy/dist/pypy/interpreter/pyparser/pythonutil.py	Sun Jul  3 18:39:11 2005
@@ -16,15 +16,15 @@
     }
 
 ## convenience functions around CPython's parser functions
-def python_parsefile(filename):
+def python_parsefile(filename, lineno=False):
     """parse <filename> using CPython's parser module and return nested tuples
     """
     pyf = file(filename)
     source = pyf.read()
     pyf.close()
-    return python_parse(source)
+    return python_parse(source, 'exec', lineno)
 
-def python_parse(source, mode='exec'):
+def python_parse(source, mode='exec', lineno=False):
     """parse python source using CPython's parser module and return
     nested tuples
     """
@@ -35,7 +35,7 @@
     return tp.totuple()
 
 ## convenience functions around recparser functions
-def pypy_parsefile(filename):
+def pypy_parsefile(filename, lineno=False):
     """parse <filename> using PyPy's parser module and return
     a tuple of three elements :
      - The encoding declaration symbol or None if there were no encoding
@@ -49,9 +49,9 @@
     pyf = file(filename)
     source = pyf.read()
     pyf.close()
-    return pypy_parse(source)
+    return pypy_parse(source, 'exec', lineno)
 
-def pypy_parse(source, mode='exec'):
+def pypy_parse(source, mode='exec', lineno=False):
     """parse <source> using PyPy's parser module and return
     a tuple of three elements :
      - The encoding declaration symbol or None if there were no encoding
@@ -74,21 +74,24 @@
     target_rule = TARGET_DICT[mode]
     pythonparse.parse_python_source(strings, PYTHON_PARSER,
                                     target_rule, builder)
-    # stack_element is a tuplerbuilder.StackElement's instance
+##     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
     stack_element = builder.stack[-1]
     # convert the stack element into nested tuples
     # XXX : the annotator can't follow this call
-    nested_tuples = stack_element.as_tuple()
+    nested_tuples = stack_element.as_tuple(lineno)
     if builder.source_encoding is not None:
         return (symbol.encoding_decl, nested_tuples, builder.source_encoding)
     else:
         return nested_tuples
 
-## convenience functions for computing AST objects based on recparser
+## convenience functions for computing AST objects using recparser
 def ast_from_input(input, mode):
-    tuples = pypy_parse(input, mode)
+    tuples = pypy_parse(input, mode, True)
     transformer = Transformer()
-    ast = transformer.transform(tuples)
+    ast = transformer.compile_node(tuples)
     return ast
 
 ## TARGET FOR ANNOTATORS #############################################



More information about the Pypy-commit mailing list