bblfsh / sdk

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

Question: XPath to get function names? #365

Closed vmarkovtsev closed 5 years ago

vmarkovtsev commented 5 years ago

I give up: I cannot compose the XPath to extract function names in Semantic mode.

I get all the functions by //uast:FunctionGroup, however, the Name node is inside the Nodes array and I don't know how to address it. //uast:FunctionGroup/*[1] returns the position and //uast:FunctionGroup/*[2] is already empty. //uast:FunctionGroup/descendant::uast:Identifier returns all identifiers inside a function. I tried with child but failed. So the question is, how do I dig inside the immediate array of Node-s inside functions?

vmarkovtsev commented 5 years ago

I finally extracted them with //uast:Function/../../Name but damn that was hard. Is there a better solution?

creachadair commented 5 years ago

I suspect #366 and #367 saturate this issue, but assigning for triage in case I missed something.

dennwc commented 5 years ago

@vmarkovtsev For functions, this query should work: //uast:FunctionGroup/Nodes/uast:Alias/Name or //uast:FunctionGroup/*/uast:Alias/Name

vmarkovtsev commented 5 years ago

This works, thanks. Is the first uast:Alias node guaranteed to be the function name?

dennwc commented 5 years ago

Yes, an Alias will always be there. It's our way to bind a specific function declaration to a name. Anonymous functions won't have it, for example - they are just Function without a FunctionGroup.