unparser 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +32 -8
- data/Changelog.md +5 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +26 -20
- data/README.md +21 -21
- data/config/flay.yml +1 -1
- data/config/reek.yml +9 -48
- data/lib/unparser.rb +62 -2
- data/lib/unparser/ast.rb +1 -1
- data/lib/unparser/cli/differ.rb +1 -1
- data/lib/unparser/cli/source.rb +2 -15
- data/lib/unparser/constants.rb +4 -2
- data/lib/unparser/emitter.rb +0 -14
- data/lib/unparser/emitter/argument.rb +62 -0
- data/lib/unparser/emitter/assignment.rb +4 -16
- data/lib/unparser/emitter/block.rb +29 -4
- data/lib/unparser/emitter/hookexe.rb +1 -1
- data/lib/unparser/emitter/index.rb +136 -0
- data/lib/unparser/emitter/lambda.rb +25 -0
- data/lib/unparser/emitter/literal/array.rb +1 -4
- data/lib/unparser/emitter/meta.rb +2 -2
- data/lib/unparser/emitter/rescue.rb +1 -1
- data/lib/unparser/emitter/send.rb +14 -28
- data/lib/unparser/emitter/send/attribute_assignment.rb +10 -24
- data/spec/spec_helper.rb +0 -11
- data/spec/unit/unparser/comments/consume_spec.rb +1 -1
- data/spec/unit/unparser/comments/take_all_spec.rb +1 -1
- data/spec/unit/unparser/comments/take_before_spec.rb +2 -2
- data/spec/unit/unparser/comments/take_eol_comments_spec.rb +6 -6
- data/spec/unit/unparser_spec.rb +365 -248
- data/unparser.gemspec +1 -1
- metadata +5 -6
- data/lib/unparser/emitter/send/index.rb +0 -127
- data/spec/support/parser_class_generator.rb +0 -21
data/unparser.gemspec
CHANGED
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.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Markus Schirp
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-12-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: abstract_type
|
@@ -212,6 +212,8 @@ files:
|
|
212
212
|
- lib/unparser/emitter/for.rb
|
213
213
|
- lib/unparser/emitter/hookexe.rb
|
214
214
|
- lib/unparser/emitter/if.rb
|
215
|
+
- lib/unparser/emitter/index.rb
|
216
|
+
- lib/unparser/emitter/lambda.rb
|
215
217
|
- lib/unparser/emitter/literal.rb
|
216
218
|
- lib/unparser/emitter/literal/array.rb
|
217
219
|
- lib/unparser/emitter/literal/dynamic.rb
|
@@ -237,7 +239,6 @@ files:
|
|
237
239
|
- lib/unparser/emitter/send/attribute_assignment.rb
|
238
240
|
- lib/unparser/emitter/send/binary.rb
|
239
241
|
- lib/unparser/emitter/send/conditional.rb
|
240
|
-
- lib/unparser/emitter/send/index.rb
|
241
242
|
- lib/unparser/emitter/send/regular.rb
|
242
243
|
- lib/unparser/emitter/send/unary.rb
|
243
244
|
- lib/unparser/emitter/splat.rb
|
@@ -251,7 +252,6 @@ files:
|
|
251
252
|
- spec/integration/unparser/corpus_spec.rb
|
252
253
|
- spec/integrations.yml
|
253
254
|
- spec/spec_helper.rb
|
254
|
-
- spec/support/parser_class_generator.rb
|
255
255
|
- spec/unit/unparser/buffer/append_spec.rb
|
256
256
|
- spec/unit/unparser/buffer/append_without_prefix_spec.rb
|
257
257
|
- spec/unit/unparser/buffer/capture_content_spec.rb
|
@@ -287,7 +287,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
287
287
|
version: '0'
|
288
288
|
requirements: []
|
289
289
|
rubyforge_project:
|
290
|
-
rubygems_version: 2.7.
|
290
|
+
rubygems_version: 2.7.6
|
291
291
|
signing_key:
|
292
292
|
specification_version: 4
|
293
293
|
summary: Generate equivalent source for parser gem AST nodes
|
@@ -295,7 +295,6 @@ test_files:
|
|
295
295
|
- spec/integration/unparser/corpus_spec.rb
|
296
296
|
- spec/integrations.yml
|
297
297
|
- spec/spec_helper.rb
|
298
|
-
- spec/support/parser_class_generator.rb
|
299
298
|
- spec/unit/unparser/buffer/append_spec.rb
|
300
299
|
- spec/unit/unparser/buffer/append_without_prefix_spec.rb
|
301
300
|
- spec/unit/unparser/buffer/capture_content_spec.rb
|
@@ -1,127 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Unparser
|
4
|
-
class Emitter
|
5
|
-
class Send
|
6
|
-
# Emitter for send to index references
|
7
|
-
class Index < self
|
8
|
-
|
9
|
-
private
|
10
|
-
|
11
|
-
# Perform dispatch
|
12
|
-
#
|
13
|
-
# @return [undefined]
|
14
|
-
#
|
15
|
-
# @api private
|
16
|
-
#
|
17
|
-
def dispatch
|
18
|
-
emit_receiver
|
19
|
-
emit_operation
|
20
|
-
end
|
21
|
-
|
22
|
-
# Emit receiver
|
23
|
-
#
|
24
|
-
# @return [undefined]
|
25
|
-
#
|
26
|
-
# @api private
|
27
|
-
#
|
28
|
-
def emit_receiver
|
29
|
-
visit(first_child)
|
30
|
-
end
|
31
|
-
|
32
|
-
# Emitter for index reference nodes
|
33
|
-
class Reference < self
|
34
|
-
include Terminated
|
35
|
-
|
36
|
-
private
|
37
|
-
|
38
|
-
# Emit arguments
|
39
|
-
#
|
40
|
-
# @return [undefined]
|
41
|
-
#
|
42
|
-
# @api private
|
43
|
-
#
|
44
|
-
def emit_operation
|
45
|
-
parentheses(*INDEX_PARENS) do
|
46
|
-
delimited_plain(arguments)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end # Reference
|
50
|
-
|
51
|
-
# Emitter for assign to index nodes
|
52
|
-
class Assign < self
|
53
|
-
include Unterminated
|
54
|
-
|
55
|
-
# Test if assign will be emitted terminated
|
56
|
-
#
|
57
|
-
# @return [Boolean]
|
58
|
-
#
|
59
|
-
# @api private
|
60
|
-
#
|
61
|
-
def terminated?
|
62
|
-
mlhs?
|
63
|
-
end
|
64
|
-
|
65
|
-
private
|
66
|
-
|
67
|
-
define_group(:indices, 2..-2)
|
68
|
-
define_child(:value, -1)
|
69
|
-
|
70
|
-
# Emit arguments
|
71
|
-
#
|
72
|
-
# @return [undefined]
|
73
|
-
#
|
74
|
-
# @api private
|
75
|
-
#
|
76
|
-
def emit_operation
|
77
|
-
if arguments.empty?
|
78
|
-
emit_regular_with_empty_args
|
79
|
-
elsif mlhs?
|
80
|
-
emit_mlhs_operation
|
81
|
-
else
|
82
|
-
emit_normal_operation
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
# Emit mlhs arguments
|
87
|
-
#
|
88
|
-
# @return [undefined]
|
89
|
-
#
|
90
|
-
# @api private
|
91
|
-
#
|
92
|
-
def emit_mlhs_operation
|
93
|
-
parentheses(*INDEX_PARENS) do
|
94
|
-
delimited(arguments)
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
# Emit normal arguments
|
99
|
-
#
|
100
|
-
# @return [undefined]
|
101
|
-
#
|
102
|
-
# @api private
|
103
|
-
#
|
104
|
-
def emit_normal_operation
|
105
|
-
parentheses(*INDEX_PARENS) do
|
106
|
-
delimited_plain(indices)
|
107
|
-
end
|
108
|
-
write(WS, T_ASN, WS)
|
109
|
-
visit(value)
|
110
|
-
end
|
111
|
-
|
112
|
-
# Emit regular with empty ars
|
113
|
-
#
|
114
|
-
# @return [undefined]
|
115
|
-
#
|
116
|
-
# @api private
|
117
|
-
#
|
118
|
-
def emit_regular_with_empty_args
|
119
|
-
write(T_DOT, '[]=()')
|
120
|
-
end
|
121
|
-
|
122
|
-
end # Assign
|
123
|
-
|
124
|
-
end # Index
|
125
|
-
end # Send
|
126
|
-
end # Emitter
|
127
|
-
end # Unparser
|
@@ -1,21 +0,0 @@
|
|
1
|
-
module ParserClassGenerator
|
2
|
-
def self.generate_with_options(base_parser_class, builder_options)
|
3
|
-
# This builds a dynamic subclass of the base_parser_class (e.g. Parser::Ruby23)
|
4
|
-
# and overrides the default_parser method to return a parser whose builder
|
5
|
-
# has various options set.
|
6
|
-
#
|
7
|
-
# Currently the only builder option is :emit_file_line_as_literals
|
8
|
-
|
9
|
-
Class.new(base_parser_class) do
|
10
|
-
define_singleton_method(:default_parser) do |*args|
|
11
|
-
super(*args).tap do |parser|
|
12
|
-
parser.builder.emit_file_line_as_literals = builder_options[:emit_file_line_as_literals]
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
define_singleton_method(:inspect) do
|
17
|
-
"#{base_parser_class.inspect} with builder options: #{builder_options.inspect}"
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|