{"id":13994280,"url":"https://github.com/ruby/lrama","last_synced_at":"2025-05-15T03:06:37.177Z","repository":{"id":65607242,"uuid":"585747748","full_name":"ruby/lrama","owner":"ruby","description":"Pure Ruby LALR parser generator","archived":false,"fork":false,"pushed_at":"2025-05-07T23:15:42.000Z","size":4423,"stargazers_count":299,"open_issues_count":23,"forks_count":28,"subscribers_count":34,"default_branch":"master","last_synced_at":"2025-05-08T00:24:32.385Z","etag":null,"topics":["bison","parser","ruby"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ruby.png","metadata":{"files":{"readme":"README.md","changelog":"NEWS.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2023-01-06T00:59:17.000Z","updated_at":"2025-05-07T23:15:46.000Z","dependencies_parsed_at":"2023-10-12T12:47:12.139Z","dependency_job_id":"6f25fc3d-999f-452f-a364-5b135663529e","html_url":"https://github.com/ruby/lrama","commit_stats":{"total_commits":898,"total_committers":20,"mean_commits":44.9,"dds":0.5456570155902005,"last_synced_commit":"a7842f820e4d5849696c084bad8f68adc73bd864"},"previous_names":[],"tags_count":31,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ruby%2Flrama","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ruby%2Flrama/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ruby%2Flrama/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ruby%2Flrama/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ruby","download_url":"https://codeload.github.com/ruby/lrama/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254264766,"owners_count":22041793,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bison","parser","ruby"],"created_at":"2024-08-09T14:02:48.019Z","updated_at":"2025-05-15T03:06:32.160Z","avatar_url":"https://github.com/ruby.png","language":"Ruby","funding_links":[],"categories":["Ruby"],"sub_categories":[],"readme":"# Lrama\n\n[![Gem Version](https://badge.fury.io/rb/lrama.svg)](https://badge.fury.io/rb/lrama)\n[![build](https://github.com/ruby/lrama/actions/workflows/test.yaml/badge.svg)](https://github.com/ruby/lrama/actions/workflows/test.yaml)\n[![RubyDoc](https://img.shields.io/badge/%F0%9F%93%9ARubyDoc-documentation-informational.svg)](https://www.rubydoc.info/gems/lrama)\n\nLrama is LALR (1) parser generator written by Ruby. The first goal of this project is providing error tolerant parser for CRuby with minimal changes on CRuby parse.y file.\n\n- [Features](#features)\n- [Installation](#installation)\n- [Usage](#usage)\n- [Documentation](#documentation)\n- [Versions and Branches](#versions-and-branches)\n  - [v0\\_7 (`master` branch)](#v0_7-master-branch)\n  - [v0\\_6 (`lrama_0_6` branch)](#v0_6-lrama_0_6-branch)\n  - [v0\\_5 (`lrama_0_5` branch)](#v0_5-lrama_0_5-branch)\n  - [v0\\_4 (`lrama_0_4` branch)](#v0_4-lrama_0_4-branch)\n- [Supported Ruby version](#supported-ruby-version)\n- [Development](#development)\n  - [How to generate parser.rb](#how-to-generate-parserrb)\n  - [How to Write a Type Signature](#how-to-write-a-type-signature)\n  - [Test](#test)\n  - [Call-stack Profiling Lrama](#call-stack-profiling-lrama)\n    - [1. Create parse.tmp.y in ruby/ruby](#1-create-parsetmpy-in-rubyruby)\n    - [2. Enable Profiler](#2-enable-profiler)\n    - [3. Run Lrama](#3-run-lrama)\n    - [4. Generate Flamegraph](#4-generate-flamegraph)\n  - [Memory Profiling Lrama](#memory-profiling-lrama)\n    - [1. Create parse.tmp.y in ruby/ruby](#1-create-parsetmpy-in-rubyruby-1)\n    - [2. Enable Profiler](#2-enable-profiler-1)\n    - [3. Run Lrama](#3-run-lrama-1)\n  - [Build Ruby](#build-ruby)\n- [Release flow](#release-flow)\n- [License](#license)\n\n## Features\n\n* Bison style grammar file is supported with some assumptions\n  * b4_locations_if is always true\n  * b4_pure_if is always true\n  * b4_pull_if is always false\n  * b4_lac_if is always false\n* Error Tolerance parser\n  * Subset of [Repairing Syntax Errors in LR Parsers (Corchuelo et al.)](https://idus.us.es/bitstream/handle/11441/65631/Repairing%20syntax%20errors.pdf) algorithm is supported\n* Parameterizing rules\n  * The definition of a non-terminal symbol can be parameterized with other (terminal or non-terminal) symbols.\n  * Providing a generic definition of parameterized rules as a [standard library](lib/lrama/grammar/stdlib.y).\n* Inlining\n  * The %inline directive causes all references to symbols to be replaced with its definition.\n  * Resolve shift/reduce conflicts without artificially altering the grammar file.\n* Syntax Diagrams\n  * Easily generate syntax diagrams from the grammar file.\n  * These visual diagrams are an useful development tool for grammar development and can also function as automatic self-documentation.\n\n## Installation\n\n```shell\n$ gem install lrama\n```\n\nFrom source codes,\n\n```shell\n$ cd \"$(lrama root)\"\n$ bundle install\n$ bundle exec rake install\n$ bundle exec lrama --version\nlrama 0.7.0\n```\n\n## Usage\n\n```shell\n# \"y.tab.c\" and \"y.tab.h\" are generated\n$ lrama -d sample/parse.y\n```\n\n```shell\n# \"calc\", \"calc.c\", and \"calc.h\" are generated\n$ lrama -d sample/calc.y -o calc.c \u0026\u0026 gcc -Wall calc.c -o calc \u0026\u0026 ./calc\nEnter the formula:\n1\n=\u003e 1\n1+2*3\n=\u003e 7\n(1+2)*3\n=\u003e 9\n```\n\n## Documentation\n\nhttps://ruby.github.io/lrama/ provides a comprehensive guide to Lrama's features and usage.\n\n## Versions and Branches\n\n### v0_7 (`master` branch)\n\nThis branch is for Ruby 3.5. `lrama_0_7` branch is created from this branch, once Ruby 3.5 is released.\n\n### v0_6 (`lrama_0_6` branch)\n\nThis branch is for Ruby 3.4.\n\n### v0_5 (`lrama_0_5` branch)\n\nThis branch is for Ruby 3.3.\n\n### v0_4 (`lrama_0_4` branch)\n\nThis branch generates \"parse.c\" compatible with Bison 3.8.2 for ruby 3.0, 3.1, 3.2. The first version migrated to ruby is [\"0.4.0\"](https://github.com/ruby/ruby/pull/7798) therefore keep this branch for Bison compatible branch.\n\n## Supported Ruby version\n\nLrama is executed with BASERUBY when building ruby from source code. Therefore Lrama needs to support BASERUBY, currently 2.5, or later version.\n\nThis also requires Lrama to be able to run with only default gems because BASERUBY runs with `--disable=gems` option.\n\n## Development\n\n### How to generate parser.rb\n\n```shell\n$ bundle exec rake build:parser\n```\n\n`parser.rb` is generated from `parser.y` by Racc.\nRun the rake command when you update `parser.y` then commit changes of both files.\n\n### How to Write a Type Signature\n\nWe use [Steep](https://github.com/soutaro/steep) for type checking and [rbs-inline](https://github.com/soutaro/rbs-inline) for type declarations.\n\nCurrently, type signatures are declared in the [sig/lrama](https://github.com/ruby/lrama/blob/master/sig/lrama) directory. However, these files will be replaced with `rbs-inline`. This means type signatures should be written directly in the source code.\n\nFor guidance on writing type signatures, refer to the [Syntax Guide](https://github.com/soutaro/rbs-inline/wiki/Syntax-guide) in the rbs-inline documentation.\n\n### Test\n\nRunning tests:\n\n```shell\n$ bundle install\n$ bundle exec rspec\n# or\n$ bundle exec rake spec\n```\n\nRunning type check:\n\n```shell\n$ bundle install\n$ bundle exec rbs collection install\n$ bundle exec steep check\n# or\n$ bundle exec rake steep\n```\n\nRunning both of them:\n\n```shell\n$ bundle install\n$ bundle exec rake\n```\n\n### Call-stack Profiling Lrama\n\n#### 1. Create parse.tmp.y in ruby/ruby\n\n```shell\n$ ruby tool/id2token.rb parse.y \u003e parse.tmp.y\n$ cp parse.tmp.y dir/lrama/tmp\n```\n\n#### 2. Run Lrama\n\n```shell\n$ exe/lrama -o parse.tmp.c --header=parse.tmp.h --profile=call-stack tmp/parse.tmp.y\n```\n\n#### 3. Generate Flamegraph\n\n```shell\n$ stackprof --d3-flamegraph tmp/stackprof-cpu-myapp.dump \u003e tmp/flamegraph.html\n```\n\n### Memory Profiling Lrama\n\n#### 1. Create parse.tmp.y in ruby/ruby\n\n```shell\n$ ruby tool/id2token.rb parse.y \u003e parse.tmp.y\n$ cp parse.tmp.y dir/lrama/tmp\n```\n\n#### 2. Run Lrama\n\n```shell\n$ exe/lrama -o parse.tmp.c --header=parse.tmp.h --profile=memory tmp/parse.tmp.y\n```\n\nThen \"tmp/memory_profiler.txt\" is generated.\n\n### Build Ruby\n\n1. Install Lrama\n2. Run `make main`\n\n## Release flow\n\n1. Update `Lrama::VERSION` and NEWS.md\n2. Release as a gem by `rake release`\n3. Update Lrama in ruby/ruby by `cp -r LEGAL.md NEWS.md MIT exe lib template ruby/tool/lrama`\n4. Create new release on [GitHub](https://github.com/ruby/lrama/releases)\n\n## License\n\nSee [LEGAL.md](./LEGAL.md) file.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fruby%2Flrama","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fruby%2Flrama","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fruby%2Flrama/lists"}