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 +4 -4
- data/TODO +2 -1
- data/bin/unparse +16 -0
- data/lib/unparser.rb +2 -2
- data/lib/unparser/emitter/case.rb +6 -1
- data/lib/unparser/emitter/literal/composed.rb +2 -2
- data/lib/unparser/emitter/literal/primitive.rb +1 -17
- data/lib/unparser/emitter/repetition.rb +1 -1
- data/lib/unparser/finalize.rb +1 -0
- data/spec/integration/unparser/spike_spec.rb +26 -8
- data/unparser.gemspec +2 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3273de4b72cb214d459c8519c3a3e6c3a0d06e4e
|
4
|
+
data.tar.gz: dc7c765cef957d3fafcdfbf36691b56695c29443
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
@@ -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
|
25
|
+
def dispatch
|
42
26
|
buffer.append(value.inspect)
|
43
27
|
end
|
44
28
|
|
@@ -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
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
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
|
197
|
-
|
198
|
-
|
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
|
+
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.
|
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
|