rbs 2.7.0 → 2.8.0.pre.1

Sign up to get free protection for your applications and to get access to all the features.
data/lib/rbs/errors.rb CHANGED
@@ -148,7 +148,27 @@ module RBS
148
148
  end
149
149
 
150
150
  def self.check!(type_name, env:, location:)
151
- env.class_decls.key?(type_name) or raise new(type_name: type_name, location: location)
151
+ if decl = env.class_decls[type_name]
152
+ return
153
+ end
154
+
155
+ raise new(type_name: type_name, location: location)
156
+ end
157
+ end
158
+
159
+ class InheritModuleError < DefinitionError
160
+ attr_reader :super_decl
161
+
162
+ def initialize(super_decl)
163
+ @super_decl = super_decl
164
+
165
+ super "#{Location.to_string(super_decl.location)}: Cannot inherit a module: #{super_decl.name}"
166
+ end
167
+
168
+ def self.check!(super_decl, env:)
169
+ return if env.class_decls[super_decl.name].is_a?(Environment::ClassEntry)
170
+
171
+ raise new(super_decl)
152
172
  end
153
173
  end
154
174
 
@@ -2,16 +2,19 @@
2
2
 
3
3
  module RBS
4
4
  class Parser
5
- def self.parse_type(source, line: 1, column: 0, variables: [])
6
- _parse_type(buffer(source), line, column, variables)
5
+ def self.parse_type(source, line: nil, column: nil, range: nil, variables: [])
6
+ buf = buffer(source)
7
+ _parse_type(buf, range&.begin || 0, range&.end || buf.last_position, variables, range.nil?)
7
8
  end
8
9
 
9
- def self.parse_method_type(source, line: 1, column: 0, variables: [])
10
- _parse_method_type(buffer(source), line, column, variables)
10
+ def self.parse_method_type(source, line: nil, column: nil, range: nil, variables: [])
11
+ buf = buffer(source)
12
+ _parse_method_type(buf, range&.begin || 0, range&.end || buf.last_position, variables, range.nil?)
11
13
  end
12
14
 
13
- def self.parse_signature(source, line: 1, column: 0)
14
- _parse_signature(buffer(source), line, column)
15
+ def self.parse_signature(source, line: nil, column: nil)
16
+ buf = buffer(source)
17
+ _parse_signature(buf, buf.last_position)
15
18
  end
16
19
 
17
20
  def self.buffer(source)
data/lib/rbs/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RBS
4
- VERSION = "2.7.0"
4
+ VERSION = "2.8.0.pre.1"
5
5
  end
@@ -24,6 +24,8 @@ module RBS
24
24
 
25
25
  private
26
26
 
27
+ def validate_gemfile_lock_path!: (lock: Config?, gemfile_lock_path: Pathname) -> void
28
+
27
29
  def assign_gem: (name: String, version: String?) -> void
28
30
 
29
31
  def upsert_gem: (gem_entry? old, gem_entry new) -> void
@@ -52,6 +54,8 @@ module RBS
52
54
 
53
55
  @sources: Array[Sources::_Source]
54
56
 
57
+ def self.find_config_path: () -> Pathname?
58
+
55
59
  def self.generate_lockfile: (config_path: Pathname, gemfile_lock_path: Pathname, ?with_lockfile: boolish) -> Config
56
60
 
57
61
  def self.from_path: (Pathname path) -> Config
@@ -75,6 +79,10 @@ module RBS
75
79
 
76
80
  def gems: () -> Array[gem_entry]
77
81
 
82
+ def gemfile_lock_path=: (Pathname) -> Pathname
83
+
84
+ def gemfile_lock_path: () -> Pathname?
85
+
78
86
  def check_rbs_availability!: () -> void
79
87
  end
80
88
  end
data/sig/errors.rbs CHANGED
@@ -197,6 +197,8 @@ module RBS
197
197
  def location: () -> Location[untyped, untyped]?
198
198
  end
199
199
 
200
+ # MixinClassError is raised if a include/prepend/extend has a class (not a module) to mix-in
201
+ #
200
202
  class MixinClassError < DefinitionError
201
203
  type member = AST::Members::Include | AST::Members::Prepend | AST::Members::Extend
202
204
 
@@ -212,6 +214,18 @@ module RBS
212
214
  def mixin_name: () -> String
213
215
  end
214
216
 
217
+ # InheritModuleError is raised if a class definition inherits a module (not a class)
218
+ #
219
+ class InheritModuleError < DefinitionError
220
+ attr_reader super_decl: AST::Declarations::Class::Super
221
+
222
+ def initialize: (AST::Declarations::Class::Super) -> void
223
+
224
+ def location: () -> Location[untyped, untyped]?
225
+
226
+ def self.check!: (AST::Declarations::Class::Super, env: Environment) -> void
227
+ end
228
+
215
229
  class RecursiveTypeAliasError < BaseError
216
230
  attr_reader alias_names: Array[TypeName]
217
231
  attr_reader location: Location[untyped, untyped]?
data/sig/manifest.yaml CHANGED
@@ -4,6 +4,5 @@ dependencies:
4
4
  - name: pathname
5
5
  - name: json
6
6
  - name: optparse
7
- - name: rubygems
8
7
  - name: tsort
9
8
  - name: rdoc
data/sig/parser.rbs CHANGED
@@ -1,10 +1,43 @@
1
1
  module RBS
2
2
  class Parser
3
- def self.parse_method_type: (Buffer | String, ?line: Integer, ?column: Integer, ?variables: Array[Symbol]) -> MethodType
4
-
5
- def self.parse_type: (Buffer | String, ?line: Integer, ?column: Integer, ?variables: Array[Symbol]) -> Types::t
6
-
7
- def self.parse_signature: (Buffer | String, ?line: Integer, ?column: Integer) -> Array[AST::Declarations::t]
3
+ # Parse a method type and return it
4
+ #
5
+ # When `pos` keyword is specified, skips the first `pos` characters from the input.
6
+ # If no token is left in the input, it returns `nil`.
7
+ #
8
+ # ```ruby
9
+ # RBS::Parser.parse_method_type("() -> void", range: 0...) # => `() -> void`
10
+ # RBS::Parser.parse_method_type("() -> void () -> String", range: 11...) # => `() -> String`
11
+ # RBS::Parser.parse_method_type("() -> void () -> String", range: 23...) # => nil
12
+ # ```
13
+ #
14
+ # `line` and `column` is deprecated and are ignored.
15
+ #
16
+ def self.parse_method_type: (Buffer | String, range: Range[Integer?], ?variables: Array[Symbol]) -> MethodType?
17
+ | (Buffer | String, ?line: top, ?column: top, ?variables: Array[Symbol]) -> MethodType
18
+
19
+ # Parse a type and return it
20
+ #
21
+ # When `pos` keyword is specified, skips the first `pos` characters from the input.
22
+ # If no token is left in the input, it returns `nil`.
23
+ #
24
+ # ```ruby
25
+ # RBS::Parser.parse_type("String", range: 0...) # => `String`
26
+ # RBS::Parser.parse_type("String Integer", pos: 7...) # => `Integer`
27
+ # RBS::Parser.parse_type("String Integer", pos: 14...) # => nil
28
+ # ```
29
+ #
30
+ # `line` and `column` is deprecated and are ignored.
31
+ #
32
+ def self.parse_type: (Buffer | String, range: Range[Integer?], ?variables: Array[Symbol]) -> Types::t?
33
+ | (Buffer | String, ?line: top, ?column: top, ?variables: Array[Symbol]) -> Types::t
34
+
35
+ # Parse whole RBS file and return an array of declarations
36
+ #
37
+ # `line` and `column` is deprecated and are ignored.
38
+ #
39
+ def self.parse_signature: (Buffer | String) -> Array[AST::Declarations::t]
40
+ | (Buffer | String, ?line: top, ?column: top) -> Array[AST::Declarations::t]
8
41
 
9
42
  KEYWORDS: Hash[String, bot]
10
43
 
@@ -12,14 +45,11 @@ module RBS
12
45
 
13
46
  def self.buffer: (String | Buffer source) -> Buffer
14
47
 
15
- %a{no-defn}
16
- def self._parse_type: (Buffer, Integer line, Integer column, Array[Symbol] variables) -> Types::t
48
+ def self._parse_type: (Buffer, Integer start_pos, Integer end_pos, Array[Symbol] variables, boolish eof) -> Types::t?
17
49
 
18
- %a{no-defn}
19
- def self._parse_method_type: (Buffer, Integer line, Integer column, Array[Symbol] variables) -> MethodType
50
+ def self._parse_method_type: (Buffer, Integer start_pos, Integer end_pos, Array[Symbol] variables, boolish eof) -> MethodType?
20
51
 
21
- %a{no-defn}
22
- def self._parse_signature: (Buffer, Integer line, Integer column) -> Array[AST::Declarations::t]
52
+ def self._parse_signature: (Buffer, Integer end_pos) -> Array[AST::Declarations::t]
23
53
 
24
54
  class LocatedValue
25
55
  end
@@ -406,3 +406,18 @@ IPAddr::IN6FORMAT: String
406
406
  # 128 bit mask for IPv6
407
407
  #
408
408
  IPAddr::IN6MASK: Integer
409
+
410
+ # <!-- rdoc-file=lib/ipaddr.rb -->
411
+ # Regexp *internally* used for parsing IPv4 address.
412
+ #
413
+ IPAddr::RE_IPV4ADDRLIKE: Regexp
414
+
415
+ # <!-- rdoc-file=lib/ipaddr.rb -->
416
+ # Regexp *internally* used for parsing IPv6 address.
417
+ #
418
+ IPAddr::RE_IPV6ADDRLIKE_COMPRESSED: Regexp
419
+
420
+ # <!-- rdoc-file=lib/ipaddr.rb -->
421
+ # Regexp *internally* used for parsing IPv6 address.
422
+ #
423
+ IPAddr::RE_IPV6ADDRLIKE_FULL: Regexp
@@ -57,7 +57,8 @@ class Addrinfo
57
57
  # #=> [#<Addrinfo: 203.178.141.194:80 TCP (www.kame.net)>,
58
58
  # # #<Addrinfo: [2001:200:dff:fff1:216:3eff:feb1:44d7]:80 TCP (www.kame.net)>]
59
59
  #
60
- def self.getaddrinfo: (String nodename, ?String | Integer service, ?Symbol? family, ?Symbol | Integer protocol) -> Array[Addrinfo]
60
+ def self.getaddrinfo: (String nodename, ?String | Integer | nil service, ?Symbol? family, ?Symbol | Integer protocol) -> Array[Addrinfo]
61
+ | (String? nodename, ?String | Integer service, ?Symbol? family, ?Symbol | Integer protocol) -> Array[Addrinfo]
61
62
 
62
63
  # <!--
63
64
  # rdoc-file=ext/socket/raddrinfo.c