Sha256: 4a519ef4d89dd36b325685985256e6f36f5c078f3c84121679a4181a0d62d8e3

Contents?: true

Size: 1.6 KB

Versions: 12

Compression:

Stored size: 1.6 KB

Contents

# frozen_string_literal: true

require_relative "parser/lex_result"
require_relative "parser/token"

module RBS
  class Parser
    def self.parse_type(source, range: 0..., variables: [], require_eof: false)
      buf = buffer(source)
      _parse_type(buf, range.begin || 0, range.end || buf.last_position, variables, require_eof)
    end

    def self.parse_method_type(source, range: 0..., variables: [], require_eof: false)
      buf = buffer(source)
      _parse_method_type(buf, range.begin || 0, range.end || buf.last_position, variables, require_eof)
    end

    def self.parse_signature(source)
      buf = buffer(source)
      dirs, decls = _parse_signature(buf, buf.last_position)

      [buf, dirs, decls]
    end

    def self.lex(source)
      buf = buffer(source)
      list = _lex(buf, buf.last_position)
      value = list.map do |type, location|
        Token.new(type: type, location: location)
      end
      LexResult.new(buffer: buf, value: value)
    end

    def self.buffer(source)
      case source
      when String
        Buffer.new(content: source, name: "a.rbs")
      when Buffer
        source
      end
    end

    KEYWORDS = %w(
      bool
      bot
      class
      instance
      interface
      nil
      self
      singleton
      top
      void
      type
      unchecked
      in
      out
      end
      def
      include
      extend
      prepend
      alias
      module
      attr_reader
      attr_writer
      attr_accessor
      public
      private
      untyped
      true
      false
      ).each_with_object({}) do |keyword, hash|
        hash[keyword] = nil
      end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
rbs-3.7.0.dev.1 lib/rbs/parser_aux.rb
rbs-3.6.1 lib/rbs/parser_aux.rb
rbs-3.6.0 lib/rbs/parser_aux.rb
rbs-3.6.0.pre.3 lib/rbs/parser_aux.rb
rbs-3.6.0.pre.2 lib/rbs/parser_aux.rb
rbs-3.6.0.pre.1 lib/rbs/parser_aux.rb
rbs-3.6.0.dev.1 lib/rbs/parser_aux.rb
rbs-3.5.3 lib/rbs/parser_aux.rb
rbs-3.5.2 lib/rbs/parser_aux.rb
rbs-3.5.1 lib/rbs/parser_aux.rb
rbs-3.5.1.pre.1 lib/rbs/parser_aux.rb
rbs-3.5.0 lib/rbs/parser_aux.rb