rbs-inline 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/LICENSE.txt +21 -0
- data/README.md +109 -0
- data/Rakefile +12 -0
- data/Steepfile +27 -0
- data/exe/rbs-inline +6 -0
- data/lib/rbs/inline/annotation_parser.rb +765 -0
- data/lib/rbs/inline/ast/annotations.rb +454 -0
- data/lib/rbs/inline/ast/comment_lines.rb +42 -0
- data/lib/rbs/inline/ast/declarations.rb +243 -0
- data/lib/rbs/inline/ast/members.rb +599 -0
- data/lib/rbs/inline/ast/tree.rb +141 -0
- data/lib/rbs/inline/cli.rb +106 -0
- data/lib/rbs/inline/node_utils.rb +12 -0
- data/lib/rbs/inline/parser.rb +360 -0
- data/lib/rbs/inline/version.rb +7 -0
- data/lib/rbs/inline/writer.rb +210 -0
- data/lib/rbs/inline.rb +22 -0
- data/rbs_collection.lock.yaml +68 -0
- data/rbs_collection.yaml +17 -0
- data/sig/generated/rbs/inline/annotation_parser.rbs +222 -0
- data/sig/generated/rbs/inline/ast/annotations.rbs +185 -0
- data/sig/generated/rbs/inline/ast/declarations.rbs +116 -0
- data/sig/generated/rbs/inline/ast/members.rbs +179 -0
- data/sig/generated/rbs/inline/cli.rbs +21 -0
- data/sig/generated/rbs/inline/parser.rbs +116 -0
- data/sig/rbs/inline/annotation_parser.rbs +0 -0
- data/sig/rbs/inline/ast/comment_lines.rbs +27 -0
- data/sig/rbs/inline/ast/members.rbs +24 -0
- data/sig/rbs/inline/ast/tree.rbs +98 -0
- data/sig/rbs/inline/node_utils.rbs +7 -0
- data/sig/rbs/inline/writer.rbs +27 -0
- data/sig/rbs/inline.rbs +41 -0
- data/yard-samples/hello.rb +6 -0
- data/yard-samples/sample1.rb +26 -0
- metadata +111 -0
@@ -0,0 +1,185 @@
|
|
1
|
+
# Generated from lib/rbs/inline/ast/annotations.rb with RBS::Inline
|
2
|
+
|
3
|
+
module RBS
|
4
|
+
module Inline
|
5
|
+
module AST
|
6
|
+
module Annotations
|
7
|
+
class Base
|
8
|
+
attr_reader source: CommentLines
|
9
|
+
|
10
|
+
attr_reader tree: Tree
|
11
|
+
|
12
|
+
# @rbs tree: Tree
|
13
|
+
# @rbs source: CommentLines
|
14
|
+
# @rbs returns void
|
15
|
+
def initialize: (Tree tree, CommentLines source) -> void
|
16
|
+
end
|
17
|
+
|
18
|
+
class VarType < Base
|
19
|
+
attr_reader name: Symbol
|
20
|
+
|
21
|
+
attr_reader type: Types::t?
|
22
|
+
|
23
|
+
attr_reader comment: String?
|
24
|
+
|
25
|
+
# @rbs override
|
26
|
+
def initialize: ...
|
27
|
+
|
28
|
+
# :: () -> bool
|
29
|
+
def complete?: () -> bool
|
30
|
+
end
|
31
|
+
|
32
|
+
# `@rbs returns T`
|
33
|
+
class ReturnType < Base
|
34
|
+
attr_reader type: Types::t?
|
35
|
+
|
36
|
+
attr_reader comment: String?
|
37
|
+
|
38
|
+
# @rbs override
|
39
|
+
def initialize: ...
|
40
|
+
|
41
|
+
# @rbs returns bool
|
42
|
+
def complete?: () -> bool
|
43
|
+
end
|
44
|
+
|
45
|
+
# `@rbs @foo: T` or `@rbs self.@foo: T`
|
46
|
+
class IvarType < Base
|
47
|
+
attr_reader name: Symbol
|
48
|
+
|
49
|
+
attr_reader type: Types::t?
|
50
|
+
|
51
|
+
attr_reader class_instance: bool
|
52
|
+
|
53
|
+
attr_reader comment: String?
|
54
|
+
|
55
|
+
# @rbs override
|
56
|
+
def initialize: ...
|
57
|
+
end
|
58
|
+
|
59
|
+
# `#:: TYPE`
|
60
|
+
class Assertion < Base
|
61
|
+
attr_reader type: Types::t | MethodType | nil
|
62
|
+
|
63
|
+
def initialize: (untyped tree, untyped source) -> untyped
|
64
|
+
|
65
|
+
# @rbs returns bool
|
66
|
+
def complete?: () -> bool
|
67
|
+
|
68
|
+
# Returns a type if it's type
|
69
|
+
def type?: () -> Types::t?
|
70
|
+
|
71
|
+
# Returns a method type if it's a method type
|
72
|
+
def method_type?: () -> MethodType?
|
73
|
+
end
|
74
|
+
|
75
|
+
# `#[TYPE, ..., TYPE]`
|
76
|
+
class Application < Base
|
77
|
+
attr_reader types: Array[Types::t]?
|
78
|
+
|
79
|
+
# @rbs override
|
80
|
+
def initialize: ...
|
81
|
+
|
82
|
+
# @rbs returns bool
|
83
|
+
def complete?: () -> bool
|
84
|
+
end
|
85
|
+
|
86
|
+
# `# @rbs yields () -> void -- Comment`
|
87
|
+
class Yields < Base
|
88
|
+
# The type of block
|
89
|
+
#
|
90
|
+
# * Types::Block when syntactically correct input is given
|
91
|
+
# * String when syntax error is reported
|
92
|
+
# * `nil` when nothing is given
|
93
|
+
attr_reader block_type: Types::Block | String | nil
|
94
|
+
|
95
|
+
# The content of the comment or `nil`
|
96
|
+
attr_reader comment: String?
|
97
|
+
|
98
|
+
# If `[optional]` token is inserted just after `yields` token
|
99
|
+
#
|
100
|
+
# The Types::Block instance has correct `required` attribute based on the `[optional]` token.
|
101
|
+
# This is for the other cases, syntax error or omitted.
|
102
|
+
attr_reader optional: bool
|
103
|
+
|
104
|
+
# @rbs override
|
105
|
+
def initialize: ...
|
106
|
+
end
|
107
|
+
|
108
|
+
# `# @rbs %a{a} %a{a} ...`
|
109
|
+
class RBSAnnotation < Base
|
110
|
+
attr_reader contents: Array[String]
|
111
|
+
|
112
|
+
# @rbs override
|
113
|
+
def initialize: ...
|
114
|
+
end
|
115
|
+
|
116
|
+
# `# @rbs skip`
|
117
|
+
class Skip < Base
|
118
|
+
# @rbs override
|
119
|
+
def initialize: ...
|
120
|
+
end
|
121
|
+
|
122
|
+
# `# @rbs inherits T`
|
123
|
+
class Inherits < Base
|
124
|
+
attr_reader super_name: TypeName?
|
125
|
+
|
126
|
+
attr_reader args: Array[Types::t]?
|
127
|
+
|
128
|
+
# @rbs override
|
129
|
+
def initialize: ...
|
130
|
+
end
|
131
|
+
|
132
|
+
# `# @rbs override`
|
133
|
+
#
|
134
|
+
# Specify the method types as `...` (overriding super class method)
|
135
|
+
class Override < Base
|
136
|
+
# @rbs override
|
137
|
+
def initialize: ...
|
138
|
+
end
|
139
|
+
|
140
|
+
# `# @rbs use [USES]`
|
141
|
+
class Use < Base
|
142
|
+
attr_reader clauses: Array[RBS::AST::Directives::Use::clause]
|
143
|
+
|
144
|
+
# @rbs override
|
145
|
+
def initialize: ...
|
146
|
+
end
|
147
|
+
|
148
|
+
# `# @rbs module-self [MODULE_SELF]`
|
149
|
+
class ModuleSelf < Base
|
150
|
+
attr_reader constraint: RBS::AST::Declarations::Module::Self?
|
151
|
+
|
152
|
+
attr_reader comment: String?
|
153
|
+
|
154
|
+
# @rbs override
|
155
|
+
def initialize: ...
|
156
|
+
end
|
157
|
+
|
158
|
+
# `# @rbs generic [type param]`
|
159
|
+
#
|
160
|
+
# ```rb
|
161
|
+
# # @rbs generic X
|
162
|
+
# # @rbs generic in Y
|
163
|
+
# # @rbs generic unchecked out Z < String -- Comment here
|
164
|
+
# ```
|
165
|
+
class Generic < Base
|
166
|
+
# TypeParam object or `nil` if syntax error
|
167
|
+
attr_reader type_param: RBS::AST::TypeParam?
|
168
|
+
|
169
|
+
attr_reader comment: String?
|
170
|
+
|
171
|
+
# @rbs override
|
172
|
+
def initialize: ...
|
173
|
+
end
|
174
|
+
|
175
|
+
# `# @rbs!` annotation
|
176
|
+
class Embedded < Base
|
177
|
+
attr_reader content: String
|
178
|
+
|
179
|
+
# @rbs override
|
180
|
+
def initialize: ...
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
@@ -0,0 +1,116 @@
|
|
1
|
+
# Generated from lib/rbs/inline/ast/declarations.rb with RBS::Inline
|
2
|
+
|
3
|
+
module RBS
|
4
|
+
module Inline
|
5
|
+
module AST
|
6
|
+
module Declarations
|
7
|
+
module ConstantUtil
|
8
|
+
# @rbs node: Prism::Node
|
9
|
+
# @rbs returns TypeName?
|
10
|
+
def type_name: (Prism::Node node) -> TypeName?
|
11
|
+
end
|
12
|
+
|
13
|
+
type t = ClassDecl | ModuleDecl | ConstantDecl
|
14
|
+
|
15
|
+
interface _WithComments
|
16
|
+
def comments: () -> AnnotationParser::ParsingResult?
|
17
|
+
end
|
18
|
+
|
19
|
+
# @rbs module-self _WithComments
|
20
|
+
module Generics : _WithComments
|
21
|
+
# @rbs returns Array[RBS::AST::TypeParam]
|
22
|
+
def type_params: () -> Array[RBS::AST::TypeParam]
|
23
|
+
end
|
24
|
+
|
25
|
+
class Base
|
26
|
+
end
|
27
|
+
|
28
|
+
# @rbs generic NODE < Prism::Node
|
29
|
+
class ModuleOrClass[NODE < Prism::Node] < Base
|
30
|
+
# The node that represents the declaration
|
31
|
+
attr_reader node: NODE
|
32
|
+
|
33
|
+
# Leading comment
|
34
|
+
attr_reader comments: AnnotationParser::ParsingResult?
|
35
|
+
|
36
|
+
# Members included in the declaration
|
37
|
+
attr_reader members: Array[Members::t | t]
|
38
|
+
|
39
|
+
# @rbs node: NODE
|
40
|
+
# @rbs comments: AnnotationParser::ParsingResult?
|
41
|
+
def initialize: (NODE node, AnnotationParser::ParsingResult? comments) -> void
|
42
|
+
|
43
|
+
# Type parameters for the declaration
|
44
|
+
def type_params: () -> Array[RBS::AST::TypeParam]
|
45
|
+
|
46
|
+
def start_line: () -> Integer
|
47
|
+
end
|
48
|
+
|
49
|
+
class ClassDecl < ModuleOrClass[Prism::ClassNode]
|
50
|
+
include ConstantUtil
|
51
|
+
|
52
|
+
# Type application for super class
|
53
|
+
attr_reader super_app: Annotations::Application?
|
54
|
+
|
55
|
+
# @rbs node: Prism::ClassNode
|
56
|
+
# @rbs comments: AnnotationParser::ParsingResult?
|
57
|
+
# @rbs super_app: Annotations::Application?
|
58
|
+
# @rbs returns void
|
59
|
+
def initialize: (Prism::ClassNode node, AnnotationParser::ParsingResult? comments, Annotations::Application? super_app) -> void
|
60
|
+
|
61
|
+
# @rbs %a{pure}
|
62
|
+
%a{pure}
|
63
|
+
def class_name: () -> TypeName?
|
64
|
+
|
65
|
+
# @rbs %a{pure}
|
66
|
+
%a{pure}
|
67
|
+
def super_class: () -> RBS::AST::Declarations::Class::Super?
|
68
|
+
end
|
69
|
+
|
70
|
+
class ModuleDecl < ModuleOrClass[Prism::ModuleNode]
|
71
|
+
include ConstantUtil
|
72
|
+
|
73
|
+
# @rbs %a{pure}
|
74
|
+
%a{pure}
|
75
|
+
def module_name: () -> TypeName?
|
76
|
+
|
77
|
+
# @rbs %a{pure}
|
78
|
+
%a{pure}
|
79
|
+
def module_selfs: () -> Array[Annotations::ModuleSelf]
|
80
|
+
end
|
81
|
+
|
82
|
+
class ConstantDecl < Base
|
83
|
+
include ConstantUtil
|
84
|
+
|
85
|
+
attr_reader node: Prism::ConstantWriteNode
|
86
|
+
|
87
|
+
attr_reader comments: AnnotationParser::ParsingResult?
|
88
|
+
|
89
|
+
attr_reader assertion: Annotations::Assertion?
|
90
|
+
|
91
|
+
# @rbs node: Prism::ConstantWriteNode
|
92
|
+
# @rbs comments: AnnotationParser::ParsingResult?
|
93
|
+
# @rbs assertion: Annotations::Assertion?
|
94
|
+
def initialize: (Prism::ConstantWriteNode node, AnnotationParser::ParsingResult? comments, Annotations::Assertion? assertion) -> untyped
|
95
|
+
|
96
|
+
# @rbs %a{pure}
|
97
|
+
# @rbs returns Types::t
|
98
|
+
%a{pure}
|
99
|
+
def type: () -> Types::t
|
100
|
+
|
101
|
+
# @rbs %a{pure}
|
102
|
+
# @rbs return Types::t?
|
103
|
+
%a{pure}
|
104
|
+
def literal_type: () -> untyped
|
105
|
+
|
106
|
+
# @rbs %a{pure}
|
107
|
+
# @rbs returns TypeName?
|
108
|
+
%a{pure}
|
109
|
+
def constant_name: () -> TypeName?
|
110
|
+
|
111
|
+
def start_line: () -> Integer
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
@@ -0,0 +1,179 @@
|
|
1
|
+
# Generated from lib/rbs/inline/ast/members.rb with RBS::Inline
|
2
|
+
|
3
|
+
module RBS
|
4
|
+
module Inline
|
5
|
+
module AST
|
6
|
+
module Members
|
7
|
+
class Base
|
8
|
+
attr_reader location: Prism::Location
|
9
|
+
|
10
|
+
# @rbs location: Prism::Location
|
11
|
+
def initialize: (Prism::Location location) -> void
|
12
|
+
|
13
|
+
def start_line: () -> Integer
|
14
|
+
end
|
15
|
+
|
16
|
+
class RubyBase < Base
|
17
|
+
end
|
18
|
+
|
19
|
+
class RubyDef < RubyBase
|
20
|
+
attr_reader node: Prism::DefNode
|
21
|
+
|
22
|
+
attr_reader comments: AnnotationParser::ParsingResult?
|
23
|
+
|
24
|
+
# The visibility directly attached to the `def` node
|
25
|
+
#
|
26
|
+
# `nil` when the `def` node is not passed to `private`/`public` calls.
|
27
|
+
#
|
28
|
+
# ```rb
|
29
|
+
# def foo() end # <= nil
|
30
|
+
# private def foo() end # <= :private
|
31
|
+
# ```
|
32
|
+
attr_reader visibility: RBS::AST::Members::visibility?
|
33
|
+
|
34
|
+
attr_reader assertion: Annotations::Assertion?
|
35
|
+
|
36
|
+
# @rbs node: Prism::DefNode
|
37
|
+
# @rbs comments: AnnotationParser::ParsingResult?
|
38
|
+
# @rbs visibility: RBS::AST::Members::visibility?
|
39
|
+
# @rbs assertion: Annotations::Assertion?
|
40
|
+
def initialize: (Prism::DefNode node, AnnotationParser::ParsingResult? comments, RBS::AST::Members::visibility? visibility, Annotations::Assertion? assertion) -> void
|
41
|
+
|
42
|
+
# Returns the name of the method
|
43
|
+
def method_name: () -> Symbol
|
44
|
+
|
45
|
+
def method_type_annotations: () -> Array[Annotations::Assertion]
|
46
|
+
|
47
|
+
# Returns the `kind` of the method definition
|
48
|
+
#
|
49
|
+
# [FIXME] It only supports `self` receiver.
|
50
|
+
#
|
51
|
+
# ```rb
|
52
|
+
# def self.foo = () # :sigleton
|
53
|
+
# def object.foo = () # Not supported (returns :instance)
|
54
|
+
# ```
|
55
|
+
def method_kind: () -> RBS::AST::Members::MethodDefinition::kind
|
56
|
+
|
57
|
+
def return_type: () -> Types::t?
|
58
|
+
|
59
|
+
def var_type_hash: () -> Hash[Symbol, Types::t?]
|
60
|
+
|
61
|
+
def method_overloads: () -> Array[RBS::AST::Members::MethodDefinition::Overload]
|
62
|
+
|
63
|
+
def method_annotations: () -> Array[RBS::AST::Annotation]
|
64
|
+
|
65
|
+
def override_annotation: () -> AST::Annotations::Override?
|
66
|
+
|
67
|
+
def yields_annotation: () -> AST::Annotations::Yields?
|
68
|
+
end
|
69
|
+
|
70
|
+
class RubyAlias < RubyBase
|
71
|
+
attr_reader node: Prism::AliasMethodNode
|
72
|
+
|
73
|
+
attr_reader comments: AnnotationParser::ParsingResult?
|
74
|
+
|
75
|
+
# @rbs node: Prism::AliasMethodNode
|
76
|
+
# @rbs comments: AnnotationParser::ParsingResult?
|
77
|
+
def initialize: (Prism::AliasMethodNode node, AnnotationParser::ParsingResult? comments) -> untyped
|
78
|
+
|
79
|
+
# @rbs returns Symbol -- the name of *old* method
|
80
|
+
def old_name: () -> Symbol
|
81
|
+
|
82
|
+
# @rbs returns Symbol -- the name of *new* method
|
83
|
+
def new_name: () -> Symbol
|
84
|
+
end
|
85
|
+
|
86
|
+
class RubyMixin < RubyBase
|
87
|
+
# CallNode that calls `include`, `prepend`, and `extend` method
|
88
|
+
attr_reader node: Prism::CallNode
|
89
|
+
|
90
|
+
# Comments attached to the call node
|
91
|
+
attr_reader comments: AnnotationParser::ParsingResult?
|
92
|
+
|
93
|
+
# Possible following type application annotation
|
94
|
+
attr_reader application: Annotations::Application?
|
95
|
+
|
96
|
+
# @rbs node: Prism::CallNode
|
97
|
+
# @rbs comments: AnnotationParser::ParsingResult?
|
98
|
+
# @rbs application: Annotations::Application?
|
99
|
+
# @rbs returns void
|
100
|
+
def initialize: (Prism::CallNode node, AnnotationParser::ParsingResult? comments, Annotations::Application? application) -> void
|
101
|
+
|
102
|
+
# @rbs returns ::RBS::AST::Members::Include
|
103
|
+
# | ::RBS::AST::Members::Extend
|
104
|
+
# | ::RBS::AST::Members::Prepend
|
105
|
+
# | nil
|
106
|
+
def rbs: () -> (::RBS::AST::Members::Include | ::RBS::AST::Members::Extend | ::RBS::AST::Members::Prepend | nil)
|
107
|
+
end
|
108
|
+
|
109
|
+
class RubyAttr < RubyBase
|
110
|
+
attr_reader node: Prism::CallNode
|
111
|
+
|
112
|
+
attr_reader comments: AnnotationParser::ParsingResult?
|
113
|
+
|
114
|
+
attr_reader assertion: Annotations::Assertion?
|
115
|
+
|
116
|
+
# @rbs node: Prism::CallNode
|
117
|
+
# @rbs comments: AnnotationParser::ParsingResult?
|
118
|
+
# @rbs assertion: Annotations::Assertion?
|
119
|
+
# @rbs returns void
|
120
|
+
def initialize: (Prism::CallNode node, AnnotationParser::ParsingResult? comments, Annotations::Assertion? assertion) -> void
|
121
|
+
|
122
|
+
# @rbs return Array[RBS::AST::Members::AttrReader | RBS::AST::Members::AttrWriter | RBS::AST::Members::AttrAccessor]?
|
123
|
+
def rbs: () -> untyped
|
124
|
+
|
125
|
+
# Returns the type of the attribute
|
126
|
+
#
|
127
|
+
# Returns `untyped` when not annotated.
|
128
|
+
def attribute_type: () -> Types::t
|
129
|
+
end
|
130
|
+
|
131
|
+
# `private` call without arguments
|
132
|
+
class RubyPrivate < RubyBase
|
133
|
+
attr_reader node: Prism::CallNode
|
134
|
+
|
135
|
+
# @rbs node: Prism::CallNode
|
136
|
+
def initialize: (Prism::CallNode node) -> void
|
137
|
+
end
|
138
|
+
|
139
|
+
# `public` call without arguments
|
140
|
+
class RubyPublic < RubyBase
|
141
|
+
attr_reader node: Prism::CallNode
|
142
|
+
|
143
|
+
# @rbs node: Prism::CallNode
|
144
|
+
def initialize: (Prism::CallNode node) -> void
|
145
|
+
end
|
146
|
+
|
147
|
+
class RBSBase < Base
|
148
|
+
end
|
149
|
+
|
150
|
+
class RBSIvar < RBSBase
|
151
|
+
attr_reader annotation: Annotations::IvarType
|
152
|
+
|
153
|
+
attr_reader comment: AnnotationParser::ParsingResult
|
154
|
+
|
155
|
+
# @rbs comment: AnnotationParser::ParsingResult
|
156
|
+
# @rbs annotation: Annotations::IvarType
|
157
|
+
def initialize: (AnnotationParser::ParsingResult comment, Annotations::IvarType annotation) -> void
|
158
|
+
|
159
|
+
def rbs: () -> (RBS::AST::Members::InstanceVariable | RBS::AST::Members::ClassInstanceVariable | nil)
|
160
|
+
end
|
161
|
+
|
162
|
+
class RBSEmbedded < RBSBase
|
163
|
+
attr_reader annotation: Annotations::Embedded
|
164
|
+
|
165
|
+
attr_reader comment: AnnotationParser::ParsingResult
|
166
|
+
|
167
|
+
# @rbs comment: AnnotationParser::ParsingResult
|
168
|
+
# @rbs annotation: Annotations::Embedded
|
169
|
+
def initialize: (AnnotationParser::ParsingResult comment, Annotations::Embedded annotation) -> void
|
170
|
+
|
171
|
+
# Returns the array of `RBS::AST` members
|
172
|
+
#
|
173
|
+
# Returns `RBS::ParsingError` when the `content` has syntax error.
|
174
|
+
def members: () -> (Array[RBS::AST::Members::t | RBS::AST::Declarations::t] | RBS::ParsingError)
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# Generated from lib/rbs/inline/cli.rb with RBS::Inline
|
2
|
+
|
3
|
+
module RBS
|
4
|
+
module Inline
|
5
|
+
class CLI
|
6
|
+
attr_reader stdout: IO
|
7
|
+
|
8
|
+
attr_reader stderr: IO
|
9
|
+
|
10
|
+
attr_reader logger: Logger
|
11
|
+
|
12
|
+
# @rbs stdout: IO
|
13
|
+
# @rbs stderr: IO
|
14
|
+
def initialize: (?stdout: IO, ?stderr: IO) -> void
|
15
|
+
|
16
|
+
# @rbs args: Array[String]
|
17
|
+
# @rbs returns Integer
|
18
|
+
def run: (Array[String] args) -> Integer
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,116 @@
|
|
1
|
+
# Generated from lib/rbs/inline/parser.rb with RBS::Inline
|
2
|
+
|
3
|
+
use Prism::*
|
4
|
+
|
5
|
+
module RBS
|
6
|
+
module Inline
|
7
|
+
class Parser < Prism::Visitor
|
8
|
+
# The top level declarations
|
9
|
+
attr_reader decls: Array[AST::Declarations::t]
|
10
|
+
|
11
|
+
# The surrounding declarations
|
12
|
+
attr_reader surrounding_decls: Array[AST::Declarations::ModuleDecl | AST::Declarations::ClassDecl]
|
13
|
+
|
14
|
+
# ParsingResult associated with the line number at the end
|
15
|
+
#
|
16
|
+
# ```rb
|
17
|
+
# # Hello
|
18
|
+
# # world <= The comments hash includes `2` (line 2) to the two lines
|
19
|
+
# ```
|
20
|
+
#
|
21
|
+
# > [!IMPORTANT]
|
22
|
+
# > The values will be removed during parsing.
|
23
|
+
attr_reader comments: Hash[Integer, AnnotationParser::ParsingResult]
|
24
|
+
|
25
|
+
# The current visibility applied to single `def` node
|
26
|
+
#
|
27
|
+
# Assuming it's directly inside `private` or `public` calls.
|
28
|
+
# `nil` when the `def` node is not inside `private` or `public` calls.
|
29
|
+
attr_reader current_visibility: RBS::AST::Members::visibility?
|
30
|
+
|
31
|
+
def initialize: () -> void
|
32
|
+
|
33
|
+
# @rbs result: ParseResult[ProgramNode]
|
34
|
+
# @rbs returns [Array[AST::Annotations::Use], Array[AST::Declarations::t]]?
|
35
|
+
def self.parse: (ParseResult[ProgramNode] result) -> [ Array[AST::Annotations::Use], Array[AST::Declarations::t] ]?
|
36
|
+
|
37
|
+
# @rbs rturns AST::Declarations::ModuleDecl | AST::Declarations::ClassDecl | nil
|
38
|
+
def current_class_module_decl: () -> untyped
|
39
|
+
|
40
|
+
# @rbs returns AST::Declarations::ModuleDecl | AST::Declarations::ClassDecl
|
41
|
+
def current_class_module_decl!: () -> (AST::Declarations::ModuleDecl | AST::Declarations::ClassDecl)
|
42
|
+
|
43
|
+
# :: (AST::Declarations::ModuleDecl | AST::Declarations::ClassDecl) { () -> void } -> void
|
44
|
+
# :: (AST::Declarations::ConstantDecl) -> void
|
45
|
+
def push_class_module_decl: (AST::Declarations::ModuleDecl | AST::Declarations::ClassDecl) { () -> void } -> void
|
46
|
+
| (AST::Declarations::ConstantDecl) -> void
|
47
|
+
|
48
|
+
# Load inner declarations and delete them from `#comments` hash
|
49
|
+
#
|
50
|
+
# It also sorts the `members` by `#start_line`` ascending.
|
51
|
+
#
|
52
|
+
# @rbs start_line: Integer
|
53
|
+
# @rbs end_line: Integer
|
54
|
+
# @rbs members: Array[AST::Members::t | AST::Declarations::t] --
|
55
|
+
# The destination.
|
56
|
+
# The method doesn't insert declarations, but have it to please type checker.
|
57
|
+
def load_inner_annotations: (Integer start_line, Integer end_line, Array[AST::Members::t | AST::Declarations::t] members) -> void
|
58
|
+
|
59
|
+
# @rbs override
|
60
|
+
def visit_class_node: ...
|
61
|
+
|
62
|
+
# @rbs override
|
63
|
+
def visit_module_node: ...
|
64
|
+
|
65
|
+
# Returns an array of annotations from comments that is located between start_line and end_line
|
66
|
+
#
|
67
|
+
# ```rb
|
68
|
+
# module Foo # line 1 (start_line)
|
69
|
+
# # foo
|
70
|
+
# # bar
|
71
|
+
# end # line 4 (end_line)
|
72
|
+
# ```
|
73
|
+
#
|
74
|
+
# @rbs start_line: Integer
|
75
|
+
# @rbs end_line: Integer
|
76
|
+
def inner_annotations: (Integer start_line, Integer end_line) -> Array[AnnotationParser::ParsingResult]
|
77
|
+
|
78
|
+
# @rbs override
|
79
|
+
def visit_def_node: ...
|
80
|
+
|
81
|
+
# @rbs override
|
82
|
+
def visit_alias_method_node: ...
|
83
|
+
|
84
|
+
# @rbs override
|
85
|
+
def visit_call_node: ...
|
86
|
+
|
87
|
+
# @rbs new_visibility: RBS::AST::Members::visibility?
|
88
|
+
# @rbs block: ^() -> void
|
89
|
+
# @rbs returns void
|
90
|
+
def push_visibility: (RBS::AST::Members::visibility? new_visibility) { () -> void } -> void
|
91
|
+
|
92
|
+
# @rbs node: Node
|
93
|
+
# @rbs returns bool
|
94
|
+
def ignored_node?: (Node node) -> bool
|
95
|
+
|
96
|
+
# Fetch Application annotation which is associated to `node`
|
97
|
+
#
|
98
|
+
# The application annotation is removed from `comments`.
|
99
|
+
#
|
100
|
+
# @rbs node: Node
|
101
|
+
# @rbs returns AST::Annotations::Application?
|
102
|
+
def application_annotation: (Node node) -> AST::Annotations::Application?
|
103
|
+
|
104
|
+
# Fetch Assertion annotation which is associated to `node`
|
105
|
+
#
|
106
|
+
# The assertion annotation is removed from `comments`.
|
107
|
+
#
|
108
|
+
# @rbs node: Node | Location
|
109
|
+
# @rbs returns AST::Annotations::Assertion?
|
110
|
+
def assertion_annotation: (Node | Location node) -> AST::Annotations::Assertion?
|
111
|
+
|
112
|
+
# @rbs override
|
113
|
+
def visit_constant_write_node: ...
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
File without changes
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module RBS
|
2
|
+
module Inline
|
3
|
+
module AST
|
4
|
+
# CommentLines represents consecutive comments
|
5
|
+
#
|
6
|
+
# The comments construct one String.
|
7
|
+
#
|
8
|
+
# ```ruby
|
9
|
+
# # Hello <-- Comment1
|
10
|
+
# # World <-- Comment2
|
11
|
+
# ```
|
12
|
+
#
|
13
|
+
# We want to get a String of comment1 and comment2, `"Hello\nWorld".
|
14
|
+
# And want to translate a location in the string into the location in comment1 and comment2.
|
15
|
+
#
|
16
|
+
class CommentLines
|
17
|
+
attr_reader comments: Array[[Prism::Comment, Integer]]
|
18
|
+
|
19
|
+
def initialize: (Array[Prism::Comment]) -> void
|
20
|
+
|
21
|
+
def string: () -> String
|
22
|
+
|
23
|
+
def comment_location: (Integer index) -> [Prism::Comment, Integer]?
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# use RBS::AST::Members::MethodDefinition::Overload
|
2
|
+
|
3
|
+
# module RBS
|
4
|
+
# module Inline
|
5
|
+
# module AST
|
6
|
+
# # module Members
|
7
|
+
# # type ruby = RubyDef | RubyAlias | RubyMixin | RubyAttr | RubyPublic | RubyPrivate
|
8
|
+
|
9
|
+
# # type rbs = RBSDef | RBSAlias | RBSAttr | RBSIvar
|
10
|
+
|
11
|
+
# # type t = ruby | rbs
|
12
|
+
|
13
|
+
# # class RBSDef < Base
|
14
|
+
# # end
|
15
|
+
|
16
|
+
# # class RBSAlias < Base
|
17
|
+
# # end
|
18
|
+
|
19
|
+
# # class RBSAttr < Base
|
20
|
+
# # end
|
21
|
+
# # end
|
22
|
+
# end
|
23
|
+
# end
|
24
|
+
# end
|