Coder Social home page Coder Social logo

repper's Introduction

Rapper necklace with dollar pendant

Repper

Gem Version Build Status Coverage

Repper is a regular expression pretty printer and formatter 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 for Regexp pretty-printing, integrated into editors to format Regexps, or called manually.

There are also a few customization options.

REPL integration

Via Regexp#inspect (recommended)

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

screenshot1

Via 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).

Editor integration

Use vscode-repper to format Regexps in VSCode.

vscode-repper

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

Multiple formats are available out of the box:

  • :annotated is the default, verbose format, shown above
  • :inline adds only colorization and does not restructure the Regexp
  • :structured is like :annotated, just without annotations
  • :x (or :extended) returns a lightly formatted but equivalent Regexp
    • this format is used for the repper executable and vscode-repper

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 = ->(tokens, _theme) { tokens.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.

repper's People

Contributors

jaynetics avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

timkrins

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.