Class: TreeHaver::Backends::Psych::Language
- Inherits:
-
Object
- Object
- TreeHaver::Backends::Psych::Language
- Includes:
- Comparable
- Defined in:
- lib/tree_haver/backends/psych.rb
Overview
Psych language wrapper
Unlike tree-sitter which supports many languages via grammar files, Psych only parses YAML. 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 :yaml for Psych).
Class Method Summary collapse
-
.from_library(_path = nil, symbol: nil, name: nil) ⇒ Language
Load language from library path (API compatibility).
-
.yaml ⇒ Language
Create a YAML language instance.
Instance Method Summary collapse
-
#<=>(other) ⇒ Integer?
Comparison for sorting/equality.
-
#initialize(name = :yaml) ⇒ Language
constructor
Create a new Psych language instance.
-
#inspect ⇒ String
Human-readable representation.
Constructor Details
#initialize(name = :yaml) ⇒ Language
Create a new Psych language instance
91 92 93 94 |
# File 'lib/tree_haver/backends/psych.rb', line 91 def initialize(name = :yaml) @name = name.to_sym @backend = :psych end |
Instance Attribute Details
#backend ⇒ Symbol (readonly)
The backend this language is for
86 87 88 |
# File 'lib/tree_haver/backends/psych.rb', line 86 def backend @backend end |
#name ⇒ Symbol (readonly)
The language name (always :yaml for Psych)
82 83 84 |
# File 'lib/tree_haver/backends/psych.rb', line 82 def name @name end |
Class Method Details
.from_library(_path = nil, symbol: nil, name: nil) ⇒ Language
Load language from library path (API compatibility)
Psych only supports YAML, so path and symbol parameters are ignored. This method exists for API consistency with tree-sitter backends, allowing ‘TreeHaver.parser_for(:yaml)` to work regardless of backend.
115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/tree_haver/backends/psych.rb', line 115 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 || :yaml unless lang_name == :yaml raise TreeHaver::NotAvailable, "Psych backend only supports YAML, not #{lang_name}. " \ "Use a tree-sitter backend for #{lang_name} support." end yaml end |
.yaml ⇒ Language
Create a YAML language instance
100 101 102 |
# File 'lib/tree_haver/backends/psych.rb', line 100 def yaml new(:yaml) end |
Instance Method Details
#<=>(other) ⇒ Integer?
Comparison for sorting/equality
133 134 135 136 |
# File 'lib/tree_haver/backends/psych.rb', line 133 def <=>(other) return unless other.is_a?(Language) name <=> other.name end |
#inspect ⇒ String
Returns human-readable representation.
139 140 141 |
# File 'lib/tree_haver/backends/psych.rb', line 139 def inspect "#<TreeHaver::Backends::Psych::Language name=#{name}>" end |