unparser 0.8.1 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +6 -6
- data/lib/unparser/anima.rb +1 -3
- data/lib/unparser/ast/local_variable_scope.rb +4 -4
- data/lib/unparser/ast.rb +16 -29
- data/lib/unparser/cli.rb +18 -4
- data/lib/unparser/color.rb +7 -1
- data/lib/unparser/comments.rb +2 -2
- data/lib/unparser/diff.rb +8 -1
- data/lib/unparser/either.rb +7 -5
- data/lib/unparser/emitter/primitive.rb +1 -16
- data/lib/unparser/emitter.rb +2 -1
- data/lib/unparser/equalizer.rb +105 -71
- data/lib/unparser/node_details.rb +7 -1
- data/lib/unparser/util.rb +2 -1
- data/lib/unparser/validation.rb +1 -1
- data/lib/unparser.rb +9 -4
- metadata +52 -20
- data/lib/unparser/concord.rb +0 -114
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 55ff925fe35a0edc1d97f78f4c2cf18590a3f2b4a11bc33e4b786a5954b4a38b
|
|
4
|
+
data.tar.gz: 41298c66c043f4f886215b23f6e1b16cd5bfc4fda9cac590a4dcfbf79c7b3ad8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: '08b368b24f292f467d75f2cbbea4488dc117fbfc1619c0ab14eee351121221bf63d0c60aa8cffb1cc9f795eb87fd0a5e0d1cefd196ec955f8d3c0b12784f57a6'
|
|
7
|
+
data.tar.gz: 9a21fffcd287e446c6e5a459556d1c863490ebbaa906ea4f775619286405d18fab3821c5fc3e14ba4ab8fc8f68de344b6a71565f7e8980f8eac43a762b7caf66
|
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 >= 3.
|
|
13
|
+
* Only support for Ruby >= 3.3
|
|
14
14
|
|
|
15
15
|
Notable Users:
|
|
16
16
|
|
|
@@ -173,12 +173,12 @@ Included Libraries
|
|
|
173
173
|
|
|
174
174
|
For dependency reduction reasons unparser ships vendored (and reduced) versions of:
|
|
175
175
|
|
|
176
|
-
* [abstract_type](https://github.com/
|
|
176
|
+
* [abstract_type](https://github.com/dkubb/abstract_type) -> Unparser::AbstractType
|
|
177
177
|
* [adamantium](https://github.com/dkubb/adamantium) -> Unparser::Adamantium
|
|
178
|
-
* [anima](https://github.com/mbj/
|
|
179
|
-
* [
|
|
180
|
-
* [memoizable](https://github.com/dkubb/memoizable) -> Unparser::
|
|
181
|
-
* [mprelude](
|
|
178
|
+
* [anima](https://github.com/mbj/anima) -> Unparser::Anima
|
|
179
|
+
* [equalizer](https://github.com/dkubb/equalizer) -> Unparser::Equalizer
|
|
180
|
+
* [memoizable](https://github.com/dkubb/memoizable) -> Unparser::Memoizable
|
|
181
|
+
* [mprelude](http://prelude.rubyforge.org/) -> Unparser::Either
|
|
182
182
|
|
|
183
183
|
Contributing
|
|
184
184
|
-------------
|
data/lib/unparser/anima.rb
CHANGED
|
@@ -50,9 +50,7 @@ module Unparser
|
|
|
50
50
|
#
|
|
51
51
|
# @return [Hash]
|
|
52
52
|
def attributes_hash(object)
|
|
53
|
-
attributes.
|
|
54
|
-
attributes_hash[attribute.name] = attribute.get(object)
|
|
55
|
-
end
|
|
53
|
+
attributes.to_h { |attribute| [attribute.name, attribute.get(object)] }
|
|
56
54
|
end
|
|
57
55
|
|
|
58
56
|
# Return attribute names
|
|
@@ -107,8 +107,8 @@ module Unparser
|
|
|
107
107
|
end
|
|
108
108
|
|
|
109
109
|
# Enumerate each node with its local variable scope
|
|
110
|
-
def self.each(node:, stack:, &
|
|
111
|
-
new(stack: stack).each(node: node, &
|
|
110
|
+
def self.each(node:, stack:, &)
|
|
111
|
+
new(stack: stack).each(node: node, &)
|
|
112
112
|
end
|
|
113
113
|
|
|
114
114
|
# Enumerate local variable scope scope
|
|
@@ -121,8 +121,8 @@ module Unparser
|
|
|
121
121
|
#
|
|
122
122
|
# @api private
|
|
123
123
|
#
|
|
124
|
-
def each(node:, &
|
|
125
|
-
visit(node, &
|
|
124
|
+
def each(node:, &)
|
|
125
|
+
visit(node, &)
|
|
126
126
|
end
|
|
127
127
|
|
|
128
128
|
private
|
data/lib/unparser/ast.rb
CHANGED
|
@@ -90,7 +90,14 @@ module Unparser
|
|
|
90
90
|
|
|
91
91
|
# AST enumerator
|
|
92
92
|
class Enumerator
|
|
93
|
-
include Adamantium,
|
|
93
|
+
include Adamantium, Equalizer.new(:node, :controller), Enumerable
|
|
94
|
+
|
|
95
|
+
attr_reader :node, :controller
|
|
96
|
+
|
|
97
|
+
def initialize(node, controller)
|
|
98
|
+
@node = node
|
|
99
|
+
@controller = controller
|
|
100
|
+
end
|
|
94
101
|
|
|
95
102
|
# Return each node
|
|
96
103
|
#
|
|
@@ -130,38 +137,18 @@ module Unparser
|
|
|
130
137
|
select { |node| node.type.equal?(type) }
|
|
131
138
|
end
|
|
132
139
|
|
|
133
|
-
# Return frozne set of objects
|
|
134
|
-
#
|
|
135
|
-
# @param [Enumerable] enumerable
|
|
136
|
-
#
|
|
137
|
-
# @return [Set]
|
|
138
|
-
#
|
|
139
|
-
# @api private
|
|
140
|
-
#
|
|
141
|
-
def self.set(enumerable)
|
|
142
|
-
enumerable.to_set.freeze
|
|
143
|
-
end
|
|
144
|
-
private_class_method :set
|
|
145
|
-
|
|
146
|
-
# Return nodes of type
|
|
147
|
-
#
|
|
148
|
-
# @param [Parser::AST::Node] node
|
|
149
|
-
# @param [Symbol] type
|
|
150
|
-
#
|
|
151
|
-
# @return [Enumerable<Parser::AST::Node]
|
|
152
|
-
#
|
|
153
|
-
# @api private
|
|
154
|
-
#
|
|
155
|
-
def self.type(node, type)
|
|
156
|
-
new(node).type(type)
|
|
157
|
-
end
|
|
158
|
-
private_class_method :type
|
|
159
|
-
|
|
160
140
|
end # Enumerator
|
|
161
141
|
|
|
162
142
|
# Controlled AST walker walking the AST in deeth first search with pre order
|
|
163
143
|
class Walker
|
|
164
|
-
include
|
|
144
|
+
include Equalizer.new(:block, :controller)
|
|
145
|
+
|
|
146
|
+
attr_reader :block, :controller
|
|
147
|
+
|
|
148
|
+
def initialize(block, controller)
|
|
149
|
+
@block = block
|
|
150
|
+
@controller = controller
|
|
151
|
+
end
|
|
165
152
|
|
|
166
153
|
# Call ast walker
|
|
167
154
|
#
|
data/lib/unparser/cli.rb
CHANGED
|
@@ -14,7 +14,15 @@ module Unparser
|
|
|
14
14
|
|
|
15
15
|
# Path target
|
|
16
16
|
class Path < self
|
|
17
|
-
include
|
|
17
|
+
include Equalizer.new(:path)
|
|
18
|
+
|
|
19
|
+
attr_reader :path
|
|
20
|
+
|
|
21
|
+
# rubocop:disable Lint/MissingSuper
|
|
22
|
+
def initialize(path)
|
|
23
|
+
@path = path
|
|
24
|
+
end
|
|
25
|
+
# rubocop:enable Lint/MissingSuper
|
|
18
26
|
|
|
19
27
|
# Validation for this target
|
|
20
28
|
#
|
|
@@ -33,7 +41,13 @@ module Unparser
|
|
|
33
41
|
|
|
34
42
|
# String target
|
|
35
43
|
class String
|
|
36
|
-
include
|
|
44
|
+
include Equalizer.new(:string)
|
|
45
|
+
|
|
46
|
+
attr_reader :string
|
|
47
|
+
|
|
48
|
+
def initialize(string)
|
|
49
|
+
@string = string
|
|
50
|
+
end
|
|
37
51
|
|
|
38
52
|
# Validation for this target
|
|
39
53
|
#
|
|
@@ -63,8 +77,8 @@ module Unparser
|
|
|
63
77
|
# @api private
|
|
64
78
|
#
|
|
65
79
|
# mutant:disable
|
|
66
|
-
def self.run(*
|
|
67
|
-
new(*
|
|
80
|
+
def self.run(*)
|
|
81
|
+
new(*).exit_status
|
|
68
82
|
end
|
|
69
83
|
|
|
70
84
|
# Initialize object
|
data/lib/unparser/color.rb
CHANGED
data/lib/unparser/comments.rb
CHANGED
data/lib/unparser/diff.rb
CHANGED
|
@@ -3,7 +3,14 @@
|
|
|
3
3
|
module Unparser
|
|
4
4
|
# Class to create diffs from source code
|
|
5
5
|
class Diff
|
|
6
|
-
include Adamantium,
|
|
6
|
+
include Adamantium, Equalizer.new(:old, :new)
|
|
7
|
+
|
|
8
|
+
attr_reader :old, :new
|
|
9
|
+
|
|
10
|
+
def initialize(old, new)
|
|
11
|
+
@old = old
|
|
12
|
+
@new = new
|
|
13
|
+
end
|
|
7
14
|
|
|
8
15
|
ADDITION = '+'
|
|
9
16
|
DELETION = '-'
|
data/lib/unparser/either.rb
CHANGED
|
@@ -19,11 +19,13 @@ module Unparser
|
|
|
19
19
|
end # RequireBLock
|
|
20
20
|
|
|
21
21
|
class Either
|
|
22
|
-
include(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
)
|
|
22
|
+
include Adamantium, Equalizer.new(:value), RequireBlock
|
|
23
|
+
|
|
24
|
+
attr_reader :value
|
|
25
|
+
|
|
26
|
+
def initialize(value)
|
|
27
|
+
@value = value
|
|
28
|
+
end
|
|
27
29
|
|
|
28
30
|
# Execute block and wrap error in left
|
|
29
31
|
#
|
|
@@ -13,23 +13,8 @@ module Unparser
|
|
|
13
13
|
|
|
14
14
|
private
|
|
15
15
|
|
|
16
|
-
# mutant:disable
|
|
17
16
|
def dispatch
|
|
18
|
-
|
|
19
|
-
write(":#{value.name.inspect}")
|
|
20
|
-
else
|
|
21
|
-
write(value.inspect)
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
# mutant:disable
|
|
26
|
-
def inspect_breaks_parsing?
|
|
27
|
-
return false unless RUBY_VERSION < '3.2.'
|
|
28
|
-
|
|
29
|
-
Unparser.parse(value.inspect)
|
|
30
|
-
false
|
|
31
|
-
rescue Parser::SyntaxError
|
|
32
|
-
true
|
|
17
|
+
write(value.inspect)
|
|
33
18
|
end
|
|
34
19
|
end # Symbol
|
|
35
20
|
|
data/lib/unparser/emitter.rb
CHANGED
data/lib/unparser/equalizer.rb
CHANGED
|
@@ -4,95 +4,129 @@ module Unparser
|
|
|
4
4
|
# Define equality, equivalence and inspection methods
|
|
5
5
|
#
|
|
6
6
|
# Original code before vendoring and reduction from: https://github.com/dkubb/equalizer.
|
|
7
|
-
|
|
8
|
-
#
|
|
7
|
+
module Equalizer
|
|
8
|
+
# Creates a module providing equality methods based on the given attributes
|
|
9
9
|
#
|
|
10
|
-
#
|
|
11
|
-
# #
|
|
10
|
+
# @param keys [Array<Symbol>] attribute names to use for equality
|
|
11
|
+
# @param inspect [Boolean] whether to override #inspect and #pretty_print
|
|
12
|
+
# @return [Module] a module to include in your class
|
|
13
|
+
# @raise [ArgumentError] if keys is empty or contains non-Symbols
|
|
12
14
|
#
|
|
13
|
-
# @
|
|
14
|
-
|
|
15
|
-
|
|
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
|
|
15
|
+
# @api public
|
|
16
|
+
def self.new(*keys, inspect: true)
|
|
17
|
+
build_module(keys.freeze, inspect:)
|
|
37
18
|
end
|
|
38
19
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
20
|
+
# Instance methods mixed into classes that include an Equalizer module
|
|
21
|
+
#
|
|
22
|
+
# @api private
|
|
23
|
+
module InstanceMethods
|
|
24
|
+
# Equality comparison allowing subclasses
|
|
25
|
+
#
|
|
26
|
+
# @param other [Object] object to compare
|
|
27
|
+
# @return [Boolean] true if other is_a? same class with equal attributes
|
|
28
|
+
def ==(other)
|
|
29
|
+
other.is_a?(self.class) &&
|
|
30
|
+
cmp?(:==, other)
|
|
45
31
|
end
|
|
46
|
-
private :cmp?
|
|
47
|
-
end
|
|
48
32
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
33
|
+
# Strict equality requiring exact class match
|
|
34
|
+
#
|
|
35
|
+
# @param other [Object] object to compare
|
|
36
|
+
# @return [Boolean] true if other is exact same class with eql? attributes
|
|
37
|
+
def eql?(other)
|
|
38
|
+
other.instance_of?(self.class) &&
|
|
39
|
+
cmp?(:eql?, other)
|
|
53
40
|
end
|
|
54
|
-
end
|
|
55
41
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
"#<#{name}#{keys.map { |key| " #{key}=#{__send__(key).inspect}" }.join}>"
|
|
42
|
+
# Hash code based on class and attribute values
|
|
43
|
+
#
|
|
44
|
+
# @return [Integer] hash code
|
|
45
|
+
def hash
|
|
46
|
+
[self.class, *deconstruct].hash
|
|
62
47
|
end
|
|
63
|
-
end
|
|
64
48
|
|
|
65
|
-
|
|
66
|
-
module Methods
|
|
67
|
-
# Compare the object with other object for equality
|
|
49
|
+
# Array deconstruction for pattern matching
|
|
68
50
|
#
|
|
69
|
-
# @
|
|
70
|
-
|
|
51
|
+
# @return [Array] attribute values in order
|
|
52
|
+
def deconstruct
|
|
53
|
+
equalizer_keys.map { |key| public_send(key) }
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# Hash deconstruction for pattern matching
|
|
71
57
|
#
|
|
72
|
-
# @param [
|
|
73
|
-
#
|
|
58
|
+
# @param requested [Array<Symbol>, nil] keys to include, or nil for all
|
|
59
|
+
# @return [Hash{Symbol => Object}] requested attribute key-value pairs
|
|
60
|
+
def deconstruct_keys(requested)
|
|
61
|
+
subset = requested.nil? ? equalizer_keys : equalizer_keys & requested
|
|
62
|
+
subset.to_h { |key| [key, public_send(key)] }
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
private
|
|
66
|
+
|
|
67
|
+
# Compare all attributes using the given comparator
|
|
74
68
|
#
|
|
75
|
-
# @
|
|
69
|
+
# @param comparator [Symbol] method to use for comparison
|
|
70
|
+
# @param other [Object] object to compare against
|
|
71
|
+
# @return [Boolean] true if all attributes match
|
|
76
72
|
#
|
|
77
|
-
# @api
|
|
78
|
-
def
|
|
79
|
-
|
|
73
|
+
# @api private
|
|
74
|
+
def cmp?(comparator, other)
|
|
75
|
+
equalizer_keys.all? do |key|
|
|
76
|
+
public_send(key)
|
|
77
|
+
.public_send(comparator, other.public_send(key))
|
|
78
|
+
end
|
|
80
79
|
end
|
|
80
|
+
end
|
|
81
81
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
82
|
+
# Instance methods for inspect and pretty print output
|
|
83
|
+
#
|
|
84
|
+
# @api private
|
|
85
|
+
module InspectMethods
|
|
86
|
+
# String representation showing only equalizer attributes
|
|
86
87
|
#
|
|
87
|
-
# @
|
|
88
|
-
|
|
88
|
+
# @return [String] inspect output
|
|
89
|
+
def inspect
|
|
90
|
+
attrs = equalizer_keys
|
|
91
|
+
.map { |key| "@#{key}=#{public_send(key).inspect}" }
|
|
92
|
+
.join(', ')
|
|
93
|
+
Object.instance_method(:to_s).bind_call(self).sub(/>\z/, " #{attrs}>")
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
# Pretty print output using PP's object formatting
|
|
89
97
|
#
|
|
90
|
-
# @
|
|
98
|
+
# @param q [PP] pretty printer
|
|
99
|
+
# @return [void]
|
|
100
|
+
def pretty_print(pretty_printer)
|
|
101
|
+
pretty_printer.pp_object(self)
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
# Instance variables to display in pretty print output
|
|
91
105
|
#
|
|
92
|
-
# @
|
|
93
|
-
def
|
|
94
|
-
|
|
106
|
+
# @return [Array<Symbol>] instance variable names
|
|
107
|
+
def pretty_print_instance_variables
|
|
108
|
+
equalizer_keys.map { |key| :"@#{key}" }
|
|
95
109
|
end
|
|
96
|
-
end
|
|
97
|
-
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
# Builds the module with equality methods for the given keys
|
|
113
|
+
#
|
|
114
|
+
# @param keys [Array<Symbol>] attribute names (frozen)
|
|
115
|
+
# @param inspect [Boolean] whether to include inspect methods
|
|
116
|
+
# @return [Module] the configured module
|
|
117
|
+
#
|
|
118
|
+
# @api private
|
|
119
|
+
def self.build_module(keys, inspect:)
|
|
120
|
+
Module.new do
|
|
121
|
+
include InstanceMethods
|
|
122
|
+
include InspectMethods if inspect
|
|
123
|
+
|
|
124
|
+
set_temporary_name("Equalizer(#{keys.join(', ')})")
|
|
125
|
+
|
|
126
|
+
define_method(:equalizer_keys) { keys }
|
|
127
|
+
private :equalizer_keys
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
private_class_method :build_module
|
|
131
|
+
end # module Equalizer
|
|
98
132
|
end # Unparser
|
|
@@ -7,7 +7,13 @@ module Unparser
|
|
|
7
7
|
# mutant:disable
|
|
8
8
|
def self.included(descendant)
|
|
9
9
|
descendant.class_eval do
|
|
10
|
-
include Adamantium,
|
|
10
|
+
include Adamantium, Equalizer.new(:node)
|
|
11
|
+
|
|
12
|
+
attr_reader :node
|
|
13
|
+
|
|
14
|
+
def initialize(node)
|
|
15
|
+
@node = node
|
|
16
|
+
end
|
|
11
17
|
|
|
12
18
|
extend DSL
|
|
13
19
|
end
|
data/lib/unparser/util.rb
CHANGED
|
@@ -4,7 +4,8 @@ module Unparser
|
|
|
4
4
|
# Original code before vendoring and reduction from: https://github.com/mbj/mutant/blob/main/lib/mutant/util.rb
|
|
5
5
|
module Util
|
|
6
6
|
# Error raised by `Util.one` if size is not exactly one
|
|
7
|
-
SizeError
|
|
7
|
+
class SizeError < IndexError
|
|
8
|
+
end
|
|
8
9
|
|
|
9
10
|
# Return only element in array if it contains exactly one member
|
|
10
11
|
#
|
data/lib/unparser/validation.rb
CHANGED
|
@@ -145,7 +145,7 @@ module Unparser
|
|
|
145
145
|
# mutant:disable
|
|
146
146
|
def report_exception(phase_exception)
|
|
147
147
|
if phase_exception
|
|
148
|
-
[phase_exception.inspect].concat(phase_exception.backtrace
|
|
148
|
+
[phase_exception.inspect].concat(phase_exception.backtrace&.take(20) || [])
|
|
149
149
|
else
|
|
150
150
|
%w[undefined]
|
|
151
151
|
end
|
data/lib/unparser.rb
CHANGED
|
@@ -3,14 +3,12 @@
|
|
|
3
3
|
require 'diff/lcs'
|
|
4
4
|
require 'diff/lcs/hunk'
|
|
5
5
|
require 'optparse'
|
|
6
|
-
require 'set'
|
|
7
6
|
|
|
8
7
|
require 'unparser/equalizer'
|
|
9
8
|
require 'unparser/adamantium'
|
|
10
9
|
require 'unparser/adamantium/method_builder'
|
|
11
10
|
require 'unparser/abstract_type'
|
|
12
11
|
|
|
13
|
-
require 'unparser/concord'
|
|
14
12
|
require 'unparser/either'
|
|
15
13
|
require 'unparser/anima'
|
|
16
14
|
require 'unparser/anima/attribute'
|
|
@@ -53,7 +51,14 @@ module Unparser # rubocop:disable Metrics/ModuleLength
|
|
|
53
51
|
end
|
|
54
52
|
end
|
|
55
53
|
else
|
|
56
|
-
|
|
54
|
+
prism_translation_parser =
|
|
55
|
+
if Gem::Version.new(RUBY_VERSION) >= '4.0'
|
|
56
|
+
Prism::Translation::Parser40
|
|
57
|
+
else
|
|
58
|
+
Prism::Translation::Parser34
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
Class.new(prism_translation_parser) do
|
|
57
62
|
def declare_local_variable(local_variable)
|
|
58
63
|
(@local_variables ||= Set.new) << local_variable
|
|
59
64
|
end
|
|
@@ -67,7 +72,7 @@ module Unparser # rubocop:disable Metrics/ModuleLength
|
|
|
67
72
|
EMPTY_STRING = ''.freeze
|
|
68
73
|
EMPTY_ARRAY = [].freeze
|
|
69
74
|
|
|
70
|
-
private_constant(*constants(false) - %i[Adamantium AbstractType Anima
|
|
75
|
+
private_constant(*constants(false) - %i[Adamantium AbstractType Anima Either Equalizer Memoizable])
|
|
71
76
|
|
|
72
77
|
# Error raised when unparser encounters an invalid AST
|
|
73
78
|
class InvalidNodeError < RuntimeError
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: unparser
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.9.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Markus Schirp
|
|
@@ -13,16 +13,22 @@ dependencies:
|
|
|
13
13
|
name: diff-lcs
|
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|
|
15
15
|
requirements:
|
|
16
|
-
- - "
|
|
16
|
+
- - ">="
|
|
17
17
|
- !ruby/object:Gem::Version
|
|
18
18
|
version: '1.6'
|
|
19
|
+
- - "<"
|
|
20
|
+
- !ruby/object:Gem::Version
|
|
21
|
+
version: '3'
|
|
19
22
|
type: :runtime
|
|
20
23
|
prerelease: false
|
|
21
24
|
version_requirements: !ruby/object:Gem::Requirement
|
|
22
25
|
requirements:
|
|
23
|
-
- - "
|
|
26
|
+
- - ">="
|
|
24
27
|
- !ruby/object:Gem::Version
|
|
25
28
|
version: '1.6'
|
|
29
|
+
- - "<"
|
|
30
|
+
- !ruby/object:Gem::Version
|
|
31
|
+
version: '3'
|
|
26
32
|
- !ruby/object:Gem::Dependency
|
|
27
33
|
name: parser
|
|
28
34
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -52,75 +58,101 @@ dependencies:
|
|
|
52
58
|
- !ruby/object:Gem::Version
|
|
53
59
|
version: 1.5.1
|
|
54
60
|
- !ruby/object:Gem::Dependency
|
|
55
|
-
name:
|
|
61
|
+
name: benchmark
|
|
56
62
|
requirement: !ruby/object:Gem::Requirement
|
|
57
63
|
requirements:
|
|
58
64
|
- - "~>"
|
|
59
65
|
- !ruby/object:Gem::Version
|
|
60
|
-
version: 0.
|
|
66
|
+
version: 0.5.0
|
|
61
67
|
type: :development
|
|
62
68
|
prerelease: false
|
|
63
69
|
version_requirements: !ruby/object:Gem::Requirement
|
|
64
70
|
requirements:
|
|
65
71
|
- - "~>"
|
|
66
72
|
- !ruby/object:Gem::Version
|
|
67
|
-
version: 0.
|
|
73
|
+
version: 0.5.0
|
|
74
|
+
- !ruby/object:Gem::Dependency
|
|
75
|
+
name: mutant
|
|
76
|
+
requirement: !ruby/object:Gem::Requirement
|
|
77
|
+
requirements:
|
|
78
|
+
- - ">="
|
|
79
|
+
- !ruby/object:Gem::Version
|
|
80
|
+
version: 0.14.2
|
|
81
|
+
type: :development
|
|
82
|
+
prerelease: false
|
|
83
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
84
|
+
requirements:
|
|
85
|
+
- - ">="
|
|
86
|
+
- !ruby/object:Gem::Version
|
|
87
|
+
version: 0.14.2
|
|
68
88
|
- !ruby/object:Gem::Dependency
|
|
69
89
|
name: mutant-rspec
|
|
70
90
|
requirement: !ruby/object:Gem::Requirement
|
|
71
91
|
requirements:
|
|
72
|
-
- - "
|
|
92
|
+
- - ">="
|
|
73
93
|
- !ruby/object:Gem::Version
|
|
74
|
-
version: 0.
|
|
94
|
+
version: 0.14.2
|
|
75
95
|
type: :development
|
|
76
96
|
prerelease: false
|
|
77
97
|
version_requirements: !ruby/object:Gem::Requirement
|
|
78
98
|
requirements:
|
|
79
|
-
- - "
|
|
99
|
+
- - ">="
|
|
80
100
|
- !ruby/object:Gem::Version
|
|
81
|
-
version: 0.
|
|
101
|
+
version: 0.14.2
|
|
82
102
|
- !ruby/object:Gem::Dependency
|
|
83
103
|
name: rspec
|
|
84
104
|
requirement: !ruby/object:Gem::Requirement
|
|
85
105
|
requirements:
|
|
86
|
-
- - "
|
|
106
|
+
- - ">="
|
|
87
107
|
- !ruby/object:Gem::Version
|
|
88
108
|
version: '3.13'
|
|
109
|
+
- - "<"
|
|
110
|
+
- !ruby/object:Gem::Version
|
|
111
|
+
version: '5'
|
|
89
112
|
type: :development
|
|
90
113
|
prerelease: false
|
|
91
114
|
version_requirements: !ruby/object:Gem::Requirement
|
|
92
115
|
requirements:
|
|
93
|
-
- - "
|
|
116
|
+
- - ">="
|
|
94
117
|
- !ruby/object:Gem::Version
|
|
95
118
|
version: '3.13'
|
|
119
|
+
- - "<"
|
|
120
|
+
- !ruby/object:Gem::Version
|
|
121
|
+
version: '5'
|
|
96
122
|
- !ruby/object:Gem::Dependency
|
|
97
123
|
name: rspec-core
|
|
98
124
|
requirement: !ruby/object:Gem::Requirement
|
|
99
125
|
requirements:
|
|
100
|
-
- - "
|
|
126
|
+
- - ">="
|
|
101
127
|
- !ruby/object:Gem::Version
|
|
102
128
|
version: '3.13'
|
|
129
|
+
- - "<"
|
|
130
|
+
- !ruby/object:Gem::Version
|
|
131
|
+
version: '5'
|
|
103
132
|
type: :development
|
|
104
133
|
prerelease: false
|
|
105
134
|
version_requirements: !ruby/object:Gem::Requirement
|
|
106
135
|
requirements:
|
|
107
|
-
- - "
|
|
136
|
+
- - ">="
|
|
108
137
|
- !ruby/object:Gem::Version
|
|
109
138
|
version: '3.13'
|
|
139
|
+
- - "<"
|
|
140
|
+
- !ruby/object:Gem::Version
|
|
141
|
+
version: '5'
|
|
110
142
|
- !ruby/object:Gem::Dependency
|
|
111
143
|
name: rspec-its
|
|
112
144
|
requirement: !ruby/object:Gem::Requirement
|
|
113
145
|
requirements:
|
|
114
146
|
- - "~>"
|
|
115
147
|
- !ruby/object:Gem::Version
|
|
116
|
-
version:
|
|
148
|
+
version: '2.0'
|
|
117
149
|
type: :development
|
|
118
150
|
prerelease: false
|
|
119
151
|
version_requirements: !ruby/object:Gem::Requirement
|
|
120
152
|
requirements:
|
|
121
153
|
- - "~>"
|
|
122
154
|
- !ruby/object:Gem::Version
|
|
123
|
-
version:
|
|
155
|
+
version: '2.0'
|
|
124
156
|
- !ruby/object:Gem::Dependency
|
|
125
157
|
name: rubocop
|
|
126
158
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -172,7 +204,6 @@ files:
|
|
|
172
204
|
- lib/unparser/cli.rb
|
|
173
205
|
- lib/unparser/color.rb
|
|
174
206
|
- lib/unparser/comments.rb
|
|
175
|
-
- lib/unparser/concord.rb
|
|
176
207
|
- lib/unparser/constants.rb
|
|
177
208
|
- lib/unparser/diff.rb
|
|
178
209
|
- lib/unparser/dsl.rb
|
|
@@ -262,10 +293,11 @@ files:
|
|
|
262
293
|
- lib/unparser/writer/send/conditional.rb
|
|
263
294
|
- lib/unparser/writer/send/regular.rb
|
|
264
295
|
- lib/unparser/writer/send/unary.rb
|
|
265
|
-
homepage:
|
|
296
|
+
homepage: https://github.com/mbj/unparser
|
|
266
297
|
licenses:
|
|
267
298
|
- MIT
|
|
268
299
|
metadata:
|
|
300
|
+
homepage_uri: https://github.com/mbj/unparser
|
|
269
301
|
bug_tracker_uri: https://github.com/mbj/unparser/issues
|
|
270
302
|
changelog_uri: https://github.com/mbj/unparser/blob/main/Changelog.md
|
|
271
303
|
funding_uri: https://github.com/sponsors/mbj
|
|
@@ -278,14 +310,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
278
310
|
requirements:
|
|
279
311
|
- - ">="
|
|
280
312
|
- !ruby/object:Gem::Version
|
|
281
|
-
version: '3.
|
|
313
|
+
version: '3.3'
|
|
282
314
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
283
315
|
requirements:
|
|
284
316
|
- - ">="
|
|
285
317
|
- !ruby/object:Gem::Version
|
|
286
318
|
version: '0'
|
|
287
319
|
requirements: []
|
|
288
|
-
rubygems_version:
|
|
320
|
+
rubygems_version: 4.0.8
|
|
289
321
|
specification_version: 4
|
|
290
322
|
summary: Generate equivalent source for parser gem AST nodes
|
|
291
323
|
test_files: []
|
data/lib/unparser/concord.rb
DELETED
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Unparser
|
|
4
|
-
# A mixin to define a composition
|
|
5
|
-
#
|
|
6
|
-
# Original code before vendoring and reduction from: https://github.com/mbj/concord.
|
|
7
|
-
class Concord < Module
|
|
8
|
-
include Adamantium, Equalizer.new(:names)
|
|
9
|
-
|
|
10
|
-
# The maximum number of objects the hosting class is composed of
|
|
11
|
-
MAX_NR_OF_OBJECTS = 3
|
|
12
|
-
|
|
13
|
-
# Return names
|
|
14
|
-
#
|
|
15
|
-
# @return [Enumerable<Symbol>]
|
|
16
|
-
#
|
|
17
|
-
# @api private
|
|
18
|
-
#
|
|
19
|
-
attr_reader :names
|
|
20
|
-
|
|
21
|
-
private
|
|
22
|
-
|
|
23
|
-
# Initialize object
|
|
24
|
-
#
|
|
25
|
-
# @return [undefined]
|
|
26
|
-
#
|
|
27
|
-
# @api private
|
|
28
|
-
#
|
|
29
|
-
# rubocop:disable Lint/MissingSuper
|
|
30
|
-
def initialize(*names)
|
|
31
|
-
if names.length > MAX_NR_OF_OBJECTS
|
|
32
|
-
fail "Composition of more than #{MAX_NR_OF_OBJECTS} objects is not allowed"
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
@names = names
|
|
36
|
-
define_initialize
|
|
37
|
-
define_readers
|
|
38
|
-
define_equalizer
|
|
39
|
-
end
|
|
40
|
-
# rubocop:enable Lint/MissingSuper
|
|
41
|
-
|
|
42
|
-
# Define equalizer
|
|
43
|
-
#
|
|
44
|
-
# @return [undefined]
|
|
45
|
-
#
|
|
46
|
-
# @api private
|
|
47
|
-
#
|
|
48
|
-
def define_equalizer
|
|
49
|
-
include(Equalizer.new(*names))
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
# Define readers
|
|
53
|
-
#
|
|
54
|
-
# @return [undefined]
|
|
55
|
-
#
|
|
56
|
-
# @api private
|
|
57
|
-
#
|
|
58
|
-
def define_readers
|
|
59
|
-
attribute_names = names
|
|
60
|
-
attr_reader(*attribute_names)
|
|
61
|
-
|
|
62
|
-
protected(*attribute_names) if attribute_names.any?
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
# Define initialize method
|
|
66
|
-
#
|
|
67
|
-
# @return [undefined]
|
|
68
|
-
#
|
|
69
|
-
# @api private
|
|
70
|
-
#
|
|
71
|
-
#
|
|
72
|
-
def define_initialize
|
|
73
|
-
ivars = instance_variable_names
|
|
74
|
-
size = names.size
|
|
75
|
-
|
|
76
|
-
define_method :initialize do |*args|
|
|
77
|
-
args_size = args.size
|
|
78
|
-
unless args_size.equal?(size)
|
|
79
|
-
fail ArgumentError, "wrong number of arguments (#{args_size} for #{size})"
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
ivars.zip(args) { |ivar, arg| instance_variable_set(ivar, arg) }
|
|
83
|
-
end
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
# Return instance variable names
|
|
87
|
-
#
|
|
88
|
-
# @return [String]
|
|
89
|
-
#
|
|
90
|
-
# @api private
|
|
91
|
-
#
|
|
92
|
-
def instance_variable_names
|
|
93
|
-
names.map { |name| "@#{name}" }
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
# Mixin for public attribute readers
|
|
97
|
-
class Public < self
|
|
98
|
-
|
|
99
|
-
# Hook called when module is included
|
|
100
|
-
#
|
|
101
|
-
# @param [Class,Module] descendant
|
|
102
|
-
#
|
|
103
|
-
# @return [undefined]
|
|
104
|
-
#
|
|
105
|
-
# @api private
|
|
106
|
-
#
|
|
107
|
-
def included(descendant)
|
|
108
|
-
names.each do |name|
|
|
109
|
-
descendant.__send__(:public, name)
|
|
110
|
-
end
|
|
111
|
-
end
|
|
112
|
-
end # Public
|
|
113
|
-
end # Concord
|
|
114
|
-
end # Unparser
|