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

Renamig by color? #2

Closed
Krastanov opened this issue May 24, 2024 · 2 comments
Closed

Renamig by color? #2

Krastanov opened this issue May 24, 2024 · 2 comments

Comments

@Krastanov
Copy link

This is a very exciting package!

What would be the proper way to take code like this (with potentially even more nested scopes)

a = 1
b = 2
for a in [b]
    println(a)
end
let b = a
    println(b)
end

and use JuliaSyntax/JuliaLowering to transform it into something like

a = 1
b = 2
for a_scope1 in [b]
    println(a_scope1)
end
let b_scope2 = a
    println(b_scope2)
end

This is a usability question, please feel free to close/redirect if this is the wrong venue to ask.

@Krastanov
Copy link
Author

This was just mentioned on slack. For now the functions too look up are parsestmt, annotate_scopes, and formatsrc

image

@c42f
Copy link
Owner

c42f commented May 24, 2024

Yea, I just posted that over there. Glad you find this work exciting :)

JuliaLowering adds a var_id to each identifier in the resolve_scopes pass - a unique ID for each identifier. Currently that ID goes with the var_info map which is attached to the ScopeResolutionContext where you can find out more information about the variable.

annotate_scopes and formatsrc are currently just hacky tools in test/demo.jl. As for renaming, the extremely new JuliaSyntaxFormatter package could do this if you create a custom format_token_str function and pass it to format().

Do feel free to play around with these things, just be aware that none of this is near "ready for production use" - JuliaLowering doesn't even support most Julia syntax yet!

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