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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ae5d17d8e6292f29138e1cbfe8feaf07425c55bdc2db58e0110ab1587bef062a
4
- data.tar.gz: 724784da1b64edba217ea75a344ba67f787a4be3f53949b2c94c5ab00b15846f
3
+ metadata.gz: b4cab7a047064bc63f7fdab6b3644e019dc397cb6bc17670b4acf0d18227b949
4
+ data.tar.gz: 7cdf8af9f9cea0302b88095be8bd8ce98ccdc64c72cad37634de54fb3591c86d
5
5
  SHA512:
6
- metadata.gz: f27081184ca9da7caa25fcd25dbac29dfa2b7cd3ef32bf00f49cf7232fd182b7b7f3d13f4f88f254e0b98cf93d5fbfbb5f47a65cc4edbd1cf68822c43d143fb2
7
- data.tar.gz: ca45ade090eb276344b7a30457d74a7467d48caeb94b875b86fbfe51777841bbc04fcb85ea4c4df9b7399b7d8d3ec7fe03f2f5fab08dda5f2908e383ebb0365f
6
+ metadata.gz: 4d58a223aa21d7dc8db739a329c9037f7158aa41ddb30c500e30636730d21fe2bfba4492d9ffea1eeebd990e593028b009df0a8f74a938c15b93ef8267090eb3
7
+ data.tar.gz: 253a53938a1b1e20217e45dea9cf102ec5dfd1bb60be6b79b034da451cdd6b5f976d3c5cf5adc360201f676664bface13f3f26a0ab8d2bc780bbc0e6e78e92e8
@@ -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
- buffer = RBS::Buffer.new(
166
- name: "orthoses/content.rb",
167
- content: original_rbs
168
- )
169
- _, _, parsed_decls = RBS::Parser.parse_signature(buffer)
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
- rescue RBS::ParsingError
178
- Orthoses.logger.error "```rbs\n#{original_rbs}```"
179
- raise
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)
@@ -32,7 +32,7 @@ module Orthoses
32
32
  )
33
33
 
34
34
  patterns = @patterns || store.keys
35
- env = RBS::Environment.new
35
+ env = Utils.rbs_environment
36
36
  merge = false
37
37
  owners_included = []
38
38
  RBS::Prototype::Runtime.new(
@@ -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.map do |type|
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 << ::RBS::Types::Bases::Bool.new(location: nil)
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Orthoses
4
- VERSION = "1.10.0"
4
+ VERSION = "1.12.0"
5
5
  end
@@ -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.10.0
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-08-30 00:00:00.000000000 Z
11
+ date: 2023-09-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rbs