Module: TreeHaver::Backends::Prism
- Defined in:
- lib/tree_haver/backends/prism.rb
Overview
This backend only parses Ruby source code
Prism backend using Ruby's built-in Prism parser
This backend wraps Prism, Ruby's official parser (stdlib in Ruby 3.4+, available as a gem for 3.2+). Unlike tree-sitter backends which are language-agnostic runtime parsers, Prism is specifically designed for parsing Ruby source code.
Prism provides excellent error recovery, detailed location information, and is the future of Ruby parsing (used by CRuby, JRuby, TruffleRuby).
Defined Under Namespace
Classes: Comment, 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
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/tree_haver/backends/prism.rb', line 39 def available? return @loaded if @load_attempted @load_attempted = true begin require 'prism' @loaded = true rescue LoadError @loaded = false rescue StandardError # simplecov:disable defensive code - StandardError during require is extremely rare @loaded = false # simplecov:enable end @loaded end |
.capabilities ⇒ Hash{Symbol => Object}
Get capabilities supported by this backend
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/tree_haver/backends/prism.rb', line 71 def capabilities return {} unless available? { backend: :prism, query: false, # Prism doesn't have tree-sitter-style queries (has pattern matching) bytes_field: true, # Prism provides byte offsets via Location incremental: false, # Prism doesn't support incremental parsing (yet) pure_ruby: false, # Prism has native C extension (but also pure Ruby mode) ruby_only: true, # Prism only parses Ruby source code error_tolerant: true, # Prism has excellent error recovery comment_support: :partial, comment_attachment_hints: true } 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)
60 61 62 63 |
# File 'lib/tree_haver/backends/prism.rb', line 60 def reset! @load_attempted = false @loaded = false end |