# Generating Elm Code

**URL:** <https://discourse.elm-lang.org/t/generating-elm-code/4203>\
**Category:** Show and Tell\
**Created:** [August 21, 2019, 3:42pm UTC](https://discourse.elm-lang.org/t/generating-elm-code/4203 "2019-08-21T15:42:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![rupert](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/rupert/32/1775_2.png) [@rupert](https://discourse.elm-lang.org/u/rupert)\
**Post date:** [August 21, 2019, 3:42pm UTC](https://discourse.elm-lang.org/t/generating-elm-code/4203/1 "2019-08-21T15:42:00Z")

</div>

Hi,

I started using the excellent `stil4m/elm-syntax` but for various reasons found it a little awkward to use; having to wrap things in nodes, having lots of records to pass args in, and having so many modules to import. So I have tried to turn it into something easier to use from the perspective of doing codegen of Elm. It is a bit of an act of vandalism since @stil4m took care to define lots of records as type aliases, which helps to document function parameters - I tried to strip those out and just pass as function args, making it shorter to write.

[https://package.elm-lang.org/packages/the-sett/elm-syntax-dsl/latest/](https://package.elm-lang.org/packages/the-sett/elm-syntax-dsl/latest/)

Still a WIP but took a cut to publish a 1.0.0. I’ve been making great progress with it the last couple of days mapping a simple data modelling language onto Elm types and records with encoders and decoders. More on that to come…

---

<div class="post-metadata">

**Author:** ![gampleman](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/gampleman/32/43_2.png) [@gampleman](https://discourse.elm-lang.org/u/gampleman)\
**Post date:** [August 21, 2019, 3:48pm UTC](https://discourse.elm-lang.org/t/generating-elm-code/4203/2 "2019-08-21T15:48:58Z")

</div>

I’ve built something similar before, you can see it here: [https://github.com/gampleman/elm-mapbox/tree/master/style-generator/src/MyElm](https://github.com/gampleman/elm-mapbox/tree/master/style-generator/src/MyElm)

Haven’t extracted it as a library, but its used in a real project.

---

<div class="post-metadata">

**Author:** ![rupert](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/rupert/32/1775_2.png) [@rupert](https://discourse.elm-lang.org/u/rupert)\
**Post date:** [August 21, 2019, 4:00pm UTC](https://discourse.elm-lang.org/t/generating-elm-code/4203/3 "2019-08-21T16:00:43Z")

</div>

Another idea I have - as `elm-syntax` comes with a parser, could write a code generator that takes a parsed Elm file and outputs Elm code to generate that Elm code. A code-generator-generator if you like. The idea would be that when writing a code generator you can start by writing an example snippet of Elm code, and then turn that into a generator for that code and use that as a starting template to begin parameterising it into a generator for similar code.

---

<div class="post-metadata">

**Author:** ![thought2](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/thought2/32/2478_2.png) [@thought2](https://discourse.elm-lang.org/u/thought2)\
**Post date:** [August 26, 2019, 1:36pm UTC](https://discourse.elm-lang.org/t/generating-elm-code/4203/4 "2019-08-26T13:36:41Z")

</div>

Interesting package, both elm-syntax and the DSL for it. With @rupert’s comment macros are almost on its way… 🙂

---

<div class="post-metadata">

**Author:** ![jqx](https://avatars.discourse-cdn.com/v4/letter/j/8baadc/32.png) [@jqx](https://discourse.elm-lang.org/u/jqx)\
**Post date:** [September 2, 2019, 2:06pm UTC](https://discourse.elm-lang.org/t/generating-elm-code/4203/5 "2019-09-02T14:06:07Z")

</div>

Beginning to start a lot like macros, haha.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex035/uploads/elm_lang/original/1X/50a05e53677a2c3b47776d7abd0f113eb50193a1.png) [@system](https://discourse.elm-lang.org/u/system)\
**Post date:** [September 12, 2019, 2:11pm UTC](https://discourse.elm-lang.org/t/generating-elm-code/4203/6 "2019-09-12T14:11:21Z")

</div>

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.
