Generate Gleam
Gleam code generator in Gleam.
See tests for examples of usage.
Maturity
Not generally usable.
Yet, used this code (with a few usages of direct(String)
) to generate Gleam Code to solve the Dec 19, 2023 puzzles of Advent of Code, some 3000 resp. 4000 lines of Gleam for the 523 rules in my input.
TODO
-
extract some
OuterStatement
for imports, type defs and function defs, so we can generate a whole file, and eventually, multiple files - define types/functions for imports, so usage can, in principle, be type-checked
-
add functionality for
use
- add functionality for operators
- add functionality for @external
- add functionality for private types and functions
- support for base types: string, tuple, …
-
support for proper, nested pattern matching, e.g.
VariantPattern("Ok", [VariablePattern("x")])
even better if we get aVariableStatement("x")
returned (prolly in hierarchy), that we can use in the subsequent statements. - add helpers prelude types and functions
- add helpers stdlib types and functions
- add functionality for …
Done
- Construct a basic AST, supporting type definitions, case statements and function definitions
- generate Gleam code from that AST
Types
- Nil
- Int
- Variant type
-
Parametrized type e.g.
a
inList(a)
- Function type
Pattern matching
- literal constants (bit blunt)
- let array
- let tuple
Statements
- instances of nil, int, variants, tuples
- case
- function
Prelude
- Boolean
- Result
StdLib
- Dict