-
Notifications
You must be signed in to change notification settings - Fork 27
getting an attribute doesn't work #359
Comments
Works for me with this query:
|
It's not clear for me why your query looks like that. |
|
Please help me understand what property is. I don't see such thing in specification. The closest thing I see there is "attribute" but it has different syntax to query (starts with If by property you mean just another level of nodes in the tree when I print results of Sorry for maybe stupid question but I'm not that good in xpath and all my previous experience doesn't match with what I see with bblfsh at all and I'm really struggling. As an example when I follow spec and use js on this page: Get a node:
Get a text node:
Get an attribute:
There is no "property" in any of these queries. |
@smacker Juanjo is referring to a UAST schema for Alias and Identifier, both have a |
Yes, I was speaking of properties in the JSON sense. No expert in XPath either. |
@dennwc could you please explain what is <uast:FunctionGroup>
<uast:Alias>
<Name> -- I'll call this one Name1 below to avoid misunderstanding
<uast:Identifier>
<Name> -- special kind of node that can be converted to a string
</uast:Identifier>
</Name>
</uast:Alias>
</uast:FunctionGroup> I also tried to explore the tree a little bit more using this code: fmt.Println("Name node:")
name, err := tools.Filter(res, "//uast:FunctionGroup/*/uast:Alias/Name")
if err != nil {
panic(err)
}
if !name.Next() {
panic("shouldn't be empty")
}
nodeName := name.Node()
fmt.Println(uast.TypeOf(nodeName), nodeName)
fmt.Println("uast:Identifier node:")
name, err = tools.Filter(res, "//uast:FunctionGroup/*/uast:Alias/Name/uast:Identifier")
if err != nil {
panic(err)
}
if !name.Next() {
panic("shouldn't be empty")
}
identNode := name.Node()
fmt.Println(uast.TypeOf(identNode), identNode)
fmt.Println("same?", nodeName.SameAs(identNode)) As the result I see:
So |
It makes sense. Once you write a
So, to walk over to the last |
I'm not sure of the exact mapping to XML on the SDK (@dennwc can you help us on this?) but I know it makes sense related to how the UAST is organized. If you think of it as as C structs. The |
There may be a more general question here as to whether aliases should be "collapsed" during traversal (there are good arguments on either side). |
I would say it's more important at least to document how AST maps to XML. |
This is unexpected for me as well. |
According to documentation getting an attribute works like this:
and it produces
(you can run this on this page in console)
As in the new api everything is a node, I expect to get a node that I can convert to a string using
.(nodes.String)
(in go-client, not sure about other because only go client is available right now).I use this code:
The text was updated successfully, but these errors were encountered: