question about module compiler: line numbers and positions of substring, which are covered by AST nodes

Peter Bulychev peter.bulychev at gmail.com
Sun Mar 16 05:00:46 EDT 2008


Hello.

I use standard module Compiler to build ASTs of Python code.

Given AST subtree I want to restore coordinates of substring in the input,
which is covered by the subtree.

Example:
Suppose, the input is 'a+(b+c)'. It is parsed to the tree ADD(a, ADD(b,c))
by module Compiler.
I want to have a function, which given ADD(b,c) will return the coordinates
of the substring '(b+c)'.

Module Compiler provides only line numbers  for each node. But even this
information is incorrect: only the first line of multi-lined statements is
stored.

What is the easiest way of doing what I want?
As I understand, module Compiler is automatically generated by some parser
generator. Maybe I can modify it?

-- 
Best regards,
   Peter Bulychev.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080316/bf560faa/attachment.html>


More information about the Python-list mailing list