rbi 0.0.13 → 0.0.14

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: c5ef2a157e342a16c69748e0f09b67839152d10e99a3b7eab4da23354b8993f9
4
- data.tar.gz: 6622c783e58b67a950e4661a025f8d0a9508612eda9ee53af45f72e6c5057286
3
+ metadata.gz: 570f1035fa8bb56861eabd49590fbf2374f428c053f0fc189e27958feedf0c4b
4
+ data.tar.gz: 0dbb944e45b675851de18089c22a23c4c527f03dfca281426db8fb3cff94372e
5
5
  SHA512:
6
- metadata.gz: 598e6384b4aca8b6db5aa97d6a00e6a75cb1bb4273d5401006c969c4d89730797942c8d0ff7fed0a8da25f6170747126c064c6aadbec210ebb28e4781772ab26
7
- data.tar.gz: 6021bd1134be4dfd834ece8648ea904ad30666216411c7524a9f4245f14ecab7b1e6da9d013a8c0bb4a9620fde7db83190b54f7bb512f7d1d23275300112482e
6
+ metadata.gz: 45e5f53144cc46f1cd2c86b55c1d490ab5bd4b2d3bf5e593b3f6405e6b4583645c13130cdc6762f0e5eb18f5f74bfa1dfe990d108f6db21da394ba4d30a7b810
7
+ data.tar.gz: 603617b73fc3e4e862f897bf0b10b165efd4ac608c07b71e3ef43e1190e4d1fff2f26484a65d8f4d9e5965eafa99435d02bf668fef756abe5a24f1fa3e41f52b
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- # typed: true
1
+ # typed: strict
2
2
  # frozen_string_literal: true
3
3
 
4
4
  source "https://rubygems.org"
data/Rakefile CHANGED
@@ -1,4 +1,4 @@
1
- # typed: true
1
+ # typed: strict
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require "bundler/gem_tasks"
data/lib/rbi/loc.rb CHANGED
@@ -32,5 +32,20 @@ module RBI
32
32
  def to_s
33
33
  "#{file}:#{begin_line}:#{begin_column}-#{end_line}:#{end_column}"
34
34
  end
35
+
36
+ sig { returns(T.nilable(String)) }
37
+ def source
38
+ file = self.file
39
+ return nil unless file
40
+ return nil unless ::File.file?(file)
41
+
42
+ return ::File.read(file) unless begin_line && end_line
43
+
44
+ string = String.new
45
+ ::File.foreach(file).with_index do |line, line_number|
46
+ string << line if line_number + 1 >= begin_line && line_number + 1 <= end_line
47
+ end
48
+ string
49
+ end
35
50
  end
36
51
  end
data/lib/rbi/parser.rb CHANGED
@@ -17,6 +17,39 @@ module RBI
17
17
  end
18
18
  end
19
19
 
20
+ class UnexpectedParserError < StandardError
21
+ extend T::Sig
22
+
23
+ sig { returns(Loc) }
24
+ attr_reader :last_location
25
+
26
+ sig { params(parent_exception: Exception, last_location: Loc).void }
27
+ def initialize(parent_exception, last_location)
28
+ super(parent_exception)
29
+ set_backtrace(parent_exception.backtrace)
30
+ @last_location = last_location
31
+ end
32
+
33
+ sig { params(io: T.any(IO, StringIO)).void }
34
+ def print_debug(io: $stderr)
35
+ io.puts ""
36
+ io.puts "##################################"
37
+ io.puts "### RBI::Parser internal error ###"
38
+ io.puts "##################################"
39
+ io.puts ""
40
+ io.puts "There was an internal parser error while processing this source."
41
+ io.puts ""
42
+ io.puts "Error: #{message} while parsing #{last_location}:"
43
+ io.puts ""
44
+ io.puts last_location.source || "<no source>"
45
+ io.puts ""
46
+ io.puts "Please open an issue at https://github.com/Shopify/rbi/issues/new."
47
+ io.puts ""
48
+ io.puts "##################################"
49
+ io.puts ""
50
+ end
51
+ end
52
+
20
53
  class Parser
21
54
  extend T::Sig
22
55
 
@@ -77,6 +110,19 @@ module RBI
77
110
  builder.tree
78
111
  rescue ::Parser::SyntaxError => e
79
112
  raise ParseError.new(e.message, Loc.from_ast_loc(file, e.diagnostic.location))
113
+ rescue ParseError => e
114
+ raise e
115
+ rescue => e
116
+ last_node = builder&.last_node
117
+ last_location = if last_node
118
+ Loc.from_ast_loc(file, last_node.location)
119
+ else
120
+ Loc.new(file: file)
121
+ end
122
+
123
+ exception = UnexpectedParserError.new(e, last_location)
124
+ exception.print_debug
125
+ raise exception
80
126
  end
81
127
  end
82
128
 
@@ -113,6 +159,9 @@ module RBI
113
159
  sig { returns(Tree) }
114
160
  attr_reader :tree
115
161
 
162
+ sig { returns(T.nilable(::AST::Node)) }
163
+ attr_reader :last_node
164
+
116
165
  sig do
117
166
  params(
118
167
  file: String,
@@ -127,6 +176,7 @@ module RBI
127
176
  @nodes_comments_assoc = nodes_comments_assoc
128
177
  @tree = T.let(Tree.new, Tree)
129
178
  @scopes_stack = T.let([@tree], T::Array[Tree])
179
+ @last_node = T.let(nil, T.nilable(::AST::Node))
130
180
  @last_sigs = T.let([], T::Array[RBI::Sig])
131
181
 
132
182
  separate_header_comments
@@ -141,6 +191,8 @@ module RBI
141
191
  sig { override.params(node: T.nilable(Object)).void }
142
192
  def visit(node)
143
193
  return unless node.is_a?(AST::Node)
194
+ @last_node = node
195
+
144
196
  case node.type
145
197
  when :module, :class, :sclass
146
198
  scope = parse_scope(node)
@@ -165,6 +217,8 @@ module RBI
165
217
  else
166
218
  visit_all(node.children)
167
219
  end
220
+
221
+ @last_node = nil
168
222
  end
169
223
 
170
224
  private
@@ -612,19 +666,25 @@ module RBI
612
666
  when :overridable
613
667
  @current.is_overridable = true
614
668
  when :checked
615
- @current.checked = node.children[2].children[0]
669
+ if node.children.length >= 3
670
+ @current.checked = node.children[2].children[0]
671
+ end
616
672
  when :type_parameters
617
673
  node.children[2..-1].each do |child|
618
674
  @current.type_params << child.children[0].to_s
619
675
  end
620
676
  when :params
621
- node.children[2].children.each do |child|
622
- name = child.children[0].children[0].to_s
623
- type = parse_expr(child.children[1])
624
- @current << SigParam.new(name, type)
677
+ if node.children.length >= 3
678
+ node.children[2].children.each do |child|
679
+ name = child.children[0].children[0].to_s
680
+ type = parse_expr(child.children[1])
681
+ @current << SigParam.new(name, type)
682
+ end
625
683
  end
626
684
  when :returns
627
- @current.return_type = parse_expr(node.children[2])
685
+ if node.children.length >= 3
686
+ @current.return_type = parse_expr(node.children[2])
687
+ end
628
688
  when :void
629
689
  @current.return_type = nil
630
690
  else
data/lib/rbi/version.rb CHANGED
@@ -1,6 +1,6 @@
1
- # typed: true
1
+ # typed: strict
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module RBI
5
- VERSION = "0.0.13"
5
+ VERSION = "0.0.14"
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.13
4
+ version: 0.0.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexandre Terrasa
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-03-03 00:00:00.000000000 Z
11
+ date: 2022-03-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ast
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: 2.6.4.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: 2.6.4.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: sorbet-runtime
43
43
  requirement: !ruby/object:Gem::Requirement