sexp2ruby 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3a09363137ce2f11cc78ad2733dce55fcf56c27c
4
+ data.tar.gz: 804d653482abc54b86ef47119067f80657df796b
5
+ SHA512:
6
+ metadata.gz: 7a7d4b703d320e202289deee5eb673d27e1457e25fb0b42e3adb894bddb811ba41816933dda1766ee2bbd08be78c1cff7105d12d598adf5bc9636a89dcabb636
7
+ data.tar.gz: b91c818789cc96b280af027092ce11dce5d38e4d1648c2e35e4806d216b2288d75c7f20923f802155421294b8a04a5d92dfece52aa314565a6d6cde13f520920
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ /Gemfile.lock
2
+
data/.travis.yml ADDED
@@ -0,0 +1,10 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.8.7
4
+ - 1.9.3
5
+ - 2.0.0
6
+ - 2.1.6
7
+ - 2.2.2
8
+ script: bundle exec rspec
9
+ notifications:
10
+ email: false
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ === 0.0.1 / 2015-05-31
2
+
3
+ Initial version. Just claiming the gem name.
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,24 @@
1
+ == LICENSE:
2
+
3
+ (The MIT License)
4
+
5
+ Copyright (c) Ryan Davis, seattle.rb
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining
8
+ a copy of this software and associated documentation files (the
9
+ 'Software'), to deal in the Software without restriction, including
10
+ without limitation the rights to use, copy, modify, merge, publish,
11
+ distribute, sublicense, and/or sell copies of the Software, and to
12
+ permit persons to whom the Software is furnished to do so, subject to
13
+ the following conditions:
14
+
15
+ The above copyright notice and this permission notice shall be
16
+ included in all copies or substantial portions of the Software.
17
+
18
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
19
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
22
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,32 @@
1
+ sexp2ruby
2
+ =========
3
+
4
+ `sexp2ruby` generates ruby from RubyParser S-expressions.
5
+ It is a fork of [ruby2ruby][1] with slightly different goals.
6
+
7
+ - Generates ruby that follows [ruby-style-guide][3] where possible
8
+ - Prefers OO design over performance
9
+ - Uses bundler instead of hoe
10
+ - Uses rspec instead of minitest
11
+
12
+ Example
13
+ -------
14
+
15
+ ```ruby
16
+ require 'ruby_parser'
17
+ require 'sexp2ruby'
18
+
19
+ ruby = "def a\n puts 'A'\nend\n\ndef b\n a\nend"
20
+ sexp = RubyParser.new.process(ruby)
21
+ # => s(:block, s(:defn, .. etc.
22
+
23
+ Sexp2Ruby::Processor.new.process(sexp.deep_clone)
24
+ # => "def a\n puts(\"A\")\nend\ndef b\n a\nend\n"
25
+ ```
26
+
27
+ As with all `SexpProcessor`s, `Sexp2Ruby#process` destroys its input,
28
+ so `deep_clone` if you need to preserve it.
29
+
30
+ [1]: https://github.com/seattlerb/ruby2ruby
31
+ [2]: http://docs.seattlerb.org/ruby2ruby
32
+ [3]: https://github.com/bbatsov/ruby-style-guide
data/Rakefile ADDED
@@ -0,0 +1,92 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'rubygems'
4
+ require 'hoe'
5
+
6
+ Hoe.add_include_dirs("lib",
7
+ "../../ruby_parser/dev/lib",
8
+ "../../sexp_processor/dev/lib")
9
+
10
+ Hoe.plugin :seattlerb
11
+ Hoe.plugin :isolate
12
+
13
+ Hoe.spec 'ruby2ruby' do
14
+ developer 'Ryan Davis', 'ryand-ruby@zenspider.com'
15
+
16
+ license "MIT"
17
+
18
+ dependency "sexp_processor", "~> 4.0"
19
+ dependency "ruby_parser", "~> 3.1"
20
+ end
21
+
22
+ def process ruby, file="stdin"
23
+ require "ruby_parser"
24
+ require "ruby2ruby"
25
+
26
+ parser = RubyParser.new
27
+ ruby2ruby = Ruby2Ruby.new
28
+
29
+ begin
30
+ sexp = parser.process(ruby, file)
31
+
32
+ ruby2ruby.process(sexp)
33
+ rescue Interrupt => e
34
+ raise e
35
+ end
36
+ end
37
+
38
+ task :stress do
39
+ $: << "lib"
40
+ $: << "../../ruby_parser/dev/lib"
41
+ require "pp"
42
+
43
+ files = Dir["../../*/dev/**/*.rb"]
44
+
45
+ warn "Stress testing against #{files.size} files"
46
+
47
+ bad = {}
48
+
49
+ files.each do |file|
50
+ warn file
51
+
52
+ begin
53
+ process File.read(file), file
54
+ rescue Interrupt => e
55
+ raise e
56
+ rescue Exception => e
57
+ bad[file] = e
58
+ end
59
+ end
60
+
61
+ pp bad
62
+ end
63
+
64
+ task :debug => :isolate do
65
+ ENV["V"] ||= "18"
66
+
67
+ $: << "lib"
68
+ require 'ruby_parser'
69
+
70
+ parser = if ENV["V"] == "18" then
71
+ Ruby18Parser.new
72
+ else
73
+ Ruby19Parser.new
74
+ end
75
+
76
+ file = ENV["F"] || ENV["FILE"]
77
+
78
+ ruby = if file then
79
+ File.read(file)
80
+ else
81
+ file = "env"
82
+ ENV["R"] || ENV["RUBY"]
83
+ end
84
+
85
+ puts process(ruby, file)
86
+ end
87
+
88
+ task :bugs do
89
+ sh "for f in bug*.rb ; do #{Gem.ruby} -S rake debug F=$f && rm $f ; done"
90
+ end
91
+
92
+ # vim: syntax=ruby
@@ -0,0 +1,26 @@
1
+ # Original comment from Ryan:
2
+ #
3
+ # > REFACTOR: stolen from ruby_parser
4
+ #
5
+ # Maybe there's an explanation in ruby_parser?
6
+ #
7
+ class Regexp
8
+ unless defined? ENC_NONE then
9
+ ENC_NONE = /x/n.options
10
+ ENC_EUC = /x/e.options
11
+ ENC_SJIS = /x/s.options
12
+ ENC_UTF8 = /x/u.options
13
+ end
14
+
15
+ unless defined? CODES then
16
+ CODES = {
17
+ EXTENDED => 'x',
18
+ IGNORECASE => 'i',
19
+ MULTILINE => 'm',
20
+ ENC_NONE => 'n',
21
+ ENC_EUC => 'e',
22
+ ENC_SJIS => 's',
23
+ ENC_UTF8 => 'u',
24
+ }
25
+ end
26
+ end
@@ -0,0 +1,7 @@
1
+ module Sexp2Ruby
2
+
3
+ # Raised when `Processor` is initialized with an unknown
4
+ # option, or a known option with an invalid value.
5
+ class InvalidOption < StandardError
6
+ end
7
+ end