Rust port of gram-hs pattern data structure and graph views.
This library provides a faithful port of the gram-hs reference implementation, emphasizing correctness and compatibility while adopting Rust-native idioms. The library is designed as a shared library that compiles for native Rust, WebAssembly, and other target environments.
This project is a port of the gram-hs reference implementation. The reference implementation is available locally at ../gram-hs (relative to this repository root).
Key Reference Locations:
- Source Code (Authoritative):
../gram-hs/libs/- Haskell library implementations - This is the source of truth - Documentation (Up-to-date):
../gram-hs/docs/- Up-to-date documentation about the implementation - Tests (Authoritative):
../gram-hs/libs/*/tests/- Test suites for behavioral equivalence verification - Shows expected behavior - Historical Notes (Context Only):
../gram-hs/specs/- Historical notes that guided incremental development (may be outdated, use for context only) - Online Repository: https://github.com/gram-data/gram-hs
All functionality is designed to faithfully replicate the behavior of the Haskell implementation. We are porting the Haskell implementation to idiomatic Rust. When porting features, developers should study the actual Haskell source code in ../gram-hs/libs/ as the authoritative source and refer to up-to-date documentation in ../gram-hs/docs/. The historical notes in ../gram-hs/specs/ guided incremental development and may be useful for understanding the feature's purpose and approach, but they are NOT authoritative and may be outdated.
- Rust: 1.70.0 or later (check with
rustc --version) - Cargo: Included with Rust (check with
cargo --version) - WASM Target (for WebAssembly compilation): Install with
rustup target add wasm32-unknown-unknown
-
Clone the repository:
git clone <repository-url> cd gram-rs
-
Build the library:
cargo build
-
Run tests:
cargo test -
Build for WASM (after installing WASM target):
cargo build --target wasm32-unknown-unknown
This project is organized as a Cargo workspace with multiple crates:
gram-rs/
├── Cargo.toml # Workspace root configuration
├── crates/
│ ├── pattern-core/ # Core pattern data structures
│ ├── pattern-ops/ # Pattern operations and algorithms
│ ├── gram-codec/ # Gram notation serialization/deserialization
│ ├── pattern-store/ # Optimized storage (placeholder)
│ └── pattern-wasm/ # WASM bindings (placeholder)
└── .github/workflows/ # CI/CD configuration
# Build all workspace crates (native target)
cargo build --workspace
# Build a specific crate
cargo build -p pattern-core
# Build for WebAssembly
cargo build --workspace --target wasm32-unknown-unknown
# Run all workspace tests
cargo test --workspace
# Test a specific crate
cargo test -p pattern-core
# Check all crates
cargo check --workspace
# Format all crates
cargo fmt --all
# Lint all crates
cargo clippy --workspaceBefore pushing, you can run all CI checks locally:
# Run all CI checks (format, lint, build, test)
./scripts/ci-local.shThis script runs the same checks that GitHub Actions runs, so you can catch issues before pushing. See .github/workflows/README.md for more details.
The library is designed to be WASM-compatible. All public APIs avoid blocking I/O and file system access unless explicitly feature-flagged. Platform-specific code uses conditional compilation with the wasm feature flag.
The project includes comprehensive testing infrastructure:
- Property-Based Testing: Using
proptestfor automated test case generation - Equivalence Checking: Utilities for comparing gram-rs and gram-hs implementations
- Snapshot Testing: Using
instafor regression detection - Benchmarks: Using
criterionfor performance tracking - Test Helpers: Utilities for pattern comparison and validation
See docs/testing-infrastructure.md for detailed documentation and specs/003-test-infrastructure/quickstart.md for usage examples.
For using the gram-hs CLI tool for testing and equivalence checking, see gram-hs CLI Testing Guide.
See the examples/ directory for usage examples:
- WASM/JavaScript:
examples/wasm-js/- Demonstrates WebAssembly compilation and JavaScript integration
Solution: Ensure you're in the repository root directory
Solution:
- Check Rust installation:
rustc --version - Update Rust:
rustup update stable - Ensure Rust 1.70.0 or later is installed
Solution: Install WASM target: rustup target add wasm32-unknown-unknown
Solution:
- Run the local CI script to reproduce:
./scripts/ci-local.sh - Check for platform-specific issues (CI runs on Linux, you might be on macOS/Windows)
- Ensure you're using the same Rust version:
rustup default stable - Clear caches and rebuild:
cargo clean && cargo build --workspace
Tip: Always run ./scripts/ci-local.sh before pushing to catch issues early.
Solution:
- Run
cargo buildto fetch dependencies - Check
Cargo.tomlfor correct dependency declarations - Ensure network access is available for downloading dependencies
Solution:
- Review warnings and fix legitimate issues
- Suppress false positives in code if needed
- Update
clippy.tomlif project-wide configuration needed
Solution:
- Run
cargo fmtto auto-format code - Ensure
rustfmt.tomlis properly configured
When porting features from gram-hs, see PORTING_GUIDE.md for detailed instructions. The guide covers:
- How to reference the local gram-hs implementation at
../gram-hs - Systematic workflow for porting features
- Haskell → Rust translation patterns
- Verification and testing strategies
Quick Start for Porting:
- Study the Haskell implementation in
../gram-hs/libs/- This is the source of truth - Review the up-to-date documentation in
../gram-hs/docs/- Information about the implementation - Review the Haskell tests in
../gram-hs/libs/*/tests/- Shows expected behavior - Review the historical notes in
../gram-hs/specs/XXX-feature-name/(for context only, may be outdated) - Create a new feature specification using
/speckit.specify - Follow the porting guide for implementation (porting Haskell to idiomatic Rust)
BSD-3-Clause (see LICENSE file)