unparser 0.1.7 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +7 -0
  3. data/.travis.yml +3 -0
  4. data/Changelog.md +4 -0
  5. data/README.md +4 -2
  6. data/config/flay.yml +1 -1
  7. data/config/flog.yml +1 -1
  8. data/config/reek.yml +24 -19
  9. data/config/rubocop.yml +2 -3
  10. data/lib/unparser.rb +8 -22
  11. data/lib/unparser/ast.rb +232 -0
  12. data/lib/unparser/ast/local_variable_scope.rb +198 -0
  13. data/lib/unparser/cli.rb +41 -24
  14. data/lib/unparser/cli/differ.rb +38 -16
  15. data/lib/unparser/cli/source.rb +46 -17
  16. data/lib/unparser/constants.rb +23 -6
  17. data/lib/unparser/emitter.rb +32 -0
  18. data/lib/unparser/emitter/argument.rb +30 -4
  19. data/lib/unparser/emitter/assignment.rb +12 -1
  20. data/lib/unparser/emitter/begin.rb +23 -2
  21. data/lib/unparser/emitter/case.rb +1 -1
  22. data/lib/unparser/emitter/class.rb +1 -0
  23. data/lib/unparser/emitter/def.rb +28 -1
  24. data/lib/unparser/emitter/defined.rb +3 -1
  25. data/lib/unparser/emitter/flow_modifier.rb +63 -0
  26. data/lib/unparser/emitter/if.rb +44 -0
  27. data/lib/unparser/emitter/literal/dynamic.rb +25 -1
  28. data/lib/unparser/emitter/literal/hash.rb +3 -3
  29. data/lib/unparser/emitter/literal/primitive.rb +9 -47
  30. data/lib/unparser/emitter/literal/regexp.rb +5 -16
  31. data/lib/unparser/emitter/module.rb +1 -0
  32. data/lib/unparser/emitter/repetition.rb +52 -0
  33. data/lib/unparser/emitter/resbody.rb +4 -2
  34. data/lib/unparser/emitter/rescue.rb +12 -2
  35. data/lib/unparser/emitter/root.rb +2 -11
  36. data/lib/unparser/emitter/send.rb +19 -2
  37. data/lib/unparser/emitter/send/index.rb +42 -4
  38. data/lib/unparser/emitter/send/unary.rb +4 -0
  39. data/lib/unparser/emitter/undef.rb +1 -3
  40. data/lib/unparser/node_helpers.rb +13 -1
  41. data/lib/unparser/preprocessor.rb +226 -0
  42. data/lib/unparser/strip_helper.rb +23 -0
  43. data/rubyspec.sh +20 -0
  44. data/spec/spec_helper.rb +2 -0
  45. data/spec/unit/unparser_spec.rb +390 -151
  46. data/unparser.gemspec +1 -1
  47. metadata +27 -24
  48. data/lib/unparser/cli/preprocessor.rb +0 -197
  49. data/lib/unparser/emitter/break.rb +0 -27
  50. data/lib/unparser/emitter/next.rb +0 -28
  51. data/lib/unparser/emitter/return.rb +0 -41
data/unparser.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |gem|
4
4
  gem.name = 'unparser'
5
- gem.version = '0.1.7'
5
+ gem.version = '0.1.8'
6
6
 
7
7
  gem.authors = ['Markus Schirp']
8
8
  gem.email = 'mbj@schir-dso.com'
metadata CHANGED
@@ -1,97 +1,97 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unparser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Markus Schirp
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-03 00:00:00.000000000 Z
11
+ date: 2014-01-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parser
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
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
26
  version: 2.1.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: procto
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: 0.0.2
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: 0.0.2
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: concord
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: 0.1.4
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: 0.1.4
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: adamantium
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ~>
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0.1'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ~>
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0.1'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: equalizer
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ~>
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
75
  version: 0.0.7
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ~>
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: 0.0.7
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: abstract_type
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ~>
87
+ - - "~>"
88
88
  - !ruby/object:Gem::Version
89
89
  version: 0.0.7
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ~>
94
+ - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: 0.0.7
97
97
  description: Generate equivalent source for parser gem AST nodes
@@ -102,9 +102,10 @@ extensions: []
102
102
  extra_rdoc_files:
103
103
  - README.md
104
104
  files:
105
- - .gitignore
106
- - .rspec
107
- - .travis.yml
105
+ - ".gitignore"
106
+ - ".rspec"
107
+ - ".rubocop.yml"
108
+ - ".travis.yml"
108
109
  - Changelog.md
109
110
  - Gemfile
110
111
  - Gemfile.devtools
@@ -123,11 +124,12 @@ files:
123
124
  - config/rubocop.yml
124
125
  - config/yardstick.yml
125
126
  - lib/unparser.rb
127
+ - lib/unparser/ast.rb
128
+ - lib/unparser/ast/local_variable_scope.rb
126
129
  - lib/unparser/buffer.rb
127
130
  - lib/unparser/cli.rb
128
131
  - lib/unparser/cli/color.rb
129
132
  - lib/unparser/cli/differ.rb
130
- - lib/unparser/cli/preprocessor.rb
131
133
  - lib/unparser/cli/source.rb
132
134
  - lib/unparser/comments.rb
133
135
  - lib/unparser/constants.rb
@@ -138,7 +140,6 @@ files:
138
140
  - lib/unparser/emitter/begin.rb
139
141
  - lib/unparser/emitter/binary.rb
140
142
  - lib/unparser/emitter/block.rb
141
- - lib/unparser/emitter/break.rb
142
143
  - lib/unparser/emitter/case.rb
143
144
  - lib/unparser/emitter/cbase.rb
144
145
  - lib/unparser/emitter/class.rb
@@ -147,6 +148,7 @@ files:
147
148
  - lib/unparser/emitter/empty.rb
148
149
  - lib/unparser/emitter/ensure.rb
149
150
  - lib/unparser/emitter/flipflop.rb
151
+ - lib/unparser/emitter/flow_modifier.rb
150
152
  - lib/unparser/emitter/for.rb
151
153
  - lib/unparser/emitter/hookexe.rb
152
154
  - lib/unparser/emitter/if.rb
@@ -162,14 +164,12 @@ files:
162
164
  - lib/unparser/emitter/literal/singleton.rb
163
165
  - lib/unparser/emitter/match.rb
164
166
  - lib/unparser/emitter/module.rb
165
- - lib/unparser/emitter/next.rb
166
167
  - lib/unparser/emitter/op_assign.rb
167
168
  - lib/unparser/emitter/redo.rb
168
169
  - lib/unparser/emitter/repetition.rb
169
170
  - lib/unparser/emitter/resbody.rb
170
171
  - lib/unparser/emitter/rescue.rb
171
172
  - lib/unparser/emitter/retry.rb
172
- - lib/unparser/emitter/return.rb
173
173
  - lib/unparser/emitter/root.rb
174
174
  - lib/unparser/emitter/send.rb
175
175
  - lib/unparser/emitter/send/arguments.rb
@@ -185,6 +185,9 @@ files:
185
185
  - lib/unparser/emitter/yield.rb
186
186
  - lib/unparser/finalize.rb
187
187
  - lib/unparser/node_helpers.rb
188
+ - lib/unparser/preprocessor.rb
189
+ - lib/unparser/strip_helper.rb
190
+ - rubyspec.sh
188
191
  - spec/spec_helper.rb
189
192
  - spec/unit/unparser/buffer/append_spec.rb
190
193
  - spec/unit/unparser/buffer/append_without_prefix_spec.rb
@@ -211,17 +214,17 @@ require_paths:
211
214
  - lib
212
215
  required_ruby_version: !ruby/object:Gem::Requirement
213
216
  requirements:
214
- - - '>='
217
+ - - ">="
215
218
  - !ruby/object:Gem::Version
216
219
  version: '0'
217
220
  required_rubygems_version: !ruby/object:Gem::Requirement
218
221
  requirements:
219
- - - '>='
222
+ - - ">="
220
223
  - !ruby/object:Gem::Version
221
224
  version: '0'
222
225
  requirements: []
223
226
  rubyforge_project:
224
- rubygems_version: 2.0.14
227
+ rubygems_version: 2.2.0
225
228
  signing_key:
226
229
  specification_version: 4
227
230
  summary: Generate equivalent source for parser gem AST nodes
@@ -1,197 +0,0 @@
1
- # encoding: utf-8
2
-
3
- module Unparser
4
- class CLI
5
-
6
- # CLI Specific preprocessor used for equivalency testing
7
- class Preprocessor
8
- include Adamantium::Flat, NodeHelpers, AbstractType, Concord.new(:node), Procto.call(:result)
9
-
10
- # Return preprocessor result
11
- #
12
- # @return [Parser::AST::Node]
13
- #
14
- # @api private
15
- #
16
- abstract_method :result
17
-
18
- # Run preprocessor for node
19
- #
20
- # @param [Parser::AST::Node, nil] node
21
- #
22
- # @return [Parser::AST::Node, nil]
23
- #
24
- # @api private
25
- #
26
- def self.run(node)
27
- return if node.nil?
28
- REGISTRY.fetch(node.type, Noop).new(node).result
29
- end
30
-
31
- REGISTRY = {}
32
-
33
- # Register preprocessor
34
- #
35
- # @param [Symbol] type
36
- #
37
- # @return [undefined]
38
- #
39
- # @api private
40
- #
41
- def self.register(type)
42
- REGISTRY[type] = self
43
- end
44
- private_class_method :register
45
-
46
- private
47
-
48
- # Visit node
49
- #
50
- # @param [Parser::AST::Node]
51
- #
52
- # @api private
53
- #
54
- def visit(node)
55
- self.class.run(node)
56
- end
57
-
58
- # Return children
59
- #
60
- # @return [Array<Parser::AST::Node>]
61
- #
62
- # @api private
63
- #
64
- def children
65
- node.children
66
- end
67
-
68
- # Return mapped children
69
- #
70
- # @return [Array<Parser::Ast::Node>]
71
- #
72
- # @api private
73
- #
74
- def mapped_children
75
- children.map do |node|
76
- if node.kind_of?(Parser::AST::Node)
77
- visit(node)
78
- else
79
- node
80
- end
81
- end
82
- end
83
-
84
- # Noop preprocessor that just passes through noode.
85
- class Noop < self
86
-
87
- # Return preprocessor result
88
- #
89
- # @return [Parser::AST::Node]
90
- #
91
- # @api private
92
- #
93
- def result
94
- s(node.type, mapped_children)
95
- end
96
-
97
- end # Noop
98
-
99
- # Preprocessor for dynamic string nodes. Collapses adjacent string segments into one.
100
- class Dstr < self
101
-
102
- register :dstr
103
-
104
- # Return preprocessor result
105
- #
106
- # @return [Parser::AST::Node]
107
- #
108
- # @api private
109
- #
110
- def result
111
- if collapsed_children.all? { |node| node.type == :str }
112
- s(:str, [collapsed_children.map { |node| node.children.first }.join])
113
- else
114
- node.updated(nil, collapsed_children)
115
- end
116
- end
117
-
118
- private
119
-
120
- # Return collapsed children
121
- #
122
- # @return [Array<Parser::AST::Node>]
123
- #
124
- # @api private
125
- #
126
- def collapsed_children
127
- chunked_children.each_with_object([]) do |(type, nodes), aggregate|
128
- if type == :str
129
- aggregate << s(:str, [nodes.map { |node| node.children.first }.join])
130
- else
131
- aggregate.concat(nodes)
132
- end
133
- end
134
- end
135
- memoize :collapsed_children
136
-
137
- # Return chunked children
138
- #
139
- # @return [Array<Parser::AST::Node>]
140
- #
141
- # @api private
142
- #
143
- def chunked_children
144
- mapped_children.chunk do |item|
145
- item.type
146
- end
147
- end
148
-
149
- end # Begin
150
-
151
- # Preprocessor for regexp nodes. Normalizes quoting.
152
- class Regexp < self
153
-
154
- register :regexp
155
-
156
- # Return preprocesso result
157
- #
158
- # @return [Parser::AST::Node]
159
- #
160
- # @api private
161
- #
162
- def result
163
- location = node.location
164
- if location && location.begin.source.start_with?('%r')
165
- Parser::CurrentRuby.parse(Unparser.unparse(node))
166
- else
167
- node
168
- end
169
- end
170
- end
171
-
172
- # Preprocessor for begin nodes. Removes begin nodes with one child.
173
- #
174
- # These superflownosely currently get generated by unparser.
175
- #
176
- class Begin < self
177
-
178
- register :begin
179
-
180
- # Return preprocessor result
181
- #
182
- # @return [Parser::AST::Node]
183
- #
184
- # @api private
185
- #
186
- def result
187
- if children.one?
188
- visit(children.first)
189
- else
190
- Noop.call(node)
191
- end
192
- end
193
-
194
- end # Begin
195
- end # Preprocessor
196
- end # CLI
197
- end # Unparser
@@ -1,27 +0,0 @@
1
- # encoding: utf-8
2
-
3
- module Unparser
4
- class Emitter
5
- # Emitter for break nodes
6
- class Break < Return
7
-
8
- handle :break
9
-
10
- private
11
-
12
- # Perform dispatch
13
- #
14
- # @return [undefined]
15
- #
16
- # @api private
17
- #
18
- def dispatch
19
- conditional_parentheses(parent_type == :or || parent_type == :and) do
20
- write(K_BREAK)
21
- emit_break_return_arguments
22
- end
23
- end
24
-
25
- end # Break
26
- end # Emitter
27
- end # Unparser
@@ -1,28 +0,0 @@
1
- # encoding: utf-8
2
-
3
- module Unparser
4
- class Emitter
5
- # Emitter for next nodes
6
- class Next < self
7
-
8
- handle :next
9
-
10
- private
11
-
12
- # Perform dispatch
13
- #
14
- # @return [undefined]
15
- #
16
- # @api private
17
- #
18
- def dispatch
19
- conditional_parentheses(parent_type == :or || parent_type == :and) do
20
- write(K_NEXT)
21
- return if children.empty?
22
- visit_parentheses(children.first)
23
- end
24
- end
25
-
26
- end # Next
27
- end # Emitter
28
- end # Unparser