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.



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

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.



746
747
748
# File 'lib/prism/parse_result.rb', line 746

def value
  @value
end

Instance Method Details

#attach_comments!Object

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



760
761
762
# File 'lib/prism/parse_result.rb', line 760

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

#deconstruct_keys(keys) ⇒ Object

Implement the hash pattern matching interface for ParseResult.



755
756
757
# File 'lib/prism/parse_result.rb', line 755

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

#errors_formatObject

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



772
773
774
# File 'lib/prism/parse_result.rb', line 772

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.



766
767
768
# File 'lib/prism/parse_result.rb', line 766

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