Class: TreeHaver::Backends::Prism::Tree Private
- Inherits:
-
Object
- Object
- TreeHaver::Backends::Prism::Tree
- Defined in:
- lib/tree_haver/backends/prism.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Prism tree wrapper
Wraps a Prism::ParseResult to provide tree-sitter-compatible API.
Instance Attribute Summary collapse
-
#parse_result ⇒ ::Prism::ParseResult
readonly
private
The underlying Prism parse result.
-
#source ⇒ String
readonly
private
The source code.
Instance Method Summary collapse
-
#comments ⇒ Array<::Prism::Comment>
private
Get comments from the parse.
-
#data_loc ⇒ ::Prism::Location?
private
Get data locations (__END__ section).
-
#errors ⇒ Array<::Prism::ParseError>
private
Get parse errors.
-
#has_errors? ⇒ Boolean
private
Check if the parse had errors.
-
#initialize(parse_result, source) ⇒ Tree
constructor
private
A new instance of Tree.
-
#inner_tree ⇒ ::Prism::ParseResult
private
Access the underlying Prism result (passthrough).
-
#magic_comments ⇒ Array<::Prism::MagicComment>
private
Get magic comments (e.g., frozen_string_literal).
-
#root_node ⇒ Node
private
Get the root node of the parse tree.
-
#warnings ⇒ Array<::Prism::ParseWarning>
private
Get parse warnings.
Constructor Details
#initialize(parse_result, source) ⇒ Tree
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.
Returns a new instance of Tree.
261 262 263 264 |
# File 'lib/tree_haver/backends/prism.rb', line 261 def initialize(parse_result, source) @parse_result = parse_result @source = source end |
Instance Attribute Details
#parse_result ⇒ ::Prism::ParseResult (readonly)
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.
Returns the underlying Prism parse result.
256 257 258 |
# File 'lib/tree_haver/backends/prism.rb', line 256 def parse_result @parse_result end |
#source ⇒ String (readonly)
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.
Returns the source code.
259 260 261 |
# File 'lib/tree_haver/backends/prism.rb', line 259 def source @source end |
Instance Method Details
#comments ⇒ Array<::Prism::Comment>
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.
Get comments from the parse
297 298 299 |
# File 'lib/tree_haver/backends/prism.rb', line 297 def comments @parse_result.comments end |
#data_loc ⇒ ::Prism::Location?
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.
Get data locations (__END__ section)
311 312 313 |
# File 'lib/tree_haver/backends/prism.rb', line 311 def data_loc @parse_result.data_loc end |
#errors ⇒ Array<::Prism::ParseError>
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.
Get parse errors
283 284 285 |
# File 'lib/tree_haver/backends/prism.rb', line 283 def errors @parse_result.errors end |
#has_errors? ⇒ Boolean
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.
Check if the parse had errors
276 277 278 |
# File 'lib/tree_haver/backends/prism.rb', line 276 def has_errors? @parse_result.failure? end |
#inner_tree ⇒ ::Prism::ParseResult
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.
Access the underlying Prism result (passthrough)
318 319 320 |
# File 'lib/tree_haver/backends/prism.rb', line 318 def inner_tree @parse_result end |
#magic_comments ⇒ Array<::Prism::MagicComment>
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.
Get magic comments (e.g., frozen_string_literal)
304 305 306 |
# File 'lib/tree_haver/backends/prism.rb', line 304 def magic_comments @parse_result.magic_comments end |
#root_node ⇒ Node
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.
Get the root node of the parse tree
269 270 271 |
# File 'lib/tree_haver/backends/prism.rb', line 269 def root_node Node.new(@parse_result.value, @source) end |
#warnings ⇒ Array<::Prism::ParseWarning>
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.
Get parse warnings
290 291 292 |
# File 'lib/tree_haver/backends/prism.rb', line 290 def warnings @parse_result.warnings end |