Class: Prism::ParseResult
- Defined in:
- lib/prism/parse_result.rb,
lib/prism/parse_result/errors.rb,
lib/prism/parse_result/comments.rb,
lib/prism/parse_result/newlines.rb,
ext/prism/extension.c
Overview
This is a result specific to the ‘parse` and `parse_file` methods.
Instance Attribute Summary collapse
-
#value ⇒ Object
readonly
The syntax tree that was parsed from the source code.
Attributes inherited from Result
#comments, #data_loc, #errors, #magic_comments, #source, #warnings
Instance Method Summary collapse
-
#attach_comments! ⇒ Object
Attach the list of comments to their respective locations in the tree.
-
#deconstruct_keys(keys) ⇒ Object
Implement the hash pattern matching interface for ParseResult.
-
#errors_format ⇒ Object
Returns a string representation of the syntax tree with the errors displayed inline.
-
#initialize(value, comments, magic_comments, data_loc, errors, warnings, source) ⇒ ParseResult
constructor
Create a new parse result object with the given values.
-
#mark_newlines! ⇒ Object
Walk the tree and mark nodes that are on a new line, loosely emulating the behavior of CRuby’s ‘:line` tracepoint event.
Methods inherited from Result
#code_units_cache, #encoding, #failure?, #success?
Constructor Details
#initialize(value, comments, magic_comments, data_loc, errors, warnings, source) ⇒ ParseResult
Create a new parse result object with the given values.
735 736 737 738 |
# 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 ⇒ Object (readonly)
The syntax tree that was parsed from the source code.
732 733 734 |
# File 'lib/prism/parse_result.rb', line 732 def value @value end |
Instance Method Details
#attach_comments! ⇒ Object
Attach the list of comments to their respective locations in the tree.
746 747 748 |
# File 'lib/prism/parse_result.rb', line 746 def attach_comments! Comments.new(self).attach! # steep:ignore end |
#deconstruct_keys(keys) ⇒ Object
Implement the hash pattern matching interface for ParseResult.
741 742 743 |
# File 'lib/prism/parse_result.rb', line 741 def deconstruct_keys(keys) super.merge!(value: value) end |
#errors_format ⇒ Object
Returns a string representation of the syntax tree with the errors displayed inline.
758 759 760 |
# File 'lib/prism/parse_result.rb', line 758 def errors_format Errors.new(self).format end |
#mark_newlines! ⇒ Object
Walk the tree and mark nodes that are on a new line, loosely emulating the behavior of CRuby’s ‘:line` tracepoint event.
752 753 754 |
# File 'lib/prism/parse_result.rb', line 752 def mark_newlines! value.accept(Newlines.new(source.offsets.size)) # steep:ignore end |