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
The list of comments that were encountered during parsing.
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 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.
The list of warnings that were generated during parsing.
Public Class Methods
Create a new parse result object with the given values.
# File prism/parse_result.rb, line 357 def initialize(value, comments, magic_comments, errors, warnings, source) @value = value @comments = comments @magic_comments = magic_comments @errors = errors @warnings = warnings @source = source end
Public Instance Methods
Attach the list of comments to their respective locations in the tree.
# File prism/parse_result/comments.rb, line 173 def attach_comments! Comments.new(self).attach! end
Implement the hash pattern matching interface for ParseResult
.
# File prism/parse_result.rb, line 367 def deconstruct_keys(keys) { value: value, comments: comments, magic_comments: magic_comments, errors: errors, warnings: warnings } end
Returns true if there were errors during parsing and false if there were not.
# File prism/parse_result.rb, line 379 def failure? !success? end
Walk the tree and mark nodes that are on a new line.
# File prism/parse_result/newlines.rb, line 60 def mark_newlines! value.accept(Newlines.new(Array.new(1 + source.offsets.size, false))) end
Returns true if there were no errors during parsing and false if there were.
# File prism/parse_result.rb, line 373 def success? errors.empty? end