Class: Prism::ParseResult

Inherits:
Result
  • Object
show all
Defined in:
lib/prism/parse_result.rb,
lib/prism/parse_result/errors.rb,
lib/prism/parse_result/comments.rb,
lib/prism/parse_result/newlines.rb,
ext/prism/extension.c

Overview

This is a result specific to the ‘parse` and `parse_file` methods.

Instance Attribute Summary collapse

Attributes inherited from Result

#comments, #data_loc, #errors, #magic_comments, #source, #warnings

Instance Method Summary collapse

Methods inherited from Result

#encoding, #failure?, #success?

Constructor Details

#initialize(value, comments, magic_comments, data_loc, errors, warnings, source) ⇒ ParseResult

Create a new parse result object with the given values.



598
599
600
601
# File 'lib/prism/parse_result.rb', line 598

def initialize(value, comments, magic_comments, data_loc, errors, warnings, source)
  @value = value
  super(comments, magic_comments, data_loc, errors, warnings, source)
end

Instance Attribute Details

#valueObject (readonly)

The syntax tree that was parsed from the source code.



595
596
597
# File 'lib/prism/parse_result.rb', line 595

def value
  @value
end

Instance Method Details

#attach_comments!Object

Attach the list of comments to their respective locations in the tree.



609
610
611
# File 'lib/prism/parse_result.rb', line 609

def attach_comments!
  Comments.new(self).attach! # steep:ignore
end

#deconstruct_keys(keys) ⇒ Object

Implement the hash pattern matching interface for ParseResult.



604
605
606
# File 'lib/prism/parse_result.rb', line 604

def deconstruct_keys(keys)
  super.merge!(value: value)
end

#errors_formatObject

Returns a string representation of the syntax tree with the errors displayed inline.



621
622
623
# File 'lib/prism/parse_result.rb', line 621

def errors_format
  Errors.new(self).format
end

#mark_newlines!Object

Walk the tree and mark nodes that are on a new line, loosely emulating the behavior of CRuby’s ‘:line` tracepoint event.



615
616
617
# File 'lib/prism/parse_result.rb', line 615

def mark_newlines!
  value.accept(Newlines.new(source.offsets.size)) # steep:ignore
end