gleamgen 0.1.0

Gleam generator.
Documentation
  • Coverage
  • 0%
    0 out of 2 items documented0 out of 1 items with examples
  • Size
  • Source code size: 16.51 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.42 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 38s Average build duration of successful builds.
  • all releases: 37s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • aleph-lang/gleamgen
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • roquess

Gleam Code Generator for aleph-syntax-tree

This crate provides a code generator that transforms an abstract syntax tree (AST) from the aleph-syntax-tree crate into Gleam source code.

Features

  • Converts AlephTree nodes into Gleam source code
  • Supports common language constructs:
    • Literals: Int, Float, Bool, String, Bytes
    • Data structures: Array, Tuple
    • Control flow: If, Let, LetRec, Match
    • Boolean and arithmetic operations: And, Or, Add, Sub, Mul, Div, Eq, LE, In
    • Pattern matching with case expressions
    • Comments, assertions, simple imports
  • Skips unsupported nodes like Class, While, Put, Remove, or complex constructs

Usage

Add to your project

Ensure you depend on the aleph-syntax-tree crate.

Example

use aleph_syntax_tree::syntax::AlephTree as at;
use your_crate::generate;

fn main() {
    let ast = at::Let {
        var: "answer".into(),
        is_pointer: false,
        value: Box::new(at::Int { value: "42".into() }),
        expr: Box::new(at::Return {
            value: Box::new(at::Var { var: "answer".into(), is_pointer: false }),
        }),
    };

    let gleam_code = generate(ast);
    println!("{}", gleam_code);
}

Output

let answer = 42
answer

Function Signature

pub fn generate(ast: AlephTree) -> String

Returns the generated Gleam code as a String.

Limitations

  • Does not support class structures, Put, Remove, or While loops
  • Let expressions are line-based, no expression wrapping
  • Match and function definitions are translated using simple case and pub fn formats
  • Pattern matching does not include type destructuring