bblfsh / python-driver

GNU General Public License v3.0
10 stars 16 forks source link

The same line + column for multiple call expressions #174

Closed cuonglm closed 5 years ago

cuonglm commented 5 years ago

With a test.py file:

res.offset(offset).limit(limit).all()

Parsing with bblfsh server:

import bblfsh

client = bblfsh.BblfshClient("0.0.0.0:9432")
uast = client.parse("./test.py").uast
it = bblfsh.iterator(uast, bblfsh.TreeOrder.PRE_ORDER)
for node in it:
    if node.internal_type == 'Call':
        print(node.start_position)

Output:

line: 1
col: 1

line: 1
col: 1

line: 1
col: 1
juanjux commented 5 years ago

Sorry for the late reply, I was on holidays. Will take a look at this soon, thanks for reporting!

juanjux commented 5 years ago

Ok, here is the problem:

Some Python nodes doesn't add the correct positions, Call being one of them. We fix them with a light tokenizing pass by finding the token positions and updating the node ones, but in this case the node doesn't have a token since it's a "Containing" or virtual one, so you need to get the position of the Call token which you can get with:

nodes = bblfsh.filter(uast, "//*[@roleCall and @roleIdentifier]")

Or, if you want to only show non empty tokens:

nodes = bblfsh.filter(uast, "//*[@roleCall and @roleIdentifier and string-length(@token) > 0]")