oak-erlang

Crates.iooak-erlang
lib.rsoak-erlang
version0.0.1
created_at2025-10-20 16:36:17.502162+00
updated_at2026-01-23 04:27:55.377826+00
descriptionErlang language parser with support for concurrent programming and OTP features.
homepagehttps://github.com/ygg-lang/oaks
repositoryhttps://github.com/ygg-lang/oaks
max_upload_size
id1892307
size88,002
publisher (github:ygg-lang:publisher)

documentation

https://docs.rs/oak-erlang

README

Oak Erlang Parser

Crates.io Documentation

High-performance incremental Erlang parser for the oak ecosystem with flexible configuration, optimized for static analysis and code generation.

🎯 Overview

Oak Erlang is a robust parser for Erlang, designed to handle complete Erlang syntax including modern features. Built on the solid foundation of oak-core, it provides both high-level convenience and detailed AST generation for static analysis and code generation.

✨ Features

  • Complete Erlang Syntax: Supports all Erlang features including modern specifications
  • Full AST Generation: Generates comprehensive Abstract Syntax Trees
  • Lexer Support: Built-in tokenization with proper span information
  • Error Recovery: Graceful handling of syntax errors with detailed diagnostics

🚀 Quick Start

Basic example:

use oak_erlang::{Parser, ErlangLanguage, SourceText};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let parser = Parser::new();
    let source = SourceText::new(r#"
-module(hello).
-export([greet/0]).

greet() ->
    io:format("Hello, Erlang!~n").
    "#);
    
    let result = parser.parse(&source);
    println!("Parsed Erlang successfully.");
    Ok(())
}

📋 Parsing Examples

Function Parsing

use oak_erlang::{Parser, ErlangLanguage, SourceText};

let parser = Parser::new();
let source = SourceText::new(r#"
-module(math).
-export([add/2, factorial/1]).

add(A, B) ->
    A + B.

factorial(0) ->
    1;
factorial(N) when N > 0 ->
    N * factorial(N - 1).
"#);

let result = parser.parse(&source);
println!("Function parsed successfully.");

Module Parsing

use oak_erlang::{Parser, ErlangLanguage, SourceText};

let parser = Parser::new();
let source = SourceText::new(r#"
-module(calculator).
-export([new/0, add/2, subtract/2, get_result/1]).

new() ->
    0.

add(Acc, Value) ->
    Acc + Value.

subtract(Acc, Value) ->
    Acc - Value.

get_result(Acc) ->
    Acc.
"#);

let result = parser.parse(&source);
println!("Module parsed successfully.");

🔧 Advanced Features

Token-Level Parsing

use oak_erlang::{Parser, ErlangLanguage, SourceText};

let parser = Parser::new();
let source = SourceText::new("X = 42.");
let result = parser.parse(&source);
println!("Token parsing completed.");

Error Handling

use oak_erlang::{Parser, ErlangLanguage, SourceText};

let parser = Parser::new();
let source = SourceText::new(r#"
-module(broken).
-export([broken_function/0]).

broken_function() ->
    io:format("Hello"
    % Missing closing parenthesis
"#);

let result = parser.parse(&source);
if let Some(errors) = result.result.err() {
    println!("Parse errors found: {:?}", errors);
} else {
    println!("Parsed successfully.");
}

🏗️ AST Structure

The parser generates a comprehensive AST with the following main structures:

  • ErlangModule: Root container for Erlang modules
  • Function: Erlang functions and clauses
  • Pattern: Pattern matching constructs
  • Expression: Various expression types including operators
  • Statement: Various statement types including control flow
  • Type: Erlang type system constructs

📊 Performance

  • Streaming: Parse large Erlang files without loading entirely into memory
  • Incremental: Re-parse only changed sections
  • Memory Efficient: Smart AST node allocation
  • Fast Recovery: Quick error recovery for better IDE integration

🔗 Integration

Oak Erlang integrates seamlessly with:

  • Static Analysis: Code quality and security analysis
  • Code Generation: Generating code from Erlang AST
  • IDE Support: Language server protocol compatibility
  • Refactoring: Automated code refactoring
  • Documentation: Generating documentation from Erlang code

📚 Examples

Check out the examples directory for comprehensive examples:

  • Complete Erlang module parsing
  • Function and pattern analysis
  • Code transformation
  • Integration with development workflows

🤝 Contributing

Contributions are welcome!

Please feel free to submit pull requests at the project repository or open issues.

Commit count: 80

cargo fmt