Project

repper

0.0
The project is in a healthy, maintained state
Regexp pretty printer for Ruby
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
 Dependencies

Runtime

~> 3.1
~> 2.8
 Project Readme

Rapper necklace with dollar pendant

Repper

Repper is a regular expression pretty printer for Ruby.

Installation

gem install repper, or add it to your Gemfile.

Usage

repper can be integrated into the REPL (e.g. IRB) through core extensions or used manually.

There are also a few customization options.

Full REPL integration (recommended)

require 'repper/core_ext/regexp' in your ~/.irbrc or ~/.pryrc to override Regexp#inspect and automatically use repper to display Regexps:

screenshot1

Extending Kernel#pp

Alternatively, require 'repper/core_ext/kernel' to make the pp command give nicer output for Regexps (which will look like above by default).

Using Repper manually

Repper.call(/foo/)   # pretty prints the given Regexp and returns nil
Repper.render(/foo/) # returns the pretty print String

Customization

Customizing the format

The default format is the annotated, indented format shown above.

If you want to see the indented structure without annotations, use the :structured format.

If you only want colorization you can use the :inline format.

You can change the format globally:

Repper.format = :structured

Or pick a format on a case-by-case basis:

screenshot2

Or create your own format:

require 'csv'

csv_format = ->(elements, _theme) { elements.map(&:text).to_csv }
Repper.render(/re[\p{pe}\r]$/, format: csv_format)
=> "/,re,[,\\p{pe},\\r,],$,/\n"

Customizing the colors

The color theme can also be set globally or passed on call:

Repper.theme = :monokai # a nicer theme, if the terminal supports it

screenshot3

Repper.call(/foo/, theme: nil) # render without colors

Or create your own theme - you can use all colors supported by the rainbow gem.

Repper.theme = {
  group:   :green,
  set:     :red,
  default: :white,
}

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/jaynetics/repper.

License

The gem is available as open source under the terms of the MIT License.