unparser 0.2.4 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Changelog.md +7 -0
- data/Gemfile +1 -7
- data/README.md +6 -1
- data/Rakefile +11 -2
- data/bin/unparser +0 -2
- data/config/devtools.yml +1 -1
- data/config/flay.yml +1 -1
- data/config/flog.yml +1 -1
- data/config/reek.yml +4 -1
- data/config/rubocop.yml +0 -4
- data/lib/unparser.rb +1 -2
- data/lib/unparser/ast.rb +0 -2
- data/lib/unparser/ast/local_variable_scope.rb +0 -2
- data/lib/unparser/buffer.rb +0 -2
- data/lib/unparser/cli.rb +3 -4
- data/lib/unparser/cli/color.rb +0 -2
- data/lib/unparser/cli/differ.rb +0 -2
- data/lib/unparser/cli/source.rb +1 -3
- data/lib/unparser/comments.rb +0 -2
- data/lib/unparser/constants.rb +0 -2
- data/lib/unparser/emitter.rb +4 -3
- data/lib/unparser/emitter/alias.rb +0 -2
- data/lib/unparser/emitter/argument.rb +0 -2
- data/lib/unparser/emitter/assignment.rb +0 -2
- data/lib/unparser/emitter/begin.rb +1 -3
- data/lib/unparser/emitter/binary.rb +0 -2
- data/lib/unparser/emitter/block.rb +0 -2
- data/lib/unparser/emitter/case.rb +0 -2
- data/lib/unparser/emitter/cbase.rb +0 -2
- data/lib/unparser/emitter/class.rb +1 -3
- data/lib/unparser/emitter/def.rb +0 -2
- data/lib/unparser/emitter/defined.rb +0 -2
- data/lib/unparser/emitter/empty.rb +0 -2
- data/lib/unparser/emitter/ensure.rb +0 -2
- data/lib/unparser/emitter/flipflop.rb +0 -2
- data/lib/unparser/emitter/flow_modifier.rb +0 -2
- data/lib/unparser/emitter/for.rb +0 -2
- data/lib/unparser/emitter/hookexe.rb +0 -2
- data/lib/unparser/emitter/if.rb +0 -2
- data/lib/unparser/emitter/literal.rb +0 -2
- data/lib/unparser/emitter/literal/array.rb +0 -2
- data/lib/unparser/emitter/literal/dynamic.rb +2 -43
- data/lib/unparser/emitter/literal/dynamic_body.rb +0 -6
- data/lib/unparser/emitter/literal/execute_string.rb +0 -2
- data/lib/unparser/emitter/literal/hash.rb +1 -3
- data/lib/unparser/emitter/literal/primitive.rb +0 -2
- data/lib/unparser/emitter/literal/range.rb +0 -2
- data/lib/unparser/emitter/literal/regexp.rb +0 -2
- data/lib/unparser/emitter/literal/singleton.rb +0 -2
- data/lib/unparser/emitter/match.rb +0 -2
- data/lib/unparser/emitter/module.rb +0 -2
- data/lib/unparser/emitter/op_assign.rb +0 -2
- data/lib/unparser/emitter/redo.rb +0 -2
- data/lib/unparser/emitter/repetition.rb +0 -2
- data/lib/unparser/emitter/resbody.rb +0 -2
- data/lib/unparser/emitter/rescue.rb +0 -2
- data/lib/unparser/emitter/retry.rb +0 -2
- data/lib/unparser/emitter/root.rb +0 -2
- data/lib/unparser/emitter/send.rb +0 -2
- data/lib/unparser/emitter/send/arguments.rb +0 -2
- data/lib/unparser/emitter/send/attribute_assignment.rb +0 -2
- data/lib/unparser/emitter/send/binary.rb +0 -2
- data/lib/unparser/emitter/send/conditional.rb +38 -0
- data/lib/unparser/emitter/send/index.rb +0 -2
- data/lib/unparser/emitter/send/regular.rb +0 -2
- data/lib/unparser/emitter/send/unary.rb +3 -2
- data/lib/unparser/emitter/splat.rb +0 -2
- data/lib/unparser/emitter/super.rb +0 -2
- data/lib/unparser/emitter/undef.rb +0 -2
- data/lib/unparser/emitter/variable.rb +0 -2
- data/lib/unparser/emitter/yield.rb +0 -2
- data/lib/unparser/finalize.rb +0 -2
- data/lib/unparser/node_helpers.rb +0 -2
- data/lib/unparser/preprocessor.rb +3 -80
- data/spec/integration/unparser/corpus_spec.rb +3 -16
- data/spec/integrations.yml +10 -11
- data/spec/spec_helper.rb +0 -2
- data/spec/unit/unparser/buffer/append_spec.rb +0 -2
- data/spec/unit/unparser/buffer/append_without_prefix_spec.rb +0 -2
- data/spec/unit/unparser/buffer/capture_content_spec.rb +0 -2
- data/spec/unit/unparser/buffer/content_spec.rb +0 -2
- data/spec/unit/unparser/buffer/fresh_line_spec.rb +0 -2
- data/spec/unit/unparser/buffer/indent_spec.rb +0 -2
- data/spec/unit/unparser/buffer/nl_spec.rb +0 -2
- data/spec/unit/unparser/buffer/unindent_spec.rb +0 -2
- data/spec/unit/unparser/comments/consume_spec.rb +0 -2
- data/spec/unit/unparser/comments/take_all_spec.rb +0 -2
- data/spec/unit/unparser/comments/take_before_spec.rb +0 -2
- data/spec/unit/unparser/comments/take_eol_comments_spec.rb +0 -2
- data/spec/unit/unparser/emitter/class_methods/handle_spec.rb +1 -3
- data/spec/unit/unparser_spec.rb +47 -71
- data/unparser.gemspec +20 -17
- metadata +69 -28
- data/.travis.yml +0 -20
- data/Guardfile +0 -20
- 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
|
@@ -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
|
49
|
+
COLON = ': '.freeze
|
52
50
|
|
53
51
|
handle :pair_colon
|
54
52
|
|
@@ -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
|
data/lib/unparser/finalize.rb
CHANGED
@@ -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
|
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
|
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
|
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
|
-
|
6
|
-
|
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
|
75
|
+
raise "System command #{arguments.inspect} failed!"
|
89
76
|
end
|
90
77
|
end
|
91
78
|
|
data/spec/integrations.yml
CHANGED
@@ -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/
|
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/
|
23
|
+
- core/io/readpartial_spec.rb
|
29
24
|
- core/regexp/shared/new_ascii_8bit.rb
|
30
|
-
- core/regexp/
|
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
|
-
-
|
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
|