manishshettym / codescholar

codescholar: growing programs graphs idiomatically for API usage examples
10 stars 0 forks source link

Add an ancestors field to the AST object instead of a separate datastructure #8

Closed manishshettym closed 1 year ago

manishshettym commented 2 years ago

Instead of adding the ancestors to the walk, might be worth considering adding to the AST object in one of two ways:

  1. parent field on every node that points to its parent node (and then can be navigated to root in a linked list fashion)
  2. ancestors field on every node that has an ordered list of ancestors (which can then be navigated by reading through the list)

Whichever one is more efficient is a design decision you're probably better equipped to make. A NodeTransformer from the ast library would be able to achieve this.

_Originally posted by @somaniarushi in https://github.com/manishshettym/codescholar/pull/5#discussion_r982875161_