# Code file generators examples

**URL:** <https://discourse.julialang.org/t/code-file-generators-examples/71415>\
**Category:** General Usage\
**Tags:** metaprogramming\
**Created:** [November 13, 2021, 12:55am UTC](https://discourse.julialang.org/t/code-file-generators-examples/71415 "2021-11-13T00:55:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![andrey2185](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/andrey2185/32/9889_2.png) [@andrey2185](https://discourse.julialang.org/u/andrey2185)\
**Post date:** [November 13, 2021, 12:55am UTC](https://discourse.julialang.org/t/code-file-generators-examples/71415/1 "2021-11-13T00:55:17Z")

</div>

Hello, has anyone generated code files?  
Please give examples of packages.  
At first I tried on the basis of strings, then I began to create structures-models of code blocks, which is why I decided that it was better to use expressions right away. Now I can’t just add comments to the generated code and I don’t like the style of the generated code:

```julia

julia> (: (foo (a) = a + 2)) |> Base.remove_linenums! |> println

foo (a) = begin
        a + 2
    end
 
# instead of `foo (a) = a + 2`

julia> Meta.parse ("""
           \"\"\"
               documentation
           \"\"\"
           function test_fun ()
               return nothing
           end
       """) |> Base.remove_linenums! |> String |> println

#= none: 1 =# Core.@doc "documentation \n" function test_fun()
        return nothing
    end

```

---

<div class="post-metadata">

**Author:** ![melonedo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/melonedo/32/15503_2.png) [@melonedo](https://discourse.julialang.org/u/melonedo)\
**Post date:** [November 14, 2021, 5:46am UTC](https://discourse.julialang.org/t/code-file-generators-examples/71415/2 "2021-11-14T05:46:19Z")

</div>

Julia’s `Expr` does not preserve the syntactic structure of code, you may be interested in [CSTParsers.jl](https://github.com/julia-vscode/CSTParser.jl) which is more faithful to source code.
