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

Peter Bulychev peter.bulychev at
Sun Mar 16 10:00:46 CET 2008


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.

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

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: <>

More information about the Python-list mailing list