Skip to main content

Crate oak_erlang

Crate oak_erlang 

Source
Expand description

ยง๐Ÿ› ๏ธ oak-erlang Developer Guide

Erlang support for the Oak language framework.

Welcome to the internal implementation of the Erlang parser. This module provides the core logic for tokenizing and parsing Erlang source code into a high-fidelity syntax tree.

ยง๐Ÿ“ฆ Core Components

  • Lexer: Tokenizes Erlang source code, handling atoms, variables, and macros with full fidelity.
  • Parser: Implements the Erlang grammar, producing a Green Tree that represents the concrete syntax.
  • AST: Provides a type-safe Red Tree facade for easy traversal and analysis.
  • Language: Defines the ErlangLanguage configuration and integration with the Oak framework.

ยง๐Ÿš€ Usage Example

ยงBasic Parsing

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

fn parse_erlang_code(code: &str) {
    let source = SourceText::new(code);
    let config = ErlangLanguage::new();
    let parser = ErlangParser::new(&config);
    let result = parser.parse(&source);

    if result.is_success() {
        let root = result.root();
        println!("AST Root: {:?}", root);
    }
}

ยงIncremental Parsing

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

fn incremental_update(old_code: &str, new_code: &str) {
    let config = ErlangLanguage::new();
    let mut parser = ErlangParser::new(&config);
    
    // Initial parse
    let initial_source = SourceText::new(old_code);
    let _ = parser.parse(&initial_source);
    
    // Incremental update
    let updated_source = SourceText::new(new_code);
    let result = parser.parse(&updated_source);
    
    if result.is_success() {
        println!("Incremental parse completed successfully.");
    }
}

ยง๐Ÿ” Diagnostics

The parser provides detailed diagnostics for syntax errors, including error ranges and helpful messages.

let result = parser.parse(&source);
for diagnostic in result.diagnostics() {
    println!("Error at {:?}: {}", diagnostic.range(), diagnostic.message());
}

Re-exportsยง

pub use crate::ast::ErlangRoot;
pub use crate::builder::ErlangBuilder;
pub use crate::language::ErlangLanguage;
pub use crate::lexer::ErlangLexer;
pub use crate::lexer::token_type::ErlangTokenType;
pub use crate::parser::element_type::ErlangElementType;

Modulesยง

ast
Erlang AST module.
builder
Erlang builder module.
language
Erlang language configuration.
lexer
Erlang lexer module.
lsp
Erlang LSP module.
parser
Erlang parser module.