I have a quote block in Julia containing functions, modules, and etc. Assuming that quote block is in Main module and Main module does not have these symbols with same names. I want to separate the symbols based on their scoping and create a symbol table that stores their names which reflect their scopes along with their locations in AST where they occur. Specifically, I want to handle cases where symbols with the same name have different scoping.
exp = Meta.parse("quote
x = 2
function foo(x)
y = 2 * x
z = x + y
end
function bar(a)
y = a + x
end
end")
In this quote block, there are multiple symbols named x
and y
, … each with its own scoping. I want to parse this code and generate a symbol table that reflects this scoping, something like:
Symbol: x
ScopeName: x@_1, Location: exp.args[1].args[2].args[1] (or) (1,2,1)
ScopeName: x@_2, Location: exp.args[1].args[4].args[1].args[2] (or) (1,4,1,2)
ScopeName: x@_2, Location: exp.args[1].args[4].args[2].args[3].args[2].args[3] (or) (1,4,2,3,2,3)
ScopeName: x@_2, Location: exp.args[1].args[4].args[2].args[5].args[2].args[2] (or) (1,4,2,5,2,2)
ScopeName: x@_3, Location: exp.args[1].args[6].args[2].args[3].args[2].args[3] (or) (1,6,2,3,2,3)
Symbol: y
ScopeName: y@_1, Location: exp.args[1].args[4].args[2].args[3].args[1] (or) (1,4,2,3)
ScopeName: y@_1, Location: exp.args[1].args[4].args[2].args[5].args[2].args[3] (or) (1,4,2,5,2,3)
ScopeName: y@_2, Location: exp.args[1].args[6].args[2].args[3].args[1] (or) (1,6,2,3,1)
.
.
.
Could someone provide guidance on how to achieve this in Julia? Additionally, are there any existing packages or libraries that could simplify this task?