Project

sexp2ruby

0.0
No commit activity in last 3 years
No release in over 3 years
Generates ruby from RubyParser-compatible S-expressions. It is a fork of ruby2ruby with slightly different goals.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

 Project Readme

sexp2ruby

Build Status Code Climate

sexp2ruby generates ruby from ruby_parser S-expressions. It is a fork of ruby2ruby with different goals and tools.

  • Follows ruby-style-guide where possible
  • Prefers OO design over performance
  • Drops support for ruby 1.8.7
  • Uses bundler instead of hoe
  • Uses rspec instead of minitest
  • Depends on (a small subset of) activesupport

When to Use ruby2ruby Instead

If you want to use the latest version of ruby_parser, please use ruby2ruby instead. Ryan does not often make breaking changes to his S-expression format, but when he does, ruby2ruby is more likely to keep up to date. Following the ruby-style-guide is not a goal of ruby2ruby, so you may want to use a tool like rubocop --auto-correct. In fact, rubocop's auto-correct is getting so good that it may not make sense to continue working on this project.

Example

require 'ruby_parser'
require 'sexp2ruby'

ruby = "def a\n  puts 'A'\nend\n\ndef b\n  a\nend"
sexp = RubyParser.new.process(ruby)
# => s(:block, s(:defn, .. etc.

Sexp2Ruby::Processor.new.process(sexp.deep_clone)
# => "def a\n  puts(\"A\")\nend\ndef b\n  a\nend\n"

As with all SexpProcessors, Sexp2Ruby#process destroys its input, so deep_clone as shown above if you need to preserve it.

Configuration

Configure output by passing options to Sexp2Ruby::Processor.new:

hash = s(:hash, s(:lit, :a), s(:lit, 1))
Sexp2Ruby::Processor.new(hash_syntax: :ruby18).process
# => "{ :a => 1 }"
Sexp2Ruby::Processor.new(hash_syntax: :ruby19).process
# => "{ a: 1 }"
  • :hash_syntax - either :ruby18 or :ruby19. Default is :ruby19.
  • :no_paren_methods - an array of symbols, these methods will omit argument parentheses. Default is [].