class Ruby::Prism::Result

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

Attributes

The list of comments that were encountered during parsing.

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

The list of errors that were generated during parsing.

The list of magic comments that were encountered during parsing.

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

The list of warnings that were generated during parsing.

Public Class Methods

Create a new result object with the given values.

: (Array comments, Array magic_comments, Location? data_loc, Array errors, Array warnings, bool continuable, Source source) -> void

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

Public Instance Methods

Create a code units cache for the given encoding.

: (Encoding encoding) -> _CodeUnitsCache

# File lib/ruby/prism/parse_result.rb, line 997
def code_units_cache(encoding)
  source.code_units_cache(encoding)
end

Returns true if the parsed source is an incomplete expression that could become valid with additional input. This is useful for REPL contexts (such as IRB) where the user may be entering a multi-line expression one line at a time and the implementation needs to determine whether to wait for more input or to evaluate what has been entered so far.

Concretely, this returns true when every error present is caused by the parser reaching the end of the input before a construct was closed (e.g. an unclosed string, array, block, or keyword), and returns false when any error is caused by a token that makes the input structurally invalid regardless of what might follow (e.g. a stray end, ], or ) with no matching opener).

Examples:

 Ruby::Prism.parse("1 + [").continuable?      #=> true  (unclosed array)
 Ruby::Prism.parse("1 + ]").continuable?      #=> false (stray ])
 Ruby::Prism.parse("tap do").continuable?     #=> true  (unclosed block)
 Ruby::Prism.parse("end.tap do").continuable? #=> false (stray end)

: () -> bool

# File lib/ruby/prism/parse_result.rb, line 990
def continuable?
  @continuable
end

Returns the encoding of the source code that was parsed.

: () -> Encoding

# File lib/ruby/prism/parse_result.rb, line 949
def encoding
  source.encoding
end

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

: () -> bool

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

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

: () -> bool

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