A modular, open-source COBOL tooling ecosystem in Rust. Cobalt provides a collection of small, composable libraries that form the foundation for COBOL analysis, refactoring, and modernization tools.
- Modular: Small, focused crates that work together
- Fast: Built with Rust for performance
- Composable: Use what you need, combine as needed
- Open Source: MIT/Apache-2.0 licensed
- Production Ready: Comprehensive error handling and testing
Fast, modular lexer for COBOL source code supporting both fixed-format and free-format COBOL.
Features:
- β Free-format COBOL lexing
- β Fixed-format COBOL lexing with column-based parsing
- β Case-insensitive keyword recognition
- β Comprehensive token types (keywords, identifiers, literals, operators, punctuation)
- β Source location tracking (line, column, span)
- β Error reporting with precise location information
- β Supports continuation lines and comment handling
Status: β Complete
Abstract Syntax Tree (AST) data structures for COBOL programs.
Features:
- β Complete AST representation of all four COBOL divisions
- β Data Division structures (data items, PICTURE clauses, OCCURS, etc.)
- β Procedure Division statements (DISPLAY, MOVE, COMPUTE, IF, PERFORM, etc.)
- β Expression trees
- β Source span tracking for all nodes
- β Visitor pattern for AST traversal
- β Optional serialization support (serde)
Status: β Core structures defined
Recursive descent parser that converts tokens into a structured AST.
Features:
- β Parses all four COBOL divisions (Identification, Environment, Data, Procedure)
- β Data item definitions with PICTURE, VALUE, OCCURS clauses
- β Comprehensive statement support (DISPLAY, ACCEPT, MOVE, COMPUTE, IF, EVALUATE, PERFORM, etc.)
- β File operations (OPEN, CLOSE, READ, WRITE, REWRITE, DELETE)
- β String manipulation (STRING, UNSTRING)
- β Table operations (SEARCH, SORT)
- β Complex data structures (OCCURS DEPENDING ON, REDEFINES)
- β Subprogram support (CALL, LINKAGE SECTION)
- β Error recovery and detailed error messages
- β Handles whitespace and comments gracefully
Status: β Comprehensive parsing implemented
CLI tool for assessing COBOL systems for cloud migration and microservices transformation.
Features:
- β Cloud readiness analysis with detailed scoring
- β Microservices decomposition recommendations
- β Effort estimation with resource requirements
- β Technical debt assessment using real AST analysis
- β Multiple cloud platform support (AWS, Azure, GCP, Hybrid, Kubernetes)
- β Migration strategy recommendations (Lift-and-shift, Replatform, Refactor, Rebuild, Replace)
- β Real COBOL parsing integration (no mock data)
- β Executive summary generation
- β Comprehensive risk assessment
Status: β Production ready
Usage:
cargo run --bin cobol-migrate -- \
--input program.cbl \
--platform aws \
--strategy replatform \
--output report.jsonCLI tool that generates human-readable documentation from COBOL programs.
Features:
- β Extracts program structure and logic from real COBOL AST
- β Generates documentation in multiple formats (HTML, Markdown, JSON)
- β Comprehensive complexity metrics (cyclomatic complexity, nesting depth, maintainability index)
- β Cross-references and variable usage tracking
- β Paragraph and section flow analysis
- β PERFORM call analysis and call graphs
- β Technical debt calculation
- β Real COBOL parsing integration (no mock data)
- β Customizable templates with security validation
Status: β Production ready
Usage:
cargo run --bin cobol-doc -- \
--input program.cbl \
--format html \
--output docs/ \
--include-source \
--include-metricsInteractive REPL (Read-Eval-Print Loop) for exploring COBOL code.
Features:
- β Interactive COBOL code parsing and exploration
- β Load and parse COBOL files
- β Tokenize COBOL code
- β View AST structures
- β List and manage loaded programs
- β Command history support
Status: β Core functionality ready
Usage:
cargo run --bin cobol-replStatic analysis tool for COBOL code quality and compliance.
Features:
- β Naming convention checks
- β Deprecated syntax detection (GO TO statements)
- β Y2K-style date format warnings
- β COBOL 2014 compliance checks
- β Multiple output formats (text, JSON)
- β Severity-based filtering
Status: β Production ready
Usage:
cargo run --bin cobol-linter -- program.cblAST visualization tool for COBOL programs.
Features:
- β Generate visual representations of COBOL AST
- β SVG output format
- β Program structure visualization
- β Division and section highlighting
Status: β Core functionality ready
Usage:
cargo run --bin cobol-visualizer -- program.cbl output.svgAuto-formatter for COBOL source code (like rustfmt or black).
Features:
- β AST-based formatting for better code quality
- β Configurable indentation (spaces/tabs, width)
- β Keyword case normalization (UPPER, lower, preserve)
- β Identifier case normalization
- β PICTURE clause formatting
- β Data item alignment by level number
- β Spacing around operators
- β Line length enforcement
- β Comment preservation
- β Traditional and modern style presets
Status: β Core functionality ready
Usage:
cargo run --bin cobol-fmt -- program.cblDead code detector for COBOL programs.
Features:
- β Control Flow Graph (CFG) construction
- β Reachability analysis
- β Unused variable detection
- β Unused paragraph/section detection
- β Unreachable statement detection
- β JSON and text output formats
- β Filtering options (variables-only, procedures-only, unreachable-only)
Status: β Core functionality ready
Usage:
cargo run --bin cobol-dead-code -- program.cbl# Clone the repository
git clone https://github.com/MarsZDF/cobalt.git
cd cobalt
# Build all crates
cargo build --alluse cobol_lexer::{tokenize, Format};
let source = r#"
IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO-WORLD.
PROCEDURE DIVISION.
DISPLAY "Hello, World!".
STOP RUN.
"#;
let tokens = tokenize(source, Format::FreeFormat)?;
for token in tokens {
println!("{:?} at line {}", token.token_type, token.line);
}use cobol_parser::parse_source;
use cobol_ast::Program;
let source = r#"
IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO-WORLD.
PROCEDURE DIVISION.
DISPLAY "Hello, World!".
STOP RUN.
"#;
let program: Program = parse_source(source)?;
println!("Program ID: {:?}", program.identification.program_id);use cobol_lexer::{tokenize, Format};
use cobol_parser::parse;
use cobol_ast::{Program, Visitor};
let source = "/* your COBOL code */";
// Step 1: Tokenize
let tokens = tokenize(source, Format::FreeFormat)?;
// Step 2: Parse
let program: Program = parse(&tokens)?;
// Step 3: Analyze (using visitor pattern)
struct MyVisitor;
impl Visitor for MyVisitor {
// Implement visitor methods
}βββββββββββββββββββββββ
β COBOL Source β
β (.cbl, .cob, etc.) β
ββββββββββββ¬βββββββββββ
β
v
βββββββββββββββββββββββ
β cobol-lexer β Tokenizes source code
β β (free-format β
, fixed-format β
)
ββββββββββββ¬βββββββββββ
β
v
βββββββββββββββββββββββ
β cobol-parser β Parses tokens into AST
β β (comprehensive COBOL support β
)
ββββββββββββ¬βββββββββββ
β
v
βββββββββββββββββββββββ
β cobol-ast β AST data structures
β β (with visitor pattern β
)
ββββββββββββ¬βββββββββββ
β
ββββββββββββ¬βββββββββββ¬βββββββββββ¬βββββββββββ¬βββββββββββ
β β β β β β
v v v v v v
ββββββββββββββββ ββββββββββββ ββββββββββββ ββββββββββββ ββββββββββββ ββββββββββββ
β cobol- β β cobol- β β cobol- β β cobol- β β cobol- β β cobol- β
β migration- β β doc-gen β β repl β β linter β β visual- β β fmt β
β analyzer β
β β β
β β β
β β β
β β izer β
β β β
β
ββββββββββββββββ ββββββββββββ ββββββββββββ ββββββββββββ ββββββββββββ ββββββββββββ
β
v
ββββββββββββββββ
β cobol- β
β dead-code β
β
ββββββββββββββββ
- Rust 1.70+ (stable, beta, or nightly)
- Cargo (comes with Rust)
# Build all crates
cargo build --all
# Build a specific crate
cd cobol-lexer && cargo build
# Build with optimizations
cargo build --all --release# Run all tests
cargo test --all
# Run tests for a specific crate
cd cobol-lexer && cargo test
# Run with output
cargo test --all -- --nocapture# Run lexer example
cd cobol-lexer && cargo run --example basic_tokenize
# Run parser example
cd cobol-parser && cargo run --example basic_parse# Run migration analyzer
cargo run --bin cobol-migrate -- --help
# Run documentation generator
cargo run --bin cobol-doc -- --help# Format code
cargo fmt --all
# Run clippy
cargo clippy --all -- -D warningscd cobol-lexer && cargo benchcobalt/
βββ Cargo.toml # Workspace configuration
βββ README.md # This file
βββ .github/
β βββ workflows/
β βββ ci.yml # CI/CD pipeline
βββ cobol-lexer/ # Lexer crate
β βββ src/
β βββ tests/
β βββ examples/
β βββ benches/
βββ cobol-ast/ # AST crate
β βββ src/
β βββ tests/
βββ cobol-parser/ # Parser crate
β βββ src/
β βββ tests/
β βββ examples/
βββ cobol-migration-analyzer/ # Migration tool
β βββ src/
βββ cobol-doc-gen/ # Documentation generator
β βββ src/
βββ cobol-repl/ # Interactive REPL
β βββ src/
βββ cobol-linter/ # Static analysis linter
β βββ src/
βββ cobol-visualizer/ # AST visualization
β βββ src/
βββ cobol-fmt/ # Code formatter
β βββ src/
βββ cobol-dead-code/ # Dead code detector
βββ src/
We use GitHub Actions for continuous integration:
- β Tests on stable, beta, and nightly Rust
- β Tests on Linux, Windows, and macOS
- β Linting with clippy and rustfmt
- β Builds examples and documentation
- β All crates tested in the pipeline
See `.github/workflows/ci.yml` for details.
Contributions are welcome! This project follows standard Rust conventions:
- Fork the repository
- Create a feature branch (`git checkout -b feature/amazing-feature`)
- Make your changes
- Add tests for new functionality
- Ensure all tests pass (`cargo test --all`)
- Run clippy and fix warnings (`cargo clippy --all`)
- Format code (`cargo fmt --all`)
- Update documentation as needed
- Submit a pull request
- Follow Rust naming conventions
- Write comprehensive tests
- Document public APIs with rustdoc
- Handle errors explicitly (use `Result` types)
- Keep crates focused and modular
- Use workspace dependencies where appropriate
- cobol-lexer - Complete lexer with free-format and fixed-format support
- cobol-ast - Comprehensive AST structures for all COBOL constructs
- cobol-parser - Full COBOL grammar support (EVALUATE, PERFORM VARYING, file I/O, string operations, etc.)
- cobol-migration-analyzer - Production-ready migration assessment tool with real AST integration
- cobol-doc-gen - Complete documentation generator with complexity metrics and cross-references
- cobol-repl - Interactive REPL for COBOL exploration
- cobol-linter - Static analysis tool with compliance checks
- cobol-visualizer - AST visualization tool
- cobol-fmt - Auto-formatter for COBOL source code
- cobol-dead-code - Dead code detector with CFG analysis
- Security hardening - Fixed unsafe operations across all crates
- Parser integration - Real COBOL parsing in all analysis tools
- Workspace setup and CI/CD
- Comprehensive testing framework with real COBOL programs
- Performance benchmarking and optimization
- Enhanced error messages and recovery strategies
- Expand dead code detection (handle dynamic calls, ALTER statements)
- Security and Compliance Scanner - OWASP-style security checks, PCI-DSS, GDPR compliance
- Enhanced dead code detection - Better handling of dynamic PERFORM calls
- Language server support (LSP)
- Refactoring tools
- COBOL to Rust transpiler (experimental)
This project aims to modernize COBOL tooling using Rust's excellent performance and safety guarantees. Special thanks to:
- The Rust community for excellent tooling and documentation
- COBOL maintainers for keeping legacy systems running
- Contributors and users of this project
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Pull Requests: GitHub Pull Requests
Built with β€οΈ in Rust