Class: Rbs::Merge::Backends::RbsBackend::Language

Inherits:
TreeHaver::Base::Language
  • Object
show all
Defined in:
lib/rbs/merge/backends/rbs_backend.rb

Overview

RBS language wrapper

The RBS gem only parses RBS type signature files. This class exists
for API compatibility with other TreeHaver backends.

Examples:

language = Rbs::Merge::Backends::RbsBackend::Language.rbs
parser.language = language

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = :rbs, options: {}) ⇒ Language

Returns a new instance of Language.

Parameters:

  • name (Symbol) (defaults to: :rbs)

    language name (should be :rbs)

  • options (Hash) (defaults to: {})

    parsing options (reserved for future use)



108
109
110
111
112
113
114
115
116
# File 'lib/rbs/merge/backends/rbs_backend.rb', line 108

def initialize(name = :rbs, options: {})
  super(name, backend: :rbs, options: options)

  unless @name == :rbs
    raise TreeHaver::NotAvailable,
      "RBS backend only supports RBS parsing. " \
        "Got language: #{name.inspect}"
  end
end

Class Method Details

.from_library(_path = nil, symbol: nil, name: nil) ⇒ Language Also known as: from_path

Load language from library path (API compatibility)

RBS gem only supports RBS, so path and symbol parameters are ignored.
This method exists for API consistency with tree-sitter backends,
allowing TreeHaver.parser_for(:rbs) to work regardless of backend.

Parameters:

  • _path (String) (defaults to: nil)

    Ignored - RBS gem doesn’t load external grammars

  • symbol (String, nil) (defaults to: nil)

    Ignored

  • name (String, nil) (defaults to: nil)

    Language name hint (defaults to :rbs)

Returns:

Raises:

  • (TreeHaver::NotAvailable)

    if requested language is not RBS



140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/rbs/merge/backends/rbs_backend.rb', line 140

def from_library(_path = nil, symbol: nil, name: nil)
  # Derive language name from symbol if provided
  lang_name = name || symbol&.to_s&.sub(/^tree_sitter_/, "")&.to_sym || :rbs

  unless lang_name == :rbs
    raise TreeHaver::NotAvailable,
      "RBS backend only supports RBS, not #{lang_name}. " \
        "Use a tree-sitter backend for #{lang_name} support."
  end

  rbs
end

.rbs(options = {}) ⇒ Language

Create an RBS language instance (convenience method)

Examples:

lang = Rbs::Merge::Backends::RbsBackend::Language.rbs

Parameters:

  • options (Hash) (defaults to: {})

    parsing options (reserved for future use)

Returns:



125
126
127
# File 'lib/rbs/merge/backends/rbs_backend.rb', line 125

def rbs(options = {})
  new(:rbs, options: options)
end