| Crates.io | oak-crystal |
| lib.rs | oak-crystal |
| version | 0.0.1 |
| created_at | 2025-10-20 12:21:27.909148+00 |
| updated_at | 2026-01-23 04:18:42.209034+00 |
| description | Crystal language parser with support for modern Crystal syntax and Ruby-like features. |
| homepage | https://github.com/ygg-lang/oaks |
| repository | https://github.com/ygg-lang/oaks |
| max_upload_size | |
| id | 1891842 |
| size | 82,584 |
High-performance incremental C# parser for the oak ecosystem with flexible configuration, optimized for code analysis and compilation.
Oak-csharp is a robust parser for C#, designed to handle complete C# 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.
use oak_csharp::{CsharpParser, ast::ClassDefinition};
let parser = CsharpParser::new();
let csharp_code = r#"
public class Calculator {
public int Add(int a, int b) {
return a + b;
}
}
"#;
let program = parser.parse_program(csharp_code)?;
if let Some(ClassDefinition { name, .. }) = program.classes.get(0) {
println!("Parsed class: {}", name);
}
use oak_csharp::{CsharpParser, ast::MethodDefinition};
let parser = CsharpParser::new();
let csharp_code = r#"
public static string Greet(string name) {
return $"Hello, {name}!";
}
"#;
let method = parser.parse_method(csharp_code)?;
println!("Method name: {}", method.name);
Basic example:
```rust
use oak_csharp::CsharpParser;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let parser = CsharpParser::new();
let csharp_code = r#"
using System;
class Program {
static void Main() {
Console.WriteLine("Hello, C#!");
}
}
"#;
let program = parser.parse_program(csharp_code)?;
println!("Parsed C# program successfully.");
Ok(())
}
The oak library allows for flexible customization of the parser. You can modify the grammar rules or add new ones to suit your specific needs. Refer to the oak documentation for more details on parser customization.
Oak of csharp can be extended with error recovery mechanisms to handle malformed C# code gracefully, allowing for partial parsing and better resilience in real-world scenarios.
The generated AST for C# code provides a hierarchical representation of the source. For instance, a simple class definition might result in an AST structure similar to this:
// Simplified AST representation for:
// public class MyClass { /* ... */ }
pex_csharp::ast::Node::ClassDefinition {
modifiers: vec![
pex_csharp::ast::Modifier::Public,
],
name: "MyClass".to_string(),
members: vec![
// ... method definitions, field definitions, etc.
],
}
Oak of csharp is designed for performance. Benchmarks show efficient parsing of large C# codebases. Optimizations include memoization, efficient backtracking, and direct AST construction.
Oak-csharp integrates seamlessly with:
Explore the examples directory within the oak-csharp project for more usage examples and demonstrations of specific C# language features being parsed.
Contributions to Oak of csharp are welcome! If you find a bug or have a feature request, please open an issue on the GitHub repository. For major changes, please open a discussion first.