Class: TreeHaver::Backends::Prism::Tree Private

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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.



248
249
250
251
# File 'lib/tree_haver/backends/prism.rb', line 248

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.

Returns:

  • (::Prism::ParseResult)

    the underlying Prism parse result



243
244
245
# File 'lib/tree_haver/backends/prism.rb', line 243

def parse_result
  @parse_result
end

#sourceString (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.

Returns:

  • (String)

    the source code



246
247
248
# File 'lib/tree_haver/backends/prism.rb', line 246

def source
  @source
end

Instance Method Details

#commentsArray<::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

Returns:

  • (Array<::Prism::Comment>)


284
285
286
# File 'lib/tree_haver/backends/prism.rb', line 284

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)

Returns:

  • (::Prism::Location, nil)


298
299
300
# File 'lib/tree_haver/backends/prism.rb', line 298

def data_loc
  @parse_result.data_loc
end

#errorsArray<::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

Returns:

  • (Array<::Prism::ParseError>)


270
271
272
# File 'lib/tree_haver/backends/prism.rb', line 270

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

Returns:

  • (Boolean)


263
264
265
# File 'lib/tree_haver/backends/prism.rb', line 263

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)

Returns:

  • (::Prism::ParseResult)


305
306
307
# File 'lib/tree_haver/backends/prism.rb', line 305

def inner_tree
  @parse_result
end

#magic_commentsArray<::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)

Returns:

  • (Array<::Prism::MagicComment>)


291
292
293
# File 'lib/tree_haver/backends/prism.rb', line 291

def magic_comments
  @parse_result.magic_comments
end

#root_nodeNode

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

Returns:

  • (Node)

    wrapped root node



256
257
258
# File 'lib/tree_haver/backends/prism.rb', line 256

def root_node
  Node.new(@parse_result.value, @source)
end

#warningsArray<::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

Returns:

  • (Array<::Prism::ParseWarning>)


277
278
279
# File 'lib/tree_haver/backends/prism.rb', line 277

def warnings
  @parse_result.warnings
end