Generate Gleam code with Gleam
Find a file
2024-03-20 22:40:27 +01:00
src/gen_gleam format 2024-02-07 16:02:10 +01:00
test aplit off gen_gleam repository 2024-01-29 17:13:21 +01:00
.gitignore aplit off gen_gleam repository 2024-01-29 17:13:21 +01:00
gleam.toml release 0.3.2 upgrade dependencies 2024-03-20 22:40:27 +01:00
manifest.toml release 0.3.2 upgrade dependencies 2024-03-20 22:40:27 +01:00
README.md aplit off gen_gleam repository 2024-01-29 17:13:21 +01:00

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 a VariableStatement("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 in List(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