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

Question: how to get the node's token and internal type #100

Closed
vmarkovtsev opened this issue Oct 24, 2018 · 10 comments
Closed

Question: how to get the node's token and internal type #100

vmarkovtsev opened this issue Oct 24, 2018 · 10 comments
Assignees
Labels

Comments

@vmarkovtsev
Copy link
Contributor

vmarkovtsev commented Oct 24, 2018

Before:

uast.Node.Token
uast.Node.InternalType
uast.Node.StartPosition
uast.Node.EndPosition

After (Annotated mode)?..

@dennwc
Copy link
Member

dennwc commented Oct 24, 2018

token := uast.TokenOf(node)

typ = uast.TypeOf(node)

pos := uast.PositionsOf(node)
start := pos.Start()
end := pos.End()

See bblfsh/sdk#318 regarding the token reliability.

@vmarkovtsev
Copy link
Contributor Author

👍

@dennwc
Copy link
Member

dennwc commented Oct 30, 2018

Reopening until documentation is updated

@dennwc dennwc reopened this Oct 30, 2018
@bzz
Copy link
Contributor

bzz commented Nov 20, 2018

Where in docs do you @dennwc think this and #99 does belong to? The only I can think of right now is https://docs.sourced.tech/babelfish/using-babelfish/grpc-usage-example.

Rationale - it seems too advanced for https://docs.sourced.tech/babelfish/using-babelfish/clients but https://docs.sourced.tech/babelfish/using-babelfish/advanced-usage does not have any code.

Please, let me know what would be the best place and I'll be happy to add it there.

@juanjux
Copy link
Contributor

juanjux commented Feb 12, 2019

Outside of the go client godoc, probably the right place would be the clients documentation page already has a Go example it won't hurt to add this there too and I don't think getting the token or position is very advanced. I'll open a PR.

@vmarkovtsev
Copy link
Contributor Author

vmarkovtsev commented Feb 14, 2019

@dennwc @bzz I've got

cannot use element (type nodes.Node) as type nodes.Object in argument to "gopkg.in/src-d/hercules.v7/vendor/gopkg.in/bblfsh/sdk.v2/uast".TokenOf: need type assertion

So to get the token you need to

uast.TokenOf(node.(nodes.Object))

The same for PositionsOf

@juanjux
Copy link
Contributor

juanjux commented Feb 14, 2019

Yes. That's how I needed to document it. It's certainly not beautiful.

@dennwc
Copy link
Member

dennwc commented Feb 14, 2019

Let's change it to node.Node instead of nodes.Object and document that it returns an empty string if it's not an object.

@dennwc dennwc reopened this Feb 14, 2019
@dennwc dennwc assigned dennwc and unassigned juanjux Feb 14, 2019
@creachadair
Copy link
Contributor

creachadair commented Mar 6, 2019

Does bblfsh/sdk#363 resolve this issue?

@vmarkovtsev
Copy link
Contributor Author

It seems so. I will use the new release in Hercules and report any left problems separately, ok?

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

No branches or pull requests

5 participants