Or, to put things another way, when you reach the end of a subtree, you don't automatically know how many levels (or indents, if you think of levels as indents) to return to. The leaf of a subtree won't have a next link, so you need some state to know where to go next.
On Thursday, March 31, 2022 at 8:01:34 PM UTC-4 Edward K. Ream wrote: > On Thursday, March 31, 2022 at 3:52:55 PM UTC-5 Edward K. Ream wrote: > > > After looking at leoAst.py with fresh eyes, the following Aha's emerged: > > There is a third Aha: parent/child (or any other threading links) are > almost useless! No amount of links will suffice to drive a tree traversal. > > It's not enough to know in what order to visit tree nodes. One must also > remember the (coroutine) state as well! Recursive descent, generators and > the new iterative scheme all remember the state. Links do not. End of > story. > > My long-time fixation on tree links confused and mislead me for decades. > I'm glad to put this delusion to rest. Now I see why ast.walk is so useful: > often it *doesn't matter* how one discovers nodes of a particular type. > > For example, Fstringify.visit uses none of the links that were so > carefully (and uselessly) created. It only uses the already existing links > in an ast.BinOp node whose operator (node.op) is '%'. Otoh, we can't > *just* use ast.walk in the Fstringify class. Fstringify.make_fstring > *does* use the list of tokens associated with the BinOp node. > > Edward > -- You received this message because you are subscribed to the Google Groups "leo-editor" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/leo-editor/bbc31997-74ca-49df-a6a9-1d8acbc10a9bn%40googlegroups.com.
