rbs-inline 0.4.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,11 +3,11 @@
3
3
  module RBS
4
4
  module Inline
5
5
  module AST
6
- class Tree
7
- type token = [ Symbol, String ]
6
+ type token = [ Symbol, String ]
8
7
 
9
- type tree = token | Tree | Types::t | MethodType | nil
8
+ type tree = token | Tree | Types::t | MethodType | nil
10
9
 
10
+ class Tree
11
11
  attr_reader trees: Array[tree]
12
12
 
13
13
  attr_reader type: Symbol
@@ -16,21 +16,27 @@ module RBS
16
16
  attr_reader non_trivia_trees: Array[tree]
17
17
 
18
18
  # @rbs type: Symbol
19
- def initialize: (Symbol type) -> untyped
19
+ def initialize: (Symbol type) -> void
20
20
 
21
21
  # @rbs tok: tree
22
- # @rbs returns self
22
+ # @rbs return: self
23
23
  def <<: (tree tok) -> self
24
24
 
25
25
  # Returns the source code associated to the tree
26
26
  def to_s: () -> String
27
27
 
28
+ # Returns `true` if token at the given index is of the given type
29
+ def token?: (untyped type, at: untyped) -> untyped
30
+
31
+ # Returns `true` if tree at the given index is of the given type
32
+ def tree?: (untyped type, at: untyped) -> untyped
33
+
28
34
  # Returns n-th token from the children
29
35
  #
30
36
  # Raises if the value is not a token or nil.
31
37
  #
32
38
  # @rbs index: Integer
33
- # @rbs returns token?
39
+ # @rbs return: token?
34
40
  def nth_token: (Integer index) -> token?
35
41
 
36
42
  # Returns n-th token from the children
@@ -38,7 +44,7 @@ module RBS
38
44
  # Returns `nil` if the value is not a token.
39
45
  #
40
46
  # @rbs index: Integer
41
- # @rbs returns token?
47
+ # @rbs return: token?
42
48
  def nth_token?: (Integer index) -> token?
43
49
 
44
50
  # Returns n-th token from the children
@@ -46,7 +52,7 @@ module RBS
46
52
  # Raises if the value is not token.
47
53
  #
48
54
  # @rbs index: Integer
49
- # @rbs returns token
55
+ # @rbs return: token
50
56
  def nth_token!: (Integer index) -> token
51
57
 
52
58
  # Returns n-th tree from the children
@@ -54,7 +60,7 @@ module RBS
54
60
  # Raises if the value is not a tree or nil.
55
61
  #
56
62
  # @rbs index: Integer
57
- # @rbs returns Tree?
63
+ # @rbs return: Tree?
58
64
  def nth_tree: (Integer index) -> Tree?
59
65
 
60
66
  # Returns n-th tree from the children
@@ -62,7 +68,7 @@ module RBS
62
68
  # Returns `nil` if the value is not a tree or nil.
63
69
  #
64
70
  # @rbs index: Integer
65
- # @rbs returns Tree?
71
+ # @rbs return: Tree?
66
72
  def nth_tree?: (Integer index) -> Tree?
67
73
 
68
74
  # Returns n-th tree from the children
@@ -70,7 +76,7 @@ module RBS
70
76
  # Raises if the value is not a tree.
71
77
  #
72
78
  # @rbs index: Integer
73
- # @rbs returns Tree
79
+ # @rbs return: Tree
74
80
  def nth_tree!: (Integer index) -> Tree
75
81
 
76
82
  # Returns n-th type from the children
@@ -78,7 +84,7 @@ module RBS
78
84
  # Raises if the value is not a type or nil.
79
85
  #
80
86
  # @rbs index: Integer
81
- # @rbs returns Types::t?
87
+ # @rbs return: Types::t?
82
88
  def nth_type: (Integer index) -> Types::t?
83
89
 
84
90
  # Returns n-th type from the children
@@ -86,7 +92,7 @@ module RBS
86
92
  # Returns `nil` if the value is not a type.
87
93
  #
88
94
  # @rbs index: Integer
89
- # @rbs returns Types::t?
95
+ # @rbs return: Types::t?
90
96
  def nth_type?: (Integer index) -> Types::t?
91
97
 
92
98
  # Returns n-th type from the children
@@ -94,7 +100,7 @@ module RBS
94
100
  # Raises if the value is not a type.
95
101
  #
96
102
  # @rbs index: Integer
97
- # @rbs returns Types::t
103
+ # @rbs return: Types::t
98
104
  def nth_type!: (Integer index) -> Types::t
99
105
 
100
106
  # Returns n-th method type from the children
@@ -102,7 +108,7 @@ module RBS
102
108
  # Raises if the value is not a method type or `nil`.
103
109
  #
104
110
  # @rbs index: Integer
105
- # @rbs returns MethodType?
111
+ # @rbs return: MethodType?
106
112
  def nth_method_type: (Integer index) -> MethodType?
107
113
 
108
114
  # Returns n-th method type from the children
@@ -110,7 +116,7 @@ module RBS
110
116
  # Returns `nil` if the value is not a method type.
111
117
  #
112
118
  # @rbs index: Integer
113
- # @rbs returns MethodType?
119
+ # @rbs return: MethodType?
114
120
  def nth_method_type?: (Integer index) -> MethodType?
115
121
 
116
122
  # Returns n-th method tree from the children
@@ -118,7 +124,7 @@ module RBS
118
124
  # Raises if the value is not a method tree.
119
125
  #
120
126
  # @rbs index: Integer
121
- # @rbs returns MethodType
127
+ # @rbs return: MethodType
122
128
  def nth_method_type!: (Integer index) -> MethodType
123
129
  end
124
130
  end
@@ -25,12 +25,12 @@ module RBS
25
25
  # @rbs output_path: Pathname
26
26
  def initialize: (Pathname pwd, Array[Pathname] base_paths, Pathname output_path) -> void
27
27
 
28
- # :: (Pathname) -> Pathname?
28
+ # : (Pathname) -> Pathname?
29
29
  def calculate: (Pathname) -> Pathname?
30
30
 
31
31
  # @rbs path: Pathname
32
32
  # @rbs prefix: Pathname
33
- # @rbs returns bool
33
+ # @rbs return: bool
34
34
  def has_prefix?: (Pathname path, prefix: Pathname) -> bool
35
35
  end
36
36
 
@@ -45,7 +45,7 @@ module RBS
45
45
  def initialize: (?stdout: IO, ?stderr: IO) -> void
46
46
 
47
47
  # @rbs args: Array[String]
48
- # @rbs returns Integer
48
+ # @rbs return: Integer
49
49
  def run: (Array[String] args) -> Integer
50
50
  end
51
51
  end
@@ -4,7 +4,7 @@ module RBS
4
4
  module Inline
5
5
  module NodeUtils
6
6
  # @rbs node: Prism::Node
7
- # @rbs returns TypeName?
7
+ # @rbs return: TypeName?
8
8
  def type_name: (Prism::Node node) -> TypeName?
9
9
  end
10
10
  end
@@ -5,11 +5,13 @@ use Prism::*
5
5
  module RBS
6
6
  module Inline
7
7
  class Parser < Prism::Visitor
8
+ type with_members = AST::Declarations::ModuleDecl | AST::Declarations::ClassDecl | AST::Declarations::SingletonClassDecl | AST::Declarations::BlockDecl
9
+
8
10
  # The top level declarations
9
11
  attr_reader decls: Array[AST::Declarations::t]
10
12
 
11
13
  # The surrounding declarations
12
- attr_reader surrounding_decls: Array[AST::Declarations::ModuleDecl | AST::Declarations::ClassDecl]
14
+ attr_reader surrounding_decls: Array[with_members]
13
15
 
14
16
  # ParsingResult associated with the line number at the end
15
17
  #
@@ -30,21 +32,30 @@ module RBS
30
32
 
31
33
  def initialize: () -> void
32
34
 
35
+ # Parses the given Prism result to a three tuple
36
+ #
37
+ # Returns a three tuple of:
38
+ #
39
+ # 1. An array of `use` directives
40
+ # 2. An array of declarations
41
+ # 3. An array of RBS declarations given as `@rbs!` annotation at top-level
42
+ #
43
+ # Note that only RBS declarations are allowed in the top-level `@rbs!` annotations.
44
+ # RBS *members* are ignored in the array.
45
+ #
33
46
  # @rbs result: ParseResult
34
47
  # @rbs opt_in: bool -- `true` for *opt-out* mode, `false` for *opt-in* mode.
35
- # @rbs returns [Array[AST::Annotations::Use], Array[AST::Declarations::t]]?
36
- def self.parse: (ParseResult result, opt_in: bool) -> [ Array[AST::Annotations::Use], Array[AST::Declarations::t] ]?
48
+ # @rbs return: [Array[AST::Annotations::Use], Array[AST::Declarations::t], Array[RBS::AST::Declarations::t]]?
49
+ def self.parse: (ParseResult result, opt_in: bool) -> [ Array[AST::Annotations::Use], Array[AST::Declarations::t], Array[RBS::AST::Declarations::t] ]?
37
50
 
38
- # @rbs returns AST::Declarations::ModuleDecl | AST::Declarations::ClassDecl | nil
39
- def current_class_module_decl: () -> (AST::Declarations::ModuleDecl | AST::Declarations::ClassDecl | nil)
51
+ # @rbs return: with_members?
52
+ def current_class_module_decl: () -> with_members?
40
53
 
41
- # @rbs returns AST::Declarations::ModuleDecl | AST::Declarations::ClassDecl
42
- def current_class_module_decl!: () -> (AST::Declarations::ModuleDecl | AST::Declarations::ClassDecl)
54
+ # @rbs return: with_members
55
+ def current_class_module_decl!: () -> with_members
43
56
 
44
- # :: (AST::Declarations::ModuleDecl | AST::Declarations::ClassDecl | AST::Declarations::SingletonClassDecl) { () -> void } -> void
45
- # :: (AST::Declarations::ConstantDecl) -> void
46
- def push_class_module_decl: (AST::Declarations::ModuleDecl | AST::Declarations::ClassDecl | AST::Declarations::SingletonClassDecl) { () -> void } -> void
47
- | (AST::Declarations::ConstantDecl) -> void
57
+ # : (with_members) { () -> void } -> void
58
+ def push_class_module_decl: (with_members) { () -> void } -> void
48
59
 
49
60
  # Load inner declarations and delete them from `#comments` hash
50
61
  #
@@ -89,12 +100,15 @@ module RBS
89
100
  def visit_call_node: ...
90
101
 
91
102
  # @rbs new_visibility: RBS::AST::Members::visibility?
92
- # @rbs block: ^() -> void
93
- # @rbs returns void
103
+ # @rbs &block: () -> void
104
+ # @rbs return: void
94
105
  def push_visibility: (RBS::AST::Members::visibility? new_visibility) { () -> void } -> void
95
106
 
107
+ # @rbs [A] (Node) { () -> A } -> A?
108
+ def process_nesting_node: [A] (Node) { () -> A } -> A?
109
+
96
110
  # @rbs node: Node
97
- # @rbs returns bool
111
+ # @rbs return: bool
98
112
  def ignored_node?: (Node node) -> bool
99
113
 
100
114
  # Fetch Application annotation which is associated to `node`
@@ -102,19 +116,22 @@ module RBS
102
116
  # The application annotation is removed from `comments`.
103
117
  #
104
118
  # @rbs node: Node
105
- # @rbs returns AST::Annotations::Application?
119
+ # @rbs return: AST::Annotations::Application?
106
120
  def application_annotation: (Node node) -> AST::Annotations::Application?
107
121
 
108
- # Fetch Assertion annotation which is associated to `node`
122
+ # Fetch TypeAssertion annotation which is associated to `node`
109
123
  #
110
124
  # The assertion annotation is removed from `comments`.
111
125
  #
112
126
  # @rbs node: Node | Location
113
- # @rbs returns AST::Annotations::Assertion?
114
- def assertion_annotation: (Node | Location node) -> AST::Annotations::Assertion?
127
+ # @rbs return: AST::Annotations::TypeAssertion?
128
+ def assertion_annotation: (Node | Location node) -> AST::Annotations::TypeAssertion?
115
129
 
116
130
  # @rbs override
117
131
  def visit_constant_write_node: ...
132
+
133
+ # @rbs override
134
+ def visit_block_node: ...
118
135
  end
119
136
  end
120
137
  end
@@ -3,50 +3,80 @@
3
3
  module RBS
4
4
  module Inline
5
5
  class Writer
6
+ interface _Content
7
+ def <<: (RBS::AST::Declarations::t | RBS::AST::Members::t) -> void
8
+
9
+ def concat: (Array[RBS::AST::Declarations::t | RBS::AST::Members::t]) -> void
10
+ end
11
+
6
12
  attr_reader output: String
7
13
 
8
14
  attr_reader writer: RBS::Writer
9
15
 
10
16
  # @rbs buffer: String
11
- def initialize: (?String buffer) -> untyped
17
+ def initialize: (?String buffer) -> void
12
18
 
13
19
  # @rbs uses: Array[AST::Annotations::Use]
14
20
  # @rbs decls: Array[AST::Declarations::t]
15
- def self.write: (Array[AST::Annotations::Use] uses, Array[AST::Declarations::t] decls) -> untyped
21
+ # @rbs rbs_decls: Array[RBS::AST::Declarations::t]
22
+ def self.write: (Array[AST::Annotations::Use] uses, Array[AST::Declarations::t] decls, Array[RBS::AST::Declarations::t] rbs_decls) -> void
16
23
 
17
- # @rbs lines: Array[String]
18
- # @rbs returns void
24
+ # @rbs *lines: String
25
+ # @rbs return: void
19
26
  def header: (*String lines) -> void
20
27
 
21
28
  # @rbs uses: Array[AST::Annotations::Use]
22
29
  # @rbs decls: Array[AST::Declarations::t]
23
- # @rbs returns void
24
- def write: (Array[AST::Annotations::Use] uses, Array[AST::Declarations::t] decls) -> void
30
+ # @rbs rbs_decls: Array[RBS::AST::Declarations::t] --
31
+ # Top level `rbs!` declarations
32
+ # @rbs return: void
33
+ def write: (Array[AST::Annotations::Use] uses, Array[AST::Declarations::t] decls, Array[RBS::AST::Declarations::t] rbs_decls) -> void
25
34
 
26
35
  # @rbs decl: AST::Declarations::t
27
- # @rbs returns RBS::AST::Declarations::t?
28
- def translate_decl: (AST::Declarations::t decl) -> RBS::AST::Declarations::t?
36
+ # @rbs rbs: _Content
37
+ # @rbs return: void
38
+ def translate_decl: (AST::Declarations::t decl, _Content rbs) -> void
29
39
 
30
40
  # @rbs decl: AST::Declarations::ClassDecl
31
- # @rbs returns RBS::AST::Declarations::Class?
32
- def translate_class_decl: (AST::Declarations::ClassDecl decl) -> RBS::AST::Declarations::Class?
41
+ # @rbs rbs: _Content
42
+ # @rbs return: void
43
+ def translate_class_decl: (AST::Declarations::ClassDecl decl, _Content rbs) -> void
44
+
45
+ # @rbs members: Array[AST::Declarations::t | AST::Members::t]
46
+ # @rbs decl: AST::Declarations::SingletonClassDecl?
47
+ # @rbs rbs: _Content
48
+ # @rbs return: void
49
+ def translate_members: (Array[AST::Declarations::t | AST::Members::t] members, AST::Declarations::SingletonClassDecl? decl, _Content rbs) -> void
33
50
 
34
51
  # @rbs decl: AST::Declarations::ModuleDecl
35
- # @rbs returns RBS::AST::Declarations::Module?
36
- def translate_module_decl: (AST::Declarations::ModuleDecl decl) -> RBS::AST::Declarations::Module?
52
+ # @rbs rbs: _Content
53
+ # @rbs return: void
54
+ def translate_module_decl: (AST::Declarations::ModuleDecl decl, _Content rbs) -> void
37
55
 
38
56
  # @rbs decl: AST::Declarations::ConstantDecl
39
- # @rbs returns RBS::AST::Declarations::Constant?
40
- def translate_constant_decl: (AST::Declarations::ConstantDecl decl) -> RBS::AST::Declarations::Constant?
57
+ # @rbs rbs: _Content
58
+ # @rbs return: void
59
+ def translate_constant_decl: (AST::Declarations::ConstantDecl decl, _Content rbs) -> void
60
+
61
+ # @rbs decl: AST::Declarations::DataAssignDecl
62
+ # @rbs rbs: _Content
63
+ def translate_data_assign_decl: (AST::Declarations::DataAssignDecl decl, _Content rbs) -> void
64
+
65
+ # @rbs decl: AST::Declarations::StructAssignDecl
66
+ # @rbs rbs: _Content
67
+ def translate_struct_assign_decl: (AST::Declarations::StructAssignDecl decl, _Content rbs) -> void
41
68
 
42
69
  # @rbs decl: AST::Declarations::SingletonClassDecl
43
- # @rbs returns Array[RBS::AST::Members::t]
44
- def translate_singleton_decl: (AST::Declarations::SingletonClassDecl decl) -> Array[RBS::AST::Members::t]
70
+ # @rbs rbs: _Content
71
+ # @rbs return: void
72
+ def translate_singleton_decl: (AST::Declarations::SingletonClassDecl decl, _Content rbs) -> void
45
73
 
46
74
  # @rbs member: AST::Members::t
47
- # @rbs decl: AST::Declarations::ClassDecl | AST::Declarations::ModuleDecl | AST::Declarations::SingletonClassDecl
48
- # @rbs returns Array[RBS::AST::Members::t | RBS::AST::Declarations::t]?
49
- def translate_member: (AST::Members::t member, AST::Declarations::ClassDecl | AST::Declarations::ModuleDecl | AST::Declarations::SingletonClassDecl decl) -> Array[RBS::AST::Members::t | RBS::AST::Declarations::t]?
75
+ # @rbs decl: AST::Declarations::SingletonClassDecl? --
76
+ # The surrouding singleton class definition
77
+ # @rbs rbs: _Content
78
+ # @rbs return void
79
+ def translate_member: (AST::Members::t member, AST::Declarations::SingletonClassDecl? decl, _Content rbs) -> void
50
80
 
51
81
  private
52
82
 
@@ -64,9 +94,19 @@ module RBS
64
94
  # ```
65
95
  #
66
96
  # @rbs member: AST::Members::RubyDef
67
- # @rbs decl: AST::Declarations::ClassDecl | AST::Declarations::ModuleDecl | AST::Declarations::SingletonClassDecl
68
- # @rbs returns RBS::AST::Members::MethodDefinition::kind
69
- def method_kind: (AST::Members::RubyDef member, AST::Declarations::ClassDecl | AST::Declarations::ModuleDecl | AST::Declarations::SingletonClassDecl decl) -> RBS::AST::Members::MethodDefinition::kind
97
+ # @rbs decl: AST::Declarations::SingletonClassDecl?
98
+ # @rbs return: RBS::AST::Members::MethodDefinition::kind
99
+ def method_kind: (AST::Members::RubyDef member, AST::Declarations::SingletonClassDecl? decl) -> RBS::AST::Members::MethodDefinition::kind
100
+
101
+ # @rbs block: AST::Declarations::BlockDecl
102
+ # @rbs rbs: _Content
103
+ # @rbs return: void
104
+ def translate_module_block_decl: (AST::Declarations::BlockDecl block, _Content rbs) -> void
105
+
106
+ # @rbs block: AST::Declarations::BlockDecl
107
+ # @rbs rbs: _Content
108
+ # @rbs return: void
109
+ def translate_class_block_decl: (AST::Declarations::BlockDecl block, _Content rbs) -> void
70
110
  end
71
111
  end
72
112
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbs-inline
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Soutaro Matsumoto
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-06-12 00:00:00.000000000 Z
11
+ date: 2024-08-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: prism
@@ -61,6 +61,7 @@ files:
61
61
  - exe/rbs-inline
62
62
  - lib/rbs/inline.rb
63
63
  - lib/rbs/inline/annotation_parser.rb
64
+ - lib/rbs/inline/annotation_parser/tokenizer.rb
64
65
  - lib/rbs/inline/ast/annotations.rb
65
66
  - lib/rbs/inline/ast/comment_lines.rb
66
67
  - lib/rbs/inline/ast/declarations.rb
@@ -75,6 +76,7 @@ files:
75
76
  - rbs_collection.yaml
76
77
  - sig/generated/rbs/inline.rbs
77
78
  - sig/generated/rbs/inline/annotation_parser.rbs
79
+ - sig/generated/rbs/inline/annotation_parser/tokenizer.rbs
78
80
  - sig/generated/rbs/inline/ast/annotations.rbs
79
81
  - sig/generated/rbs/inline/ast/comment_lines.rbs
80
82
  - sig/generated/rbs/inline/ast/declarations.rbs
@@ -108,7 +110,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
108
110
  - !ruby/object:Gem::Version
109
111
  version: '0'
110
112
  requirements: []
111
- rubygems_version: 3.5.3
113
+ rubygems_version: 3.5.11
112
114
  signing_key:
113
115
  specification_version: 4
114
116
  summary: Inline RBS type declaration.