oak-go

Crates.iooak-go
lib.rsoak-go
version0.0.1
created_at2025-10-22 05:52:07.897995+00
updated_at2026-01-23 04:28:21.906178+00
descriptionHigh-performance incremental Go parser for the oak ecosystem with flexible configuration, supporting concurrent programming and cloud-native development.
homepagehttps://github.com/ygg-lang/oaks
repositoryhttps://github.com/ygg-lang/oaks
max_upload_size
id1895036
size127,184
publisher (github:ygg-lang:publisher)

documentation

https://docs.rs/oak-go

README

Oak Go Parser

Crates.io Documentation

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

🎯 Overview

Oak Go is a robust parser for Go, designed to handle complete Go 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 Go Syntax: Supports all Go 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_go::{Parser, GoLanguage, SourceText};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let parser = Parser::new();
    let source = SourceText::new(r#"
package main

import "fmt"

func main() {
    fmt.Println("Hello, Go!")
}
    "#);
    
    let result = parser.parse(&source);
    println!("Parsed Go successfully.");
    Ok(())
}

📋 Parsing Examples

Function Parsing

use oak_go::{Parser, GoLanguage, SourceText};

let parser = Parser::new();
let source = SourceText::new(r#"
func add(a, b int) int {
    return a + b
}
"#);

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

Struct Parsing

use oak_go::{Parser, GoLanguage, SourceText};

let parser = Parser::new();
let source = SourceText::new(r#"
type Person struct {
    Name string
    Age  int
}

func (p *Person) Greet() {
    fmt.Printf("Hello, I'm %s and I'm %d years old\n", p.Name, p.Age)
}
"#);

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

🔧 Advanced Features

Token-Level Parsing

use oak_go::{Parser, GoLanguage, SourceText};

let parser = Parser::new();
let source = SourceText::new("x := 42");
let result = parser.parse(&source);
// Token information is available in the parse result

Error Handling

use oak_go::{Parser, GoLanguage, SourceText};

let parser = Parser::new();
let source = SourceText::new(r#"
func main() {
    fmt.Println("Hello, Go!")
// Missing closing brace
"#);

let result = parser.parse(&source);
if let Err(e) = result.result {
    println!("Parse error: {:?}", e);
}

🏗️ AST Structure

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

  • Package: Root container for Go programs
  • Function: Go functions and methods
  • Struct: Go struct definitions
  • Interface: Go interface definitions
  • Statement: Various statement types
  • Expression: Various expression types

📊 Performance

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

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

📚 Examples

Check out the examples directory for comprehensive examples:

  • Complete Go program parsing
  • Function and struct 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