erlanggen

Crates.ioerlanggen
lib.rserlanggen
version0.1.0
created_at2025-07-27 05:33:34.629817+00
updated_at2025-07-27 05:33:34.629817+00
descriptionErlang generator.
homepage
repositoryhttps://github.com/aleph-lang/erlanggen
max_upload_size
id1769734
size31,352
Roques Steve (roquess)

documentation

README

Erlang Code Generator for aleph-syntax-tree

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

Overview

The core function generate(ast: AlephTree) -> String takes an AlephTree and returns equivalent Erlang code.

This generator supports:

  • Basic expressions: Add, Sub, Not, Let, If, etc.
  • Data structures: Tuple, Array, Bytes
  • Control flow: Match, While, Return, Stmts
  • Function definitions: LetRec, App
  • COBOL-like constructs: ProcedureDivision, Perform, Accept, Display, etc.

Output is properly indented and aims to be readable and idiomatic Erlang.

Installation

Add the dependency to your Cargo.toml:

[dependencies]
aleph-syntax-tree = "0.1"

Usage

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

fn main() {
    let ast: AlephTree = /* build or parse your AST */;
    let code = generate(ast);
    println!("{}", code);
}

Example

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

Produces Erlang code:

X = 42,
X

Related

Commit count: 0

cargo fmt