Class: TreeHaver::Backends::Prism::Tree Private
- Inherits:
-
TreeHaver::Base::Tree
- Object
- TreeHaver::Base::Tree
- 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.
Attributes inherited from TreeHaver::Base::Tree
Instance Method Summary collapse
-
#comments ⇒ Array<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.
-
#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.
Methods inherited from TreeHaver::Base::Tree
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.
232 233 234 235 |
# File 'lib/tree_haver/backends/prism.rb', line 232 def initialize(parse_result, source) super(parse_result, source: source) @parse_result = parse_result 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.
230 231 232 |
# File 'lib/tree_haver/backends/prism.rb', line 230 def parse_result @parse_result end |
Instance Method Details
#comments ⇒ Array<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
268 269 270 271 272 273 274 275 |
# File 'lib/tree_haver/backends/prism.rb', line 268 def comments @comments ||= begin hint_map = comment_hint_map @parse_result.comments.map do |comment| Comment.new(comment, source: source, attachment_hint: hint_map[comment.object_id]) end end 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)
287 288 289 |
# File 'lib/tree_haver/backends/prism.rb', line 287 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
254 255 256 |
# File 'lib/tree_haver/backends/prism.rb', line 254 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
247 248 249 |
# File 'lib/tree_haver/backends/prism.rb', line 247 def has_errors? @parse_result.failure? 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)
280 281 282 |
# File 'lib/tree_haver/backends/prism.rb', line 280 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
240 241 242 |
# File 'lib/tree_haver/backends/prism.rb', line 240 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
261 262 263 |
# File 'lib/tree_haver/backends/prism.rb', line 261 def warnings @parse_result.warnings end |