Skip to main content

Crate oak_elm

Crate oak_elm 

Source
Expand description

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

Elm support for the Oak language framework.

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

ยง๐Ÿ“ฆ Core Components

  • Lexer: Tokenizes Elixir source code, handling sigils, atoms, and strings with full fidelity.
  • Parser: Implements the Elixir 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 ElixirLanguage configuration and integration with the Oak framework.

ยง๐Ÿš€ Usage Example

ยงBasic Parsing

use oak_elixir::{ElixirParser, SourceText, ElixirLanguage};

fn parse_elixir_code(code: &str) {
    let source = SourceText::new(code);
    let config = ElixirLanguage::new();
    let parser = ElixirParser::new(&config);
    let result = parser.parse(&source);

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

ยงIncremental Parsing

use oak_elixir::{ElixirParser, SourceText, ElixirLanguage};

fn incremental_update(old_code: &str, new_code: &str) {
    let config = ElixirLanguage::new();
    let mut parser = ElixirParser::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::ElmRoot;
pub use crate::builder::ElmBuilder;
pub use crate::language::ElmLanguage;
pub use crate::lexer::ElmLexer;
pub use crate::lexer::token_type::ElmTokenType;
pub use crate::parser::element_type::ElmElementType;

Modulesยง

ast
AST module for Elm.
builder
Builder module for Elm.
language
Language configuration for Elm.
lexer
Lexer for Elm.
lsp
LSP support for Elm.
parser
Parser for Elm.