Skip to content
This repository has been archived by the owner on Mar 8, 2020. It is now read-only.

Question: XPath to get function names? #365

Closed
vmarkovtsev opened this issue Feb 17, 2019 · 5 comments
Closed

Question: XPath to get function names? #365

vmarkovtsev opened this issue Feb 17, 2019 · 5 comments

Comments

@vmarkovtsev
Copy link

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
Copy link
Author

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

@creachadair
Copy link
Contributor

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

@dennwc
Copy link
Member

dennwc commented Feb 19, 2019

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

@vmarkovtsev
Copy link
Author

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

@dennwc
Copy link
Member

dennwc commented Feb 19, 2019

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants