# class Prism::ParseResult

This represents the result of a call to ::parse or ::parse_file. It contains the AST, any comments that were encounters, and any errors that were encountered.

### Attributes

comments[R]

The list of comments that were encountered during parsing.

data_loc[R]

An optional location that represents the location of the content after the __END__ marker. This content is loaded into the DATA constant when the file being parsed is the main file being executed.

errors[R]

The list of errors that were generated during parsing.

magic_comments[R]

The list of magic comments that were encountered during parsing.

source[R]

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

value[R]

The value that was generated by parsing. Normally this holds the AST, but it can sometimes how a list of tokens or other results passed back from the parser.

warnings[R]

The list of warnings that were generated during parsing.

### Public Class Methods

new(value, comments, magic_comments, data_loc, errors, warnings, source) click to toggle source

Create a new parse result object with the given values.

    # File lib/prism/parse_result.rb, line 387
    def initialize(value, comments, magic_comments, data_loc, errors, warnings, source)
      @value = value
      @comments = comments
      @magic_comments = magic_comments
      @data_loc = data_loc
      @errors = errors
      @warnings = warnings
      @source = source
    end

### Public Instance Methods

attach_comments!() click to toggle source

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

    # File lib/prism/parse_result/comments.rb, line 173
    def attach_comments!
      Comments.new(self).attach!
    end

deconstruct_keys(keys) click to toggle source

Implement the hash pattern matching interface for `ParseResult`.

    # File lib/prism/parse_result.rb, line 398
    def deconstruct_keys(keys)
      { value: value, comments: comments, magic_comments: magic_comments, data_loc: data_loc, errors: errors, warnings: warnings }
    end

failure?() click to toggle source

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

    # File lib/prism/parse_result.rb, line 410
    def failure?
      !success?
    end

mark_newlines!() click to toggle source

Walk the tree and mark nodes that are on a new line.

    # File lib/prism/parse_result/newlines.rb, line 60
    def mark_newlines!
      value.accept(Newlines.new(Array.new(1 + source.offsets.size, false)))
    end

success?() click to toggle source

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

    # File lib/prism/parse_result.rb, line 404
    def success?
      errors.empty?
    end