bblfsh / sdk

Babelfish driver SDK
GNU General Public License v3.0
23 stars 27 forks source link

ChildrenOrder unexpected behaviour #421

Closed ncordon closed 5 years ago

ncordon commented 5 years ago

Using the python-client

from bblfsh import *

def set_position(node: dict, start_offset: int, start_line: int, start_col: int,
                 end_offset: int, end_line: int, end_col: int) -> None:
            node["@pos"] = {
                "@type": "uast:Positions",
                "start": {
                    "@type": "uast:Position",
                    "offset": start_offset,
                    "line": start_line,
                    "col": start_col
                },
                "end": {
                    "@type": "uast:Position",
                    "offset": end_offset,
                    "line": end_line,
                    "col": end_col
                }
            }

root = {"@type": "root"}
set_position(root, 0,1,1, 1,1,2)

son1 = {"@type": "son1"}
set_position(son1, 2,2,2, 3,2,3)

son1_1 = {"@type": "son1_1"}
set_position(son1_1, 10,10,1, 12,2,2)

son1_2 = {"@type": "son1_2"}
set_position(son1_2, 10,10,1, 12,2,2)

son1["children"] = [son1_1, son1_2]

son2 = {"@type": "son2"}
set_position(son2, 100,100,1,  101,100,2)

son2_1 = {"@type": "son2_1"}
set_position(son2_1, 5,5,1, 6,5,2)

son2_2 = {"@type": "son2_2"}
set_position(son2_2, 15,15,1, 16,15,2)

son2["children"] = [son2_1, son2_2]
root["children"] = [son1, son2]

it = iterator(root, TreeOrder.CHILDREN_ORDER)
next(it)
#[{'@type': 'son1', '@pos': {'@type': 'uast:Positions', 'start': {'@type': 'uast:Position', 'offset': 2, 'line': 2, 'col': 2}, 'end': {'@type': 'uast:Position', 'offset': 3, 'line': 2, 'col': 3}}, 'children': [{'@type': 'son1_1', '@pos': {'@type': 'uast:Positions', 'start': {'@type': 'uast:Position', 'offset': 10, 'line': 10, 'col': 1}, 'end': {'@type': 'uast:Position', 'offset': 12, 'line': 2, 'col': 2}}}, {'@type': 'son1_2', '@pos': {'@type': 'uast:Positions', 'start': {'@type': 'uast:Position', 'offset': 10, 'line': 10, 'col': 1}, 'end': {'@type': 'uast:Position', 'offset': 12, 'line': 2, 'col': 2}}}]}, {'@type': 'son2', '@pos': {'@type': 'uast:Positions', 'start': {'@type': 'uast:Position', 'offset': 100, 'line': 100, 'col': 1}, 'end': {'@type': 'uast:Position', 'offset': 101, 'line': 100, 'col': 2}}, 'children': [{'@type': 'son2_1', '@pos': {'@type': 'uast:Positions', 'start': {'@type': 'uast:Position', 'offset': 5, 'line': 5, 'col': 1}, 'end': {'@type': 'uast:Position', 'offset': 6, 'line': 5, 'col': 2}}}, {'@type': 'son2_2', '@pos': {'@type': 'uast:Positions', 'start': {'@type': 'uast:Position', 'offset': 15, 'line': 15, 'col': 1}, 'end': {'@type': 'uast:Position', 'offset': 16, 'line': 15, 'col': 2}}}]}]

We get an array [son1, son2] rather than son1 then son2 next time we call the iterator

creachadair commented 5 years ago

It looks like #422 didn't auto-close this (maybe that doesn't work in the title?)

ncordon commented 5 years ago

I forgot to reference the number of the issue in the title. Normally I put Closes #zzz but this time I forgot :see_no_evil: