Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kddnewton/ripper-docs
Documentation for the ripper Ruby standard library
https://github.com/kddnewton/ripper-docs
Last synced: 23 days ago
JSON representation
Documentation for the ripper Ruby standard library
- Host: GitHub
- URL: https://github.com/kddnewton/ripper-docs
- Owner: kddnewton
- License: mit
- Created: 2021-10-12T14:33:03.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-08-26T15:16:40.000Z (over 1 year ago)
- Last Synced: 2024-11-13T08:36:40.877Z (3 months ago)
- Homepage: https://kddnewton.com/ripper-docs
- Size: 440 KB
- Stars: 15
- Watchers: 2
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## Ripper
Ripper is a Ruby standard library that acts as an event-based Ruby script parser. It can be used to gather information about Ruby scripts without running them. It can also generate [syntax trees](https://en.wikipedia.org/wiki/Abstract_syntax_tree) from source code.
Ripper is generated from Ruby's own parsing code, and is distributed with Ruby. That means the Ripper syntax is completely up-to-date with its corresponding Ruby.
When Ruby parses source code, it first [scans](https://en.wikipedia.org/wiki/Lexical_analysis) the source code into a series of tokens. When a scanner token is recognized, Ripper dispatches a scanner event. The scanner events are then grouped into parser events by applying the Ruby grammar. When a set of scanner events is grouped (i.e., the production rule in the grammar is reduced), Ripper dispatches a parser event.
Each event will create a node in the syntax tree. For instance, an assignment node ([assign](events#assign)) for `value = 7` would come from scanner nodes for `value` ([ident](events#ident)), `=` ([op](events#op)) and `7` ([int](events#int)). A parser event can group parser events, scanner events, or both.
Ruby's parser generator (in `parse.y`) contains [comments for Ripper to use](https://github.com/ruby/ruby/blob/79f9f8326a34e499bb2d84d8282943188b1131bd/parse.y#L1519). When Ripper is compiled, it modifies Ruby's compiler code in `parse.y` based on these comments to make its own compiler code, very similar to Ruby's.
Ripper allows you to define handlers for scanner and parser events, which can let you analyze Ruby programs, or recognize control structures (e.g. an assignment inside an `if` statement, which is often an error).
This document contains notes on various subjects pertaining to Ripper, as well as references for all of the various events and methods that Ripper uses internally. Here is a list of the pages that you can find in this document:
* [Usage](usage) will give you a general overview of how to use Ripper for your own purposes
* [Naming](naming) will give you an idea of some of the event types that Ripper contains and how they are named
* [Lists](lists) will help you understand how Ripper represents and parses lists of values
* [Location](location) explains how to determine source location information inside event handlers
* [Events](events) contains a reference for every scanner and parser event that Ripper dispatches