# Automated semantic analysis and modification of Julia code

**URL:** https://discourse.julialang.org/t/automated-semantic-analysis-and-modification-of-julia-code/57267
**Category:** Tooling
**Created:** [March 16, 2021, 7:11am UTC](https://discourse.julialang.org/t/automated-semantic-analysis-and-modification-of-julia-code/57267 "2021-03-16T07:11:39Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![sloede](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sloede/32/44787_2.png) [@sloede](https://discourse.julialang.org/u/sloede)
#### Post date: [March 16, 2021, 7:11am UTC](https://discourse.julialang.org/t/automated-semantic-analysis-and-modification-of-julia-code/57267/1 "2021-03-16T07:11:39Z")

</div>

Is there a package or tool available that allows to automate the semantic analysis _and_ modification of Julia code, e.g., in a file or in an entire module? I am thinking about use cases like where we have lots of code with both variables and functions prefixed with `foo_` and I want to change this prefix to `bar_` but only for variables. Or, e.g, I would like to find out how many local variables are defined that start with `int_` etc.

Is there something available that already fits the bill (or to a large degree, at least) and if not, what would be a good way to do this? I realize that this is probably too complex a question to be answered in a Discourse thread, but I’d appreciate any pointers to similar packages or some keywords I can be looking for to figure it out myself.

---

<div class="post-metadata">

### Author: ![marius311](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marius311/32/3953_2.png) [@marius311](https://discourse.julialang.org/u/marius311)
#### Post date: [March 16, 2021, 7:31am UTC](https://discourse.julialang.org/t/automated-semantic-analysis-and-modification-of-julia-code/57267/2 "2021-03-16T07:31:34Z")

</div>

The Julia VSCode plugin has something like this in the “Rename Symbol” command, which does a semantic rename. Its not always perfect but usually surprises me how good it is, e.g. it gets this totally right regardless what you rename:

```julia
function foo()
    foo = 2
    foo
end

foo()

```

and works across multiple included files in a module.

---

<div class="post-metadata">

### Author: ![sloede](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sloede/32/44787_2.png) [@sloede](https://discourse.julialang.org/u/sloede)
#### Post date: [March 16, 2021, 5:08pm UTC](https://discourse.julialang.org/t/automated-semantic-analysis-and-modification-of-julia-code/57267/3 "2021-03-16T17:08:49Z")

</div>

Thanks for this hint. Would you happen to know how the plugin does this internally and whether it relies on a dedicated package or whether it’s deeply integrated in the plugin code somewhere?

---

<div class="post-metadata">

### Author: ![ericphanson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ericphanson/32/215186_2.png) [@ericphanson](https://discourse.julialang.org/u/ericphanson)
#### Post date: [March 16, 2021, 5:15pm UTC](https://discourse.julialang.org/t/automated-semantic-analysis-and-modification-of-julia-code/57267/4 "2021-03-16T17:15:55Z")

</div>

the VSCode plugin uses [CSTParser.jl](https://github.com/julia-vscode/CSTParser.jl), which is also used by [Vimes.jl](https://github.com/MikeInnes/Vimes.jl) that does some mutation like you mention an interest in (although I don’t know if that package is maintained, unfortunately). [JuliaFormatter.jl](https://github.com/domluna/JuliaFormatter.jl) also uses CSTParser.jl, by the way.

---

<div class="post-metadata">

### Author: ![sloede](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sloede/32/44787_2.png) [@sloede](https://discourse.julialang.org/u/sloede)
#### Post date: [March 24, 2021, 11:16am UTC](https://discourse.julialang.org/t/automated-semantic-analysis-and-modification-of-julia-code/57267/5 "2021-03-24T11:16:53Z")

</div>

Sorry for the late answer, but thanks a lot for the information on `CSTParser.jl`, I will look into it!
