Skip to content

MarsZDF/cobalt

Repository files navigation

Cobalt

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.

🎯 Goals

  • 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

πŸ“¦ Crates

cobol-lexer

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

πŸ“– Documentation | Examples

cobol-ast

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

πŸ“– Documentation

cobol-parser

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

πŸ“– Documentation | Examples

cobol-migration-analyzer

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.json

cobol-doc-gen

CLI 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-metrics

cobol-repl

Interactive 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-repl

cobol-linter

Static 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.cbl

cobol-visualizer

AST 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.svg

cobol-fmt

Auto-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.cbl

cobol-dead-code

Dead 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

πŸš€ Quick Start

Installation

# Clone the repository
git clone https://github.com/MarsZDF/cobalt.git
cd cobalt

# Build all crates
cargo build --all

Using the Lexer

use 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);
}

Using the Parser

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);

Complete Pipeline Example

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
}

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   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 βœ… β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ§ͺ Development

Prerequisites

  • Rust 1.70+ (stable, beta, or nightly)
  • Cargo (comes with Rust)

Building

# Build all crates
cargo build --all

# Build a specific crate
cd cobol-lexer && cargo build

# Build with optimizations
cargo build --all --release

Testing

# Run all tests
cargo test --all

# Run tests for a specific crate
cd cobol-lexer && cargo test

# Run with output
cargo test --all -- --nocapture

Running Examples

# Run lexer example
cd cobol-lexer && cargo run --example basic_tokenize

# Run parser example
cd cobol-parser && cargo run --example basic_parse

Running CLI Tools

# Run migration analyzer
cargo run --bin cobol-migrate -- --help

# Run documentation generator
cargo run --bin cobol-doc -- --help

Linting and Formatting

# Format code
cargo fmt --all

# Run clippy
cargo clippy --all -- -D warnings

Benchmarks

cd cobol-lexer && cargo bench

πŸ”§ Workspace Structure

cobalt/
β”œβ”€β”€ 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/

🚦 CI/CD

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.

πŸ“ Contributing

Contributions are welcome! This project follows standard Rust conventions:

  1. Fork the repository
  2. Create a feature branch (`git checkout -b feature/amazing-feature`)
  3. Make your changes
  4. Add tests for new functionality
  5. Ensure all tests pass (`cargo test --all`)
  6. Run clippy and fix warnings (`cargo clippy --all`)
  7. Format code (`cargo fmt --all`)
  8. Update documentation as needed
  9. Submit a pull request

Development Guidelines

  • 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

πŸ—ΊοΈ Roadmap

Completed βœ…

  • 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

In Progress 🚧

  • 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)

Planned πŸ“‹

  • 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)

🀝 Acknowledgments

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

πŸ“š Additional Resources

πŸ’¬ Community


Built with ❀️ in Rust

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages