Class: TreeHaver::Backends::Commonmarker::Language
- Inherits:
-
Object
- Object
- TreeHaver::Backends::Commonmarker::Language
- Includes:
- Comparable
- Defined in:
- lib/tree_haver/backends/commonmarker.rb
Overview
Commonmarker language wrapper
Commonmarker only parses Markdown. This class exists for API compatibility.
Instance Attribute Summary collapse
-
#backend ⇒ Symbol
readonly
The backend this language is for.
-
#name ⇒ Symbol
readonly
The language name (always :markdown for Commonmarker).
-
#options ⇒ Hash
readonly
Commonmarker parse options.
Class Method Summary collapse
-
.from_library(_path = nil, symbol: nil, name: nil) ⇒ Language
Load language from library path (API compatibility).
-
.markdown(options: {}) ⇒ Language
Create a Markdown language instance.
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
Comparison for sorting/equality.
-
#initialize(name = :markdown, options: {}) ⇒ Language
constructor
Create a new Commonmarker language instance.
- #inspect ⇒ Object
Constructor Details
#initialize(name = :markdown, options: {}) ⇒ Language
Create a new Commonmarker language instance
91 92 93 94 95 |
# File 'lib/tree_haver/backends/commonmarker.rb', line 91 def initialize(name = :markdown, options: {}) @name = name.to_sym @backend = :commonmarker = end |
Instance Attribute Details
#backend ⇒ Symbol (readonly)
The backend this language is for
81 82 83 |
# File 'lib/tree_haver/backends/commonmarker.rb', line 81 def backend @backend end |
#name ⇒ Symbol (readonly)
The language name (always :markdown for Commonmarker)
77 78 79 |
# File 'lib/tree_haver/backends/commonmarker.rb', line 77 def name @name end |
#options ⇒ Hash (readonly)
Commonmarker parse options
85 86 87 |
# File 'lib/tree_haver/backends/commonmarker.rb', line 85 def end |
Class Method Details
.from_library(_path = nil, symbol: nil, name: nil) ⇒ Language
Load language from library path (API compatibility)
Commonmarker only supports Markdown, so path and symbol parameters are ignored. This method exists for API consistency with tree-sitter backends, allowing ‘TreeHaver.parser_for(:markdown)` to work regardless of backend.
117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/tree_haver/backends/commonmarker.rb', line 117 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 || :markdown unless lang_name == :markdown raise TreeHaver::NotAvailable, "Commonmarker backend only supports Markdown, not #{lang_name}. " \ "Use a tree-sitter backend for #{lang_name} support." end markdown end |
.markdown(options: {}) ⇒ Language
Create a Markdown language instance
102 103 104 |
# File 'lib/tree_haver/backends/commonmarker.rb', line 102 def markdown(options: {}) new(:markdown, options: ) end |
Instance Method Details
#<=>(other) ⇒ Object
Comparison for sorting/equality
132 133 134 135 |
# File 'lib/tree_haver/backends/commonmarker.rb', line 132 def <=>(other) return unless other.is_a?(Language) name <=> other.name end |
#inspect ⇒ Object
137 138 139 |
# File 'lib/tree_haver/backends/commonmarker.rb', line 137 def inspect "#<TreeHaver::Backends::Commonmarker::Language name=#{name} options=#{options}>" end |