Module: TreeHaver::Backends::Parslet
- Defined in:
- lib/tree_haver/backends/parslet.rb
Overview
This backend requires a Parslet grammar class for the specific language
Parslet backend using pure Ruby PEG parser
This backend wraps Parslet-based parsers (like the toml gem) to provide a
pure Ruby alternative to tree-sitter. Parslet is a PEG (Parsing Expression
Grammar) parser generator written in Ruby that produces Hash/Array/Slice
results rather than a traditional AST.
Unlike tree-sitter backends which are language-agnostic runtime parsers,
Parslet parsers are grammar-specific and defined as Ruby classes. Each
language needs its own Parslet grammar (e.g., TOML::Parslet 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
41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/tree_haver/backends/parslet.rb', line 41 def available? return @loaded if @load_attempted # rubocop:disable ThreadSafety/ClassInstanceVariable @load_attempted = true # rubocop:disable ThreadSafety/ClassInstanceVariable begin require "parslet" @loaded = true # rubocop:disable ThreadSafety/ClassInstanceVariable rescue LoadError @loaded = false # rubocop:disable ThreadSafety/ClassInstanceVariable rescue StandardError @loaded = false # rubocop:disable ThreadSafety/ClassInstanceVariable end @loaded # rubocop:disable ThreadSafety/ClassInstanceVariable end |
.capabilities ⇒ Hash{Symbol => Object}
Get capabilities supported by this backend
70 71 72 73 74 75 76 77 78 79 |
# File 'lib/tree_haver/backends/parslet.rb', line 70 def capabilities return {} unless available? { backend: :parslet, query: false, # Parslet doesn't have a query API like tree-sitter bytes_field: true, # Parslet::Slice provides offset and length incremental: false, # Parslet doesn't support incremental parsing pure_ruby: true, # Parslet 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)
59 60 61 62 |
# File 'lib/tree_haver/backends/parslet.rb', line 59 def reset! @load_attempted = false # rubocop:disable ThreadSafety/ClassInstanceVariable @loaded = false # rubocop:disable ThreadSafety/ClassInstanceVariable end |