| Crates.io | oak-fortran |
| lib.rs | oak-fortran |
| version | 0.0.1 |
| created_at | 2025-10-20 16:36:55.822038+00 |
| updated_at | 2026-01-23 04:28:04.61545+00 |
| description | Fortran scientific computing language parser with support for modern Fortran standards and numerical computing. |
| homepage | https://github.com/ygg-lang/oaks |
| repository | https://github.com/ygg-lang/oaks |
| max_upload_size | |
| id | 1892309 |
| size | 98,808 |
High-performance incremental Fortran parser for the oak ecosystem with flexible configuration, optimized for code analysis and compilation.
Oak Fortran is a robust parser for Fortran, designed to handle complete Fortran 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_fortran::{Parser, FortranLanguage, SourceText};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let parser = Parser::new();
let source = SourceText::new(r#"
program hello
print *, "Hello, Fortran!"
end program hello
"#);
let result = parser.parse(&source);
println!("Parsed Fortran successfully.");
Ok(())
}
use oak_fortran::{Parser, FortranLanguage, SourceText};
let parser = Parser::new();
let source = SourceText::new(r#"
program calculator
implicit none
real :: a, b, result
print *, "Enter two numbers:"
read *, a, b
result = a + b
print *, "Sum:", result
end program calculator
"#);
let result = parser.parse(&source);
println!("Program parsed successfully.");
use oak_fortran::{Parser, FortranLanguage, SourceText};
let parser = Parser::new();
let source = SourceText::new(r#"
subroutine swap(a, b)
implicit none
real, intent(inout) :: a, b
real :: temp
temp = a
a = b
b = temp
end subroutine swap
program test
implicit none
real :: x = 1.0, y = 2.0
print *, "Before swap: x =", x, "y =", y
call swap(x, y)
print *, "After swap: x =", x, "y =", y
end program test
"#);
let result = parser.parse(&source);
println!("Subroutine parsed successfully.");
use oak_fortran::{Parser, FortranLanguage, SourceText};
let parser = Parser::new();
let source = SourceText::new(r#"
function factorial(n) result(fact)
implicit none
integer, intent(in) :: n
integer :: fact
if (n <= 0) then
fact = 1
else
fact = n * factorial(n - 1)
end if
end function factorial
program test
implicit none
integer :: n = 5
print *, "Factorial of", n, "is", factorial(n)
end program test
"#);
let result = parser.parse(&source);
println!("Function parsed successfully.");
use oak_fortran::{Parser, FortranLanguage, SourceText};
let parser = Parser::new();
let source = SourceText::new("x = 42.0");
let result = parser.parse(&source);
println!("Token parsing completed.");
use oak_fortran::{Parser, FortranLanguage, SourceText};
let parser = Parser::new();
let source = SourceText::new(r#"
program broken
implicit none
real :: x
print *, "Hello, Fortran!"
x = 5
! Missing end program statement
"#);
let result = parser.parse(&source);
if let Some(errors) = result.result.err() {
println!("Parse errors found: {:?}", errors);
} else {
println!("Parsed successfully.");
}
The parser generates a comprehensive AST with the following main structures:
Oak Fortran 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.