Skip to main content

Crate oak_ada

Crate oak_ada 

Source
Expand description

ยง๐Ÿ› ๏ธ Ada Parser Developer Guide

This guide is designed to help you quickly get started with developing and integrating oak-ada.

ยง๐Ÿšฆ Quick Start

ยงBasic Parsing Example

The following is a standard workflow for parsing an Ada package specification:

use oak_ada::{AdaParser, SourceText, AdaLanguage};

fn main() {
    // 1. Prepare source code
    let code = r#"
        package Hello_World is
           procedure Say_Hello;
        end Hello_World;
    "#;
    let source = SourceText::new(code);

    // 2. Initialize parser
    let config = AdaLanguage::new();
    let parser = AdaParser::new(&config);

    // 3. Execute parsing
    let result = parser.parse(&source);

    // 4. Handle results
    if result.is_success() {
        println!("Parsing successful! AST node count: {}", result.node_count());
    } else {
        eprintln!("Errors found during parsing.");
    }
}

ยง๐Ÿ” Core API Usage

ยง1. Syntax Tree Traversal

After a successful parse, you can use the built-in visitor pattern or manually traverse the Green/Red Tree to extract Ada constructs like package declarations, procedure signatures, or tasking statements.

ยง2. Incremental Parsing

No need to re-parse the entire file when small changes occur:

// Assuming you have an old parse result 'old_result' and new source text 'new_source'
let new_result = parser.reparse(&new_source, &old_result);

ยง3. Diagnostics

oak-ada provides rich error contexts specifically tailored for Ada developers:

for diag in result.diagnostics() {
    println!("[{}:{}] {}", diag.line, diag.column, diag.message);
}

ยง๐Ÿ—๏ธ Architecture Overview

  • Lexer: Tokenizes Ada source text into a stream of tokens, handling keywords (case-insensitive), operators, and numeric literals.
  • Parser: Syntax analyzer based on the Pratt parsing algorithm to handle Adaโ€™s structural declarations and expression precedence.
  • AST: A strongly-typed syntax abstraction layer designed for building high-performance Ada analysis tools and IDEs.

ยง๐Ÿ”— Advanced Resources

  • Full Examples: Check the examples/ folder in the project root.
  • API Documentation: Run cargo doc --open for detailed type definitions.
  • Test Cases: See tests/ for handling of various Ada edge cases and language versions. Ada support for the Oak language framework.

Re-exportsยง

pub use crate::ast::AdaRoot;
pub use crate::language::AdaLanguage;
pub use crate::lexer::AdaLexer;
pub use crate::parser::AdaParser;
pub use crate::lsp::highlighter::AdaHighlighter;
pub use crate::lsp::AdaLanguageService;
pub use crate::lsp::formatter::AdaFormatter;
pub use crate::mcp::serve_ada_mcp;
pub use lexer::token_type::AdaTokenType;
pub use parser::element_type::AdaElementType;

Modulesยง

ast
AST module.
builder
Builder module.
language
Type definitions module. Language configuration module.
lexer
Lexer module.
lsp
LSP module.
mcp
MCP module.
parser
Parser module.

Traitsยง

ElementType
Element type definitions for nodes in the parsed tree.
TokenType
Token type definitions for tokens in the parsing system.