Class: TreeHaver::Backends::MRI::Language
- Inherits:
-
Object
- Object
- TreeHaver::Backends::MRI::Language
- Includes:
- Comparable
- Defined in:
- lib/tree_haver/backends/mri.rb
Overview
Wrapper for ruby_tree_sitter Language
Wraps ::TreeSitter::Language from ruby_tree_sitter to provide a consistent API across all backends.
Instance Attribute Summary collapse
-
#backend ⇒ Symbol
readonly
The backend this language is for.
-
#inner_language ⇒ ::TreeSitter::Language
readonly
The wrapped TreeSitter::Language object.
-
#path ⇒ String?
readonly
The path this language was loaded from (if known).
-
#symbol ⇒ String?
readonly
The symbol name (if known).
Class Method Summary collapse
Instance Method Summary collapse
-
#<=>(other) ⇒ Integer?
Compare languages for equality.
-
#hash ⇒ Integer
Hash value for this language (for use in Sets/Hashes).
-
#initialize(lang, path: nil, symbol: nil) ⇒ Language
constructor
private
A new instance of Language.
-
#to_language ⇒ ::TreeSitter::Language
(also: #to_ts_language)
Convert to the underlying TreeSitter::Language for passing to parser.
Constructor Details
#initialize(lang, path: nil, symbol: nil) ⇒ Language
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Language.
116 117 118 119 120 121 |
# File 'lib/tree_haver/backends/mri.rb', line 116 def initialize(lang, path: nil, symbol: nil) @inner_language = lang @backend = :mri @path = path @symbol = symbol end |
Instance Attribute Details
#backend ⇒ Symbol (readonly)
The backend this language is for
102 103 104 |
# File 'lib/tree_haver/backends/mri.rb', line 102 def backend @backend end |
#inner_language ⇒ ::TreeSitter::Language (readonly)
The wrapped TreeSitter::Language object
98 99 100 |
# File 'lib/tree_haver/backends/mri.rb', line 98 def inner_language @inner_language end |
#path ⇒ String? (readonly)
The path this language was loaded from (if known)
106 107 108 |
# File 'lib/tree_haver/backends/mri.rb', line 106 def path @path end |
#symbol ⇒ String? (readonly)
The symbol name (if known)
110 111 112 |
# File 'lib/tree_haver/backends/mri.rb', line 110 def symbol @symbol end |
Class Method Details
.from_library(path, symbol: nil, name: nil) ⇒ Object
168 169 170 171 172 |
# File 'lib/tree_haver/backends/mri.rb', line 168 def from_library(path, symbol: nil, name: nil) # Derive symbol from path if not provided using shared utility symbol ||= LibraryPathUtils.derive_symbol_from_path(path) from_path(path, symbol: symbol, name: name) end |
Instance Method Details
#<=>(other) ⇒ Integer?
Compare languages for equality
MRI languages are equal if they have the same backend, path, and symbol. Path and symbol uniquely identify a loaded language.
130 131 132 133 134 135 136 137 138 139 |
# File 'lib/tree_haver/backends/mri.rb', line 130 def <=>(other) return unless other.is_a?(Language) return unless other.backend == @backend # Compare by path first, then symbol cmp = (@path || "") <=> (other.path || "") return cmp if cmp.nonzero? (@symbol || "") <=> (other.symbol || "") end |
#hash ⇒ Integer
Hash value for this language (for use in Sets/Hashes)
143 144 145 |
# File 'lib/tree_haver/backends/mri.rb', line 143 def hash [@backend, @path, @symbol].hash end |
#to_language ⇒ ::TreeSitter::Language Also known as: to_ts_language
Convert to the underlying TreeSitter::Language for passing to parser
153 154 155 |
# File 'lib/tree_haver/backends/mri.rb', line 153 def to_language @inner_language end |