| Crates.io | oak-dart |
| lib.rs | oak-dart |
| version | 0.0.1 |
| created_at | 2025-10-20 14:50:10.101358+00 |
| updated_at | 2026-01-23 04:21:15.961589+00 |
| description | High-performance incremental Dart parser for the oak ecosystem with flexible configuration, supporting cross-platform development and modern UI frameworks. |
| homepage | https://github.com/ygg-lang/oaks |
| repository | https://github.com/ygg-lang/oaks |
| max_upload_size | |
| id | 1892037 |
| size | 70,664 |
High-performance incremental Dart parser for the oak ecosystem with flexible configuration, optimized for code analysis and compilation.
Oak Dart is a robust parser for Dart, designed to handle complete Dart 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.
Basic example:
use oak_dart::{Parser, DartLanguage, SourceText};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let parser = Parser::new();
let source = SourceText::new(r#"
import 'dart:io';
void main() {
print('Hello, Dart!');
var numbers = [1, 2, 3, 4, 5];
numbers.forEach((number) {
print(number * 2);
});
}
"#);
let result = parser.parse(&source);
println!("Parsed Dart program successfully.");
Ok(())
}
use oak_dart::{Parser, DartLanguage, SourceText};
let parser = Parser::new();
let source = SourceText::new(r#"
class Calculator {
double _result = 0.0;
double add(double a, double b) {
_result = a + b;
return _result;
}
double subtract(double a, double b) {
_result = a - b;
return _result;
}
double get result => _result;
}
"#);
let result = parser.parse(&source);
println!("Parsed Dart class successfully.");
use oak_dart::{Parser, DartLanguage, SourceText};
let parser = Parser::new();
let source = SourceText::new(r#"
String greet(String name, {String greeting = 'Hello'}) {
return '$greeting, $name!';
}
int fibonacci(int n) {
if (n <= 1) return n;
return fibonacci(n - 1) + fibonacci(n - 2);
}
"#);
let result = parser.parse(&source);
println!("Parsed Dart functions successfully.");
use oak_dart::{Parser, DartLanguage, SourceText};
let parser = Parser::new();
let source = SourceText::new(r#"
import 'dart:convert';
import 'package:http/http.dart' as http;
Future<Map<String, dynamic>> fetchData(String url) async {
final response = await http.get(Uri.parse(url));
if (response.statusCode == 200) {
return jsonDecode(response.body) as Map<String, dynamic>;
} else {
throw Exception('Failed to load data');
}
}
void main() async {
try {
final data = await fetchData('https://api.example.com/data');
print('Data loaded: $data');
} catch (e) {
print('Error: $e');
}
}
"#);
let result = parser.parse(&source);
println!("Parsed Dart async code successfully.");
use oak_dart::{Parser, DartLanguage, SourceText};
let parser = Parser::new();
let source = SourceText::new("void main() { print('Hello'); }");
let result = parser.parse(&source);
// Token information is available in the parse result
use oak_dart::{Parser, DartLanguage, SourceText};
let parser = Parser::new();
let source = SourceText::new(r#"
void main() {
print('Hello, Dart!'
// Missing closing parenthesis
}
"#);
let result = parser.parse(&source);
if let Err(e) = result.result {
println!("Parse error: {:?}", e);
}
The parser generates a comprehensive AST with the following main structures:
Oak Dart integrates seamlessly with:
Check out the examples directory for comprehensive examples:
Contributions are welcome!
Please feel free to submit pull requests at the project repository or open issues.