module RBS
  class Parser
    # Parse a method type and return it
    #
    # When `range` keyword is specified, it starts parsing from the `begin` to the `end` of the range.
    #
    # ```ruby
    # RBS::Parser.parse_method_type("() -> void")                                # => `() -> void`
    # RBS::Parser.parse_method_type("() -> void", range: 0...)                   # => `() -> void`
    # RBS::Parser.parse_method_type("() -> void () -> String", range: 11...)     # => `() -> String`
    # RBS::Parser.parse_method_type("() -> void () -> String", range: 23...)     # => nil
    # ```
    #
    # When `require_eof` is `true`, an error is raised if more tokens are left in the input.
    # (Defaults to `false`.)
    #
    # ```ruby
    # RBS::Parser.parse_method_type("() -> void () -> String", require_eof: false)    # => `() -> void`
    # RBS::Parser.parse_method_type("() -> void () -> String", require_eof: true)     # => Raises an error
    #
    # RBS::Parser.parse_method_type("", require_eof: true)                            # => nil
    # ```
    #
    def self.parse_method_type: (Buffer | String, ?range: Range[Integer?], ?variables: Array[Symbol], ?require_eof: bool) -> MethodType?

    # Parse a type and return it
    #
    # When `range` keyword is specified, it starts parsing from the `begin` to the `end` of the range.
    #
    # ```ruby
    # RBS::Parser.parse_type("String")                          # => `String`
    # RBS::Parser.parse_type("String", range: 0...)             # => `String`
    # RBS::Parser.parse_type("String Integer", pos: 7...)       # => `Integer`
    # RBS::Parser.parse_type("String Integer", pos: 14...)      # => nil
    # ```
    #
    # When `require_eof` is `true`, an error is raised if more tokens are left in the input.
    # (Defaults to `false`.)
    #
    # ```ruby
    # RBS::Parser.parse_type("String untyped", require_eof: false)    # => `String`
    # RBS::Parser.parse_type("String untyped", require_eof: true)     # => Raises an error
    #
    # RBS::Parser.parse_type("", require_eof: true)                   # => nil
    # ```
    #
    def self.parse_type: (Buffer | String, ?range: Range[Integer?], ?variables: Array[Symbol], ?require_eof: bool) -> Types::t?

    # Parse whole RBS file and return an array of declarations
    #
    def self.parse_signature: (Buffer | String) -> [Buffer, Array[AST::Directives::t], Array[AST::Declarations::t]]

    KEYWORDS: Hash[String, bot]

    private

    def self.buffer: (String | Buffer source) -> Buffer

    def self._parse_type: (Buffer, Integer start_pos, Integer end_pos, Array[Symbol] variables, bool require_eof) -> Types::t?

    def self._parse_method_type: (Buffer, Integer start_pos, Integer end_pos, Array[Symbol] variables, bool require_eof) -> MethodType?

    def self._parse_signature: (Buffer, Integer end_pos) -> [Array[AST::Directives::t], Array[AST::Declarations::t]]

    class LocatedValue
    end
  end
end
