sorcerer 0.3.0 → 0.3.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.
data/README.textile CHANGED
@@ -7,6 +7,8 @@ p. Sorcerer is targetted mainly at small snippets of Ruby code,
7
7
  expressable in a single line. Longer examples may be re-sourced, but
8
8
  they will be rendered in a single line format.
9
9
 
10
+ *Version: 0.3.1*
11
+
10
12
  h2. Limitations
11
13
 
12
14
  Sorcerer is only testing on Ruby 1.9.
@@ -120,8 +122,16 @@ output emitted, then use the debug option:
120
122
  h2. History
121
123
 
122
124
  * 0.0.7 - Basic single line version
125
+
123
126
  * 0.1.0 - Added support for multi-line output. Improved rendering of a
124
- number of constructs
127
+ number of constructs
128
+
125
129
  * 0.2.0 - Added support for indented output.
126
130
 
131
+ * 0.3.0 - New hash literal support. Multi-line output always end with
132
+ a newline.
133
+
134
+ * 0.3.1 - 1.9.3 support. Indenting stabby procs. RedCloth not required
135
+ for testing.
136
+
127
137
 
@@ -261,6 +261,11 @@ module Sorcerer
261
261
  PASS2 = lambda { |sexp| resource(sexp[2]) }
262
262
  EMIT1 = lambda { |sexp| emit(sexp[1]) }
263
263
 
264
+ # Earlier versions of ripper miss array node for words, see
265
+ # http://bugs.ruby-lang.org/issues/4365 for more details
266
+ MISSES_ARRAY_NODE_FOR_WORDS = RUBY_VERSION < '1.9.2' ||
267
+ (RUBY_VERSION == '1.9.2' && RUBY_PATCHLEVEL < 320)
268
+
264
269
  HANDLERS = {
265
270
  # parser keywords
266
271
 
@@ -345,9 +350,15 @@ module Sorcerer
345
350
  :args_new => NOOP,
346
351
  :args_prepend => NYI,
347
352
  :array => lambda { |sexp|
348
- emit("[")
349
- resource(sexp[1]) if sexp[1]
350
- emit("]")
353
+ if !MISSES_ARRAY_NODE_FOR_WORDS &&
354
+ sexp[1] &&
355
+ [:words_add, :qwords_add].include?(sexp[1].first)
356
+ resource(sexp[1])
357
+ else
358
+ emit("[")
359
+ resource(sexp[1]) if sexp[1]
360
+ emit("]")
361
+ end
351
362
  },
352
363
  :assign => lambda { |sexp|
353
364
  resource(sexp[1])
@@ -580,14 +591,16 @@ module Sorcerer
580
591
  emit("->")
581
592
  resource(sexp[1])
582
593
  emit(" {")
583
- if ! void?(sexp[2])
584
- soft_newline
585
- resource(sexp[2])
586
- end
587
- if void?(sexp[2])
588
- emit(" ")
589
- else
590
- soft_newline
594
+ indent do
595
+ if ! void?(sexp[2])
596
+ soft_newline
597
+ resource(sexp[2])
598
+ end
599
+ if void?(sexp[2])
600
+ emit(" ")
601
+ else
602
+ soft_newline
603
+ end
591
604
  end
592
605
  emit("}")
593
606
  },
@@ -698,9 +711,16 @@ module Sorcerer
698
711
  end
699
712
  },
700
713
  :rescue_mod => lambda { |sexp|
701
- resource(sexp[2])
714
+ if RUBY_VERSION <= '1.9.2'
715
+ # Pre ruby 1.9.3 these nodes were returned in the reverse order, see
716
+ # http://bugs.ruby-lang.org/issues/4716 for more details
717
+ first_node, second_node = sexp[2], sexp[1]
718
+ else
719
+ first_node, second_node = sexp[1], sexp[2]
720
+ end
721
+ resource(first_node)
702
722
  emit(" rescue ")
703
- resource(sexp[1])
723
+ resource(second_node)
704
724
  },
705
725
  :rest_param => lambda { |sexp|
706
726
  emit("*")
@@ -796,6 +816,7 @@ module Sorcerer
796
816
  :var_alias => NYI,
797
817
  :var_field => PASS1,
798
818
  :var_ref => PASS1,
819
+ :vcall => PASS1,
799
820
  :void_stmt => NOOP,
800
821
  :when => lambda { |sexp|
801
822
  outdent do emit("when ") end
@@ -32,7 +32,7 @@ module Sorcerer
32
32
 
33
33
  def tagged_sexp(sexp)
34
34
  case sexp.first
35
- when :var_ref, :binary, :array, :hash, :unary
35
+ when :var_ref, :vcall, :binary, :array, :hash, :unary
36
36
  @result << sexp
37
37
  list_sexp(sexp)
38
38
  when :aref
@@ -1,7 +1,7 @@
1
1
  module Sorcerer
2
2
  VERSION_MAJOR = 0
3
3
  VERSION_MINOR = 3
4
- VERSION_BUILD = 0
4
+ VERSION_BUILD = 1
5
5
  VERSION_BETA = 0
6
6
 
7
7
  VERSION_NUMBERS = [VERSION_MAJOR, VERSION_MINOR, VERSION_BUILD] +
data/rakelib/git.rake CHANGED
@@ -1,4 +1,3 @@
1
-
2
1
  namespace "git" do
3
2
  desc "Tag the current version of the project as #{PROJ}-#{PKG_VERSION}"
4
3
  task :tag do
data/rakelib/readme.rake CHANGED
@@ -1,19 +1,44 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'redcloth'
3
+ begin
4
+ require 'redcloth'
5
+ directory "html"
4
6
 
5
- directory "html"
7
+ desc "Display the README file"
8
+ task :readme => "html/README.html" do
9
+ sh "open html/README.html"
10
+ end
6
11
 
7
- desc "Display the README file"
8
- task :readme => "html/README.html" do
9
- sh "open html/README.html"
10
- end
12
+ desc "format the README file"
13
+ task "html/README.html" => ['html', 'README.textile', "readme:update"] do
14
+ open("README.textile") do |source|
15
+ open('html/README.html', 'w') do |out|
16
+ out.write(RedCloth.new(source.read).to_html)
17
+ end
18
+ end
19
+ end
11
20
 
12
- desc "format the README file"
13
- task "html/README.html" => ['html', 'README.textile'] do
14
- open("README.textile") do |source|
15
- open('html/README.html', 'w') do |out|
16
- out.write(RedCloth.new(source.read).to_html)
21
+ namespace "readme" do
22
+ desc "Update the version in the readme"
23
+ task :update do
24
+ open("README.textile") do |ins|
25
+ open("new_readme.txt", "w") do |outs|
26
+ while line = ins.gets
27
+ if line =~ /^\*Version: .*\*$/
28
+ line = "*Version: #{PKG_VERSION}*"
29
+ end
30
+ outs.puts line
31
+ end
32
+ end
33
+ end
34
+ mv "README.textile", "README.bak"
35
+ mv "new_readme.txt", "README.textile"
17
36
  end
18
37
  end
38
+
39
+ rescue LoadError => ex
40
+ task :readme do
41
+ fail "Install RedCloth to generate the README"
42
+ end
19
43
  end
44
+
@@ -32,10 +32,10 @@ class SourcerTest < Test::Unit::TestCase
32
32
  # * "#" is expected to be a tabbed indent in indent mode and a null
33
33
  # string in single line and multi-line modes.
34
34
  #
35
- def assert_resource_lines(string)
36
- assert_resource_for_mode(string, multiline: false) { |s| for_single_line(s) }
37
- assert_resource_for_mode(string, multiline: true) { |s| for_multi_line(s) }
38
- assert_resource_for_mode(string, indent: true) { |s| for_indented(s) }
35
+ def assert_resource_lines(string, options={})
36
+ assert_resource_for_mode(string, options.merge(multiline: false)) { |s| for_single_line(s) }
37
+ assert_resource_for_mode(string, options.merge(multiline: true)) { |s| for_multi_line(s) }
38
+ assert_resource_for_mode(string, options.merge(indent: true)) { |s| for_indented(s) }
39
39
  end
40
40
 
41
41
  # Assert the string is correctly resourced given the options and the
@@ -68,12 +68,20 @@ class SourcerTest < Test::Unit::TestCase
68
68
  gsub(/#/,' ') + "\n"
69
69
  end
70
70
 
71
+ def quietly
72
+ original_verbosity = $VERBOSE
73
+ $VERBOSE = nil
74
+ yield
75
+ ensure
76
+ $VERBOSE = original_verbosity
77
+ end
78
+
71
79
  def source(string, options={})
72
80
  if options[:debug]
73
81
  puts
74
82
  puts "***************************** options: #{options.inspect}"
75
83
  end
76
- sexp = Ripper::SexpBuilder.new(string).parse
84
+ sexp = quietly { Ripper::SexpBuilder.new(string).parse }
77
85
  fail "Failed to parts '#{string}'" if sexp.nil?
78
86
  Sorcerer.source(sexp, options)
79
87
  end
@@ -151,7 +159,7 @@ class SourcerTest < Test::Unit::TestCase
151
159
  assert_resource "meth &code"
152
160
  assert_resource "meth a, &code"
153
161
  assert_resource "meth a, *args, &code"
154
- assert_resource "meth a, *args do |x| x.y end",
162
+ assert_resource "meth a, *args do |x| x.y end"
155
163
  end
156
164
 
157
165
  def test_can_source_method_with_bare_assoc
@@ -204,7 +212,7 @@ class SourcerTest < Test::Unit::TestCase
204
212
  assert_resource_lines "->(a, b) { }"
205
213
  assert_resource_lines "->(a, *args) { }"
206
214
  assert_resource_lines "->(a, b=12, *args, &block) { }"
207
- assert_resource_lines "->(a) {~b~}"
215
+ assert_resource_lines "->(a) {~#b~}"
208
216
  end
209
217
 
210
218
  def test_can_source_dot_calls
@@ -623,7 +631,7 @@ class SourcerTest < Test::Unit::TestCase
623
631
  end
624
632
 
625
633
  def test_can_use_ripper_sexp_output
626
- sexp = Ripper.sexp("a = 1")
634
+ sexp = quietly { Ripper.sexp("a = 1") }
627
635
  assert_equal "a = 1", Sorcerer.source(sexp)
628
636
  end
629
637
 
metadata CHANGED
@@ -1,27 +1,23 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: sorcerer
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.1
4
5
  prerelease:
5
- version: 0.3.0
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Jim Weirich
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2012-07-05 00:00:00 Z
12
+ date: 2012-07-09 00:00:00.000000000 Z
14
13
  dependencies: []
15
-
16
- description: Generate the original Ruby source from a Ripper-style abstract syntax tree.
14
+ description: Generate the original Ruby source from a Ripper-style abstract syntax
15
+ tree.
17
16
  email: jim.weirich@gmail.com
18
17
  executables: []
19
-
20
18
  extensions: []
21
-
22
19
  extra_rdoc_files: []
23
-
24
- files:
20
+ files:
25
21
  - README.textile
26
22
  - Rakefile
27
23
  - doc/jamis.rb
@@ -36,35 +32,32 @@ files:
36
32
  - test/sorcerer/subexpression_test.rb
37
33
  homepage: http://github.com/jimweirich/sorcerer
38
34
  licenses: []
39
-
40
35
  post_install_message:
41
- rdoc_options:
36
+ rdoc_options:
42
37
  - --line-numbers
43
38
  - --inline-source
44
39
  - --main
45
40
  - README.textile
46
41
  - --title
47
42
  - Rake -- Ruby Make
48
- require_paths:
43
+ require_paths:
49
44
  - lib
50
- required_ruby_version: !ruby/object:Gem::Requirement
45
+ required_ruby_version: !ruby/object:Gem::Requirement
51
46
  none: false
52
- requirements:
53
- - - ">="
54
- - !ruby/object:Gem::Version
55
- version: "0"
56
- required_rubygems_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ! '>='
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
52
  none: false
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: "0"
53
+ requirements:
54
+ - - ! '>='
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
62
57
  requirements: []
63
-
64
58
  rubyforge_project: sorcerer
65
59
  rubygems_version: 1.8.15
66
60
  signing_key:
67
61
  specification_version: 3
68
62
  summary: Generate Source from Ripper ASTs
69
63
  test_files: []
70
-