Module: TreeHaver::Backends::Citrus
- Defined in:
- lib/tree_haver/backends/citrus.rb
Overview
This backend requires a Citrus grammar for the specific language
Citrus backend using pure Ruby PEG parser
This backend wraps Citrus-based parsers (like toml-rb) to provide a pure Ruby alternative to tree-sitter. Citrus is a PEG (Parsing Expression Grammar) parser generator written in Ruby.
Unlike tree-sitter backends which are language-agnostic runtime parsers, Citrus parsers are grammar-specific and compiled into Ruby code. Each language needs its own Citrus grammar (e.g., toml-rb for TOML).
Defined Under Namespace
Classes: Language, Node, Parser, Tree
Class Method Summary collapse
- .available? ⇒ Boolean
-
.capabilities ⇒ Hash{Symbol => Object}
Get capabilities supported by this backend.
-
.reset! ⇒ void
private
Reset the load state (primarily for testing).
Class Method Details
.available? ⇒ Boolean
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/tree_haver/backends/citrus.rb', line 40 def available? return @loaded if @load_attempted # rubocop:disable ThreadSafety/ClassInstanceVariable @load_attempted = true # rubocop:disable ThreadSafety/ClassInstanceVariable begin require "citrus" @loaded = true # rubocop:disable ThreadSafety/ClassInstanceVariable rescue LoadError @loaded = false # rubocop:disable ThreadSafety/ClassInstanceVariable end @loaded # rubocop:disable ThreadSafety/ClassInstanceVariable end |
.capabilities ⇒ Hash{Symbol => Object}
Get capabilities supported by this backend
68 69 70 71 72 73 74 75 76 77 |
# File 'lib/tree_haver/backends/citrus.rb', line 68 def capabilities return {} unless available? { backend: :citrus, query: false, # Citrus doesn't have a query API like tree-sitter bytes_field: true, # Citrus::Match provides offset and length incremental: false, # Citrus doesn't support incremental parsing pure_ruby: true, # Citrus is pure Ruby (portable) } end |
.reset! ⇒ void
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.
This method returns an undefined value.
Reset the load state (primarily for testing)
57 58 59 60 |
# File 'lib/tree_haver/backends/citrus.rb', line 57 def reset! @load_attempted = false # rubocop:disable ThreadSafety/ClassInstanceVariable @loaded = false # rubocop:disable ThreadSafety/ClassInstanceVariable end |