rbs-inline 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +8 -5
- data/Rakefile +12 -0
- data/lib/rbs/inline/annotation_parser/tokenizer.rb +361 -0
- data/lib/rbs/inline/annotation_parser.rb +548 -326
- data/lib/rbs/inline/ast/annotations.rb +427 -138
- data/lib/rbs/inline/ast/comment_lines.rb +17 -20
- data/lib/rbs/inline/ast/declarations.rb +64 -28
- data/lib/rbs/inline/ast/members.rb +129 -115
- data/lib/rbs/inline/ast/tree.rb +37 -22
- data/lib/rbs/inline/cli.rb +12 -12
- data/lib/rbs/inline/node_utils.rb +1 -1
- data/lib/rbs/inline/parser.rb +134 -65
- data/lib/rbs/inline/version.rb +1 -1
- data/lib/rbs/inline/writer.rb +195 -118
- data/lib/rbs/inline.rb +1 -0
- data/sig/generated/rbs/inline/annotation_parser/tokenizer.rbs +221 -0
- data/sig/generated/rbs/inline/annotation_parser.rbs +148 -92
- data/sig/generated/rbs/inline/ast/annotations.rbs +141 -37
- data/sig/generated/rbs/inline/ast/comment_lines.rbs +8 -4
- data/sig/generated/rbs/inline/ast/declarations.rbs +26 -10
- data/sig/generated/rbs/inline/ast/members.rbs +26 -15
- data/sig/generated/rbs/inline/ast/tree.rbs +23 -17
- data/sig/generated/rbs/inline/cli.rbs +3 -3
- data/sig/generated/rbs/inline/node_utils.rbs +1 -1
- data/sig/generated/rbs/inline/parser.rbs +35 -18
- data/sig/generated/rbs/inline/writer.rbs +54 -22
- metadata +4 -2
@@ -3,127 +3,148 @@
|
|
3
3
|
module RBS
|
4
4
|
module Inline
|
5
5
|
class AnnotationParser
|
6
|
+
# ParsingResut groups consecutive comments, which may contain several annotations
|
7
|
+
#
|
8
|
+
# *Consecutive comments* are comments are defined in below.
|
9
|
+
# They are basically comments that follows from the previous line, but there are some more requirements.
|
10
|
+
#
|
11
|
+
# ```ruby
|
12
|
+
# # Line 1
|
13
|
+
# # Line 2 #=> Line 1 and Line 2 are consecutive
|
14
|
+
#
|
15
|
+
# # Line 3
|
16
|
+
# # Line4 #=> Line 3 and Line 4 are not consecutive, because the starting column are different
|
17
|
+
#
|
18
|
+
# # Line 5
|
19
|
+
# foo() # Line 6 #=> Line 5 and Line 6 are not consecutive, because Line 6 has leading code
|
20
|
+
# ```
|
6
21
|
class ParsingResult
|
7
22
|
attr_reader comments: Array[Prism::Comment]
|
8
23
|
|
9
|
-
attr_reader annotations: Array[AST::Annotations::t]
|
24
|
+
attr_reader annotations: Array[AST::Annotations::t | AST::CommentLines]
|
10
25
|
|
11
26
|
attr_reader first_comment_offset: Integer
|
12
27
|
|
28
|
+
# : () { (AST::Annotations::t) -> void } -> void
|
29
|
+
# : () -> Enumerator[AST::Annotations::t, void]
|
30
|
+
def each_annotation: () { (AST::Annotations::t) -> void } -> void
|
31
|
+
| () -> Enumerator[AST::Annotations::t, void]
|
32
|
+
|
13
33
|
# @rbs first_comment: Prism::Comment
|
14
|
-
def initialize: (Prism::Comment first_comment) ->
|
34
|
+
def initialize: (Prism::Comment first_comment) -> void
|
15
35
|
|
16
|
-
# @rbs
|
36
|
+
# @rbs return: Range[Integer]
|
17
37
|
def line_range: () -> Range[Integer]
|
18
38
|
|
19
|
-
# @rbs
|
39
|
+
# @rbs return: Prism::Comment
|
20
40
|
def last_comment: () -> Prism::Comment
|
21
41
|
|
22
42
|
# @rbs comment: Prism::Comment
|
23
|
-
# @rbs
|
43
|
+
# @rbs return: self?
|
24
44
|
def add_comment: (Prism::Comment comment) -> self?
|
25
45
|
|
26
|
-
# @rbs
|
27
|
-
def
|
46
|
+
# @rbs trim: bool -- `true` to trim the leading whitespaces
|
47
|
+
def content: (?trim: bool) -> String
|
28
48
|
|
29
|
-
|
30
|
-
def content: () -> String
|
49
|
+
def lines: () -> Array[String]
|
31
50
|
end
|
32
51
|
|
52
|
+
include Tokens
|
53
|
+
|
33
54
|
attr_reader input: Array[Prism::Comment]
|
34
55
|
|
35
56
|
# @rbs input: Array[Prism::Comment]
|
36
|
-
def initialize: (Array[Prism::Comment] input) ->
|
57
|
+
def initialize: (Array[Prism::Comment] input) -> void
|
37
58
|
|
38
59
|
# @rbs input: Array[Prism::Comment]
|
39
|
-
# @rbs
|
60
|
+
# @rbs return: Array[ParsingResult]
|
40
61
|
def self.parse: (Array[Prism::Comment] input) -> Array[ParsingResult]
|
41
62
|
|
42
|
-
# @rbs
|
63
|
+
# @rbs return: Array[ParsingResult]
|
43
64
|
def parse: () -> Array[ParsingResult]
|
44
65
|
|
45
66
|
private
|
46
67
|
|
47
|
-
#
|
48
|
-
#
|
49
|
-
#
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
attr_reader current_token: token?
|
56
|
-
|
57
|
-
KEYWORDS: Hash[String, Symbol]
|
58
|
-
|
59
|
-
KW_RE: ::Regexp
|
60
|
-
|
61
|
-
PUNCTS: Hash[String, Symbol]
|
62
|
-
|
63
|
-
PUNCTS_RE: Regexp
|
64
|
-
|
65
|
-
# @rbs scanner: StringScanner
|
66
|
-
# @rbs returns void
|
67
|
-
def initialize: (StringScanner scanner) -> void
|
68
|
-
|
69
|
-
# @rbs tree: AST::Tree
|
70
|
-
# @rbs returns token?
|
71
|
-
def advance: (AST::Tree tree) -> token?
|
72
|
-
|
73
|
-
# Consume given token type and inserts the token to the tree or `nil`
|
74
|
-
#
|
75
|
-
# @rbs type: Array[Symbol]
|
76
|
-
# @rbs tree: AST::Tree
|
77
|
-
# @rbs returns void
|
78
|
-
def consume_token: (*untyped types, tree: AST::Tree) -> void
|
79
|
-
|
80
|
-
# Consume given token type and inserts the token to the tree or raise
|
81
|
-
#
|
82
|
-
# @rbs type: Array[Symbol]
|
83
|
-
# @rbs tree: AST::Tree
|
84
|
-
# @rbs returns void
|
85
|
-
def consume_token!: (*untyped types, tree: AST::Tree) -> void
|
68
|
+
# Test if the comment is an annotation comment
|
69
|
+
#
|
70
|
+
# - Returns `nil` if the comment is not an annotation.
|
71
|
+
# - Returns `true` if the comment is `#:` or `#[` annotation. (Offset is `1`)
|
72
|
+
# - Returns Integer if the comment is `#@rbs` annotation. (Offset is the number of leading spaces including `#`)
|
73
|
+
#
|
74
|
+
# : (Prism::Comment) -> (Integer | true | nil)
|
75
|
+
def annotation_comment?: (Prism::Comment) -> (Integer | true | nil)
|
86
76
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
77
|
+
# Split lines of comments in `result` into paragraphs
|
78
|
+
#
|
79
|
+
# A paragraph consists of:
|
80
|
+
#
|
81
|
+
# * An annotation syntax constructs -- starting with `@rbs` or `::`, or
|
82
|
+
# * A lines something else
|
83
|
+
#
|
84
|
+
# Yields an array of comments, and a boolean indicating if the comments may be an annotation.
|
85
|
+
#
|
86
|
+
# : (ParsingResult) { (Array[Prism::Comment], bool is_annotation) -> void } -> void
|
87
|
+
def each_annotation_paragraph: (ParsingResult) { (Array[Prism::Comment], bool is_annotation) -> void } -> void
|
92
88
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
89
|
+
# The first annotation line is already detected and consumed.
|
90
|
+
# The annotation comment is already in `comments`.
|
91
|
+
#
|
92
|
+
# @rbs comments: Array[Prism::Comment] -- Annotation comments
|
93
|
+
# @rbs lines: Array[Prism::Comment] -- Lines to be consumed
|
94
|
+
# @rbs offset: Integer -- Offset of the first character of the first annotation comment from the `#` (>= 1)
|
95
|
+
# @rbs allow_empty_lines: bool -- `true` if empty line is allowed inside the annotation comments
|
96
|
+
# @rbs &block: (Array[Prism::Comment], bool is_annotation) -> void
|
97
|
+
# @rbs return: void
|
98
|
+
def yield_annotation: (Array[Prism::Comment] comments, Array[Prism::Comment] lines, Integer offset, allow_empty_lines: bool) { (Array[Prism::Comment], bool is_annotation) -> void } -> void
|
99
|
+
|
100
|
+
# The first line is NOT consumed.
|
101
|
+
#
|
102
|
+
# The `comments` may be empty.
|
103
|
+
#
|
104
|
+
# @rbs comments: Array[Prism::Comment] -- Leading comments
|
105
|
+
# @rbs lines: Array[Prism::Comment] -- Lines to be consumed
|
106
|
+
# @rbs &block: (Array[Prism::Comment], bool is_annotation) -> void
|
107
|
+
# @rbs return: void
|
108
|
+
def yield_paragraph: (Array[Prism::Comment] comments, Array[Prism::Comment] lines) { (Array[Prism::Comment], bool is_annotation) -> void } -> void
|
98
109
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
110
|
+
# Consumes empty lines between annotation lines
|
111
|
+
#
|
112
|
+
# An empty line is already detected and consumed.
|
113
|
+
# The line is already removed from `lines` and put in `empty_comments`.
|
114
|
+
#
|
115
|
+
# Note that the arguments, `comments`, `empty_comments`, and `lines` are modified in place.
|
116
|
+
#
|
117
|
+
# @rbs comments: Array[Prism::Comment] -- Non empty annotation comments
|
118
|
+
# @rbs empty_comments: Array[Prism::Comment] -- Empty comments that may be part of the annotation
|
119
|
+
# @rbs lines: Array[Prism::Comment] -- Lines
|
120
|
+
# @rbs offset: Integer -- Offset of the first character of the annotation
|
121
|
+
# @rbs &block: (Array[Prism::Comment], bool is_annotation) -> void
|
122
|
+
# @rbs return: void
|
123
|
+
def yield_empty_annotation: (Array[Prism::Comment] comments, Array[Prism::Comment] empty_comments, Array[Prism::Comment] lines, Integer offset) { (Array[Prism::Comment], bool is_annotation) -> void } -> void
|
106
124
|
|
107
125
|
# @rbs comments: AST::CommentLines
|
108
|
-
# @rbs
|
126
|
+
# @rbs return: AST::Annotations::t?
|
109
127
|
def parse_annotation: (AST::CommentLines comments) -> AST::Annotations::t?
|
110
128
|
|
111
129
|
# @rbs tokenizer: Tokenizer
|
112
|
-
# @rbs
|
130
|
+
# @rbs return: AST::Tree
|
113
131
|
def parse_var_decl: (Tokenizer tokenizer) -> AST::Tree
|
114
132
|
|
115
133
|
# @rbs tokenizer: Tokenizer
|
116
|
-
# @rbs
|
134
|
+
# @rbs return: AST::Tree
|
117
135
|
def parse_return_type_decl: (Tokenizer tokenizer) -> AST::Tree
|
118
136
|
|
119
137
|
# @rbs tokenizer: Tokenizer
|
120
|
-
# @rbs
|
138
|
+
# @rbs return: AST::Tree
|
121
139
|
def parse_comment: (Tokenizer tokenizer) -> AST::Tree
|
122
140
|
|
123
141
|
# @rbs tokenizer: Tokenizer
|
124
|
-
# @rbs
|
142
|
+
# @rbs return: AST::Tree
|
125
143
|
def parse_type_app: (Tokenizer tokenizer) -> AST::Tree
|
126
144
|
|
145
|
+
# @rbs (Tokenizer) -> AST::Tree
|
146
|
+
def parse_method_type_annotation: (Tokenizer) -> AST::Tree
|
147
|
+
|
127
148
|
# Parse a RBS method type or type and returns it
|
128
149
|
#
|
129
150
|
# It tries parsing a method type, and then parsing a type if failed.
|
@@ -134,9 +155,20 @@ module RBS
|
|
134
155
|
#
|
135
156
|
# @rbs tokenizer: Tokenizer
|
136
157
|
# @rbs parent_tree: AST::Tree
|
137
|
-
# @rbs
|
158
|
+
# @rbs return: MethodType | AST::Tree | Types::t | nil
|
138
159
|
def parse_type_method_type: (Tokenizer tokenizer, AST::Tree parent_tree) -> (MethodType | AST::Tree | Types::t | nil)
|
139
160
|
|
161
|
+
# Parse a RBS method type
|
162
|
+
#
|
163
|
+
# If parsing failed, it returns a Tree(`:type_syntax_error), consuming all of the remaining input.
|
164
|
+
#
|
165
|
+
# Note that this doesn't recognize `--` comment unlike `parse_type`.
|
166
|
+
#
|
167
|
+
# @rbs tokenizer: Tokenizer
|
168
|
+
# @rbs parent_tree: AST::Tree
|
169
|
+
# @rbs return: MethodType | AST::Tree
|
170
|
+
def parse_method_type: (Tokenizer tokenizer, AST::Tree parent_tree) -> (MethodType | AST::Tree)
|
171
|
+
|
140
172
|
# Parse a RBS type and returns it
|
141
173
|
#
|
142
174
|
# If parsing failed, it returns a Tree(`:type_syntax_error), consuming
|
@@ -152,27 +184,27 @@ module RBS
|
|
152
184
|
#
|
153
185
|
# @rbs tokenizer: Tokenizer
|
154
186
|
# @rbs parent_tree: AST::Tree
|
155
|
-
# @rbs
|
187
|
+
# @rbs return: Types::t | AST::Tree | nil
|
156
188
|
def parse_type: (Tokenizer tokenizer, AST::Tree parent_tree) -> (Types::t | AST::Tree | nil)
|
157
189
|
|
158
190
|
# @rbs tokenizer: Tokenizer
|
159
|
-
# @rbs
|
191
|
+
# @rbs return: AST::Tree
|
160
192
|
def parse_rbs_annotation: (Tokenizer tokenizer) -> AST::Tree
|
161
193
|
|
162
|
-
# @rbs
|
163
|
-
# @rbs
|
164
|
-
def parse_inherits: (
|
194
|
+
# @rbs tokenizer: Tokenizer
|
195
|
+
# @rbs return: AST::Tree
|
196
|
+
def parse_inherits: (Tokenizer tokenizer) -> AST::Tree
|
165
197
|
|
166
198
|
# Parse `@rbs override` annotation
|
167
199
|
#
|
168
200
|
# @rbs tokenizer: Tokenizer
|
169
|
-
# @rbs
|
201
|
+
# @rbs return: AST::Tree
|
170
202
|
def parse_override: (Tokenizer tokenizer) -> AST::Tree
|
171
203
|
|
172
204
|
# Parse `@rbs use [CLAUSES]` annotation
|
173
205
|
#
|
174
206
|
# @rbs tokenizer: Tokenizer
|
175
|
-
# @rbs
|
207
|
+
# @rbs return: AST::Tree
|
176
208
|
def parse_use: (Tokenizer tokenizer) -> AST::Tree
|
177
209
|
|
178
210
|
# Parses use clause
|
@@ -185,11 +217,11 @@ module RBS
|
|
185
217
|
# * [`::`?, [UIDENT) `::`]*, `*`]
|
186
218
|
#
|
187
219
|
# @rbs tokenizer: Tokenizer
|
188
|
-
# @rbs
|
220
|
+
# @rbs return: AST::Tree
|
189
221
|
def parse_use_clause: (Tokenizer tokenizer) -> AST::Tree
|
190
222
|
|
191
223
|
# @rbs tokenizer: Tokenizer
|
192
|
-
# @rbs
|
224
|
+
# @rbs return: AST::Tree
|
193
225
|
def parse_module_self: (Tokenizer tokenizer) -> AST::Tree
|
194
226
|
|
195
227
|
# Yield the block and return the resulting tree if tokenizer has current token of `types`
|
@@ -197,26 +229,50 @@ module RBS
|
|
197
229
|
# ```rb
|
198
230
|
# # Test if tokenize has `--` token, then parse comment or insert `nil` to tree
|
199
231
|
#
|
200
|
-
# tree << parse_optional(tokenizer,
|
232
|
+
# tree << parse_optional(tokenizer, K_MINUS2) do
|
201
233
|
# parse_comment(tokenizer)
|
202
234
|
# end
|
203
235
|
# ```
|
204
236
|
#
|
237
|
+
# If `tree:` is given, it consumes trivia tokens before yielding the block.
|
238
|
+
#
|
205
239
|
# @rbs tokenizer: Tokenizer
|
206
|
-
# @rbs types:
|
207
|
-
# @rbs
|
208
|
-
# @rbs
|
209
|
-
|
240
|
+
# @rbs *types: Symbol
|
241
|
+
# @rbs tree: AST::Tree? -- the parent tree to consume leading trivia tokens
|
242
|
+
# @rbs &block: () -> AST::Tree
|
243
|
+
# @rbs return: AST::Tree?
|
244
|
+
def parse_optional: (Tokenizer tokenizer, *Symbol types, ?tree: AST::Tree?) { () -> AST::Tree } -> AST::Tree?
|
210
245
|
|
211
246
|
# @rbs tokenizer: Tokenizer
|
212
|
-
# @rbs
|
247
|
+
# @rbs return: AST::Tree
|
213
248
|
def parse_generic: (Tokenizer tokenizer) -> AST::Tree
|
214
249
|
|
215
|
-
#
|
250
|
+
# @rbs (Tokenizer) -> AST::Tree
|
251
|
+
def parse_type_param: (Tokenizer) -> AST::Tree
|
252
|
+
|
253
|
+
# : (Tokenizer) -> AST::Tree
|
216
254
|
def parse_ivar_type: (Tokenizer) -> AST::Tree
|
217
255
|
|
218
|
-
#
|
219
|
-
def
|
256
|
+
# : (Tokenizer) -> AST::Tree
|
257
|
+
def parse_splat_param_type: (Tokenizer) -> AST::Tree
|
258
|
+
|
259
|
+
# : (Tokenizer) -> AST::Tree
|
260
|
+
def parse_block_type: (Tokenizer) -> AST::Tree
|
261
|
+
|
262
|
+
# @rbs (Tokenizer) -> AST::Tree
|
263
|
+
def parse_module_decl: (Tokenizer) -> AST::Tree
|
264
|
+
|
265
|
+
# @rbs (Tokenizer) -> AST::Tree
|
266
|
+
def parse_class_decl: (Tokenizer) -> AST::Tree
|
267
|
+
|
268
|
+
# @rbs (Tokenizer) -> AST::Tree
|
269
|
+
def parse_module_name: (Tokenizer) -> AST::Tree
|
270
|
+
|
271
|
+
# @rbs (Tokenizer) -> AST::Tree
|
272
|
+
def parse_type_params: (Tokenizer) -> AST::Tree
|
273
|
+
|
274
|
+
# @rbs (Tokenizer) -> AST::Tree
|
275
|
+
def parse_module_selfs: (Tokenizer) -> AST::Tree
|
220
276
|
end
|
221
277
|
end
|
222
278
|
end
|
@@ -4,7 +4,24 @@ module RBS
|
|
4
4
|
module Inline
|
5
5
|
module AST
|
6
6
|
module Annotations
|
7
|
-
type t = VarType | ReturnType | Use | Inherits | Generic | ModuleSelf | Skip |
|
7
|
+
type t = VarType | ReturnType | Use | Inherits | Generic | ModuleSelf | Skip | MethodTypeAssertion | TypeAssertion | SyntaxErrorAssertion | Dot3Assertion | Application | RBSAnnotation | Override | IvarType | Embedded | Method | SplatParamType | DoubleSplatParamType | BlockType | ModuleDecl | ClassDecl
|
8
|
+
|
9
|
+
module Utils
|
10
|
+
# @rbs (Tree) -> RBS::AST::TypeParam?
|
11
|
+
def translate_type_param: (Tree) -> RBS::AST::TypeParam?
|
12
|
+
|
13
|
+
# @rbs (Types::t) -> RBS::AST::Declarations::Class::Super?
|
14
|
+
def translate_super_class: (Types::t) -> RBS::AST::Declarations::Class::Super?
|
15
|
+
|
16
|
+
# Assumes the tree is generated through `#parse_module_name`
|
17
|
+
#
|
18
|
+
# Returns a type name, or `nil` if the tree is something invalid.
|
19
|
+
#
|
20
|
+
# @param tree -- A tree object that is generated through `#parse_module_name`
|
21
|
+
#
|
22
|
+
# @rbs (AST::Tree) -> TypeName?
|
23
|
+
def translate_type_name: (AST::Tree) -> TypeName?
|
24
|
+
end
|
8
25
|
|
9
26
|
class Base
|
10
27
|
attr_reader source: CommentLines
|
@@ -13,7 +30,7 @@ module RBS
|
|
13
30
|
|
14
31
|
# @rbs tree: Tree
|
15
32
|
# @rbs source: CommentLines
|
16
|
-
# @rbs
|
33
|
+
# @rbs return: void
|
17
34
|
def initialize: (Tree tree, CommentLines source) -> void
|
18
35
|
end
|
19
36
|
|
@@ -27,11 +44,46 @@ module RBS
|
|
27
44
|
# @rbs override
|
28
45
|
def initialize: ...
|
29
46
|
|
30
|
-
#
|
47
|
+
# : () -> bool
|
31
48
|
def complete?: () -> bool
|
32
49
|
end
|
33
50
|
|
34
|
-
|
51
|
+
class SpecialVarTypeAnnotation < Base
|
52
|
+
attr_reader name: Symbol?
|
53
|
+
|
54
|
+
attr_reader type: Types::t?
|
55
|
+
|
56
|
+
attr_reader comment: String?
|
57
|
+
|
58
|
+
attr_reader type_source: String
|
59
|
+
|
60
|
+
# @rbs override
|
61
|
+
def initialize: ...
|
62
|
+
end
|
63
|
+
|
64
|
+
# `@rbs *x: T`
|
65
|
+
class SplatParamType < SpecialVarTypeAnnotation
|
66
|
+
end
|
67
|
+
|
68
|
+
# `@rbs` **x: T
|
69
|
+
class DoubleSplatParamType < SpecialVarTypeAnnotation
|
70
|
+
end
|
71
|
+
|
72
|
+
# `@rbs &block: METHOD-TYPE` or `@rbs &block: ? METHOD-TYPE`
|
73
|
+
class BlockType < Base
|
74
|
+
attr_reader name: Symbol?
|
75
|
+
|
76
|
+
attr_reader type: Types::Block?
|
77
|
+
|
78
|
+
attr_reader comment: String?
|
79
|
+
|
80
|
+
attr_reader type_source: String
|
81
|
+
|
82
|
+
# @rbs override
|
83
|
+
def initialize: ...
|
84
|
+
end
|
85
|
+
|
86
|
+
# `@rbs return: T`
|
35
87
|
class ReturnType < Base
|
36
88
|
attr_reader type: Types::t?
|
37
89
|
|
@@ -40,7 +92,7 @@ module RBS
|
|
40
92
|
# @rbs override
|
41
93
|
def initialize: ...
|
42
94
|
|
43
|
-
# @rbs
|
95
|
+
# @rbs return: bool
|
44
96
|
def complete?: () -> bool
|
45
97
|
end
|
46
98
|
|
@@ -58,53 +110,45 @@ module RBS
|
|
58
110
|
def initialize: ...
|
59
111
|
end
|
60
112
|
|
61
|
-
|
62
|
-
|
63
|
-
attr_reader type: Types::t | MethodType | nil
|
113
|
+
class MethodTypeAssertion < Base
|
114
|
+
attr_reader method_type: MethodType
|
64
115
|
|
65
|
-
|
66
|
-
|
67
|
-
# @rbs returns bool
|
68
|
-
def complete?: () -> bool
|
69
|
-
|
70
|
-
# Returns a type if it's type
|
71
|
-
def type?: () -> Types::t?
|
116
|
+
# @rbs override
|
117
|
+
def initialize: ...
|
72
118
|
|
73
|
-
|
74
|
-
def method_type?: () -> MethodType?
|
119
|
+
def type_source: () -> String
|
75
120
|
end
|
76
121
|
|
77
|
-
|
78
|
-
|
79
|
-
attr_reader types: Array[Types::t]?
|
122
|
+
class TypeAssertion < Base
|
123
|
+
attr_reader type: Types::t
|
80
124
|
|
81
125
|
# @rbs override
|
82
126
|
def initialize: ...
|
83
127
|
|
84
|
-
|
85
|
-
def complete?: () -> bool
|
128
|
+
def type_source: () -> String
|
86
129
|
end
|
87
130
|
|
88
|
-
|
89
|
-
|
90
|
-
# The type of block
|
91
|
-
#
|
92
|
-
# * Types::Block when syntactically correct input is given
|
93
|
-
# * String when syntax error is reported
|
94
|
-
# * `nil` when nothing is given
|
95
|
-
attr_reader block_type: Types::Block | String | nil
|
131
|
+
class SyntaxErrorAssertion < Base
|
132
|
+
attr_reader error_string: String
|
96
133
|
|
97
|
-
#
|
98
|
-
|
134
|
+
# @rbs override
|
135
|
+
def initialize: ...
|
136
|
+
end
|
99
137
|
|
100
|
-
|
101
|
-
#
|
102
|
-
|
103
|
-
|
104
|
-
|
138
|
+
class Dot3Assertion < Base
|
139
|
+
# @rbs override
|
140
|
+
def initialize: ...
|
141
|
+
end
|
142
|
+
|
143
|
+
# `#[TYPE, ..., TYPE]`
|
144
|
+
class Application < Base
|
145
|
+
attr_reader types: Array[Types::t]?
|
105
146
|
|
106
147
|
# @rbs override
|
107
148
|
def initialize: ...
|
149
|
+
|
150
|
+
# @rbs return: bool
|
151
|
+
def complete?: () -> bool
|
108
152
|
end
|
109
153
|
|
110
154
|
# `# @rbs %a{a} %a{a} ...`
|
@@ -170,6 +214,8 @@ module RBS
|
|
170
214
|
|
171
215
|
attr_reader comment: String?
|
172
216
|
|
217
|
+
include Utils
|
218
|
+
|
173
219
|
# @rbs override
|
174
220
|
def initialize: ...
|
175
221
|
end
|
@@ -181,6 +227,64 @@ module RBS
|
|
181
227
|
# @rbs override
|
182
228
|
def initialize: ...
|
183
229
|
end
|
230
|
+
|
231
|
+
# `@rbs METHOD-TYPE``
|
232
|
+
class Method < Base
|
233
|
+
type method_type = [ MethodType, method_type? ] | String
|
234
|
+
|
235
|
+
attr_reader method_types: method_type?
|
236
|
+
|
237
|
+
# `true` if the method definition is overloading something
|
238
|
+
attr_reader overloading: bool
|
239
|
+
|
240
|
+
attr_reader type: MethodType?
|
241
|
+
|
242
|
+
attr_reader method_type_source: String
|
243
|
+
|
244
|
+
# @rbs override
|
245
|
+
def initialize: ...
|
246
|
+
|
247
|
+
# : (Array[tree]) -> method_type?
|
248
|
+
def construct_method_types: (Array[tree]) -> method_type?
|
249
|
+
|
250
|
+
# @rbs () { (MethodType) -> void } -> void
|
251
|
+
# | () -> Enumerator[MethodType, void]
|
252
|
+
def each_method_type: () { (MethodType) -> void } -> void
|
253
|
+
| () -> Enumerator[MethodType, void]
|
254
|
+
|
255
|
+
# Returns the parsing error overload string
|
256
|
+
#
|
257
|
+
# Returns `nil` if no parsing error found.
|
258
|
+
def error_source: () -> String?
|
259
|
+
end
|
260
|
+
|
261
|
+
# `@rbs module Foo`
|
262
|
+
class ModuleDecl < Base
|
263
|
+
attr_reader name: TypeName?
|
264
|
+
|
265
|
+
attr_reader type_params: Array[RBS::AST::TypeParam]
|
266
|
+
|
267
|
+
attr_reader self_types: Array[RBS::AST::Declarations::Module::Self]
|
268
|
+
|
269
|
+
include Utils
|
270
|
+
|
271
|
+
# @rbs override
|
272
|
+
def initialize: ...
|
273
|
+
end
|
274
|
+
|
275
|
+
# `@rbs class Foo`
|
276
|
+
class ClassDecl < Base
|
277
|
+
attr_reader name: TypeName?
|
278
|
+
|
279
|
+
attr_reader type_params: Array[RBS::AST::TypeParam]
|
280
|
+
|
281
|
+
attr_reader super_class: RBS::AST::Declarations::Class::Super?
|
282
|
+
|
283
|
+
include Utils
|
284
|
+
|
285
|
+
# @rbs override
|
286
|
+
def initialize: ...
|
287
|
+
end
|
184
288
|
end
|
185
289
|
end
|
186
290
|
end
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module RBS
|
4
4
|
module Inline
|
5
5
|
module AST
|
6
|
-
# CommentLines represents consecutive comments
|
6
|
+
# CommentLines represents consecutive comments, providing a mapping from locations in `#string` to a pair of a comment and its offset
|
7
7
|
#
|
8
8
|
# The comments construct one String.
|
9
9
|
#
|
@@ -15,15 +15,19 @@ module RBS
|
|
15
15
|
# We want to get a String of comment1 and comment2, `"Hello\nWorld".
|
16
16
|
# And want to translate a location in the string into the location in comment1 and comment2.
|
17
17
|
class CommentLines
|
18
|
-
attr_reader comments: Array[
|
18
|
+
attr_reader comments: Array[Prism::Comment]
|
19
19
|
|
20
20
|
# @rbs comments: Array[Prism::Comment]
|
21
|
-
def initialize: (Array[Prism::Comment] comments) ->
|
21
|
+
def initialize: (Array[Prism::Comment] comments) -> void
|
22
|
+
|
23
|
+
def lines: () -> Array[String]
|
22
24
|
|
23
25
|
def string: () -> String
|
24
26
|
|
27
|
+
# Translates the cursor index of `#string` into the cursor index of a specific comment object
|
28
|
+
#
|
25
29
|
# @rbs index: Integer
|
26
|
-
# @rbs
|
30
|
+
# @rbs return: [Prism::Comment, Integer]?
|
27
31
|
def comment_location: (Integer index) -> [ Prism::Comment, Integer ]?
|
28
32
|
end
|
29
33
|
end
|