unparser 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 542027219be6631d4a41c34550f0b6cbf0c1335b
4
- data.tar.gz: 622b9928d15fd69b03532eca141ea7e13e2f606f
3
+ metadata.gz: 3273de4b72cb214d459c8519c3a3e6c3a0d06e4e
4
+ data.tar.gz: dc7c765cef957d3fafcdfbf36691b56695c29443
5
5
  SHA512:
6
- metadata.gz: 94566c0a67b0b1f47fc0a80248b2bcac686ec2e63f07e36ea258f034190e989cebde63c332a620caa42269556c7de4504f5225670d38c973f4b62f5e59f2b246
7
- data.tar.gz: 633ec7ea22ade4ed28dd99796de71ac8088b94d389aa6edff71ae1934f2dff93576ab36b9681b2f15ddd2755d3bd9683d03efb69ceee7699f4be37f027823273
6
+ metadata.gz: e27666e1e5c927f64ac11777754b9e9f6df2ad61c8c62c9ca801c026ceda16b75dee95f37ae8e6b313d8ac4ac03ba273f3f7fb355f40fd03c3843a1d2ab0ea5b
7
+ data.tar.gz: 7c65227ff6738eb937e677a0b17d5fd2d1908a336f187786a0ab42ca68e3c6e38c3e25e233595ad4579579b2076cdff5b7eb66c194daab369e9e2e8b6ba86279
data/TODO CHANGED
@@ -1 +1,2 @@
1
- Refactor Emitter::Send, it is ugly.
1
+ * Refactor Emitter::Send, it is ugly.
2
+ * Remove duplicated logic with empty or non empty bodies
data/bin/unparse ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ trap('INT') do |status|
4
+ exit! 128+status
5
+ end
6
+
7
+ require 'unparser'
8
+ require 'parser/current'
9
+
10
+ ARGV.each do |file|
11
+ source = File.read(file)
12
+ node = Parser::CurrentRuby.parse(source)
13
+ $stderr.puts "File: #{file}"
14
+ $stderr.puts node.inspect
15
+ puts Unparser.unparse(node)
16
+ end
data/lib/unparser.rb CHANGED
@@ -88,5 +88,5 @@ require 'unparser/emitter/repetition'
88
88
  require 'unparser/emitter/root'
89
89
  require 'unparser/emitter/match'
90
90
  require 'unparser/emitter/empty'
91
-
92
- Unparser::Emitter::REGISTRY.freeze
91
+ # make it easy for zombie
92
+ require 'unparser/finalize'
@@ -79,7 +79,12 @@ module Unparser
79
79
  def dispatch
80
80
  write(K_WHEN, WS)
81
81
  emit_captures
82
- indented { visit(children.last) }
82
+ body = children.last
83
+ if body
84
+ indented { visit(body) }
85
+ else
86
+ nl
87
+ end
83
88
  end
84
89
 
85
90
  # Emit captures
@@ -51,8 +51,8 @@ module Unparser
51
51
 
52
52
  # Array literal emitter
53
53
  class Array < self
54
- OPEN = '['.freeze
55
- CLOSE = ']'.freeze
54
+ OPEN = '['.freeze
55
+ CLOSE = ']'.freeze
56
56
  DELIMITER = ', '.freeze
57
57
 
58
58
  handle :array
@@ -9,22 +9,6 @@ module Unparser
9
9
 
10
10
  private
11
11
 
12
- # Dispatch node
13
- #
14
- # @return [undefined]
15
- #
16
- # @api private
17
- #
18
- def dispatch
19
- if node.location
20
- emit_source_map
21
- else
22
- dispatch_value
23
- end
24
- end
25
-
26
- abstract_method :disaptch_value
27
-
28
12
  # Emitter for primitives based on Object#inspect
29
13
  class Inspect < self
30
14
 
@@ -38,7 +22,7 @@ module Unparser
38
22
  #
39
23
  # @api private
40
24
  #
41
- def dispatch_value
25
+ def dispatch
42
26
  buffer.append(value.inspect)
43
27
  end
44
28
 
@@ -10,7 +10,7 @@ module Unparser
10
10
 
11
11
  MAP = {
12
12
  :while_post => K_WHILE,
13
- :until_until => K_UNTIL
13
+ :until_post => K_UNTIL
14
14
  }.freeze
15
15
 
16
16
  handle *MAP.keys
@@ -0,0 +1 @@
1
+ Unparser::Emitter::REGISTRY.freeze
@@ -73,10 +73,11 @@ describe Unparser, 'spike' do
73
73
  assert_generates s(:int, 1), '1'
74
74
  assert_generates s(:int, -1), '-1'
75
75
  assert_source '1'
76
- assert_source '0x1'
77
- assert_source '1_000'
78
- assert_source '1e10'
79
- assert_source '?c'
76
+ assert_generates '0x1', '1'
77
+ assert_generates '1_000', '1000'
78
+ assert_generates '1e10', '10000000000.0'
79
+ assert_generates '?c', '"c"', RUBIES - %w(1.8)
80
+ assert_generates '?c', '99', %w(1.8)
80
81
  end
81
82
 
82
83
  context 'string' do
@@ -147,6 +148,7 @@ describe Unparser, 'spike' do
147
148
  assert_source '[1, *@foo]'
148
149
  assert_source '[*@foo, 1]', RUBIES - %w(1.8)
149
150
  assert_source '[*@foo, *@baz]', RUBIES - %w(1.8)
151
+ assert_generates '%w(foo bar)', %q(["foo", "bar"])
150
152
  end
151
153
 
152
154
  context 'hash' do
@@ -193,9 +195,9 @@ describe Unparser, 'spike' do
193
195
  end
194
196
 
195
197
  context 'magic keywords' do
196
- assert_generates '__ENCODING__', 'Encoding::UTF_8', RUBIES - %w(1.8)
197
- assert_source '__FILE__'
198
- assert_source '__LINE__'
198
+ assert_generates '__ENCODING__', 'Encoding::UTF_8', RUBIES - %w(1.8)
199
+ assert_generates '__FILE__', '"(string)"'
200
+ assert_generates '__LINE__', '1'
199
201
  end
200
202
 
201
203
  context 'assignment' do
@@ -497,7 +499,7 @@ describe Unparser, 'spike' do
497
499
  RUBY
498
500
 
499
501
  assert_source <<-RUBY
500
- alias foo bar
502
+ alias :foo :bar
501
503
  RUBY
502
504
  end
503
505
 
@@ -894,6 +896,15 @@ describe Unparser, 'spike' do
894
896
  end
895
897
  RUBY
896
898
 
899
+ assert_source <<-RUBY
900
+ case foo
901
+ when bar
902
+ when baz
903
+ bar
904
+ end
905
+ RUBY
906
+
907
+
897
908
  assert_source <<-RUBY
898
909
  case foo
899
910
  when bar
@@ -970,6 +981,13 @@ describe Unparser, 'spike' do
970
981
  end while baz
971
982
  RUBY
972
983
 
984
+ assert_source <<-RUBY
985
+ begin
986
+ foo
987
+ bar
988
+ end until baz
989
+ RUBY
990
+
973
991
  assert_source <<-RUBY
974
992
  begin
975
993
  foo
data/unparser.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'unparser'
5
- s.version = '0.0.5'
5
+ s.version = '0.0.6'
6
6
 
7
7
  s.authors = ['Markus Schirp']
8
8
  s.email = 'mbj@schir-dso.com'
@@ -15,6 +15,7 @@ Gem::Specification.new do |s|
15
15
  s.test_files = `git ls-files -- {spec,features}/*`.split("\n")
16
16
  s.require_paths = %w(lib)
17
17
  s.extra_rdoc_files = %w(README.md)
18
+ s.executables = [ 'unparse' ]
18
19
 
19
20
  s.add_dependency('parser', '~> 2.0.0.beta9')
20
21
  s.add_dependency('concord', '~> 0.1.0')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unparser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Markus Schirp
@@ -82,7 +82,8 @@ dependencies:
82
82
  version: 0.0.5
83
83
  description: Generate equivalent source for parser gem AST nodes
84
84
  email: mbj@schir-dso.com
85
- executables: []
85
+ executables:
86
+ - unparse
86
87
  extensions: []
87
88
  extra_rdoc_files:
88
89
  - README.md
@@ -99,6 +100,7 @@ files:
99
100
  - README.md
100
101
  - Rakefile
101
102
  - TODO
103
+ - bin/unparse
102
104
  - config/devtools.yml
103
105
  - config/flay.yml
104
106
  - config/flog.yml
@@ -153,6 +155,7 @@ files:
153
155
  - lib/unparser/emitter/undef.rb
154
156
  - lib/unparser/emitter/variable.rb
155
157
  - lib/unparser/emitter/yield.rb
158
+ - lib/unparser/finalize.rb
156
159
  - spec/integration/unparser/spike_spec.rb
157
160
  - spec/spec_helper.rb
158
161
  - spec/unit/unparser/buffer/append_spec.rb