Skip to content

kddnewton/ripper-docs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

69 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 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 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) for value = 7 would come from scanner nodes for value (ident), = (op) and 7 (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. 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 will give you a general overview of how to use Ripper for your own purposes
  • Naming will give you an idea of some of the event types that Ripper contains and how they are named
  • Lists will help you understand how Ripper represents and parses lists of values
  • Location explains how to determine source location information inside event handlers
  • Events contains a reference for every scanner and parser event that Ripper dispatches

About

Documentation for the ripper Ruby standard library

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

 

Packages

 
 
 

Contributors 4

  •  
  •  
  •  
  •