unparser 0.6.0 → 0.6.4

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: 0a585e06cf743ca1901a601efa2fb7f178528307f89a6bea190df19014e3abf3
4
- data.tar.gz: dc1980af7f00fa4b54da6fc91cc740857588bf5d1bf30f6c362be995a86a2d83
3
+ metadata.gz: bb5014c1ad5b93a94374f4f79c60735d626e7b678c2a0521c15d4aeef63bf4a4
4
+ data.tar.gz: c932ade7d867e5dafc58f538bef903c723717c03e5276cd6e00bb4b6ec1205e9
5
5
  SHA512:
6
- metadata.gz: da5524a1621bd1202f943c201b79b425ae4c203a9642a633b2a8a66fc85a0b8d3a250464c18432b791ce7e656c5b1a3940bc93d004f0bc18aa5413f931fc74bf
7
- data.tar.gz: ab9cd266e002fcf85a12e1051a6b6a9fb9f47479ac2d7d883abcb99306d09ea6a196cb5d7de98a8c4f8a6635a78284e14e689cc2786f0a994eb504db0a0545ee
6
+ metadata.gz: ba212ad02df6e81cebc47f085d0432c5a05f44a63c5e9869f356cbd78a52805fc9ef9b8ffe331e0c802399e6c450f1a2ecd6eea49d01fb1ca6b7c750200d09e1
7
+ data.tar.gz: 5fa98dd676c1f2ebd2fa4006920fb8df12056178df169728d3bb239b3b9152ce0b6ba8f8cce4359b3fc4ee935e1aa79f079d0dd72953e2f24b75b5612e00f553
data/README.md CHANGED
@@ -10,7 +10,7 @@ The following constraints apply:
10
10
 
11
11
  * No support for macruby extensions
12
12
  * Only support for the [modern AST](https://github.com/whitequark/parser/#usage) format
13
- * Only support for Ruby >= 2.5
13
+ * Only support for Ruby >= 2.6
14
14
 
15
15
  Notable Users:
16
16
 
@@ -110,7 +110,7 @@ If you need to generate Ruby Syntax outside of this band feel free to contact me
110
110
  Testing:
111
111
  --------
112
112
 
113
- Unparser currently successfully round trips almost all ruby code around. Using MRI-2.5.x.
113
+ Unparser currently successfully round trips almost all ruby code around. Using Ruby >= 2.6.
114
114
  If there is a non round trippable example that is NOT subjected to known [Limitations](#limitations).
115
115
  please report a bug.
116
116
 
@@ -101,7 +101,8 @@ module Unparser
101
101
  def visibility
102
102
  if @descendant.private_method_defined?(@method_name) then :private
103
103
  elsif @descendant.protected_method_defined?(@method_name) then :protected
104
- else :public
104
+ else
105
+ :public
105
106
  end
106
107
  end
107
108
 
@@ -114,9 +114,9 @@ module Unparser
114
114
  # @api private
115
115
  #
116
116
  def capture_content
117
- size_before = @content.size
117
+ size_before = content.size
118
118
  yield
119
- @content[size_before..-1]
119
+ content[size_before..]
120
120
  end
121
121
 
122
122
  # Write raw fragment to buffer
data/lib/unparser/cli.rb CHANGED
@@ -76,6 +76,7 @@ module Unparser
76
76
  @targets = []
77
77
 
78
78
  @fail_fast = false
79
+ @start_with = nil
79
80
  @success = true
80
81
  @validation = :validation
81
82
  @verbose = false
@@ -127,7 +127,7 @@ module Unparser
127
127
 
128
128
  def dispatch
129
129
  write('&')
130
- visit(name)
130
+ visit(name) if name
131
131
  end
132
132
 
133
133
  end # BlockPass
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Unparser
4
+ class Emitter
5
+ # Emitter for in pattern nodes
6
+ class FindPattern < self
7
+ handle :find_pattern
8
+
9
+ private
10
+
11
+ def dispatch
12
+ write('[')
13
+ delimited(children)
14
+ write(']')
15
+ end
16
+ end # FindPattern
17
+ end # Emitter
18
+ end # Unparser
@@ -60,7 +60,7 @@ module Unparser
60
60
  end
61
61
 
62
62
  def write_symbol_body(symbol)
63
- write(symbol.inspect[1..-1])
63
+ write(symbol.inspect[1..])
64
64
  end
65
65
  end # Pin
66
66
  end # Emitter
@@ -6,17 +6,25 @@ module Unparser
6
6
  class MatchPattern < self
7
7
 
8
8
  handle :match_pattern
9
- handle :match_pattern_p
10
9
 
11
10
  children :target, :pattern
12
11
 
12
+ # Modern ast format emits `match_pattern`
13
+ # node on single line pre 3.0, but 3.0+ uses `match_pattern_p`
14
+ SYMBOL =
15
+ if RUBY_VERSION < '3.0'
16
+ ' in '
17
+ else
18
+ ' => '
19
+ end
20
+
13
21
  private
14
22
 
15
23
  def dispatch
16
24
  visit(target)
17
- write(' in ')
25
+ write(SYMBOL)
18
26
  visit(pattern)
19
27
  end
20
- end # InPattern
28
+ end # MatchPattern
21
29
  end # Emitter
22
30
  end # Unparser
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Unparser
4
+ class Emitter
5
+ class MatchPatternP < self
6
+
7
+ handle :match_pattern_p
8
+
9
+ children :target, :pattern
10
+
11
+ private
12
+
13
+ def dispatch
14
+ visit(target)
15
+ write(' in ')
16
+ visit(pattern)
17
+ end
18
+ end # MatchPatternP
19
+ end # Emitter
20
+ end # Unparser
@@ -4,8 +4,15 @@ module Unparser
4
4
  class Emitter
5
5
  # Emiter for match rest nodes
6
6
  class MatchRest < self
7
+ handle :match_rest
8
+
7
9
  children :match_var
8
10
 
11
+ def dispatch
12
+ write('*')
13
+ visit(match_var) if match_var
14
+ end
15
+
9
16
  def emit_array_pattern
10
17
  write('*')
11
18
  emit_match_var
@@ -19,7 +19,10 @@ module Unparser
19
19
  end
20
20
 
21
21
  def binary_syntax_allowed?
22
- selector_binary_operator? && arguments.one? && !n_splat?(arguments.first)
22
+ selector_binary_operator? \
23
+ && arguments.one? \
24
+ && !n_splat?(arguments.first) \
25
+ && !n_kwargs?(arguments.first)
23
26
  end
24
27
 
25
28
  def selector_unary_operator?
@@ -48,7 +51,7 @@ module Unparser
48
51
  memoize :assignment?
49
52
 
50
53
  def arguments
51
- children[2..-1]
54
+ children[2..]
52
55
  end
53
56
  memoize :arguments
54
57
 
@@ -36,18 +36,20 @@ module Unparser
36
36
  args
37
37
  array
38
38
  array_pattern
39
- empty_else
40
39
  begin
41
40
  block
42
41
  cbase
43
42
  const
44
43
  dstr
44
+ empty_else
45
45
  ensure
46
46
  hash
47
47
  hash_pattern
48
48
  if
49
49
  in_pattern
50
50
  int
51
+ kwarg
52
+ kwargs
51
53
  kwsplat
52
54
  lambda
53
55
  match_rest
@@ -17,7 +17,7 @@ module Unparser
17
17
 
18
18
  write(MAP.fetch(name, name).to_s)
19
19
 
20
- if n_int?(receiver) && selector.equal?(:'+@')
20
+ if n_int?(receiver) && selector.equal?(:+@)
21
21
  write('+')
22
22
  end
23
23
 
@@ -6,8 +6,8 @@ module Unparser
6
6
  class Send
7
7
  include Writer, Adamantium, Constants, Generation
8
8
 
9
- INDEX_ASSIGN = :'[]='
10
- INDEX_REFERENCE = :'[]'
9
+ INDEX_ASSIGN = :[]=
10
+ INDEX_REFERENCE = :[]
11
11
 
12
12
  OPERATORS = {
13
13
  csend: '&.',
@@ -45,7 +45,7 @@ module Unparser
45
45
  def effective_writer_class
46
46
  if details.binary_syntax_allowed?
47
47
  Binary
48
- elsif details.selector_unary_operator? && n_send?(node)
48
+ elsif details.selector_unary_operator? && n_send?(node) && arguments.empty?
49
49
  Unary
50
50
  elsif write_as_attribute_assignment?
51
51
  AttributeAssignment
data/lib/unparser.rb CHANGED
@@ -218,7 +218,9 @@ require 'unparser/emitter/xstr'
218
218
  require 'unparser/emitter/yield'
219
219
  require 'unparser/emitter/kwargs'
220
220
  require 'unparser/emitter/pair'
221
+ require 'unparser/emitter/find_pattern'
221
222
  require 'unparser/emitter/match_pattern'
223
+ require 'unparser/emitter/match_pattern_p'
222
224
  require 'unparser/writer'
223
225
  require 'unparser/writer/binary'
224
226
  require 'unparser/writer/dynamic_string'
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.6.0
4
+ version: 0.6.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Markus Schirp
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-01-16 00:00:00.000000000 Z
11
+ date: 2022-02-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: diff-lcs
@@ -30,42 +30,42 @@ dependencies:
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 3.0.0
33
+ version: 3.1.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: 3.0.0
40
+ version: 3.1.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: mutant
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 0.10.25
47
+ version: 0.11.1
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 0.10.25
54
+ version: 0.11.1
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: mutant-rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 0.10.25
61
+ version: 0.11.1
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 0.10.25
68
+ version: 0.11.1
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -184,6 +184,7 @@ files:
184
184
  - lib/unparser/emitter/defined.rb
185
185
  - lib/unparser/emitter/dstr.rb
186
186
  - lib/unparser/emitter/dsym.rb
187
+ - lib/unparser/emitter/find_pattern.rb
187
188
  - lib/unparser/emitter/flipflop.rb
188
189
  - lib/unparser/emitter/float.rb
189
190
  - lib/unparser/emitter/flow_modifier.rb
@@ -203,6 +204,7 @@ files:
203
204
  - lib/unparser/emitter/match_alt.rb
204
205
  - lib/unparser/emitter/match_as.rb
205
206
  - lib/unparser/emitter/match_pattern.rb
207
+ - lib/unparser/emitter/match_pattern_p.rb
206
208
  - lib/unparser/emitter/match_rest.rb
207
209
  - lib/unparser/emitter/match_var.rb
208
210
  - lib/unparser/emitter/mlhs.rb
@@ -257,15 +259,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
257
259
  requirements:
258
260
  - - ">="
259
261
  - !ruby/object:Gem::Version
260
- version: '2.5'
262
+ version: '2.6'
261
263
  required_rubygems_version: !ruby/object:Gem::Requirement
262
264
  requirements:
263
265
  - - ">="
264
266
  - !ruby/object:Gem::Version
265
267
  version: '0'
266
268
  requirements: []
267
- rubyforge_project:
268
- rubygems_version: 2.7.6.2
269
+ rubygems_version: 3.3.3
269
270
  signing_key:
270
271
  specification_version: 4
271
272
  summary: Generate equivalent source for parser gem AST nodes