orthoses 1.10.0 → 1.11.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: 7a6942bb06928e29ae619e8dfd3f92ac603bda3d0feda99dafd309c4eb493327
4
+ data.tar.gz: 6affe9ebc4d0b1a3ec31c9192e271ee6a2b35765ad6c753c58fc2310fb6155ae
5
5
  SHA512:
6
- metadata.gz: f27081184ca9da7caa25fcd25dbac29dfa2b7cd3ef32bf00f49cf7232fd182b7b7f3d13f4f88f254e0b98cf93d5fbfbb5f47a65cc4edbd1cf68822c43d143fb2
7
- data.tar.gz: ca45ade090eb276344b7a30457d74a7467d48caeb94b875b86fbfe51777841bbc04fcb85ea4c4df9b7399b7d8d3ec7fe03f2f5fab08dda5f2908e383ebb0365f
6
+ metadata.gz: 7e5f33fe35dc796660ea45096401a2157ec32ac19ead7af5ead38d4ab96fb40e28a4c266726bf4c0d6769cd8cfa0d6064501c18e99bbcceb1bdb2b929f610eb1
7
+ data.tar.gz: 8adf74dc954206d5e517cf6d0151cf50500375c9363ede9305c90a0989724f61d956b07daf6a17ebe8f1018912245474e10fa944ba4ecbbda4c927a6253eb0ff
@@ -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)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Orthoses
4
- VERSION = "1.10.0"
4
+ VERSION = "1.11.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
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.11.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-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rbs