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

#code_units_cache, #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.



752
753
754
755
# File 'lib/prism/parse_result.rb', line 752

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.



749
750
751
# File 'lib/prism/parse_result.rb', line 749

def value
  @value
end

Instance Method Details

#attach_comments!Object

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



763
764
765
# File 'lib/prism/parse_result.rb', line 763

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

#deconstruct_keys(keys) ⇒ Object

Implement the hash pattern matching interface for ParseResult.



758
759
760
# File 'lib/prism/parse_result.rb', line 758

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

#errors_formatObject

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



775
776
777
# File 'lib/prism/parse_result.rb', line 775

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.



769
770
771
# File 'lib/prism/parse_result.rb', line 769

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