lrama
Version, currently 0.2.01 version
- 0.2.0latestJun 8, 2026
github.com/dsisnero/lrama.cr
Crystal port of Ruby's lrama parser generator
Installation
# Add this to your shard.yml
dependencies:
lrama:
github: dsisnero/lrama.cr
version: ~> 0.2.0Then run:
shards installshard.yml
- Crystal
>= 1.9.0- License
- MIT
- Target
lramafrom src/lrama/main.cr
Dependencies
Runtime Dependencies
Development Dependencies
- ameba*github: crystal-ameba/amebadev
README
Like a lathe shaping raw metal into precise gears, lrama turns grammar rules into deterministic parser machinery. This Crystal port keeps the engineering intent of Ruby lrama while producing native Crystal output tuned for speed and memory efficiency.
Quick Start
shards install
crystal run src/lrama/main.cr -- --help
crystal spec
Features
- Parses
.ygrammars and builds Crystal-native grammar/state structures. - Generates Crystal parser output from LR/LALR analysis.
- Includes runtime parser/lexer/location/token components under
Lrama::Runtime. - Supports reporting for grammar/rules/terms/states/conflicts.
- Provides fixture and golden-output based spec coverage.
Status
Early scaffolding: lexer, fixtures, and specs are in place to validate token streams and locations. Parser generation is in active development.
Development
Requirements:
- Crystal 1.9+
- Ameba (dev dependency)
Useful commands:
crystal tool format src spec
ameba src spec
crystal spec
See Development Guide for full setup instructions.
Profiling And Error Recovery
Profiling uses Crystal-native timing and GC stats:
crystal run src/lrama/main.cr -- --profile=memory sample/calc.y -o sample/calc_parser.cr
This prints lines like profile.time total=... and profile.memory.* deltas to STDERR.
For call-stack profiling, use an external profiler and enable the flag for a hint:
crystal run src/lrama/main.cr -- --profile=call-stack sample/calc.y -o sample/calc_parser.cr
Error recovery is controlled at codegen time:
crystal run src/lrama/main.cr -- -e sample/calc.y -o sample/calc_parser.cr
Lexer Tuning
By default the generated lexer uses fast tables and a byte-slice loop. For very large DFAs, you can opt into more compact tables or a keyword trie:
crystal run src/lrama/main.cr -- -Dlexer.row_dedup=true sample/calc.y -o sample/calc_parser.cr
crystal run src/lrama/main.cr -- -Dlexer.keyword_trie=true sample/calc.y -o sample/calc_parser.cr
These settings trade a bit of speed for memory savings on large lexers.
For quick comparisons, use the microbench harness:
crystal run --release bench/bench.cr
LRAMA_BENCH_GRAMMAR=path/to/grammar.y crystal run --release bench/bench.cr
Layout
src/- Crystal implementationspec/- Crystal specs and fixturesdocs/- Architecture and workflow documentationlrama/- Ruby lrama submodule for referenceracc/- Ruby racc submodule for reference
Submodules
Update the Ruby submodules via Make targets:
make update_lrama
make update_racc
make update_submodules
Documentation
| Document | Purpose |
|---|---|
| Architecture | System design and data flow |
| Development | Setup and daily workflow |
| Coding Guidelines | Code style and conventions |
| Testing | Test commands and patterns |
| PR Workflow | Commits, PRs, and review process |
| Migration | Ruby-to-Crystal migration guidance |
Contributing
- Create an issue:
/forge-create-issue - Implement:
/forge-implement-issue <number> - Self-review:
/forge-reflect-pr - Address feedback:
/forge-address-pr-feedback - Update changelog:
/forge-update-changelog
Examples
examples/sql.y- SQL SELECT grammar using the lexer DSL and Crystal runtime.
Documentation
Built from the current release. The first visit to a release nobody has asked for starts its build.
Links
This release
- Version
0.2.0- Tagged
- Jun 8, 2026
- Commit
4a016a852e85- Crystal
>= 1.9.0- Indexed
- yes
Dependents
No indexed shard depends on this one yet.
Repository
github.com/dsisnero/lrama.cr
Metadata
- Created
- Aug 12, 2026
- Updated
- Sep 16, 2026
- Synced
- Sep 16, 2026
- Versions
- 1