This is a parser for the Ruby programming language. It is designed to be portable, error tolerant, and maintainable. It is written in C99 and has no dependencies.
The repository contains the infrastructure for both a shared library (libprism) and a native CRuby extension. The shared library has no bindings to CRuby itself, and so can be used by other projects. The native CRuby extension links against ruby.h
, and so is suitable in the context of CRuby.
.
βββ Makefile configuration to compile the shared library and native tests
βββ Rakefile configuration to compile the native extension and run the Ruby tests
βββ bin
βΒ Β βββ lex runs the lexer on a file or string, prints the tokens, and compares to ripper
βΒ Β βββ parse runs the parse on a file or string and prints the AST
βΒ Β βββ prism a CLI for development and debugging
βββ config.yml specification for tokens and nodes in the tree
βββ doc documentation website
βββ docs markdown documentation about the project
βββ ext
βΒ Β βββ prism
βΒ Β βββ extconf.rb configuration to generate the Makefile for the native extension
βΒ Β βββ extension.c the native extension that interacts with libprism
βββ fuzz files related to fuzz testing
βββ gemfiles gemfiles used by different Ruby versions in CI
βββ include
βΒ Β βββ prism header files for the shared library
βΒ Β βββ prism.h main header file for the shared library
βββ java Java bindings for the shared library
βββ java-wasm Java WASM bindings for the shared library
βββ javascript JavaScript WASM bindings for the shared library
βββ lib
βΒ Β βββ prism Ruby library files
βΒ Β βββ prism.rb main entrypoint for the Ruby library
βββ rakelib various Rake tasks for the project
βββ rbi RBI type signatures for the Ruby library
βββ rust
βΒ Β βββ ruby-prism Rustified crate for the shared library
βΒ Β βββ ruby-prism-sys FFI binding for Rust
βββ sample
β βββ prism Sample code that uses the Ruby API for documentation purposes
βββ sig RBS type signatures for the Ruby library
βββ src
βΒ Β βββ util various utility files
βΒ Β βββ prism.c main entrypoint for the shared library
βββ templates contains ERB templates generated by templates/template.rb
βΒ Β βββ template.rb generates code from the nodes and tokens configured by config.yml
βββ test
βββ prism
βββ fixtures Ruby code used for testing
βββ snapshots snapshots of generated syntax trees corresponding to fixtures
To compile the shared library, you will need:
- C99 compiler
- GNU make
- Ruby 2.7.0 or later
Once you have these dependencies, run:
bundle install
to fetch the Ruby dependencies. Finally, run:
bundle exec rake compile
to compile the shared library. It will be built in the build
directory. To test that everything is working, run:
bin/parse -e "1 + 2"
to see the syntax tree for the expression 1 + 2
.
See the CONTRIBUTING.md file for more information. We additionally have documentation about the overall design of the project as well as various subtopics.
- Build system
- Configuration
- CRuby compilation
- Design
- Encoding
- Fuzzing
- Heredocs
- JavaScript
- Local variable depth
- Mapping
- Parser translation
- Parsing rules
- Releasing
- Ripper translation
- Ruby API
- RubyParser translation
- Serialization
- Testing
Prism has been integrated into the majority of Ruby runtimes, many libraries, and some applications. Below is a list of some of the projects that use Prism:
- CRuby (via C)
- Garnet (via WASM)
- JRuby (via Java)
- Natalie (via C++ and Ruby)
- Opal (via Ruby and WASM)
- TruffleRuby (via Java)
- dispersion
- minifyrb
- packwerk (via parser translator)
- rbi
- rails
- repl_type_completor
- rubocop (via parser translator)
- ruby-lsp
- smart_todo
- sorbet-eraser
- synvert
- typeprof