| Crates.io | oak-cobol |
| lib.rs | oak-cobol |
| version | 0.0.1 |
| created_at | 2025-10-20 10:54:41.084168+00 |
| updated_at | 2026-01-23 04:17:14.197723+00 |
| description | High-performance incremental COBOL parser for the oak ecosystem with flexible configuration, supporting legacy and modern COBOL features. |
| homepage | https://github.com/ygg-lang/oaks |
| repository | https://github.com/ygg-lang/oaks |
| max_upload_size | |
| id | 1891755 |
| size | 63,812 |
High-performance incremental COBOL parser for the oak ecosystem with flexible configuration, optimized for legacy system analysis and mainframe development.
Oak COBOL is a robust parser for COBOL, designed to handle complete COBOL syntax including legacy and modern features. Built on the solid foundation of oak-core, it provides both high-level convenience and detailed AST generation for legacy system analysis and mainframe development.
Basic example:
use oak_cobol::{Parser, CobolLanguage, SourceText};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let parser = Parser::new();
let source = SourceText::new(r#"
IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO-WORLD.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-MESSAGE PIC X(20) VALUE 'Hello, World!'.
PROCEDURE DIVISION.
MAIN-PROCEDURE.
DISPLAY WS-MESSAGE
STOP RUN.
"#);
let result = parser.parse(&source);
println!("Parsed COBOL program successfully.");
Ok(())
}
use oak_cobol::{Parser, CobolLanguage, SourceText};
let parser = Parser::new();
let source = SourceText::new(r#"
IDENTIFICATION DIVISION.
PROGRAM-ID. CALCULATOR.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 NUM1 PIC 9(3) VALUE 10.
01 NUM2 PIC 9(3) VALUE 20.
01 RESULT PIC 9(4).
PROCEDURE DIVISION.
MAIN-PROCEDURE.
COMPUTE RESULT = NUM1 + NUM2
DISPLAY 'Result: ' RESULT
STOP RUN.
"#);
let result = parser.parse(&source);
println!("Parsed COBOL program successfully.");
use oak_cobol::{Parser, CobolLanguage, SourceText};
let parser = Parser::new();
let source = SourceText::new(r#"
DATA DIVISION.
WORKING-STORAGE SECTION.
01 CUSTOMER-RECORD.
05 CUSTOMER-ID PIC 9(5).
05 CUSTOMER-NAME PIC X(30).
05 CUSTOMER-BALANCE PIC 9(7)V99.
"#);
let result = parser.parse(&source);
println!("Parsed COBOL data division successfully.");
use oak_cobol::{Parser, CobolLanguage, SourceText};
let parser = Parser::new();
let source = SourceText::new("IDENTIFICATION DIVISION.");
let result = parser.parse(&source);
// Token information is available in the parse result
use oak_cobol::{Parser, CobolLanguage, SourceText};
let parser = Parser::new();
let source = SourceText::new(r#"
IDENTIFICATION DIVISION
PROGRAM-ID. INVALID
DATA DIVISION
PROCEDURE DIVISION
DISPLAY 'Missing periods'
STOP RUN
"#);
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 COBOL 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.