123456789_123456789_123456789_123456789_123456789_

Class: Prism::ParseResult

Relationships & Source Files
Namespace Children
Classes:
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, Result
Instance Chain:
self, Result
Inherits: Prism::Result
Defined in: lib/prism/parse_result.rb,
lib/prism/parse_result/comments.rb,
lib/prism/parse_result/errors.rb,
lib/prism/parse_result/newlines.rb,
prism/extension.c

Overview

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

Class Method Summary

Result - Inherited

.new

Create a new result object with the given values.

Instance Attribute Summary

  • #value readonly

    The syntax tree that was parsed from the source code.

Result - Inherited

#comments

The list of comments that were encountered during parsing.

#data_loc

An optional location that represents the location of the __END__ marker and the rest of the content of the file.

#errors

The list of errors that were generated during parsing.

#failure?

Returns true if there were errors during parsing and false if there were not.

#magic_comments

The list of magic comments that were encountered during parsing.

#source

A Source instance that represents the source code that was parsed.

#success?

Returns true if there were no errors during parsing and false if there were.

#warnings

The list of warnings that were generated during parsing.

Instance Method Summary

  • #attach_comments!

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

  • #deconstruct_keys(keys)

    Implement the hash pattern matching interface for ParseResult.

  • #errors_format

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

  • #mark_newlines!

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

Result - Inherited

#code_units_cache

Create a code units cache for the given encoding.

#deconstruct_keys

Implement the hash pattern matching interface for Result.

#encoding

Returns the encoding of the source code that was parsed.

Constructor Details

.new(value, comments, magic_comments, data_loc, errors, warnings, source) ⇒ ParseResult

Create a new parse result object with the given values.

[ GitHub ]

  
# File 'lib/prism/parse_result.rb', line 735

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

#value (readonly)

The syntax tree that was parsed from the source code.

[ GitHub ]

  
# File 'lib/prism/parse_result.rb', line 732

attr_reader :value

Instance Method Details

#attach_comments!

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

[ GitHub ]

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

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

#deconstruct_keys(keys)

Implement the hash pattern matching interface for ParseResult.

[ GitHub ]

  
# File 'lib/prism/parse_result.rb', line 741

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

#errors_format

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

[ GitHub ]

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

def errors_format
  Errors.new(self).format
end

#mark_newlines!

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

[ GitHub ]

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

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