Class: Prism::ParseResult
- Inherits:
-
Object
- Object
- Prism::ParseResult
- Defined in:
- lib/prism/parse_result.rb,
lib/prism/parse_result/comments.rb,
lib/prism/parse_result/newlines.rb,
ext/prism/extension.c
Overview
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.
Instance Attribute Summary collapse
-
#comments ⇒ Object
readonly
Returns the value of attribute comments.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
-
#warnings ⇒ Object
readonly
Returns the value of attribute warnings.
Instance Method Summary collapse
-
#attach_comments! ⇒ Object
Attach the list of comments to their respective locations in the tree.
- #deconstruct_keys(keys) ⇒ Object
- #failure? ⇒ Boolean
-
#initialize(value, comments, errors, warnings, source) ⇒ ParseResult
constructor
A new instance of ParseResult.
-
#mark_newlines! ⇒ Object
Walk the tree and mark nodes that are on a new line.
- #success? ⇒ Boolean
Constructor Details
#initialize(value, comments, errors, warnings, source) ⇒ ParseResult
Returns a new instance of ParseResult.
211 212 213 214 215 216 217 |
# File 'lib/prism/parse_result.rb', line 211 def initialize(value, comments, errors, warnings, source) @value = value @comments = comments @errors = errors @warnings = warnings @source = source end |
Instance Attribute Details
#comments ⇒ Object (readonly)
Returns the value of attribute comments.
209 210 211 |
# File 'lib/prism/parse_result.rb', line 209 def comments @comments end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
209 210 211 |
# File 'lib/prism/parse_result.rb', line 209 def errors @errors end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
209 210 211 |
# File 'lib/prism/parse_result.rb', line 209 def source @source end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
209 210 211 |
# File 'lib/prism/parse_result.rb', line 209 def value @value end |
#warnings ⇒ Object (readonly)
Returns the value of attribute warnings.
209 210 211 |
# File 'lib/prism/parse_result.rb', line 209 def warnings @warnings end |
Instance Method Details
#attach_comments! ⇒ Object
Attach the list of comments to their respective locations in the tree.
168 169 170 |
# File 'lib/prism/parse_result/comments.rb', line 168 def attach_comments! Comments.new(self).attach! end |
#deconstruct_keys(keys) ⇒ Object
219 220 221 |
# File 'lib/prism/parse_result.rb', line 219 def deconstruct_keys(keys) { value: value, comments: comments, errors: errors, warnings: warnings } end |
#failure? ⇒ Boolean
227 228 229 |
# File 'lib/prism/parse_result.rb', line 227 def failure? !success? end |
#mark_newlines! ⇒ Object
Walk the tree and mark nodes that are on a new line.
56 57 58 |
# File 'lib/prism/parse_result/newlines.rb', line 56 def mark_newlines! value.accept(Newlines.new(Array.new(1 + source.offsets.size, false))) end |
#success? ⇒ Boolean
223 224 225 |
# File 'lib/prism/parse_result.rb', line 223 def success? errors.empty? end |