Generating Elm Code


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.

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…


I’ve built something similar before, you can see it here:

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

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.


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

Beginning to start a lot like macros, haha.

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