Module: TreeHaver::Backends::Psych
- Defined in:
- lib/tree_haver/backends/psych.rb
Overview
Note:
This backend only parses YAML source code
Psych backend using Ruby’s built-in YAML parser
This backend wraps Psych, Ruby’s standard library YAML parser.
Psych provides AST access via Psych.parse_stream which returns
Psych::Nodes::* objects (Stream, Document, Mapping, Sequence, Scalar, Alias).
Defined Under Namespace
Classes: Language, Node, Parser, Tree
Constant Summary collapse
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
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/tree_haver/backends/psych.rb', line 30 def available? return @loaded if @load_attempted # rubocop:disable ThreadSafety/ClassInstanceVariable @load_attempted = true # rubocop:disable ThreadSafety/ClassInstanceVariable begin require "psych" @loaded = true # rubocop:disable ThreadSafety/ClassInstanceVariable rescue LoadError @loaded = false # rubocop:disable ThreadSafety/ClassInstanceVariable rescue StandardError # :nocov: defensive code - StandardError during require is extremely rare @loaded = false # rubocop:disable ThreadSafety/ClassInstanceVariable # :nocov: end @loaded # rubocop:disable ThreadSafety/ClassInstanceVariable end |
.capabilities ⇒ Hash{Symbol => Object}
Get capabilities supported by this backend
58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/tree_haver/backends/psych.rb', line 58 def capabilities return {} unless available? { backend: :psych, query: false, # Psych doesn't have tree-sitter-style queries bytes_field: false, # Psych uses line/column, not byte offsets incremental: false, # Psych doesn't support incremental parsing pure_ruby: false, # Psych has native libyaml C extension yaml_only: true, # Psych only parses YAML error_tolerant: false, # Psych raises on syntax errors } 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)
50 51 52 53 |
# File 'lib/tree_haver/backends/psych.rb', line 50 def reset! @load_attempted = false # rubocop:disable ThreadSafety/ClassInstanceVariable @loaded = false # rubocop:disable ThreadSafety/ClassInstanceVariable end |