Class: TreeHaver::Backends::Prism::Language
- Inherits:
-
TreeHaver::Base::Language
- Object
- TreeHaver::Base::Language
- TreeHaver::Backends::Prism::Language
- Defined in:
- lib/tree_haver/backends/prism.rb
Overview
Prism language wrapper
Unlike tree-sitter which supports many languages via grammar files, Prism only parses Ruby. This class exists for API compatibility with other tree_haver backends.
Instance Attribute Summary
Attributes inherited from TreeHaver::Base::Language
Class Method Summary collapse
-
.from_library(_path = nil, symbol: nil, name: nil) ⇒ Language
(also: from_path)
Load language from library path (API compatibility).
-
.ruby(options = {}) ⇒ Language
Create a Ruby language instance (convenience method).
Instance Method Summary collapse
-
#<=>(other) ⇒ Integer?
Compare languages for equality by options (since name is always :ruby).
-
#initialize(name = :ruby, options: {}) ⇒ Language
constructor
A new instance of Language.
Methods inherited from TreeHaver::Base::Language
Constructor Details
#initialize(name = :ruby, options: {}) ⇒ Language
Returns a new instance of Language.
96 97 98 99 100 101 102 103 104 |
# File 'lib/tree_haver/backends/prism.rb', line 96 def initialize(name = :ruby, options: {}) super(name, backend: :prism, options: ) unless self.name == :ruby raise TreeHaver::NotAvailable, "Prism only supports Ruby 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)
Prism only supports Ruby, so path and symbol parameters are ignored.
141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/tree_haver/backends/prism.rb', line 141 def from_library(_path = nil, symbol: nil, name: nil) lang_name = name || :ruby unless lang_name == :ruby raise TreeHaver::NotAvailable, "Prism backend only supports Ruby, not #{lang_name}. " \ "Use a tree-sitter backend for #{lang_name} support." end ruby end |
.ruby(options = {}) ⇒ Language
Create a Ruby language instance (convenience method)
128 129 130 |
# File 'lib/tree_haver/backends/prism.rb', line 128 def ruby( = {}) new(:ruby, options: ) end |
Instance Method Details
#<=>(other) ⇒ Integer?
Compare languages for equality by options (since name is always :ruby)
110 111 112 113 114 115 |
# File 'lib/tree_haver/backends/prism.rb', line 110 def <=>(other) return unless other.is_a?(TreeHaver::Base::Language) return unless other.backend == backend .to_a.sort <=> other..to_a.sort end |