unparser 0.5.6 → 0.6.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +14 -2
- data/lib/unparser/abstract_type.rb +121 -0
- data/lib/unparser/adamantium/method_builder.rb +111 -0
- data/lib/unparser/adamantium.rb +150 -0
- data/lib/unparser/anima/attribute.rb +59 -0
- data/lib/unparser/anima/error.rb +23 -0
- data/lib/unparser/anima.rb +184 -0
- data/lib/unparser/ast.rb +1 -2
- data/lib/unparser/buffer.rb +2 -2
- data/lib/unparser/cli.rb +1 -0
- data/lib/unparser/color.rb +1 -1
- data/lib/unparser/concord.rb +114 -0
- data/lib/unparser/diff.rb +1 -1
- data/lib/unparser/either.rb +153 -0
- data/lib/unparser/emitter/flow_modifier.rb +6 -0
- data/lib/unparser/emitter/hash_pattern.rb +1 -1
- data/lib/unparser/emitter/index.rb +1 -1
- data/lib/unparser/emitter/op_assign.rb +2 -2
- data/lib/unparser/emitter/primitive.rb +2 -2
- data/lib/unparser/emitter/simple.rb +2 -2
- data/lib/unparser/emitter.rb +1 -1
- data/lib/unparser/equalizer.rb +98 -0
- data/lib/unparser/node_details/send.rb +5 -2
- data/lib/unparser/node_details.rb +1 -1
- data/lib/unparser/node_helpers.rb +3 -1
- data/lib/unparser/validation.rb +3 -3
- data/lib/unparser/writer/binary.rb +1 -1
- data/lib/unparser/writer/dynamic_string.rb +10 -12
- data/lib/unparser/writer/rescue.rb +1 -1
- data/lib/unparser/writer/send/unary.rb +1 -1
- data/lib/unparser/writer/send.rb +9 -5
- data/lib/unparser.rb +31 -13
- metadata +17 -106
data/lib/unparser.rb
CHANGED
@@ -1,16 +1,22 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'abstract_type'
|
4
|
-
require 'anima'
|
5
|
-
require 'concord'
|
6
3
|
require 'diff/lcs'
|
7
4
|
require 'diff/lcs/hunk'
|
8
|
-
require 'mprelude'
|
9
5
|
require 'optparse'
|
10
6
|
require 'parser/current'
|
11
|
-
require 'procto'
|
12
7
|
require 'set'
|
13
8
|
|
9
|
+
require 'unparser/equalizer'
|
10
|
+
require 'unparser/adamantium'
|
11
|
+
require 'unparser/adamantium/method_builder'
|
12
|
+
require 'unparser/abstract_type'
|
13
|
+
|
14
|
+
require 'unparser/concord'
|
15
|
+
require 'unparser/either'
|
16
|
+
require 'unparser/anima'
|
17
|
+
require 'unparser/anima/attribute'
|
18
|
+
require 'unparser/anima/error'
|
19
|
+
|
14
20
|
# Library namespace
|
15
21
|
module Unparser
|
16
22
|
# Unparser specific AST builder defaulting to modern AST format
|
@@ -27,7 +33,18 @@ module Unparser
|
|
27
33
|
EMPTY_STRING = ''.freeze
|
28
34
|
EMPTY_ARRAY = [].freeze
|
29
35
|
|
30
|
-
private_constant(*constants(false))
|
36
|
+
private_constant(*constants(false) - %i[Adamantium AbstractType Anima Concord Either Equalizer Memoizable])
|
37
|
+
|
38
|
+
# Error raised when unparser encounters an invalid AST
|
39
|
+
class InvalidNodeError < RuntimeError
|
40
|
+
attr_reader :node
|
41
|
+
|
42
|
+
def initialize(message, node)
|
43
|
+
super(message)
|
44
|
+
@node = node
|
45
|
+
freeze
|
46
|
+
end
|
47
|
+
end
|
31
48
|
|
32
49
|
# Unparse an AST (and, optionally, comments) into a string
|
33
50
|
#
|
@@ -36,8 +53,10 @@ module Unparser
|
|
36
53
|
#
|
37
54
|
# @return [String]
|
38
55
|
#
|
39
|
-
# @
|
56
|
+
# @raise InvalidNodeError
|
57
|
+
# if the node passed is invalid
|
40
58
|
#
|
59
|
+
# @api public
|
41
60
|
def self.unparse(node, comment_array = [])
|
42
61
|
return '' if node.nil?
|
43
62
|
|
@@ -61,9 +80,9 @@ module Unparser
|
|
61
80
|
validation = Validation.from_string(generated)
|
62
81
|
|
63
82
|
if validation.success?
|
64
|
-
|
83
|
+
Either::Right.new(generated)
|
65
84
|
else
|
66
|
-
|
85
|
+
Either::Left.new(validation)
|
67
86
|
end
|
68
87
|
end
|
69
88
|
|
@@ -75,8 +94,7 @@ module Unparser
|
|
75
94
|
#
|
76
95
|
# @return [Either<Exception, String>]
|
77
96
|
def self.unparse_either(node)
|
78
|
-
|
79
|
-
.wrap_error(Exception) { unparse(node) }
|
97
|
+
Either.wrap_error(Exception) { unparse(node) }
|
80
98
|
end
|
81
99
|
|
82
100
|
# Parse string into AST
|
@@ -92,9 +110,9 @@ module Unparser
|
|
92
110
|
#
|
93
111
|
# @param [String] source
|
94
112
|
#
|
95
|
-
# @return [
|
113
|
+
# @return [Either<Parser::SyntaxError, (Parser::ASTNode, nil)>]
|
96
114
|
def self.parse_either(source)
|
97
|
-
|
115
|
+
Either.wrap_error(Parser::SyntaxError) do
|
98
116
|
parser.parse(buffer(source))
|
99
117
|
end
|
100
118
|
end
|
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.
|
4
|
+
version: 0.6.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Markus Schirp
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-11-09 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.
|
47
|
+
version: 0.11.1
|
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.
|
54
|
+
version: 0.11.1
|
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.
|
61
|
+
version: 0.11.1
|
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.
|
68
|
+
version: 0.11.1
|
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
|
@@ -346,14 +257,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
346
257
|
requirements:
|
347
258
|
- - ">="
|
348
259
|
- !ruby/object:Gem::Version
|
349
|
-
version: '2.
|
260
|
+
version: '2.6'
|
350
261
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
351
262
|
requirements:
|
352
263
|
- - ">="
|
353
264
|
- !ruby/object:Gem::Version
|
354
265
|
version: '0'
|
355
266
|
requirements: []
|
356
|
-
rubygems_version: 3.
|
267
|
+
rubygems_version: 3.1.6
|
357
268
|
signing_key:
|
358
269
|
specification_version: 4
|
359
270
|
summary: Generate equivalent source for parser gem AST nodes
|