class Prism::Result
This represents the result of a call to ::parse or ::parse_file. It contains the requested structure, any comments that were encounters, and any errors that were encountered.
Attributes
Array[comment]
The list of comments that were encountered during parsing.
Location?
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.
Array[ParseError]
The list of errors that were generated during parsing.
The list of magic comments that were encountered during parsing.
Source
A Source instance that represents the source code that was parsed.
The list of warnings that were generated during parsing.
Public Class Methods
(Array[comment] comments, Array[MagicComment] magic_comments, Location? data_loc, Array[ParseError] errors, Array[ParseWarning] warnings, Source source) → void
Source
# File vendor/bundle/ruby/4.0.0/gems/prism-1.9.0/lib/prism/parse_result.rb, line 698 def initialize(comments, magic_comments, data_loc, errors, warnings, source) @comments = comments @magic_comments = magic_comments @data_loc = data_loc @errors = errors @warnings = warnings @source = source end
Create a new result object with the given values.
Public Instance Methods
(Encoding encoding) → _CodeUnitsCache
Source
# File vendor/bundle/ruby/4.0.0/gems/prism-1.9.0/lib/prism/parse_result.rb, line 730 def code_units_cache(encoding) source.code_units_cache(encoding) end
Create a code units cache for the given encoding.
# File vendor/bundle/ruby/4.0.0/gems/prism-1.9.0/lib/prism/parse_result.rb, line 708 def deconstruct_keys(keys) { comments: comments, magic_comments: magic_comments, data_loc: data_loc, errors: errors, warnings: warnings } end
Implement the hash pattern matching interface for Result.
() → Encoding
Source
# File vendor/bundle/ruby/4.0.0/gems/prism-1.9.0/lib/prism/parse_result.rb, line 713 def encoding source.encoding end
Returns the encoding of the source code that was parsed.
() → bool
Source
# File vendor/bundle/ruby/4.0.0/gems/prism-1.9.0/lib/prism/parse_result.rb, line 725 def failure? !success? end
Returns true if there were errors during parsing and false if there were not.
() → bool
Source
# File vendor/bundle/ruby/4.0.0/gems/prism-1.9.0/lib/prism/parse_result.rb, line 719 def success? errors.empty? end
Returns true if there were no errors during parsing and false if there were.