rbi 0.0.13 → 0.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/Rakefile +1 -1
- data/lib/rbi/loc.rb +15 -0
- data/lib/rbi/parser.rb +66 -6
- data/lib/rbi/version.rb +2 -2
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 570f1035fa8bb56861eabd49590fbf2374f428c053f0fc189e27958feedf0c4b
|
4
|
+
data.tar.gz: 0dbb944e45b675851de18089c22a23c4c527f03dfca281426db8fb3cff94372e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 45e5f53144cc46f1cd2c86b55c1d490ab5bd4b2d3bf5e593b3f6405e6b4583645c13130cdc6762f0e5eb18f5f74bfa1dfe990d108f6db21da394ba4d30a7b810
|
7
|
+
data.tar.gz: 603617b73fc3e4e862f897bf0b10b165efd4ac608c07b71e3ef43e1190e4d1fff2f26484a65d8f4d9e5965eafa99435d02bf668fef756abe5a24f1fa3e41f52b
|
data/Gemfile
CHANGED
data/Rakefile
CHANGED
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
|
-
|
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
|
622
|
-
|
623
|
-
|
624
|
-
|
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
|
-
|
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
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.
|
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-
|
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:
|
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:
|
40
|
+
version: 2.6.4.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: sorbet-runtime
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|