Add libuast iterators support#66
Conversation
Signed-off-by: Juanjo Alvarez <juanjo@sourced.tech>
Signed-off-by: Juanjo Alvarez <juanjo@sourced.tech>
Signed-off-by: Juanjo Alvarez <juanjo@sourced.tech>
abeaumont
left a comment
There was a problem hiding this comment.
I've created libuast 1.6.0 release.
I miss support for typed filtering functions. Not sure if those will be implemented in another PR.
| from bblfsh.aliases import * | ||
|
|
||
| class TreeOrder: | ||
| pre_order = 0 |
There was a problem hiding this comment.
There was a problem hiding this comment.
Yes, that's right for separate constants, but it's pretty common that enum-like constructs are done with classes like here, named tuples or the enum in Python 3.4 (but I didn't want to use it yet to break compatibility with older 3.x versions). Python 3.7 will introduce another one ("data classes"). It's not very important anyway, but I think the class with static members option keep things tidier than separate constants.
There was a problem hiding this comment.
Well, I was mostly referring to the written in all capital letters with underscores separating words. Examples include MAX_OVERFLOW and TOTAL. part ;)
There was a problem hiding this comment.
I was thinking you were speaking about the class 🤦♂️ yes, they better should be uppercase, I'll do it.
|
|
||
| # You can also iterate on several tree iteration orders: | ||
| it = bblfsh.iterator(uast, bblfsh.TreeOrder.pre_order) | ||
| for node in it: |
There was a problem hiding this comment.
I think something like this would be more idiomatic, not sure how more difficult this would be to implement:
for node in uast.iter(bblfsh.TreeOrder.PRE_ORDER):
There was a problem hiding this comment.
I checked a while ago (when I did something similar for the Scala client) and it was not trivial, so I would leave that for another PR (including also uast.filter).
| return NULL; | ||
| } | ||
|
|
||
| pyIt->iter = UastIteratorNew(ctx, node, (TreeOrder)order); |
There was a problem hiding this comment.
Check for null missing either here or in the caller code
Signed-off-by: Juanjo Alvarez <juanjo@sourced.tech>
|
Yes, my idea was to add the filtering functions in another PR after the Scala and Go clients have the iterators too. |
| } | ||
|
|
||
| pyIt->iter = UastIteratorNew(ctx, node, (TreeOrder)order); | ||
| if (!pyIt->iter) |
There was a problem hiding this comment.
I guess a Py_DECREF(pyIt); is also needed here
Signed-off-by: Juanjo Alvarez <juanjo@sourced.tech>
Signed-off-by: Juanjo Alvarez <juanjo@sourced.tech>
Fixes #62.
Note: CI will fail until the libuast functions' PR have been merged and tagged (I used 1.6.0 in this PR, but could update) because of the change of
inttosize_tin nodeiface**Sizeinterface functions.