[issue33416] Add endline and endcolumn to every AST node

Raymond Hettinger report at bugs.python.org
Mon Jan 14 00:33:17 EST 2019


Raymond Hettinger <raymond.hettinger at gmail.com> added the comment:

This idea seems reasonable.  Most of the AST nodes have a span and it would be nice to know what that is.  I'm sure we will find use cases though I doubt that many compiler syntax errors would benefit (since a syntax error means that we don't have a completely matched grammar rule).

BTW, does this information have to be added by the parser or could there be am AST module function that deduces the end locations from the start location of next sibling node or from the parent node?  If so, it may still be possible get the benefit without slowing down or complicating the parser logic.

Do we know what other languages do (carry the full span info in the AST or deduce the span after the fact)?  I don't know what the best practices are in this regard.

One other thought:  We should be careful not to impair existing AST capabilities that support code rewriting and movement (i.e. refactoring tools).  The copy_location() and fix_missing_locations() functions would need to be updated as well.

----------
nosy: +rhettinger

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue33416>
_______________________________________


More information about the Python-bugs-list mailing list