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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 824d898a010fcf41a3a7d243d3f6c30dc551751fccc8a7d592e73fe6685dab8c
4
- data.tar.gz: ef5e5fdc7df12831465d4ed15d35da615ff10eafb342d2a32495c42d88c7b415
3
+ metadata.gz: 21e418840b351f5e697c472127300d7733ca1c20bdf4be321ae1832133447767
4
+ data.tar.gz: c130412892dcb6a1db4835c3ef9fa9738f2a181ede78ccca6a7a13336a348e8c
5
5
  SHA512:
6
- metadata.gz: c902fd66c8d5195ba76c3f53d028112e41e4bff18e62d851e207949ea332d5c1e2a352a2eb478b626a6fee2c4d908303c595c94364c03539bb4aa8a72d53b64d
7
- data.tar.gz: 647e6ac18916a4e2454cd1c018932da6c464598ac548d84da242d6b8d8b19c06a5ee430d9fa35338e3576bb860ac3acbde3814e6d891259db1506b9004c612cc
6
+ metadata.gz: 4a25a3e71df443024af556d20ca97f9a627874ee5857a4badfa2c7bd228159732fac0060715b198acc5648879c25baf8c0b10496f6cb0303fa41841cf06521ad
7
+ data.tar.gz: 8dec6ae089dbf574a7687177993da010f2569677217032e95079e007598c04e0acbb35d967667532331187d6ab25c81346c5073454dda7665e8864fc0e31e42a
@@ -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, &method(:emit_hash_member))
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,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Unparser
4
+ class Emitter
5
+ class Kwargs < self
6
+ handle :kwargs
7
+
8
+ def dispatch
9
+ delimited(children)
10
+ end
11
+ end # Kwargs
12
+ end # Emitter
13
+ 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
- need_squiggly? ? '<<~HEREDOC' : '<<-HEREDOC'
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
- if need_squiggly?
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|
@@ -75,20 +75,7 @@ module Unparser
75
75
  end
76
76
 
77
77
  def emit_normal_arguments
78
- parentheses do
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.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-24 00:00:00.000000000 Z
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: 2.6.5
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: 2.6.5
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.19
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.19
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.19
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.19
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.6.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.6.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.0
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.0
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.1.4
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