unparser 0.5.5 → 0.5.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/unparser.rb +3 -11
- data/lib/unparser/emitter/hash.rb +1 -31
- data/lib/unparser/emitter/kwargs.rb +13 -0
- data/lib/unparser/emitter/match_pattern.rb +22 -0
- data/lib/unparser/emitter/pair.rb +33 -0
- data/lib/unparser/writer/dynamic_string.rb +2 -10
- data/lib/unparser/writer/send.rb +1 -14
- metadata +20 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 21e418840b351f5e697c472127300d7733ca1c20bdf4be321ae1832133447767
|
4
|
+
data.tar.gz: c130412892dcb6a1db4835c3ef9fa9738f2a181ede78ccca6a7a13336a348e8c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4a25a3e71df443024af556d20ca97f9a627874ee5857a4badfa2c7bd228159732fac0060715b198acc5648879c25baf8c0b10496f6cb0303fa41841cf06521ad
|
7
|
+
data.tar.gz: 8dec6ae089dbf574a7687177993da010f2569677217032e95079e007598c04e0acbb35d967667532331187d6ab25c81346c5073454dda7665e8864fc0e31e42a
|
data/lib/unparser.rb
CHANGED
@@ -117,21 +117,10 @@ module Unparser
|
|
117
117
|
Parser::CurrentRuby.new(Builder.new).tap do |parser|
|
118
118
|
parser.diagnostics.tap do |diagnostics|
|
119
119
|
diagnostics.all_errors_are_fatal = true
|
120
|
-
diagnostics.consumer = method(:consume_diagnostic)
|
121
120
|
end
|
122
121
|
end
|
123
122
|
end
|
124
123
|
|
125
|
-
# Consume diagnostic
|
126
|
-
#
|
127
|
-
# @param [Parser::Diagnostic] diagnostic
|
128
|
-
#
|
129
|
-
# @return [undefined]
|
130
|
-
def self.consume_diagnostic(diagnostic)
|
131
|
-
Kernel.warn(diagnostic.render)
|
132
|
-
end
|
133
|
-
private_class_method :consume_diagnostic
|
134
|
-
|
135
124
|
# Construct a parser buffer from string
|
136
125
|
#
|
137
126
|
# @param [String] source
|
@@ -209,6 +198,9 @@ require 'unparser/emitter/undef'
|
|
209
198
|
require 'unparser/emitter/variable'
|
210
199
|
require 'unparser/emitter/xstr'
|
211
200
|
require 'unparser/emitter/yield'
|
201
|
+
require 'unparser/emitter/kwargs'
|
202
|
+
require 'unparser/emitter/pair'
|
203
|
+
require 'unparser/emitter/match_pattern'
|
212
204
|
require 'unparser/writer'
|
213
205
|
require 'unparser/writer/binary'
|
214
206
|
require 'unparser/writer/dynamic_string'
|
@@ -4,10 +4,6 @@ module Unparser
|
|
4
4
|
class Emitter
|
5
5
|
# Emitter for Hash literals
|
6
6
|
class Hash < self
|
7
|
-
BAREWORD = /\A[A-Za-z_][A-Za-z_0-9]*[?!]?\z/.freeze
|
8
|
-
|
9
|
-
private_constant(*constants(false))
|
10
|
-
|
11
7
|
handle :hash
|
12
8
|
|
13
9
|
def emit_last_argument_hash
|
@@ -41,34 +37,8 @@ module Unparser
|
|
41
37
|
end
|
42
38
|
|
43
39
|
def emit_hash_body
|
44
|
-
delimited(children
|
45
|
-
end
|
46
|
-
|
47
|
-
def emit_hash_member(node)
|
48
|
-
if n_kwsplat?(node)
|
49
|
-
visit(node)
|
50
|
-
else
|
51
|
-
emit_pair(node)
|
52
|
-
end
|
40
|
+
delimited(children)
|
53
41
|
end
|
54
|
-
|
55
|
-
def emit_pair(pair)
|
56
|
-
key, value = *pair.children
|
57
|
-
|
58
|
-
if colon?(key)
|
59
|
-
write(key.children.first.to_s, ': ')
|
60
|
-
else
|
61
|
-
visit(key)
|
62
|
-
write(' => ')
|
63
|
-
end
|
64
|
-
|
65
|
-
visit(value)
|
66
|
-
end
|
67
|
-
|
68
|
-
def colon?(key)
|
69
|
-
n_sym?(key) && BAREWORD.match?(key.children.first)
|
70
|
-
end
|
71
|
-
|
72
42
|
end # Hash
|
73
43
|
end # Emitter
|
74
44
|
end # Unparser
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Unparser
|
4
|
+
class Emitter
|
5
|
+
# Emitter for in pattern nodes
|
6
|
+
class MatchPattern < self
|
7
|
+
|
8
|
+
handle :match_pattern
|
9
|
+
handle :match_pattern_p
|
10
|
+
|
11
|
+
children :target, :pattern
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def dispatch
|
16
|
+
visit(target)
|
17
|
+
write(' in ')
|
18
|
+
visit(pattern)
|
19
|
+
end
|
20
|
+
end # InPattern
|
21
|
+
end # Emitter
|
22
|
+
end # Unparser
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Unparser
|
4
|
+
class Emitter
|
5
|
+
# Emitter for key value pairs in hash literals or kwargs
|
6
|
+
class Pair < self
|
7
|
+
BAREWORD = /\A[A-Za-z_][A-Za-z_0-9]*[?!]?\z/.freeze
|
8
|
+
|
9
|
+
private_constant(*constants(false))
|
10
|
+
|
11
|
+
handle :pair
|
12
|
+
|
13
|
+
children :key, :value
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def dispatch
|
18
|
+
if colon?(key)
|
19
|
+
write(key.children.first.to_s, ': ')
|
20
|
+
else
|
21
|
+
visit(key)
|
22
|
+
write(' => ')
|
23
|
+
end
|
24
|
+
|
25
|
+
visit(value)
|
26
|
+
end
|
27
|
+
|
28
|
+
def colon?(key)
|
29
|
+
n_sym?(key) && BAREWORD.match?(key.children.first)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -42,7 +42,7 @@ module Unparser
|
|
42
42
|
private
|
43
43
|
|
44
44
|
def heredoc_header
|
45
|
-
|
45
|
+
'<<-HEREDOC'
|
46
46
|
end
|
47
47
|
|
48
48
|
def heredoc?
|
@@ -55,11 +55,7 @@ module Unparser
|
|
55
55
|
|
56
56
|
def emit_heredoc_body
|
57
57
|
nl
|
58
|
-
|
59
|
-
emit_squiggly_heredoc_body
|
60
|
-
else
|
61
|
-
emit_normal_heredoc_body
|
62
|
-
end
|
58
|
+
emit_normal_heredoc_body
|
63
59
|
end
|
64
60
|
|
65
61
|
def emit_heredoc_footer
|
@@ -119,10 +115,6 @@ module Unparser
|
|
119
115
|
n_str?(last) && last.children.first[-1].eql?("\n")
|
120
116
|
end
|
121
117
|
|
122
|
-
def need_squiggly?
|
123
|
-
children.any?(s(:str, ''))
|
124
|
-
end
|
125
|
-
|
126
118
|
def emit_squiggly_heredoc_body
|
127
119
|
buffer.indent
|
128
120
|
children.each do |child|
|
data/lib/unparser/writer/send.rb
CHANGED
@@ -75,20 +75,7 @@ module Unparser
|
|
75
75
|
end
|
76
76
|
|
77
77
|
def emit_normal_arguments
|
78
|
-
parentheses
|
79
|
-
arguments.each_with_index do |node, index|
|
80
|
-
write(', ') unless index.zero?
|
81
|
-
emit_argument(node, index.succ.equal?(arguments.length))
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
def emit_argument(argument, last)
|
87
|
-
if n_hash?(argument) && last
|
88
|
-
writer_with(Emitter::Hash, argument).emit_last_argument_hash
|
89
|
-
else
|
90
|
-
visit(argument)
|
91
|
-
end
|
78
|
+
parentheses { delimited(arguments) }
|
92
79
|
end
|
93
80
|
|
94
81
|
def emit_heredoc_reminder(argument)
|
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.5.
|
4
|
+
version: 0.5.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: 2020-12-
|
11
|
+
date: 2020-12-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: abstract_type
|
@@ -114,14 +114,14 @@ dependencies:
|
|
114
114
|
requirements:
|
115
115
|
- - ">="
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version:
|
117
|
+
version: 3.0.0
|
118
118
|
type: :runtime
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
122
|
- - ">="
|
123
123
|
- !ruby/object:Gem::Version
|
124
|
-
version:
|
124
|
+
version: 3.0.0
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
126
|
name: procto
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -142,28 +142,28 @@ dependencies:
|
|
142
142
|
requirements:
|
143
143
|
- - "~>"
|
144
144
|
- !ruby/object:Gem::Version
|
145
|
-
version: 0.10.
|
145
|
+
version: 0.10.21
|
146
146
|
type: :development
|
147
147
|
prerelease: false
|
148
148
|
version_requirements: !ruby/object:Gem::Requirement
|
149
149
|
requirements:
|
150
150
|
- - "~>"
|
151
151
|
- !ruby/object:Gem::Version
|
152
|
-
version: 0.10.
|
152
|
+
version: 0.10.21
|
153
153
|
- !ruby/object:Gem::Dependency
|
154
154
|
name: mutant-rspec
|
155
155
|
requirement: !ruby/object:Gem::Requirement
|
156
156
|
requirements:
|
157
157
|
- - "~>"
|
158
158
|
- !ruby/object:Gem::Version
|
159
|
-
version: 0.10.
|
159
|
+
version: 0.10.21
|
160
160
|
type: :development
|
161
161
|
prerelease: false
|
162
162
|
version_requirements: !ruby/object:Gem::Requirement
|
163
163
|
requirements:
|
164
164
|
- - "~>"
|
165
165
|
- !ruby/object:Gem::Version
|
166
|
-
version: 0.10.
|
166
|
+
version: 0.10.21
|
167
167
|
- !ruby/object:Gem::Dependency
|
168
168
|
name: rspec
|
169
169
|
requirement: !ruby/object:Gem::Requirement
|
@@ -212,28 +212,28 @@ dependencies:
|
|
212
212
|
requirements:
|
213
213
|
- - "~>"
|
214
214
|
- !ruby/object:Gem::Version
|
215
|
-
version: 1.
|
215
|
+
version: '1.7'
|
216
216
|
type: :development
|
217
217
|
prerelease: false
|
218
218
|
version_requirements: !ruby/object:Gem::Requirement
|
219
219
|
requirements:
|
220
220
|
- - "~>"
|
221
221
|
- !ruby/object:Gem::Version
|
222
|
-
version: 1.
|
222
|
+
version: '1.7'
|
223
223
|
- !ruby/object:Gem::Dependency
|
224
224
|
name: rubocop-packaging
|
225
225
|
requirement: !ruby/object:Gem::Requirement
|
226
226
|
requirements:
|
227
227
|
- - "~>"
|
228
228
|
- !ruby/object:Gem::Version
|
229
|
-
version: 0.5
|
229
|
+
version: '0.5'
|
230
230
|
type: :development
|
231
231
|
prerelease: false
|
232
232
|
version_requirements: !ruby/object:Gem::Requirement
|
233
233
|
requirements:
|
234
234
|
- - "~>"
|
235
235
|
- !ruby/object:Gem::Version
|
236
|
-
version: 0.5
|
236
|
+
version: '0.5'
|
237
237
|
description: Generate equivalent source for parser gem AST nodes
|
238
238
|
email: mbj@schirp-dso.com
|
239
239
|
executables:
|
@@ -285,17 +285,20 @@ files:
|
|
285
285
|
- lib/unparser/emitter/in_match.rb
|
286
286
|
- lib/unparser/emitter/in_pattern.rb
|
287
287
|
- lib/unparser/emitter/index.rb
|
288
|
+
- lib/unparser/emitter/kwargs.rb
|
288
289
|
- lib/unparser/emitter/kwbegin.rb
|
289
290
|
- lib/unparser/emitter/lambda.rb
|
290
291
|
- lib/unparser/emitter/masgn.rb
|
291
292
|
- lib/unparser/emitter/match.rb
|
292
293
|
- lib/unparser/emitter/match_alt.rb
|
293
294
|
- lib/unparser/emitter/match_as.rb
|
295
|
+
- lib/unparser/emitter/match_pattern.rb
|
294
296
|
- lib/unparser/emitter/match_rest.rb
|
295
297
|
- lib/unparser/emitter/match_var.rb
|
296
298
|
- lib/unparser/emitter/mlhs.rb
|
297
299
|
- lib/unparser/emitter/module.rb
|
298
300
|
- lib/unparser/emitter/op_assign.rb
|
301
|
+
- lib/unparser/emitter/pair.rb
|
299
302
|
- lib/unparser/emitter/pin.rb
|
300
303
|
- lib/unparser/emitter/primitive.rb
|
301
304
|
- lib/unparser/emitter/range.rb
|
@@ -331,7 +334,10 @@ files:
|
|
331
334
|
homepage: http://github.com/mbj/unparser
|
332
335
|
licenses:
|
333
336
|
- MIT
|
334
|
-
metadata:
|
337
|
+
metadata:
|
338
|
+
bug_tracker_uri: https://github.com/mbj/unparser/issues
|
339
|
+
changelog_uri: https://github.com/mbj/unparser/blob/master/Changelog.md
|
340
|
+
funding_uri: https://github.com/sponsors/mbj
|
335
341
|
post_install_message:
|
336
342
|
rdoc_options: []
|
337
343
|
require_paths:
|
@@ -347,7 +353,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
347
353
|
- !ruby/object:Gem::Version
|
348
354
|
version: '0'
|
349
355
|
requirements: []
|
350
|
-
rubygems_version: 3.
|
356
|
+
rubygems_version: 3.2.3
|
351
357
|
signing_key:
|
352
358
|
specification_version: 4
|
353
359
|
summary: Generate equivalent source for parser gem AST nodes
|