Class: TreeHaver::Backends::Prism::Language
- Inherits:
-
Object
- Object
- TreeHaver::Backends::Prism::Language
- Includes:
- Comparable
- 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 collapse
-
#backend ⇒ Symbol
readonly
The backend this language is for.
-
#name ⇒ Symbol
readonly
The language name (always :ruby for Prism).
-
#options ⇒ Hash
readonly
Prism parsing options.
Class Method Summary collapse
-
.from_library(path, symbol: nil, name: nil) ⇒ Object
(also: from_path)
Not applicable for Prism (tree-sitter-specific).
-
.ruby(options = {}) ⇒ Language
Create a Ruby language instance (convenience method).
Instance Method Summary collapse
-
#<=>(other) ⇒ Integer?
Compare languages for equality.
-
#hash ⇒ Integer
Hash value for this language (for use in Sets/Hashes).
-
#initialize(name = :ruby, options: {}) ⇒ Language
constructor
A new instance of Language.
Constructor Details
#initialize(name = :ruby, options: {}) ⇒ Language
Returns a new instance of Language.
107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/tree_haver/backends/prism.rb', line 107 def initialize(name = :ruby, options: {}) @name = name.to_sym @backend = :prism = unless @name == :ruby raise TreeHaver::NotAvailable, "Prism only supports Ruby parsing. " \ "Got language: #{name.inspect}" end end |
Instance Attribute Details
#backend ⇒ Symbol (readonly)
The backend this language is for
99 100 101 |
# File 'lib/tree_haver/backends/prism.rb', line 99 def backend @backend end |
#name ⇒ Symbol (readonly)
The language name (always :ruby for Prism)
95 96 97 |
# File 'lib/tree_haver/backends/prism.rb', line 95 def name @name end |
#options ⇒ Hash (readonly)
Prism parsing options
103 104 105 |
# File 'lib/tree_haver/backends/prism.rb', line 103 def end |
Class Method Details
.from_library(path, symbol: nil, name: nil) ⇒ Object Also known as: from_path
Not applicable for Prism (tree-sitter-specific)
Prism is Ruby-only and doesn’t load external grammar libraries. This method exists for API compatibility but will raise an error.
162 163 164 165 166 |
# File 'lib/tree_haver/backends/prism.rb', line 162 def from_library(path, symbol: nil, name: nil) raise TreeHaver::NotAvailable, "Prism backend doesn't use shared libraries. " \ "Use Prism::Language.ruby instead." end |
.ruby(options = {}) ⇒ Language
Create a Ruby language instance (convenience method)
152 153 154 |
# File 'lib/tree_haver/backends/prism.rb', line 152 def ruby( = {}) new(:ruby, options: ) end |
Instance Method Details
#<=>(other) ⇒ Integer?
Compare languages for equality
Prism languages are equal if they have the same backend and options.
125 126 127 128 129 130 |
# File 'lib/tree_haver/backends/prism.rb', line 125 def <=>(other) return unless other.is_a?(Language) return unless other.backend == @backend .to_a.sort <=> other..to_a.sort end |
#hash ⇒ Integer
Hash value for this language (for use in Sets/Hashes)
134 135 136 |
# File 'lib/tree_haver/backends/prism.rb', line 134 def hash [@backend, @name, .to_a.sort].hash end |