unparser 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +38 -2
- data/.travis.yml +3 -6
- data/Changelog.md +7 -0
- data/Gemfile +1 -0
- data/Gemfile.devtools +22 -17
- data/README.md +3 -4
- data/TODO +3 -2
- data/bin/unparser +10 -0
- data/circle.yml +2 -0
- data/config/flay.yml +1 -1
- data/config/flog.yml +1 -1
- data/config/reek.yml +10 -0
- data/config/rubocop.yml +9 -17
- data/lib/unparser.rb +8 -1
- data/lib/unparser/buffer.rb +2 -0
- data/lib/unparser/cli.rb +113 -0
- data/lib/unparser/cli/differ.rb +30 -0
- data/lib/unparser/cli/preprocessor.rb +196 -0
- data/lib/unparser/cli/source.rb +118 -0
- data/lib/unparser/comments.rb +64 -23
- data/lib/unparser/constants.rb +19 -7
- data/lib/unparser/emitter.rb +23 -25
- data/lib/unparser/emitter/alias.rb +2 -0
- data/lib/unparser/emitter/argument.rb +2 -0
- data/lib/unparser/emitter/assignment.rb +3 -1
- data/lib/unparser/emitter/begin.rb +3 -6
- data/lib/unparser/emitter/binary.rb +2 -0
- data/lib/unparser/emitter/block.rb +2 -0
- data/lib/unparser/emitter/break.rb +4 -5
- data/lib/unparser/emitter/case.rb +2 -0
- data/lib/unparser/emitter/cbase.rb +2 -0
- data/lib/unparser/emitter/class.rb +4 -3
- data/lib/unparser/emitter/def.rb +2 -0
- data/lib/unparser/emitter/defined.rb +2 -0
- data/lib/unparser/emitter/empty.rb +2 -0
- data/lib/unparser/emitter/ensure.rb +2 -0
- data/lib/unparser/emitter/flipflop.rb +2 -0
- data/lib/unparser/emitter/for.rb +2 -0
- data/lib/unparser/emitter/hookexe.rb +2 -0
- data/lib/unparser/emitter/if.rb +2 -0
- data/lib/unparser/emitter/literal.rb +2 -0
- data/lib/unparser/emitter/literal/array.rb +33 -0
- data/lib/unparser/emitter/literal/dynamic.rb +21 -1
- data/lib/unparser/emitter/literal/dynamic_body.rb +9 -5
- data/lib/unparser/emitter/literal/execute_string.rb +2 -0
- data/lib/unparser/emitter/literal/hash.rb +136 -0
- data/lib/unparser/emitter/literal/primitive.rb +4 -2
- data/lib/unparser/emitter/literal/range.rb +2 -0
- data/lib/unparser/emitter/literal/regexp.rb +4 -2
- data/lib/unparser/emitter/literal/singleton.rb +2 -0
- data/lib/unparser/emitter/match.rb +2 -0
- data/lib/unparser/emitter/module.rb +2 -3
- data/lib/unparser/emitter/next.rb +2 -0
- data/lib/unparser/emitter/op_assign.rb +3 -1
- data/lib/unparser/emitter/redo.rb +2 -0
- data/lib/unparser/emitter/repetition.rb +2 -0
- data/lib/unparser/emitter/resbody.rb +2 -0
- data/lib/unparser/emitter/rescue.rb +2 -0
- data/lib/unparser/emitter/retry.rb +2 -0
- data/lib/unparser/emitter/return.rb +19 -4
- data/lib/unparser/emitter/root.rb +13 -0
- data/lib/unparser/emitter/send.rb +26 -22
- data/lib/unparser/emitter/send/arguments.rb +46 -0
- data/lib/unparser/emitter/send/attribute_assignment.rb +35 -0
- data/lib/unparser/emitter/send/binary.rb +2 -0
- data/lib/unparser/emitter/send/index.rb +2 -0
- data/lib/unparser/emitter/send/regular.rb +4 -2
- data/lib/unparser/emitter/send/unary.rb +3 -1
- data/lib/unparser/emitter/splat.rb +2 -0
- data/lib/unparser/emitter/super.rb +2 -0
- data/lib/unparser/emitter/undef.rb +2 -0
- data/lib/unparser/emitter/variable.rb +2 -0
- data/lib/unparser/emitter/yield.rb +2 -0
- data/lib/unparser/finalize.rb +2 -0
- data/lib/unparser/node_helpers.rb +19 -0
- data/spec/spec_helper.rb +10 -0
- data/spec/unit/unparser/buffer/append_spec.rb +2 -0
- data/spec/unit/unparser/buffer/append_without_prefix_spec.rb +2 -0
- data/spec/unit/unparser/buffer/capture_content_spec.rb +2 -0
- data/spec/unit/unparser/buffer/content_spec.rb +3 -1
- data/spec/unit/unparser/buffer/fresh_line_spec.rb +2 -0
- data/spec/unit/unparser/buffer/indent_spec.rb +3 -1
- data/spec/unit/unparser/buffer/nl_spec.rb +2 -0
- data/spec/unit/unparser/buffer/unindent_spec.rb +2 -0
- data/spec/unit/unparser/comments/consume_spec.rb +2 -1
- data/spec/unit/unparser/comments/take_all_spec.rb +2 -1
- data/spec/unit/unparser/comments/take_before_spec.rb +6 -5
- data/spec/unit/unparser/comments/take_eol_comments_spec.rb +2 -1
- data/spec/unit/unparser/emitter/class_methods/handle_spec.rb +2 -0
- data/spec/unit/unparser_spec.rb +110 -57
- data/unparser.gemspec +5 -4
- metadata +32 -12
- data/bin/test-unparser +0 -26
- data/lib/unparser/emitter/literal/composed.rb +0 -64
- data/spec/unit/unparser/comments/skip_eol_comment_spec.rb +0 -29
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.1.
|
5
|
+
s.version = '0.1.6'
|
6
6
|
|
7
7
|
s.authors = ['Markus Schirp']
|
8
8
|
s.email = 'mbj@schir-dso.com'
|
@@ -15,11 +15,12 @@ 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 = [ '
|
18
|
+
s.executables = [ 'unparser' ]
|
19
19
|
|
20
|
-
s.add_dependency('parser', '~> 2.
|
20
|
+
s.add_dependency('parser', '~> 2.1.0')
|
21
|
+
s.add_dependency('procto', '~> 0.0.2')
|
21
22
|
s.add_dependency('concord', '~> 0.1.4')
|
22
|
-
s.add_dependency('adamantium', '~> 0.1
|
23
|
+
s.add_dependency('adamantium', '~> 0.1')
|
23
24
|
s.add_dependency('equalizer', '~> 0.0.7')
|
24
25
|
s.add_dependency('abstract_type', '~> 0.0.7')
|
25
26
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: unparser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Markus Schirp
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-12-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parser
|
@@ -16,14 +16,28 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ~>
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 2.
|
19
|
+
version: 2.1.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 2.
|
26
|
+
version: 2.1.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: procto
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.0.2
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.0.2
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: concord
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -44,14 +58,14 @@ dependencies:
|
|
44
58
|
requirements:
|
45
59
|
- - ~>
|
46
60
|
- !ruby/object:Gem::Version
|
47
|
-
version: 0.1
|
61
|
+
version: '0.1'
|
48
62
|
type: :runtime
|
49
63
|
prerelease: false
|
50
64
|
version_requirements: !ruby/object:Gem::Requirement
|
51
65
|
requirements:
|
52
66
|
- - ~>
|
53
67
|
- !ruby/object:Gem::Version
|
54
|
-
version: 0.1
|
68
|
+
version: '0.1'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: equalizer
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -83,7 +97,7 @@ dependencies:
|
|
83
97
|
description: Generate equivalent source for parser gem AST nodes
|
84
98
|
email: mbj@schir-dso.com
|
85
99
|
executables:
|
86
|
-
-
|
100
|
+
- unparser
|
87
101
|
extensions: []
|
88
102
|
extra_rdoc_files:
|
89
103
|
- README.md
|
@@ -99,7 +113,7 @@ files:
|
|
99
113
|
- README.md
|
100
114
|
- Rakefile
|
101
115
|
- TODO
|
102
|
-
- bin/
|
116
|
+
- bin/unparser
|
103
117
|
- circle.yml
|
104
118
|
- config/devtools.yml
|
105
119
|
- config/flay.yml
|
@@ -110,6 +124,10 @@ files:
|
|
110
124
|
- config/yardstick.yml
|
111
125
|
- lib/unparser.rb
|
112
126
|
- lib/unparser/buffer.rb
|
127
|
+
- lib/unparser/cli.rb
|
128
|
+
- lib/unparser/cli/differ.rb
|
129
|
+
- lib/unparser/cli/preprocessor.rb
|
130
|
+
- lib/unparser/cli/source.rb
|
113
131
|
- lib/unparser/comments.rb
|
114
132
|
- lib/unparser/constants.rb
|
115
133
|
- lib/unparser/emitter.rb
|
@@ -132,10 +150,11 @@ files:
|
|
132
150
|
- lib/unparser/emitter/hookexe.rb
|
133
151
|
- lib/unparser/emitter/if.rb
|
134
152
|
- lib/unparser/emitter/literal.rb
|
135
|
-
- lib/unparser/emitter/literal/
|
153
|
+
- lib/unparser/emitter/literal/array.rb
|
136
154
|
- lib/unparser/emitter/literal/dynamic.rb
|
137
155
|
- lib/unparser/emitter/literal/dynamic_body.rb
|
138
156
|
- lib/unparser/emitter/literal/execute_string.rb
|
157
|
+
- lib/unparser/emitter/literal/hash.rb
|
139
158
|
- lib/unparser/emitter/literal/primitive.rb
|
140
159
|
- lib/unparser/emitter/literal/range.rb
|
141
160
|
- lib/unparser/emitter/literal/regexp.rb
|
@@ -152,6 +171,8 @@ files:
|
|
152
171
|
- lib/unparser/emitter/return.rb
|
153
172
|
- lib/unparser/emitter/root.rb
|
154
173
|
- lib/unparser/emitter/send.rb
|
174
|
+
- lib/unparser/emitter/send/arguments.rb
|
175
|
+
- lib/unparser/emitter/send/attribute_assignment.rb
|
155
176
|
- lib/unparser/emitter/send/binary.rb
|
156
177
|
- lib/unparser/emitter/send/index.rb
|
157
178
|
- lib/unparser/emitter/send/regular.rb
|
@@ -162,6 +183,7 @@ files:
|
|
162
183
|
- lib/unparser/emitter/variable.rb
|
163
184
|
- lib/unparser/emitter/yield.rb
|
164
185
|
- lib/unparser/finalize.rb
|
186
|
+
- lib/unparser/node_helpers.rb
|
165
187
|
- spec/spec_helper.rb
|
166
188
|
- spec/unit/unparser/buffer/append_spec.rb
|
167
189
|
- spec/unit/unparser/buffer/append_without_prefix_spec.rb
|
@@ -172,7 +194,6 @@ files:
|
|
172
194
|
- spec/unit/unparser/buffer/nl_spec.rb
|
173
195
|
- spec/unit/unparser/buffer/unindent_spec.rb
|
174
196
|
- spec/unit/unparser/comments/consume_spec.rb
|
175
|
-
- spec/unit/unparser/comments/skip_eol_comment_spec.rb
|
176
197
|
- spec/unit/unparser/comments/take_all_spec.rb
|
177
198
|
- spec/unit/unparser/comments/take_before_spec.rb
|
178
199
|
- spec/unit/unparser/comments/take_eol_comments_spec.rb
|
@@ -199,7 +220,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
199
220
|
version: '0'
|
200
221
|
requirements: []
|
201
222
|
rubyforge_project:
|
202
|
-
rubygems_version: 2.0.
|
223
|
+
rubygems_version: 2.0.14
|
203
224
|
signing_key:
|
204
225
|
specification_version: 4
|
205
226
|
summary: Generate equivalent source for parser gem AST nodes
|
@@ -214,7 +235,6 @@ test_files:
|
|
214
235
|
- spec/unit/unparser/buffer/nl_spec.rb
|
215
236
|
- spec/unit/unparser/buffer/unindent_spec.rb
|
216
237
|
- spec/unit/unparser/comments/consume_spec.rb
|
217
|
-
- spec/unit/unparser/comments/skip_eol_comment_spec.rb
|
218
238
|
- spec/unit/unparser/comments/take_all_spec.rb
|
219
239
|
- spec/unit/unparser/comments/take_before_spec.rb
|
220
240
|
- spec/unit/unparser/comments/take_eol_comments_spec.rb
|
data/bin/test-unparser
DELETED
@@ -1,26 +0,0 @@
|
|
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
|
-
generated = Unparser.unparse(node)
|
14
|
-
unparsed = Parser::CurrentRuby.parse(generated)
|
15
|
-
unless unparsed == node
|
16
|
-
$stderr.puts 'Node:'
|
17
|
-
$stderr.puts node.inspect
|
18
|
-
$stderr.puts 'Unparsed-Node:'
|
19
|
-
$stderr.puts unparsed.inspect
|
20
|
-
$stderr.puts 'Original:'
|
21
|
-
$stderr.puts source
|
22
|
-
$stderr.puts 'Generated:'
|
23
|
-
$stderr.puts generated
|
24
|
-
fail 'BUG!'
|
25
|
-
end
|
26
|
-
end
|
@@ -1,64 +0,0 @@
|
|
1
|
-
module Unparser
|
2
|
-
class Emitter
|
3
|
-
class Literal
|
4
|
-
|
5
|
-
# Emitter for hash keyvalue pair
|
6
|
-
class HashPair < self
|
7
|
-
HASHROCKET = ' => '.freeze
|
8
|
-
|
9
|
-
handle :pair
|
10
|
-
|
11
|
-
private
|
12
|
-
|
13
|
-
# Perform dispatch
|
14
|
-
#
|
15
|
-
# @return [undefined]
|
16
|
-
#
|
17
|
-
# @api private
|
18
|
-
#
|
19
|
-
def dispatch
|
20
|
-
delimited(children, HASHROCKET)
|
21
|
-
end
|
22
|
-
|
23
|
-
end # HashPair
|
24
|
-
|
25
|
-
# Base class for compound literal emitters
|
26
|
-
class Compound < self
|
27
|
-
|
28
|
-
private
|
29
|
-
|
30
|
-
# Perform dispatch
|
31
|
-
#
|
32
|
-
# @return [undefined]
|
33
|
-
#
|
34
|
-
# @api private
|
35
|
-
#
|
36
|
-
def dispatch
|
37
|
-
util = self.class
|
38
|
-
parentheses(util::OPEN, util::CLOSE) do
|
39
|
-
delimited(children, util::DELIMITER)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
# Hash literal emitter
|
44
|
-
class Hash < self
|
45
|
-
OPEN = '{'.freeze
|
46
|
-
CLOSE = '}'.freeze
|
47
|
-
DELIMITER = ', '.freeze
|
48
|
-
|
49
|
-
handle :hash
|
50
|
-
end # Hash
|
51
|
-
|
52
|
-
# Array literal emitter
|
53
|
-
class Array < self
|
54
|
-
OPEN = '['.freeze
|
55
|
-
CLOSE = ']'.freeze
|
56
|
-
DELIMITER = ', '.freeze
|
57
|
-
|
58
|
-
handle :array
|
59
|
-
end # Array
|
60
|
-
|
61
|
-
end # Compound
|
62
|
-
end # Literal
|
63
|
-
end # Emitter
|
64
|
-
end # Unparser
|
@@ -1,29 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'parser/current'
|
3
|
-
|
4
|
-
describe Unparser::Comments, '#skip_eol_comment' do
|
5
|
-
|
6
|
-
let(:ast_and_comments) do
|
7
|
-
Parser::CurrentRuby.parse_with_comments(<<-RUBY)
|
8
|
-
def hi # comment
|
9
|
-
end # comment
|
10
|
-
RUBY
|
11
|
-
end
|
12
|
-
let(:ast) { ast_and_comments[0] }
|
13
|
-
let(:comments) { ast_and_comments[1] }
|
14
|
-
let(:object) { described_class.new(comments) }
|
15
|
-
|
16
|
-
it 'should skip the specified comment only for one subsequent take' do
|
17
|
-
object.consume(ast, :name)
|
18
|
-
object.skip_eol_comment('# comment')
|
19
|
-
expect(object.take_eol_comments).to eql([])
|
20
|
-
object.consume(ast, :end)
|
21
|
-
expect(object.take_eol_comments).to eql([comments[1]])
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'should not skip comments with different text' do
|
25
|
-
object.skip_eol_comment('# not the comment')
|
26
|
-
object.consume(ast, :end)
|
27
|
-
expect(object.take_eol_comments).to eql(comments)
|
28
|
-
end
|
29
|
-
end
|