orthoses 1.10.0 → 1.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/orthoses/content.rb +32 -8
- data/lib/orthoses/rbs_prototype_runtime.rb +1 -1
- data/lib/orthoses/utils/type_list.rb +36 -9
- data/lib/orthoses/version.rb +1 -1
- data/sig/orthoses/content.rbs +2 -0
- data/sig/orthoses/utils/type_list.rbs +2 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b4cab7a047064bc63f7fdab6b3644e019dc397cb6bc17670b4acf0d18227b949
|
4
|
+
data.tar.gz: 7cdf8af9f9cea0302b88095be8bd8ce98ccdc64c72cad37634de54fb3591c86d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4d58a223aa21d7dc8db739a329c9037f7158aa41ddb30c500e30636730d21fe2bfba4492d9ffea1eeebd990e593028b009df0a8f74a938c15b93ef8267090eb3
|
7
|
+
data.tar.gz: 253a53938a1b1e20217e45dea9cf102ec5dfd1bb60be6b79b034da451cdd6b5f976d3c5cf5adc360201f676664bface13f3f26a0ab8d2bc780bbc0e6e78e92e8
|
data/lib/orthoses/content.rb
CHANGED
@@ -144,6 +144,7 @@ module Orthoses
|
|
144
144
|
@outs
|
145
145
|
end
|
146
146
|
end
|
147
|
+
private_constant :ArrayIO
|
147
148
|
|
148
149
|
def decl_to_lines(decl)
|
149
150
|
out = ArrayIO.new
|
@@ -162,11 +163,23 @@ module Orthoses
|
|
162
163
|
end
|
163
164
|
|
164
165
|
def uniqed_body_decl
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
166
|
+
parsed_decls = begin
|
167
|
+
parse(original_rbs)
|
168
|
+
rescue RBS::ParsingError => e
|
169
|
+
begin
|
170
|
+
# retry with escape
|
171
|
+
Orthoses.logger.debug "Try to parse original rbs but ParsingError"
|
172
|
+
Orthoses.logger.debug e.message
|
173
|
+
Orthoses.logger.debug "```rbs\n#{original_rbs}```"
|
174
|
+
parse(escaped_rbs)
|
175
|
+
rescue RBS::ParsingError
|
176
|
+
# giveup
|
177
|
+
Orthoses.logger.error "Try to parse escaped rbs"
|
178
|
+
Orthoses.logger.error "```rbs\n#{escaped_rbs}```"
|
179
|
+
raise
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
170
183
|
unless parsed_decls.length == 1
|
171
184
|
raise "expect decls.length == 1, but got #{parsed_decls.length}"
|
172
185
|
end
|
@@ -174,9 +187,20 @@ module Orthoses
|
|
174
187
|
parsed_decl.tap do |decl|
|
175
188
|
DuplicationChecker.new(decl).update_decl
|
176
189
|
end
|
177
|
-
|
178
|
-
|
179
|
-
|
190
|
+
end
|
191
|
+
|
192
|
+
def escaped_rbs
|
193
|
+
rbs = original_rbs
|
194
|
+
rbs.gsub!(/def\s+(self\??\.)?(.+?):/) { "def #{$1}`#{$2}`:" }
|
195
|
+
rbs.gsub!(/alias\s+(self\.)?(.+?)\s+(self\.)?(.+)$/) { "alias #{$1}`#{$2}` #{$3}`#{$4}`" }
|
196
|
+
rbs.gsub!(/attr_(reader|writer|accessor)\s+(self\.)?(.+)\s*:\s*(.+)$/) { "attr_#{$1} #{$2}`#{$3}`: #{$4}" }
|
197
|
+
rbs
|
198
|
+
end
|
199
|
+
|
200
|
+
def parse(rbs)
|
201
|
+
rbs.then { |wraped| RBS::Buffer.new(name: "orthoses/content.rb", content: rbs) }
|
202
|
+
.then { |buffer| RBS::Parser.parse_signature(buffer) }
|
203
|
+
.then { |_, _, decls| decls }
|
180
204
|
end
|
181
205
|
|
182
206
|
def temporary_type_params(name)
|
@@ -8,19 +8,15 @@ module Orthoses
|
|
8
8
|
NIL_TYPE = ::RBS::Types::Bases::Nil.new(location: nil)
|
9
9
|
TRUE_TYPE = ::RBS::Types::Literal.new(literal: true, location: nil)
|
10
10
|
FALSE_TYPE = ::RBS::Types::Literal.new(literal: false, location: nil)
|
11
|
+
BOOL_TYPE = ::RBS::Types::Bases::Bool.new(location: nil)
|
11
12
|
|
12
13
|
def initialize(types)
|
13
|
-
@types = types
|
14
|
-
case type
|
15
|
-
when String
|
16
|
-
::RBS::Parser.parse_type(type)
|
17
|
-
else
|
18
|
-
type
|
19
|
-
end
|
20
|
-
end
|
14
|
+
@types = types
|
21
15
|
end
|
22
16
|
|
23
17
|
def inject
|
18
|
+
normalize
|
19
|
+
|
24
20
|
uniqed = @types.uniq
|
25
21
|
|
26
22
|
return UNTYPED if uniqed.find { |t| t == UNTYPED }
|
@@ -28,7 +24,7 @@ module Orthoses
|
|
28
24
|
has_true = uniqed.delete(TRUE_TYPE)
|
29
25
|
has_false = uniqed.delete(FALSE_TYPE)
|
30
26
|
if has_true || has_false
|
31
|
-
uniqed <<
|
27
|
+
uniqed << BOOL_TYPE
|
32
28
|
end
|
33
29
|
|
34
30
|
return UNTYPED if uniqed.empty?
|
@@ -68,6 +64,37 @@ module Orthoses
|
|
68
64
|
|
69
65
|
injected
|
70
66
|
end
|
67
|
+
|
68
|
+
private
|
69
|
+
|
70
|
+
def normalize
|
71
|
+
@types = @types.map do |type|
|
72
|
+
case type
|
73
|
+
when String
|
74
|
+
::RBS::Parser.parse_type(type)
|
75
|
+
else
|
76
|
+
type
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
@types = @types.map do |rbs_type|
|
81
|
+
case rbs_type
|
82
|
+
when ::RBS::Types::ClassInstance
|
83
|
+
case rbs_type.name.to_s
|
84
|
+
when 'TrueClass', '::TrueClass', 'FalseClass', '::FalseClass'
|
85
|
+
BOOL_TYPE
|
86
|
+
when 'NilClass', '::NilClass'
|
87
|
+
NIL_TYPE
|
88
|
+
else
|
89
|
+
rbs_type
|
90
|
+
end
|
91
|
+
else
|
92
|
+
rbs_type
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
self
|
97
|
+
end
|
71
98
|
end
|
72
99
|
end
|
73
100
|
end
|
data/lib/orthoses/version.rb
CHANGED
data/sig/orthoses/content.rbs
CHANGED
@@ -21,6 +21,8 @@ class Orthoses::Content
|
|
21
21
|
private def decl_to_lines: (untyped decl) -> untyped
|
22
22
|
private def uniqed_body_string: () -> String
|
23
23
|
private def uniqed_body_decl: () -> RBS::AST::Declarations::t
|
24
|
+
private def escaped_rbs: () -> untyped
|
25
|
+
private def parse: (untyped rbs) -> untyped
|
24
26
|
private def temporary_type_params: (untyped name) -> untyped
|
25
27
|
private def type_params: (untyped name) -> untyped
|
26
28
|
attr_reader name: String
|
@@ -5,6 +5,8 @@ class Orthoses::Utils::TypeList
|
|
5
5
|
@types: untyped
|
6
6
|
def initialize: (untyped types) -> void
|
7
7
|
def inject: () -> untyped
|
8
|
+
private def normalize: () -> self
|
9
|
+
BOOL_TYPE: RBS::Types::Bases::Bool
|
8
10
|
FALSE_TYPE: RBS::Types::Literal
|
9
11
|
NIL_TYPE: RBS::Types::Bases::Nil
|
10
12
|
TRUE_TYPE: RBS::Types::Literal
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: orthoses
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.12.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ksss
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-09-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rbs
|