oak-fsharp

Crates.iooak-fsharp
lib.rsoak-fsharp
version0.0.1
created_at2025-10-21 00:13:04.227851+00
updated_at2026-01-23 04:28:12.458169+00
descriptionHigh-performance incremental F# (F Sharp) parser for the oak ecosystem with flexible configuration, supporting functional programming and .NET ecosystem integration.
homepagehttps://github.com/ygg-lang/oaks
repositoryhttps://github.com/ygg-lang/oaks
max_upload_size
id1892930
size62,948
publisher (github:ygg-lang:publisher)

documentation

https://docs.rs/oak-fsharp

README

Oak F# Parser

Crates.io Documentation

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

🎯 Overview

Oak F# is a robust parser for F#, designed to handle complete F# 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 F# Syntax: Supports all F# 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_core::{Parser, SourceText, parser::session::ParseSession};
use oak_fsharp::{FSharpParser, FSharpLanguage};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut session = ParseSession::<FSharpLanguage>::default();
    let parser = FSharpParser::new();
    let source = SourceText::new(r#"
let helloWorld = 
    printfn "Hello, F#!"

helloWorld
    "#);
    
    let result = parser.parse(&source, &[], &mut session);
    println!("Parsed F# successfully.");
    Ok(())
}

📋 Parsing Examples

Function Parsing

use oak_core::{Parser, SourceText, parser::session::ParseSession};
use oak_fsharp::{FSharpParser, FSharpLanguage};

let mut session = ParseSession::<FSharpLanguage>::default();
let parser = FSharpParser::new();
let source = SourceText::new(r#"
let add x y = x + y
let result = add 5 10
"#);

let result = parser.parse(&source, &[], &mut session);
println!("Function parsed successfully.");

Type Parsing

use oak_core::{Parser, SourceText, parser::session::ParseSession};
use oak_fsharp::{FSharpParser, FSharpLanguage};

let mut session = ParseSession::<FSharpLanguage>::default();
let parser = FSharpParser::new();
let source = SourceText::new(r#"
type Person = {
    Name: string
    Age: int
}
"#);

let result = parser.parse(&source, &[], &mut session);
println!("Type parsed successfully.");

🔧 Advanced Features

Token-Level Parsing

use oak_core::{Parser, SourceText, parser::session::ParseSession};
use oak_fsharp::{FSharpParser, FSharpLanguage};

let mut session = ParseSession::<FSharpLanguage>::default();
let parser = FSharpParser::new();
let source = SourceText::new("let x = 42");
let result = parser.parse(&source, &[], &mut session);
println!("Token parsing completed.");

Error Handling

use oak_core::{Parser, SourceText, parser::session::ParseSession};
use oak_fsharp::{FSharpParser, FSharpLanguage};

let mut session = ParseSession::<FSharpLanguage>::default();
let parser = FSharpParser::new();
let source = SourceText::new(r#"
let broken = 
    if x > 0 then
# Missing else
"#);

let result = parser.parse(&source, &[], &mut session);
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:

  • FSharpProgram: Root container for F# programs
  • Module: F# module definitions
  • Function: F# functions and methods
  • Expression: Various expression types including operators
  • Type: F# type system constructs
  • Statement: Various statement types

📊 Performance

  • Streaming: Parse large F# 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 F# integrates seamlessly with:

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

📚 Examples

Check out the examples directory for comprehensive examples:

  • Complete F# program parsing
  • Function and module 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