Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Access syntax tree? #174

Open
tadamcz opened this issue Mar 30, 2023 · 3 comments
Open

Access syntax tree? #174

tadamcz opened this issue Mar 30, 2023 · 3 comments

Comments

@tadamcz
Copy link
Contributor

tadamcz commented Mar 30, 2023

Great library, thanks so much for your work! I really appreciate e.g. how you've translated exceptions in a way that lets you easily access the line and column number of a Starlark error 👌.

Does Starlark provide a way to access the syntax tree of an expression? Is this something we could add to python-starlark-go? (If Starlark exposes the tree I'm happy to take a shot at it, but my go skills are very poor).

So, for example, in the Starlark code:

a = 1
b = 2
c = a * 2
result = b + c 

we could access the fact that result depends on b and c via the operator +, and in turn c depends on a (and a literal) via *.

@jordemort
Copy link
Contributor

I think this might be possible to some degree, but we aren't using any part of the API that would give us something like this at the moment. I will keep this in mind as I am looking at the starlark-go API docs to implement some other things.

@tadamcz
Copy link
Contributor Author

tadamcz commented Mar 30, 2023

Ok, thanks! To clarify, do you know if there is an API for this in starlark-go? (Obviously they have the machinery for this internally, my question is if there's a reasonably "public-facing" API e.g. with docs).

@jordemort
Copy link
Contributor

@tadamcz Yeah I think the 'syntax` package is what you'd be looking for: https://pkg.go.dev/[email protected]/syntax

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

No branches or pull requests

2 participants