erlanggen 0.1.0

Erlang generator.
Documentation

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