unparser 0.5.7 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,7 +5,7 @@ module Unparser
5
5
 
6
6
  # Emitter base class
7
7
  class Emitter
8
- include Adamantium::Flat, AbstractType, Constants, Generation, NodeHelpers
8
+ include Adamantium, AbstractType, Constants, Generation, NodeHelpers
9
9
  include Anima.new(:buffer, :comments, :node, :local_variable_scope)
10
10
 
11
11
  public :node
@@ -36,7 +36,7 @@ module Unparser
36
36
  handle :indexasgn
37
37
 
38
38
  VALUE_RANGE = (1..-2).freeze
39
- NO_VALUE_PARENT = IceNine.deep_freeze(%i[and_asgn op_asgn or_asgn].to_set)
39
+ NO_VALUE_PARENT = %i[and_asgn op_asgn or_asgn].to_set.freeze
40
40
 
41
41
  private_constant(*constants(false))
42
42
 
@@ -7,10 +7,10 @@ module Unparser
7
7
  class BinaryAssign < self
8
8
  children :target, :expression
9
9
 
10
- MAP = IceNine.deep_freeze(
10
+ MAP = {
11
11
  and_asgn: '&&=',
12
12
  or_asgn: '||='
13
- )
13
+ }.freeze
14
14
 
15
15
  handle(*MAP.keys)
16
16
 
@@ -28,11 +28,11 @@ module Unparser
28
28
  RATIONAL_FORMAT = 'i'.freeze
29
29
 
30
30
  MAP =
31
- IceNine.deep_freeze(
31
+ {
32
32
  ::Float => :float,
33
33
  ::Rational => :rational,
34
34
  ::Integer => :int
35
- )
35
+ }.freeze
36
36
 
37
37
  private
38
38
 
@@ -4,7 +4,7 @@ module Unparser
4
4
  class Emitter
5
5
  # Emitter for simple nodes that generate a single token
6
6
  class Simple < self
7
- MAP = IceNine.deep_freeze(
7
+ MAP = {
8
8
  __ENCODING__: '__ENCODING__',
9
9
  __FILE__: '__FILE__',
10
10
  __LINE__: '__LINE__',
@@ -19,7 +19,7 @@ module Unparser
19
19
  self: 'self',
20
20
  true: 'true',
21
21
  zsuper: 'super'
22
- )
22
+ }.freeze
23
23
 
24
24
  handle(*MAP.keys)
25
25
 
@@ -0,0 +1,98 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Unparser
4
+ # Define equality, equivalence and inspection methods
5
+ #
6
+ # Original code before vendoring and reduction from: https://github.com/dkubb/equalizer.
7
+ class Equalizer < Module
8
+ # Initialize an Equalizer with the given keys
9
+ #
10
+ # Will use the keys with which it is initialized to define #cmp?,
11
+ # #hash, and #inspect
12
+ #
13
+ # @param [Array<Symbol>] keys
14
+ #
15
+ # @return [undefined]
16
+ #
17
+ # @api private
18
+ #
19
+ # rubocop:disable Lint/MissingSuper
20
+ def initialize(*keys)
21
+ @keys = keys
22
+ define_methods
23
+ freeze
24
+ end
25
+ # rubocop:enable Lint/MissingSuper
26
+
27
+ private
28
+
29
+ def included(descendant)
30
+ descendant.include(Methods)
31
+ end
32
+
33
+ def define_methods
34
+ define_cmp_method
35
+ define_hash_method
36
+ define_inspect_method
37
+ end
38
+
39
+ def define_cmp_method
40
+ keys = @keys
41
+ define_method(:cmp?) do |comparator, other|
42
+ keys.all? do |key|
43
+ __send__(key).public_send(comparator, other.__send__(key))
44
+ end
45
+ end
46
+ private :cmp?
47
+ end
48
+
49
+ def define_hash_method
50
+ keys = @keys
51
+ define_method(:hash) do
52
+ keys.map(&public_method(:__send__)).push(self.class).hash
53
+ end
54
+ end
55
+
56
+ def define_inspect_method
57
+ keys = @keys
58
+ define_method(:inspect) do
59
+ klass = self.class
60
+ name = klass.name || klass.inspect
61
+ "#<#{name}#{keys.map { |key| " #{key}=#{__send__(key).inspect}" }.join}>"
62
+ end
63
+ end
64
+
65
+ # The comparison methods
66
+ module Methods
67
+ # Compare the object with other object for equality
68
+ #
69
+ # @example
70
+ # object.eql?(other) # => true or false
71
+ #
72
+ # @param [Object] other
73
+ # the other object to compare with
74
+ #
75
+ # @return [Boolean]
76
+ #
77
+ # @api public
78
+ def eql?(other)
79
+ instance_of?(other.class) && cmp?(__method__, other)
80
+ end
81
+
82
+ # Compare the object with other object for equivalency
83
+ #
84
+ # @example
85
+ # object == other # => true or false
86
+ #
87
+ # @param [Object] other
88
+ # the other object to compare with
89
+ #
90
+ # @return [Boolean]
91
+ #
92
+ # @api public
93
+ def ==(other)
94
+ instance_of?(other.class) && cmp?(__method__, other)
95
+ end
96
+ end # module Methods
97
+ end # class Equalizer
98
+ end # Unparser
@@ -6,7 +6,7 @@ module Unparser
6
6
 
7
7
  def self.included(descendant)
8
8
  descendant.class_eval do
9
- include Adamantium::Flat, Concord.new(:node)
9
+ include Adamantium, Concord.new(:node)
10
10
 
11
11
  extend DSL
12
12
  end
@@ -3,7 +3,7 @@
3
3
  module Unparser
4
4
  # Validation of unparser results
5
5
  class Validation
6
- include Adamantium::Flat, Anima.new(
6
+ include Adamantium, Anima.new(
7
7
  :generated_node,
8
8
  :generated_source,
9
9
  :identification,
@@ -64,7 +64,7 @@ module Unparser
64
64
 
65
65
  new(
66
66
  identification: '(string)',
67
- original_source: MPrelude::Either::Right.new(original_source),
67
+ original_source: Either::Right.new(original_source),
68
68
  original_node: original_node,
69
69
  generated_source: generated_source,
70
70
  generated_node: generated_node
@@ -86,7 +86,7 @@ module Unparser
86
86
  new(
87
87
  identification: '(string)',
88
88
  original_source: generated_source,
89
- original_node: MPrelude::Either::Right.new(original_node),
89
+ original_node: Either::Right.new(original_node),
90
90
  generated_source: generated_source,
91
91
  generated_node: generated_node
92
92
  )
@@ -3,7 +3,7 @@
3
3
  module Unparser
4
4
  module Writer
5
5
  class Binary
6
- include Writer, Adamantium::Flat
6
+ include Writer, Adamantium
7
7
 
8
8
  children :left, :right
9
9
 
@@ -3,22 +3,20 @@
3
3
  module Unparser
4
4
  module Writer
5
5
  class DynamicString
6
- include Writer, Adamantium::Flat
6
+ include Writer, Adamantium
7
7
 
8
- PATTERNS_2 = IceNine.deep_freeze(
8
+ PATTERNS_2 =
9
9
  [
10
- %i[str_empty begin],
11
- %i[begin str_nl]
12
- ]
13
- )
10
+ %i[str_empty begin].freeze,
11
+ %i[begin str_nl].freeze
12
+ ].freeze
14
13
 
15
- PATTERNS_3 = IceNine.deep_freeze(
14
+ PATTERNS_3 =
16
15
  [
17
- %i[begin str_nl_eol str_nl_eol],
18
- %i[str_nl_eol begin str_nl_eol],
19
- %i[str_ws begin str_nl_eol]
20
- ]
21
- )
16
+ %i[begin str_nl_eol str_nl_eol].freeze,
17
+ %i[str_nl_eol begin str_nl_eol].freeze,
18
+ %i[str_ws begin str_nl_eol].freeze
19
+ ].freeze
22
20
 
23
21
  FLAT_INTERPOLATION = %i[ivar cvar gvar nth_ref].to_set.freeze
24
22
 
@@ -3,7 +3,7 @@
3
3
  module Unparser
4
4
  module Writer
5
5
  class Rescue
6
- include Writer, Adamantium::Flat
6
+ include Writer, Adamantium
7
7
 
8
8
  children :body, :rescue_body
9
9
 
@@ -4,7 +4,7 @@ module Unparser
4
4
  module Writer
5
5
  # Writer for send
6
6
  class Send
7
- include Writer, Adamantium::Flat, Constants, Generation
7
+ include Writer, Adamantium, Constants, Generation
8
8
 
9
9
  INDEX_ASSIGN = :'[]='
10
10
  INDEX_REFERENCE = :'[]'
@@ -91,7 +91,11 @@ module Unparser
91
91
  end
92
92
 
93
93
  def parses_as_constant?
94
- n_const?(Unparser.parse(selector.to_s))
94
+ test = Unparser.parse_either(selector.to_s).from_right do
95
+ fail InvalidNodeError.new("Invalid selector for send node: #{selector.inspect}", node)
96
+ end
97
+
98
+ n_const?(test)
95
99
  end
96
100
 
97
101
  def details
metadata CHANGED
@@ -1,71 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unparser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.7
4
+ version: 0.6.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: 2021-01-11 00:00:00.000000000 Z
11
+ date: 2021-01-16 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: abstract_type
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: 0.0.7
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: 0.0.7
27
- - !ruby/object:Gem::Dependency
28
- name: adamantium
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: 0.2.0
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: 0.2.0
41
- - !ruby/object:Gem::Dependency
42
- name: anima
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: 0.3.1
48
- type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: 0.3.1
55
- - !ruby/object:Gem::Dependency
56
- name: concord
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: 0.1.5
62
- type: :runtime
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: 0.1.5
69
13
  - !ruby/object:Gem::Dependency
70
14
  name: diff-lcs
71
15
  requirement: !ruby/object:Gem::Requirement
@@ -80,34 +24,6 @@ dependencies:
80
24
  - - "~>"
81
25
  - !ruby/object:Gem::Version
82
26
  version: '1.3'
83
- - !ruby/object:Gem::Dependency
84
- name: equalizer
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - "~>"
88
- - !ruby/object:Gem::Version
89
- version: 0.0.9
90
- type: :runtime
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - "~>"
95
- - !ruby/object:Gem::Version
96
- version: 0.0.9
97
- - !ruby/object:Gem::Dependency
98
- name: mprelude
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - "~>"
102
- - !ruby/object:Gem::Version
103
- version: 0.1.0
104
- type: :runtime
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - "~>"
109
- - !ruby/object:Gem::Version
110
- version: 0.1.0
111
27
  - !ruby/object:Gem::Dependency
112
28
  name: parser
113
29
  requirement: !ruby/object:Gem::Requirement
@@ -122,48 +38,34 @@ dependencies:
122
38
  - - ">="
123
39
  - !ruby/object:Gem::Version
124
40
  version: 3.0.0
125
- - !ruby/object:Gem::Dependency
126
- name: procto
127
- requirement: !ruby/object:Gem::Requirement
128
- requirements:
129
- - - "~>"
130
- - !ruby/object:Gem::Version
131
- version: 0.0.2
132
- type: :runtime
133
- prerelease: false
134
- version_requirements: !ruby/object:Gem::Requirement
135
- requirements:
136
- - - "~>"
137
- - !ruby/object:Gem::Version
138
- version: 0.0.2
139
41
  - !ruby/object:Gem::Dependency
140
42
  name: mutant
141
43
  requirement: !ruby/object:Gem::Requirement
142
44
  requirements:
143
45
  - - "~>"
144
46
  - !ruby/object:Gem::Version
145
- version: 0.10.22
47
+ version: 0.10.25
146
48
  type: :development
147
49
  prerelease: false
148
50
  version_requirements: !ruby/object:Gem::Requirement
149
51
  requirements:
150
52
  - - "~>"
151
53
  - !ruby/object:Gem::Version
152
- version: 0.10.22
54
+ version: 0.10.25
153
55
  - !ruby/object:Gem::Dependency
154
56
  name: mutant-rspec
155
57
  requirement: !ruby/object:Gem::Requirement
156
58
  requirements:
157
59
  - - "~>"
158
60
  - !ruby/object:Gem::Version
159
- version: 0.10.22
61
+ version: 0.10.25
160
62
  type: :development
161
63
  prerelease: false
162
64
  version_requirements: !ruby/object:Gem::Requirement
163
65
  requirements:
164
66
  - - "~>"
165
67
  - !ruby/object:Gem::Version
166
- version: 0.10.22
68
+ version: 0.10.25
167
69
  - !ruby/object:Gem::Dependency
168
70
  name: rspec
169
71
  requirement: !ruby/object:Gem::Requirement
@@ -245,15 +147,23 @@ files:
245
147
  - README.md
246
148
  - bin/unparser
247
149
  - lib/unparser.rb
150
+ - lib/unparser/abstract_type.rb
151
+ - lib/unparser/adamantium.rb
152
+ - lib/unparser/adamantium/method_builder.rb
153
+ - lib/unparser/anima.rb
154
+ - lib/unparser/anima/attribute.rb
155
+ - lib/unparser/anima/error.rb
248
156
  - lib/unparser/ast.rb
249
157
  - lib/unparser/ast/local_variable_scope.rb
250
158
  - lib/unparser/buffer.rb
251
159
  - lib/unparser/cli.rb
252
160
  - lib/unparser/color.rb
253
161
  - lib/unparser/comments.rb
162
+ - lib/unparser/concord.rb
254
163
  - lib/unparser/constants.rb
255
164
  - lib/unparser/diff.rb
256
165
  - lib/unparser/dsl.rb
166
+ - lib/unparser/either.rb
257
167
  - lib/unparser/emitter.rb
258
168
  - lib/unparser/emitter/alias.rb
259
169
  - lib/unparser/emitter/args.rb
@@ -314,6 +224,7 @@ files:
314
224
  - lib/unparser/emitter/variable.rb
315
225
  - lib/unparser/emitter/xstr.rb
316
226
  - lib/unparser/emitter/yield.rb
227
+ - lib/unparser/equalizer.rb
317
228
  - lib/unparser/finalize.rb
318
229
  - lib/unparser/generation.rb
319
230
  - lib/unparser/node_details.rb
@@ -353,7 +264,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
353
264
  - !ruby/object:Gem::Version
354
265
  version: '0'
355
266
  requirements: []
356
- rubygems_version: 3.2.3
267
+ rubyforge_project:
268
+ rubygems_version: 2.7.6.2
357
269
  signing_key:
358
270
  specification_version: 4
359
271
  summary: Generate equivalent source for parser gem AST nodes