rbs 3.9.2 → 4.0.0.dev.1
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/.github/workflows/ruby.yml +1 -1
- data/.github/workflows/windows.yml +1 -1
- data/CHANGELOG.md +0 -13
- data/Rakefile +28 -21
- data/Steepfile +1 -0
- data/config.yml +232 -62
- data/ext/rbs_extension/ast_translation.c +1149 -0
- data/ext/rbs_extension/ast_translation.h +30 -0
- data/{src/constants.c → ext/rbs_extension/class_constants.c} +15 -1
- data/{include/rbs/constants.h → ext/rbs_extension/class_constants.h} +10 -1
- data/ext/rbs_extension/extconf.rb +3 -1
- data/ext/rbs_extension/{location.c → legacy_location.c} +25 -34
- data/ext/rbs_extension/legacy_location.h +40 -0
- data/ext/rbs_extension/main.c +402 -8
- data/ext/rbs_extension/rbs_extension.h +3 -21
- data/ext/rbs_extension/rbs_string_bridging.c +9 -0
- data/ext/rbs_extension/rbs_string_bridging.h +20 -0
- data/include/rbs/ast.h +748 -0
- data/include/rbs/defines.h +60 -0
- data/{ext/rbs_extension → include/rbs}/lexer.h +40 -32
- data/include/rbs/location.h +59 -0
- data/include/rbs/parser.h +151 -0
- data/include/rbs/string.h +49 -0
- data/include/rbs/util/rbs_allocator.h +38 -0
- data/include/rbs/util/rbs_assert.h +9 -0
- data/include/rbs/util/rbs_buffer.h +83 -0
- data/include/rbs/util/rbs_constant_pool.h +3 -64
- data/include/rbs/util/rbs_encoding.h +280 -0
- data/include/rbs/util/rbs_unescape.h +23 -0
- data/include/rbs.h +1 -2
- data/lib/rbs/annotate/formatter.rb +3 -13
- data/lib/rbs/annotate/rdoc_annotator.rb +3 -1
- data/lib/rbs/annotate/rdoc_source.rb +1 -1
- data/lib/rbs/ast/ruby/annotations.rb +119 -0
- data/lib/rbs/ast/ruby/comment_block.rb +221 -0
- data/lib/rbs/ast/ruby/declarations.rb +86 -0
- data/lib/rbs/ast/ruby/helpers/constant_helper.rb +24 -0
- data/lib/rbs/ast/ruby/helpers/location_helper.rb +15 -0
- data/lib/rbs/ast/ruby/members.rb +213 -0
- data/lib/rbs/buffer.rb +104 -24
- data/lib/rbs/cli/validate.rb +39 -34
- data/lib/rbs/cli.rb +4 -5
- data/lib/rbs/definition.rb +6 -1
- data/lib/rbs/definition_builder/ancestor_builder.rb +63 -60
- data/lib/rbs/definition_builder/method_builder.rb +45 -30
- data/lib/rbs/definition_builder.rb +44 -9
- data/lib/rbs/environment/class_entry.rb +69 -0
- data/lib/rbs/environment/module_entry.rb +66 -0
- data/lib/rbs/environment.rb +185 -154
- data/lib/rbs/environment_loader.rb +2 -2
- data/lib/rbs/errors.rb +4 -3
- data/lib/rbs/inline_parser/comment_association.rb +117 -0
- data/lib/rbs/inline_parser.rb +206 -0
- data/lib/rbs/location_aux.rb +35 -3
- data/lib/rbs/parser_aux.rb +11 -1
- data/lib/rbs/prototype/runtime.rb +2 -2
- data/lib/rbs/source.rb +99 -0
- data/lib/rbs/subtractor.rb +4 -3
- data/lib/rbs/version.rb +1 -1
- data/lib/rbs.rb +12 -0
- data/lib/rdoc/discover.rb +1 -1
- data/lib/rdoc_plugin/parser.rb +2 -2
- data/rbs.gemspec +1 -0
- data/sig/ancestor_builder.rbs +1 -1
- data/sig/annotate/formatter.rbs +2 -2
- data/sig/annotate/rdoc_annotater.rbs +1 -1
- data/sig/ast/ruby/annotations.rbs +110 -0
- data/sig/ast/ruby/comment_block.rbs +119 -0
- data/sig/ast/ruby/declarations.rbs +60 -0
- data/sig/ast/ruby/helpers/constant_helper.rbs +11 -0
- data/sig/ast/ruby/helpers/location_helper.rbs +15 -0
- data/sig/ast/ruby/members.rbs +72 -0
- data/sig/buffer.rbs +63 -5
- data/sig/definition.rbs +1 -0
- data/sig/definition_builder.rbs +1 -1
- data/sig/environment/class_entry.rbs +50 -0
- data/sig/environment/module_entry.rbs +50 -0
- data/sig/environment.rbs +22 -76
- data/sig/errors.rbs +13 -6
- data/sig/inline_parser/comment_association.rbs +71 -0
- data/sig/inline_parser.rbs +87 -0
- data/sig/location.rbs +32 -7
- data/sig/method_builder.rbs +7 -4
- data/sig/parser.rbs +16 -0
- data/sig/source.rbs +48 -0
- data/src/ast.c +1345 -0
- data/src/lexer.c +2867 -0
- data/src/lexer.re +151 -0
- data/{ext/rbs_extension → src}/lexstate.c +58 -42
- data/src/location.c +71 -0
- data/src/parser.c +3739 -0
- data/src/string.c +89 -0
- data/src/util/rbs_allocator.c +149 -0
- data/src/util/rbs_assert.c +19 -0
- data/src/util/rbs_buffer.c +54 -0
- data/src/util/rbs_constant_pool.c +13 -81
- data/src/util/rbs_encoding.c +5273 -0
- data/src/util/rbs_unescape.c +130 -0
- data/stdlib/rdoc/0/code_object.rbs +2 -2
- data/stdlib/rdoc/0/comment.rbs +2 -0
- data/stdlib/rdoc/0/options.rbs +76 -0
- data/stdlib/rdoc/0/rdoc.rbs +6 -4
- data/stdlib/rdoc/0/store.rbs +1 -1
- metadata +70 -17
- data/ext/rbs_extension/lexer.c +0 -2728
- data/ext/rbs_extension/lexer.re +0 -147
- data/ext/rbs_extension/location.h +0 -85
- data/ext/rbs_extension/parser.c +0 -2982
- data/ext/rbs_extension/parser.h +0 -18
- data/ext/rbs_extension/parserstate.c +0 -411
- data/ext/rbs_extension/parserstate.h +0 -163
- data/ext/rbs_extension/unescape.c +0 -32
- data/include/rbs/ruby_objs.h +0 -72
- data/src/ruby_objs.c +0 -799
@@ -0,0 +1,71 @@
|
|
1
|
+
use RBS::AST::Ruby::CommentBlock
|
2
|
+
|
3
|
+
module RBS
|
4
|
+
class InlineParser
|
5
|
+
# CommentAssociation manages the association between `Prism::Node` and `CommentBlock`
|
6
|
+
#
|
7
|
+
class CommentAssociation
|
8
|
+
attr_reader blocks: Array[CommentBlock]
|
9
|
+
|
10
|
+
attr_reader start_line_map: Hash[Integer, CommentBlock]
|
11
|
+
|
12
|
+
attr_reader end_line_map: Hash[Integer, CommentBlock]
|
13
|
+
|
14
|
+
# CommentBlocks that are already associated to a node, which cannot be associated to another node again
|
15
|
+
#
|
16
|
+
attr_reader associated_blocks: Set[CommentBlock]
|
17
|
+
|
18
|
+
def self.build: (Buffer, Prism::Result) -> instance
|
19
|
+
|
20
|
+
def initialize: (Array[CommentBlock]) -> void
|
21
|
+
|
22
|
+
class Reference
|
23
|
+
attr_reader block: CommentBlock
|
24
|
+
|
25
|
+
@associated_blocks: Set[CommentBlock]
|
26
|
+
|
27
|
+
def initialize: (CommentBlock, Set[CommentBlock]) -> void
|
28
|
+
|
29
|
+
def associate!: () -> self
|
30
|
+
|
31
|
+
def associated?: () -> bool
|
32
|
+
end
|
33
|
+
|
34
|
+
# Returns an unassociated CommentBlock that can be associated to given node
|
35
|
+
#
|
36
|
+
# Automatically updates association status.
|
37
|
+
#
|
38
|
+
def leading_block!: (Prism::Node) -> CommentBlock?
|
39
|
+
|
40
|
+
# Returns a Reference that is associated to given node
|
41
|
+
#
|
42
|
+
# Updates association explicitly through the reference.
|
43
|
+
#
|
44
|
+
def leading_block: (Prism::Node) -> Reference?
|
45
|
+
|
46
|
+
# Returns a CommentBlock that is associated to given node, or by its location
|
47
|
+
#
|
48
|
+
# Update association status.
|
49
|
+
#
|
50
|
+
def trailing_block!: (Prism::Node | Prism::Location) -> CommentBlock?
|
51
|
+
|
52
|
+
# Returns a Reference that is associated to given node, or by its location
|
53
|
+
#
|
54
|
+
# Updates association explicitly through the reference.
|
55
|
+
#
|
56
|
+
def trailing_block: (Prism::Node | Prism::Location) -> Reference?
|
57
|
+
|
58
|
+
# Yields leading CommentBlocks that is enclosed in the given node
|
59
|
+
#
|
60
|
+
# Note that `enclosed_blocks` works only after all of the *leading* blocks inside the node is associated.
|
61
|
+
#
|
62
|
+
# Update association status.
|
63
|
+
#
|
64
|
+
def each_enclosed_block: (Prism::Node) { (CommentBlock) -> void } -> void
|
65
|
+
| (Prism::Node) -> Enumerator[CommentBlock]
|
66
|
+
|
67
|
+
def each_unassociated_block: () { (CommentBlock) -> void } -> void
|
68
|
+
| () -> Enumerator[CommentBlock]
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
use RBS::AST::Ruby::Declarations
|
2
|
+
|
3
|
+
module RBS
|
4
|
+
class InlineParser
|
5
|
+
class Result
|
6
|
+
attr_reader buffer: Buffer
|
7
|
+
attr_reader prism_result: Prism::ParseResult
|
8
|
+
attr_reader declarations: Array[AST::Ruby::Declarations::t]
|
9
|
+
attr_reader diagnostics: Array[Diagnostic::t]
|
10
|
+
|
11
|
+
def initialize: (Buffer, Prism::ParseResult) -> void
|
12
|
+
end
|
13
|
+
|
14
|
+
module Diagnostic
|
15
|
+
class Base
|
16
|
+
attr_reader message: String
|
17
|
+
|
18
|
+
attr_reader location: Location
|
19
|
+
|
20
|
+
def initialize: (Location, String) -> void
|
21
|
+
end
|
22
|
+
|
23
|
+
class NotImplementedYet < Base
|
24
|
+
end
|
25
|
+
|
26
|
+
class NonConstantClassName < Base
|
27
|
+
end
|
28
|
+
|
29
|
+
class NonConstantModuleName < Base
|
30
|
+
end
|
31
|
+
|
32
|
+
class TopLevelMethodDefinition < Base
|
33
|
+
end
|
34
|
+
|
35
|
+
class UnusedInlineAnnotation < Base
|
36
|
+
end
|
37
|
+
|
38
|
+
class AnnotationSyntaxError < Base
|
39
|
+
end
|
40
|
+
|
41
|
+
type t = NotImplementedYet
|
42
|
+
| NonConstantClassName | NonConstantModuleName
|
43
|
+
| TopLevelMethodDefinition
|
44
|
+
| UnusedInlineAnnotation | AnnotationSyntaxError
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.parse: (Buffer, Prism::ParseResult) -> Result
|
48
|
+
|
49
|
+
class Parser < Prism::Visitor
|
50
|
+
type module_context = Declarations::ClassDecl | Declarations::ModuleDecl
|
51
|
+
|
52
|
+
include AST::Ruby::Helpers::ConstantHelper
|
53
|
+
|
54
|
+
include AST::Ruby::Helpers::LocationHelper
|
55
|
+
|
56
|
+
attr_reader comments: CommentAssociation
|
57
|
+
|
58
|
+
attr_reader result: Result
|
59
|
+
|
60
|
+
attr_reader module_nesting: Array[module_context]
|
61
|
+
|
62
|
+
def initialize: (Result) -> void
|
63
|
+
|
64
|
+
def buffer: () -> Buffer
|
65
|
+
|
66
|
+
%a{pure} def current_module: () -> module_context?
|
67
|
+
|
68
|
+
%a{pure} def current_module!: () -> module_context
|
69
|
+
|
70
|
+
def diagnostics: () -> Array[Diagnostic::t]
|
71
|
+
|
72
|
+
def push_module_nesting: [T] (module_context) { () -> T } -> T
|
73
|
+
|
74
|
+
# Returns `true` if the node is a comment block including `@rbs skip` annotation
|
75
|
+
#
|
76
|
+
# Doesn't update the `association` flag if returning `false`.
|
77
|
+
#
|
78
|
+
def skip_node?: (Prism::Node) -> bool
|
79
|
+
|
80
|
+
def insert_declaration: (module_context) -> void
|
81
|
+
|
82
|
+
def report_unused_annotation: (*AST::Ruby::Annotations::t | nil | AST::Ruby::CommentBlock::AnnotationSyntaxError) -> void
|
83
|
+
|
84
|
+
def report_unused_block: (AST::Ruby::CommentBlock) -> void
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
data/sig/location.rbs
CHANGED
@@ -4,14 +4,20 @@ module RBS
|
|
4
4
|
#
|
5
5
|
# A location can have _child_ locations.
|
6
6
|
#
|
7
|
-
class Location[in RequiredChildKeys, in OptionalChildKeys]
|
7
|
+
class Location[in RequiredChildKeys = untyped, in OptionalChildKeys = untyped]
|
8
8
|
# The buffer this location points on.
|
9
9
|
attr_reader buffer (): Buffer
|
10
10
|
|
11
|
-
# The index of character the range starts from
|
11
|
+
# The absolute start index of character the range starts from
|
12
|
+
#
|
13
|
+
# It returns the index in the `buffer.top_buffer`.
|
14
|
+
#
|
12
15
|
attr_reader start_pos (): Integer
|
13
16
|
|
14
|
-
# The index of character the range ends at
|
17
|
+
# The absolute end index of character the range ends at
|
18
|
+
#
|
19
|
+
# It returns the index in the `buffer.top_buffer`.
|
20
|
+
#
|
15
21
|
attr_reader end_pos (): Integer
|
16
22
|
|
17
23
|
def initialize: (Buffer, Integer start_pos, Integer end_pos) -> void
|
@@ -24,26 +30,37 @@ module RBS
|
|
24
30
|
# Returns the name of the buffer.
|
25
31
|
def name: () -> untyped
|
26
32
|
|
27
|
-
#
|
33
|
+
# The *raw* index of character the range starts from.
|
34
|
+
attr_reader _start_pos (): Integer
|
35
|
+
|
36
|
+
# The *raw* index of character the range ends at.
|
37
|
+
attr_reader _end_pos (): Integer
|
38
|
+
|
39
|
+
# Line of the `start_pos` (1 origin, absolute)
|
28
40
|
attr_reader start_line (): Integer
|
29
41
|
|
30
|
-
# Column of the `start_pos` (0 origin)
|
42
|
+
# Column of the `start_pos` (0 origin, absolute)
|
31
43
|
attr_reader start_column (): Integer
|
32
44
|
|
33
|
-
# Line of the `end_pos` (1 origin)
|
45
|
+
# Line of the `end_pos` (1 origin, absolute)
|
34
46
|
attr_reader end_line (): Integer
|
35
47
|
|
36
|
-
# Column of the `end_pos` (0 origin)
|
48
|
+
# Column of the `end_pos` (0 origin, absolute)
|
37
49
|
attr_reader end_column (): Integer
|
38
50
|
|
51
|
+
# The absolute line-column pair of the start position
|
52
|
+
#
|
39
53
|
attr_reader start_loc (): Buffer::loc
|
40
54
|
|
41
55
|
@start_loc: Buffer::loc?
|
42
56
|
|
57
|
+
# The absolute line-column pair of the end position
|
58
|
+
#
|
43
59
|
attr_reader end_loc (): Buffer::loc
|
44
60
|
|
45
61
|
@end_loc: Buffer::loc?
|
46
62
|
|
63
|
+
# The absolute range of the start and end position
|
47
64
|
attr_reader range (): Range[Integer]
|
48
65
|
|
49
66
|
@range: Range[Integer]?
|
@@ -97,6 +114,14 @@ module RBS
|
|
97
114
|
|
98
115
|
def key?: (Symbol) -> bool
|
99
116
|
|
117
|
+
# Returns the location of the buffer, but the buffer is detached from the parent buffer
|
118
|
+
#
|
119
|
+
def local_location: () -> self
|
120
|
+
|
121
|
+
# Returns the source of `#local_location`
|
122
|
+
#
|
123
|
+
def local_source: () -> String
|
124
|
+
|
100
125
|
private
|
101
126
|
|
102
127
|
def _add_required_child: (RequiredChildKeys name, Integer start_pos, Integer end_pos) -> void
|
data/sig/method_builder.rbs
CHANGED
@@ -16,16 +16,19 @@ module RBS
|
|
16
16
|
#
|
17
17
|
class Definition
|
18
18
|
type original = AST::Members::MethodDefinition | AST::Members::Alias | AST::Members::AttrAccessor | AST::Members::AttrWriter | AST::Members::AttrReader
|
19
|
+
| AST::Ruby::Members::DefMember
|
20
|
+
|
21
|
+
type overloading_definition = AST::Members::MethodDefinition | AST::Ruby::Members::DefMember
|
19
22
|
|
20
23
|
type accessibility = RBS::Definition::accessibility
|
21
24
|
|
22
25
|
attr_reader name: Symbol
|
23
26
|
attr_reader type: instance_type
|
24
27
|
attr_reader originals: Array[original]
|
25
|
-
attr_reader overloads: Array[
|
28
|
+
attr_reader overloads: Array[overloading_definition]
|
26
29
|
attr_reader accessibilities: Array[accessibility]
|
27
30
|
|
28
|
-
def initialize: (name: Symbol, type: instance_type, originals: Array[original], overloads: Array[
|
31
|
+
def initialize: (name: Symbol, type: instance_type, originals: Array[original], overloads: Array[overloading_definition], accessibilities: Array[accessibility]) -> void
|
29
32
|
|
30
33
|
def original: () -> original?
|
31
34
|
|
@@ -74,9 +77,9 @@ module RBS
|
|
74
77
|
|
75
78
|
def build_attribute: (Methods, Methods::instance_type, member: AST::Members::AttrAccessor | AST::Members::AttrReader | AST::Members::AttrWriter, accessibility: Definition::accessibility) -> void
|
76
79
|
|
77
|
-
def build_method: (Methods, Methods::instance_type, member: AST::Members::MethodDefinition, accessibility: Definition::accessibility) -> void
|
80
|
+
def build_method: (Methods, Methods::instance_type, member: AST::Members::MethodDefinition | AST::Ruby::Members::DefMember, accessibility: Definition::accessibility) -> void
|
78
81
|
|
79
|
-
def
|
82
|
+
def each_rbs_member_with_accessibility: (Array[AST::Members::t | AST::Declarations::t], ?accessibility: Definition::accessibility) { (AST::Members::t | AST::Declarations::t, Definition::accessibility) -> void } -> void
|
80
83
|
|
81
84
|
def update: (env: Environment, except: _Each[TypeName]) -> MethodBuilder
|
82
85
|
end
|
data/sig/parser.rbs
CHANGED
@@ -82,6 +82,18 @@ module RBS
|
|
82
82
|
|
83
83
|
KEYWORDS: Hash[String, bot]
|
84
84
|
|
85
|
+
# Parse a leading annotation and return it
|
86
|
+
#
|
87
|
+
# Raises an exception if the source text contains a syntax error.
|
88
|
+
#
|
89
|
+
def self.parse_inline_leading_annotation: (Buffer | String, Range[Integer?], ?variables: Array[Symbol]) -> AST::Ruby::Annotations::leading_annotation
|
90
|
+
|
91
|
+
# Parse a leading annotation and return it
|
92
|
+
#
|
93
|
+
# Raises an exception if the source text contains a syntax error.
|
94
|
+
#
|
95
|
+
def self.parse_inline_trailing_annotation: (Buffer | String, Range[Integer?], ?variables: Array[Symbol]) -> AST::Ruby::Annotations::trailing_annotation
|
96
|
+
|
85
97
|
private
|
86
98
|
|
87
99
|
def self.buffer: (String | Buffer source) -> Buffer
|
@@ -94,6 +106,10 @@ module RBS
|
|
94
106
|
|
95
107
|
def self._lex: (Buffer, Integer end_pos) -> Array[[Symbol, Location[untyped, untyped]]]
|
96
108
|
|
109
|
+
def self._parse_inline_leading_annotation: (Buffer, Integer start_pos, Integer end_pos, Array[Symbol] variables) -> AST::Ruby::Annotations::leading_annotation
|
110
|
+
|
111
|
+
def self._parse_inline_trailing_annotation: (Buffer, Integer start_pos, Integer end_pos, Array[Symbol] variables) -> AST::Ruby::Annotations::trailing_annotation
|
112
|
+
|
97
113
|
class LocatedValue
|
98
114
|
end
|
99
115
|
end
|
data/sig/source.rbs
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
module RBS
|
2
|
+
module Source
|
3
|
+
type t = RBS | Ruby
|
4
|
+
|
5
|
+
class RBS
|
6
|
+
attr_reader buffer: Buffer
|
7
|
+
|
8
|
+
attr_reader directives: Array[AST::Directives::t]
|
9
|
+
|
10
|
+
attr_reader declarations: Array[AST::Declarations::t]
|
11
|
+
|
12
|
+
def initialize: (Buffer, Array[AST::Directives::t], Array[AST::Declarations::t]) -> void
|
13
|
+
|
14
|
+
# Enumerates defined type names in the source
|
15
|
+
#
|
16
|
+
# The order is undefined. Deduplicated per source object.
|
17
|
+
#
|
18
|
+
def each_type_name: () { (TypeName) -> void } -> void
|
19
|
+
| () -> Enumerator[TypeName]
|
20
|
+
|
21
|
+
private def each_declaration_type_name: (Set[TypeName], AST::Declarations::t) { (TypeName) -> void } -> void
|
22
|
+
end
|
23
|
+
|
24
|
+
class Ruby
|
25
|
+
attr_reader buffer: Buffer
|
26
|
+
|
27
|
+
attr_reader prism_result: Prism::ParseResult
|
28
|
+
|
29
|
+
attr_reader declarations: Array[AST::Ruby::Declarations::t]
|
30
|
+
|
31
|
+
attr_reader diagnostics: Array[untyped]
|
32
|
+
|
33
|
+
def initialize: (Buffer, Prism::ParseResult, Array[AST::Ruby::Declarations::t], Array[untyped]) -> void
|
34
|
+
|
35
|
+
def each_type_name: () { (TypeName) -> void } -> void
|
36
|
+
| () -> Enumerator[TypeName]
|
37
|
+
|
38
|
+
private def each_declaration_type_name: (Set[TypeName], AST::Ruby::Declarations::t) { (TypeName) -> void } -> void
|
39
|
+
|
40
|
+
# Compares the type declaration between `self` and `other`
|
41
|
+
#
|
42
|
+
# The comparison is based on the AST structure.
|
43
|
+
# Differences on Ruby code implementation may be ignored.
|
44
|
+
#
|
45
|
+
def ==: (other: Ruby) -> bool
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|