unparser 0.2.4 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. checksums.yaml +4 -4
  2. data/Changelog.md +7 -0
  3. data/Gemfile +1 -7
  4. data/README.md +6 -1
  5. data/Rakefile +11 -2
  6. data/bin/unparser +0 -2
  7. data/config/devtools.yml +1 -1
  8. data/config/flay.yml +1 -1
  9. data/config/flog.yml +1 -1
  10. data/config/reek.yml +4 -1
  11. data/config/rubocop.yml +0 -4
  12. data/lib/unparser.rb +1 -2
  13. data/lib/unparser/ast.rb +0 -2
  14. data/lib/unparser/ast/local_variable_scope.rb +0 -2
  15. data/lib/unparser/buffer.rb +0 -2
  16. data/lib/unparser/cli.rb +3 -4
  17. data/lib/unparser/cli/color.rb +0 -2
  18. data/lib/unparser/cli/differ.rb +0 -2
  19. data/lib/unparser/cli/source.rb +1 -3
  20. data/lib/unparser/comments.rb +0 -2
  21. data/lib/unparser/constants.rb +0 -2
  22. data/lib/unparser/emitter.rb +4 -3
  23. data/lib/unparser/emitter/alias.rb +0 -2
  24. data/lib/unparser/emitter/argument.rb +0 -2
  25. data/lib/unparser/emitter/assignment.rb +0 -2
  26. data/lib/unparser/emitter/begin.rb +1 -3
  27. data/lib/unparser/emitter/binary.rb +0 -2
  28. data/lib/unparser/emitter/block.rb +0 -2
  29. data/lib/unparser/emitter/case.rb +0 -2
  30. data/lib/unparser/emitter/cbase.rb +0 -2
  31. data/lib/unparser/emitter/class.rb +1 -3
  32. data/lib/unparser/emitter/def.rb +0 -2
  33. data/lib/unparser/emitter/defined.rb +0 -2
  34. data/lib/unparser/emitter/empty.rb +0 -2
  35. data/lib/unparser/emitter/ensure.rb +0 -2
  36. data/lib/unparser/emitter/flipflop.rb +0 -2
  37. data/lib/unparser/emitter/flow_modifier.rb +0 -2
  38. data/lib/unparser/emitter/for.rb +0 -2
  39. data/lib/unparser/emitter/hookexe.rb +0 -2
  40. data/lib/unparser/emitter/if.rb +0 -2
  41. data/lib/unparser/emitter/literal.rb +0 -2
  42. data/lib/unparser/emitter/literal/array.rb +0 -2
  43. data/lib/unparser/emitter/literal/dynamic.rb +2 -43
  44. data/lib/unparser/emitter/literal/dynamic_body.rb +0 -6
  45. data/lib/unparser/emitter/literal/execute_string.rb +0 -2
  46. data/lib/unparser/emitter/literal/hash.rb +1 -3
  47. data/lib/unparser/emitter/literal/primitive.rb +0 -2
  48. data/lib/unparser/emitter/literal/range.rb +0 -2
  49. data/lib/unparser/emitter/literal/regexp.rb +0 -2
  50. data/lib/unparser/emitter/literal/singleton.rb +0 -2
  51. data/lib/unparser/emitter/match.rb +0 -2
  52. data/lib/unparser/emitter/module.rb +0 -2
  53. data/lib/unparser/emitter/op_assign.rb +0 -2
  54. data/lib/unparser/emitter/redo.rb +0 -2
  55. data/lib/unparser/emitter/repetition.rb +0 -2
  56. data/lib/unparser/emitter/resbody.rb +0 -2
  57. data/lib/unparser/emitter/rescue.rb +0 -2
  58. data/lib/unparser/emitter/retry.rb +0 -2
  59. data/lib/unparser/emitter/root.rb +0 -2
  60. data/lib/unparser/emitter/send.rb +0 -2
  61. data/lib/unparser/emitter/send/arguments.rb +0 -2
  62. data/lib/unparser/emitter/send/attribute_assignment.rb +0 -2
  63. data/lib/unparser/emitter/send/binary.rb +0 -2
  64. data/lib/unparser/emitter/send/conditional.rb +38 -0
  65. data/lib/unparser/emitter/send/index.rb +0 -2
  66. data/lib/unparser/emitter/send/regular.rb +0 -2
  67. data/lib/unparser/emitter/send/unary.rb +3 -2
  68. data/lib/unparser/emitter/splat.rb +0 -2
  69. data/lib/unparser/emitter/super.rb +0 -2
  70. data/lib/unparser/emitter/undef.rb +0 -2
  71. data/lib/unparser/emitter/variable.rb +0 -2
  72. data/lib/unparser/emitter/yield.rb +0 -2
  73. data/lib/unparser/finalize.rb +0 -2
  74. data/lib/unparser/node_helpers.rb +0 -2
  75. data/lib/unparser/preprocessor.rb +3 -80
  76. data/spec/integration/unparser/corpus_spec.rb +3 -16
  77. data/spec/integrations.yml +10 -11
  78. data/spec/spec_helper.rb +0 -2
  79. data/spec/unit/unparser/buffer/append_spec.rb +0 -2
  80. data/spec/unit/unparser/buffer/append_without_prefix_spec.rb +0 -2
  81. data/spec/unit/unparser/buffer/capture_content_spec.rb +0 -2
  82. data/spec/unit/unparser/buffer/content_spec.rb +0 -2
  83. data/spec/unit/unparser/buffer/fresh_line_spec.rb +0 -2
  84. data/spec/unit/unparser/buffer/indent_spec.rb +0 -2
  85. data/spec/unit/unparser/buffer/nl_spec.rb +0 -2
  86. data/spec/unit/unparser/buffer/unindent_spec.rb +0 -2
  87. data/spec/unit/unparser/comments/consume_spec.rb +0 -2
  88. data/spec/unit/unparser/comments/take_all_spec.rb +0 -2
  89. data/spec/unit/unparser/comments/take_before_spec.rb +0 -2
  90. data/spec/unit/unparser/comments/take_eol_comments_spec.rb +0 -2
  91. data/spec/unit/unparser/emitter/class_methods/handle_spec.rb +1 -3
  92. data/spec/unit/unparser_spec.rb +47 -71
  93. data/unparser.gemspec +20 -17
  94. metadata +69 -28
  95. data/.travis.yml +0 -20
  96. data/Guardfile +0 -20
  97. data/TODO +0 -4
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module Unparser
4
2
  class Emitter
5
3
  class Literal
@@ -54,10 +52,6 @@ module Unparser
54
52
  # @api private
55
53
  #
56
54
  def emit_segment(node)
57
- if node.type == :str
58
- emit_str_segment(node)
59
- return
60
- end
61
55
  emit_interpolated_segment(node)
62
56
  end
63
57
 
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module Unparser
4
2
  class Emitter
5
3
  class Literal
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module Unparser
4
2
  class Emitter
5
3
  class Literal
@@ -48,7 +46,7 @@ module Unparser
48
46
 
49
47
  # Pair emitter that emits colon separated key values
50
48
  class Colon < self
51
- COLON = ': '.freeze
49
+ COLON = ': '.freeze
52
50
 
53
51
  handle :pair_colon
54
52
 
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module Unparser
4
2
  class Emitter
5
3
  class Literal
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module Unparser
4
2
  class Emitter
5
3
  class Literal
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module Unparser
4
2
  class Emitter
5
3
  class Literal
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module Unparser
4
2
  class Emitter
5
3
  class Literal
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module Unparser
4
2
  class Emitter
5
3
 
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module Unparser
4
2
  class Emitter
5
3
  # Emitter for module nodes
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module Unparser
4
2
  class Emitter
5
3
 
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module Unparser
4
2
  class Emitter
5
3
  # Emitter for redo nodes
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module Unparser
4
2
  class Emitter
5
3
 
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module Unparser
4
2
  class Emitter
5
3
  # Emitter for rescue body nodes
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module Unparser
4
2
  class Emitter
5
3
  # Emitter for rescue nodes
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module Unparser
4
2
  class Emitter
5
3
  # Emitter for retry nodes
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module Unparser
4
2
  class Emitter
5
3
  # Root emitter a special case
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module Unparser
4
2
  class Emitter
5
3
  # Emitter for send
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module Unparser
4
2
  class Emitter
5
3
  class Send
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module Unparser
4
2
  class Emitter
5
3
  class Send
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module Unparser
4
2
  class Emitter
5
3
  class Send
@@ -0,0 +1,38 @@
1
+ module Unparser
2
+ class Emitter
3
+ class Send
4
+ # Emitter for "conditional" receiver&.selector(arguments...) case
5
+ class Conditional < self
6
+ include Terminated
7
+
8
+ handle :csend
9
+
10
+ private
11
+
12
+ # Perform regular dispatch
13
+ #
14
+ # @return [undefined]
15
+ #
16
+ # @api private
17
+ #
18
+ def dispatch
19
+ emit_receiver
20
+ emit_selector
21
+ emit_arguments
22
+ end
23
+
24
+ # Emit receiver
25
+ #
26
+ # @return [undefined]
27
+ #
28
+ # @api private
29
+ #
30
+ def emit_receiver
31
+ visit(receiver)
32
+ write(T_AMP, T_DOT)
33
+ end
34
+
35
+ end # Regular
36
+ end # Send
37
+ end # Emitter
38
+ end # Unparser
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module Unparser
4
2
  class Emitter
5
3
  class Send
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module Unparser
4
2
  class Emitter
5
3
  class Send
@@ -1,9 +1,10 @@
1
- # encoding: utf-8
2
-
3
1
  module Unparser
4
2
  class Emitter
5
3
  class Send
6
4
  # Emitter for unary sends
5
+ #
6
+ # rubocop:disable Style/HashSyntax
7
+ # ^^ is false positive
7
8
  class Unary < self
8
9
  include Unterminated
9
10
 
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module Unparser
4
2
  class Emitter
5
3
  # Emitter for splats
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module Unparser
4
2
  class Emitter
5
3
 
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module Unparser
4
2
  class Emitter
5
3
  # Emitter for undef nodes
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module Unparser
4
2
  class Emitter
5
3
 
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module Unparser
4
2
  class Emitter
5
3
 
@@ -1,3 +1 @@
1
- # encoding: utf-8
2
-
3
1
  Unparser::Emitter::REGISTRY.freeze
@@ -1,5 +1,3 @@
1
- # encoding: UTF-8
2
-
3
1
  module Unparser
4
2
  module NodeHelpers
5
3
 
@@ -1,5 +1,3 @@
1
- # encoding: UTF-8
2
-
3
1
  module Unparser
4
2
  # Preprocessor to normalize AST generated by parser
5
3
  class Preprocessor
@@ -85,7 +83,7 @@ module Unparser
85
83
  end
86
84
  end
87
85
 
88
- # Noop preprocessor that just passes through noode.
86
+ # Noop preprocessor that just passes node through.
89
87
  class Noop < self
90
88
 
91
89
  register :int
@@ -103,82 +101,7 @@ module Unparser
103
101
 
104
102
  end # Noop
105
103
 
106
- # Preprocessor for dynamic string regexp and xtr nodes. Collapses adjacent string segments into one.
107
- class CollapseStrChildren < self
108
-
109
- register :dstr
110
- register :regexp
111
- register :xstr
112
-
113
- # Return preprocessor result
114
- #
115
- # @return [Parser::AST::Node]
116
- #
117
- # @api private
118
- #
119
- def result
120
- node.updated(nil, collapsed_children)
121
- end
122
-
123
- private
124
-
125
- # Return collapsed children
126
- #
127
- # @return [Array<Parser::AST::Node>]
128
- #
129
- # @api private
130
- #
131
- def collapsed_children
132
- chunked_children.each_with_object([]) do |(type, nodes), aggregate|
133
- if type.equal?(:str)
134
- aggregate << s(:str, nodes.map { |node| node.children.first }.join)
135
- else
136
- aggregate.concat(nodes)
137
- end
138
- end
139
- end
140
- memoize :collapsed_children
141
-
142
- # Return chunked children
143
- #
144
- # @return [Array<Parser::AST::Node>]
145
- #
146
- # @api private
147
- #
148
- def chunked_children
149
- visited_children.chunk(&:type)
150
- end
151
-
152
- end # CollapseStrChildren
153
-
154
- # Preprocessor eliminating unneded dstr nodes
155
- class CompactDSTR < self
156
-
157
- register :dstr
158
- register :dsym
159
-
160
- MAP = IceNine.deep_freeze(
161
- dstr: :str,
162
- dsym: :sym
163
- )
164
-
165
- # Return preprocessor result
166
- #
167
- # @return [Parser::AST::Node]
168
- #
169
- # @api private
170
- #
171
- def result
172
- if children.any? && children.all? { |child| child.type.equal?(:str) }
173
- node.updated(MAP.fetch(node.type), [children.map { |child| child.children.first }.join])
174
- else
175
- node
176
- end
177
- end
178
-
179
- end # CompactDSTR
180
-
181
- # Preprocessor transforming numeric nodes with infinity as value to round trippable aequivalent.
104
+ # Preprocessor transforming numeric nodes with infinity as value to round trippable equivalent.
182
105
  class Infinity < self
183
106
 
184
107
  register :float
@@ -190,7 +113,7 @@ module Unparser
190
113
  #
191
114
  # @param [Parser::AST::Node]
192
115
  #
193
- # @api pirvate
116
+ # @api private
194
117
  #
195
118
  def result
196
119
  value = node.children.first
@@ -1,20 +1,7 @@
1
- # encoding: UTF-8
2
-
3
1
  require 'spec_helper'
4
2
 
5
- describe 'Unparser on ruby corpus' do
6
- before do
7
- if RUBY_VERSION < '2.1.0'
8
- # Limits in encodings and complex/rational literals
9
- skip 'Corpus test not active for < 2.1.0'
10
- end
11
- if RUBY_ENGINE == 'jruby'
12
- skip 'Corpus test exhausts jruby heap space on travis'
13
- end
14
- if ENV['GUARD']
15
- skip 'Do not execute corpus spec under guard'
16
- end
17
- end
3
+ # rubocop:disable ClosingParenthesisIndentation
4
+ describe 'Unparser on ruby corpus', mutant: false do
18
5
  ROOT = Pathname.new(__FILE__).parent.parent.parent.parent
19
6
 
20
7
  TMP = ROOT.join('tmp')
@@ -85,7 +72,7 @@ describe 'Unparser on ruby corpus' do
85
72
  if block_given?
86
73
  yield
87
74
  else
88
- raise 'System command failed!'
75
+ raise "System command #{arguments.inspect} failed!"
89
76
  end
90
77
  end
91
78
 
@@ -12,26 +12,25 @@
12
12
  repo_uri: 'https://github.com/ahawkins/chassis.git'
13
13
  exclude: []
14
14
  - name: rubyspec
15
- repo_uri: 'https://github.com/rubyspec/rubyspec.git'
15
+ repo_uri: 'https://github.com/ruby/spec.git'
16
16
  exclude:
17
17
  # Binary encoded source subjected to limitations see Readme
18
- - core/array/pack/{b,h,u}_spec.rb
19
- - language/versions/*1.8*
18
+ - core/array/pack/{b,c,h,m,u,w}_spec.rb
20
19
  - core/array/pack/shared/float.rb
21
20
  - core/array/pack/shared/integer.rb
22
- - core/array/pack/{c,m,w}_spec.rb
23
- - core/regexp/shared/new.rb
24
- - core/regexp/shared/quote.rb
25
21
  - core/encoding/compatible_spec.rb
26
- - core/io/readpartial_spec.rb
27
22
  - core/env/element_reference_spec.rb
28
- - core/dir/pwd_spec.rb
23
+ - core/io/readpartial_spec.rb
29
24
  - core/regexp/shared/new_ascii_8bit.rb
30
- - core/regexp/encoding_spec.rb
25
+ - core/regexp/shared/quote.rb
31
26
  - core/string/casecmp_spec.rb
32
27
  - core/string/unpack/{b,c,h,m,u,w}_spec.rb
33
- - core/string/unpack/b_spec.rb
34
28
  - core/string/unpack/shared/float.rb
35
29
  - core/string/unpack/shared/integer.rb
36
- - core/symbol/casecmp_spec.rb
30
+ - library/zlib/gzipwriter/write_spec.rb
37
31
  - optional/capi/integer_spec.rb
32
+ # parser crashes
33
+ - core/symbol/casecmp_spec.rb
34
+ - language/regexp/escapes_spec.rb
35
+ - library/conditionvariable/broadcast_spec.rb
36
+ - library/conditionvariable/signal_spec.rb