Skip to content

henry-luo/lambda

Repository files navigation

Lambda Script

A general-purpose, cross-platform, pure functional scripting language and document processing engine.

Built from scratch in C/C++ with a custom and light-weight runtime (only 6 MB), Tree-sitter parsing, MIR-based JIT compilation.

Note: Lambda Script is still evolving — syntax/semantics and implementation details may change. A stable subset of the literal data model is separately formalised and released as Mark Notation.

Overview

Lambda is designed for two things at once:

  1. a small, expressive functional language for transforming data and documents, and
  2. an end-to-end document pipeline (parse → normalize → validate/transform → layout → render/view).

Internally, Lambda treats documents as structured data. Different input formats (Markdown, Wiki, HTML/XML, JSON/YAML/TOML/CSV, LaTeX, PDF, …) can be parsed into a unified Lambda/Mark node tree, transformed with Lambda scripts, validated with schemas, and then rendered via the Radiant HTML/CSS/SVG layout engine.

Features

1. Lambda script (pure functional runtime)

  • Pure-functional core with immutable data structures (lists, maps, elements) and first-class functions.
  • Interactive REPL for exploration and debugging.
  • Fast parsing with a Tree-sitter based frontend.
  • Optional MIR JIT execution path for performance-sensitive workloads.
  • Reference counting + pooled allocators for predictable memory behavior.

2. Markup input parsing & formatting

  • Multi-format parsing: JSON, XML, HTML, Markdown, Wiki, YAML/TOML/INI, CSV, LaTeX, PDF, and more.
  • One universal representation: parse disparate syntaxes into a common Lambda/Mark node tree.
  • Conversion pipeline: convert between formats using lambda convert (auto-detect input formats when possible).
  • Document-centric tooling: designed to treat “documents as data”, not just as text.

3. Type system & schema validation

  • Rich type system with type inference and explicit type annotations, similar to that of TypeScript.
  • Schema-based validation for structured data and document trees (including element schemas for HTML/XML-like structures).
  • Format-aware validation helpers that unwrap/normalize documents before validation.
  • Detailed error reporting with paths and expected/actual diagnostics.

4. Radiant HTML/CSS/SVG layout, rendering & viewer

  • Browser-compatible layout engine supporting block/inline flow, flexbox, grid, and tables.
  • CSS cascade + computed style resolution, with pixel-ratio aware sizing.
  • Render targets: SVG / PDF / PNG / JPEG output via lambda render.
  • Unified interactive viewer via lambda view:
    • HTML / XML (treated as HTML) with CSS styling
    • Markdown / Wiki (rendered with styling)
    • LaTeX (.tex) via conversion to HTML
    • PDF viewing
    • Lambda script results (.ls) evaluated and rendered

Demo

Run the demo

  1. Download the Lambda binary for your platform from the GitHub Releases page, and unzip it.
  2. Run:
    ./lambda.exe view

Quick Start

Prerequisites

Lambda is built from source. The dependency scripts also install Node.js/npm (used by Tree-sitter generation via npx).

macOS (native build):

./setup-mac-deps.sh

Linux (Ubuntu/Debian):

./setup-linux-deps.sh

Windows (native build under MSYS2):

./setup-windows-deps.sh

Building

Recommended (Premake-based Make targets):

make build      # Incremental build (default)
make debug      # Debug build (AddressSanitizer enabled)
make release    # Optimized release build

More build help:

make help

Running

The build produces a runnable executable at the repo root: lambda.exe.

Show help:

./lambda.exe --help

Interactive REPL:

./lambda.exe

Run a script:

./lambda.exe script.ls

CLI Commands

./lambda.exe <script.ls>                       # functional script
./lambda.exe run <script.ls>                   # procedural script
./lambda.exe validate <file> [-s <schema.ls>]
./lambda.exe convert <input> [-f <from>] -t <to> -o <output>
./lambda.exe layout <file.html|file.tex|file.ls> [options]
./lambda.exe render <input.html|input.tex|input.ls> -o <output.svg|pdf|png|jpg> [options]
./lambda.exe view [file.pdf|file.html|file.md|file.wiki|file.xml|file.tex|file.ls]

Tip: ./lambda.exe <command> --help prints detailed options and examples.

Installation

From Source

  1. Clone the repository:

    git clone https://github.com/henry-luo/lambda.git
    cd lambda
  2. Install dependencies:

    # macOS
    ./setup-mac-deps.sh
    
    # Linux
    ./setup-linux-deps.sh
    
    # Windows
    ./setup-windows-deps.sh
  3. Build:

    make build

Examples

Document Processing

// Parse JSON and convert to Markdown
let data = input("data.json", 'json')
format(data, 'markdown')

// Process CSV data
let csv = input("data.csv", 'csv')
for (row in csv) {
  if (row.age > 25) row
}

Interactive Analysis

λ> let data = input("sample.json", 'json')
λ> data.users.length
42
λ> for (u in data.users) { if (u.active) u.name }
["Alice", "Bob", "Charlie"]

Testing

make build-test
make test

Build System

Lambda uses a Premake5-based build system generated from build_lambda_config.json.

make build             # Incremental build (recommended)
make release           # Optimized release build
make clean             # Clean build artifacts
make generate-grammar  # Regenerate Tree-sitter parser (auto-runs when grammar changes)

Documentation

  • Language reference: doc/Lambda_Reference.md
  • Validator guide: doc/Lambda_Validator_Guide.md
  • Radiant layout design: doc/Radiant_Layout_Design.md
  • Mark doc schema (for lightweight markup, like Markdown, Wiki, RST, etc.): doc/Doc_Schema.md

Platform Support

Platform Status Notes
macOS ✅ Full Native development platform
Linux ✅ Full Ubuntu 20.04+ tested
Windows ✅ Full Native build via MSYS2;

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

  • MIR Project: JIT compilation infrastructure
  • Tree-sitter: Incremental parsing framework
  • ThorVG: SVG vector graphics library
  • GoogleTest: C++ unit testing framework

Support

About

A modern, general-purpose, pure functional programming language (WIP)

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •