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
The list of comments that were encountered during parsing.
-
#data_loc ⇒ Object
readonly
An optional location that represents the location of the content after the __END__ marker.
-
#errors ⇒ Object
readonly
The list of errors that were generated during parsing.
-
#magic_comments ⇒ Object
readonly
The list of magic comments that were encountered during parsing.
-
#source ⇒ Object
readonly
A Source instance that represents the source code that was parsed.
-
#value ⇒ Object
readonly
The value that was generated by parsing.
-
#warnings ⇒ Object
readonly
The list of warnings that were generated during parsing.
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.
-
#failure? ⇒ Boolean
Returns true if there were errors during parsing and false if there were not.
-
#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.
-
#success? ⇒ Boolean
Returns true if there were no errors during parsing and false if there were.
Constructor Details
#initialize(value, comments, magic_comments, data_loc, errors, warnings, source) ⇒ ParseResult
Create a new parse result object with the given values.
387 388 389 390 391 392 393 394 395 |
# File 'lib/prism/parse_result.rb', line 387 def initialize(value, comments, magic_comments, data_loc, errors, warnings, source) @value = value @comments = comments @magic_comments = magic_comments @data_loc = data_loc @errors = errors @warnings = warnings @source = source end |
Instance Attribute Details
#comments ⇒ Object (readonly)
The list of comments that were encountered during parsing.
367 368 369 |
# File 'lib/prism/parse_result.rb', line 367 def comments @comments end |
#data_loc ⇒ Object (readonly)
An optional location that represents the location of the content after the __END__ marker. This content is loaded into the DATA constant when the file being parsed is the main file being executed.
375 376 377 |
# File 'lib/prism/parse_result.rb', line 375 def data_loc @data_loc end |
#errors ⇒ Object (readonly)
The list of errors that were generated during parsing.
378 379 380 |
# File 'lib/prism/parse_result.rb', line 378 def errors @errors end |
#magic_comments ⇒ Object (readonly)
The list of magic comments that were encountered during parsing.
370 371 372 |
# File 'lib/prism/parse_result.rb', line 370 def magic_comments @magic_comments end |
#source ⇒ Object (readonly)
A Source instance that represents the source code that was parsed.
384 385 386 |
# File 'lib/prism/parse_result.rb', line 384 def source @source end |
#value ⇒ Object (readonly)
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.
364 365 366 |
# File 'lib/prism/parse_result.rb', line 364 def value @value end |
#warnings ⇒ Object (readonly)
The list of warnings that were generated during parsing.
381 382 383 |
# File 'lib/prism/parse_result.rb', line 381 def warnings @warnings end |
Instance Method Details
#attach_comments! ⇒ Object
Attach the list of comments to their respective locations in the tree.
173 174 175 |
# File 'lib/prism/parse_result/comments.rb', line 173 def attach_comments! Comments.new(self).attach! end |
#deconstruct_keys(keys) ⇒ Object
Implement the hash pattern matching interface for ParseResult.
398 399 400 |
# File 'lib/prism/parse_result.rb', line 398 def deconstruct_keys(keys) { value: value, comments: comments, magic_comments: magic_comments, data_loc: data_loc, errors: errors, warnings: warnings } end |
#failure? ⇒ Boolean
Returns true if there were errors during parsing and false if there were not.
410 411 412 |
# File 'lib/prism/parse_result.rb', line 410 def failure? !success? end |
#mark_newlines! ⇒ Object
Walk the tree and mark nodes that are on a new line.
60 61 62 |
# File 'lib/prism/parse_result/newlines.rb', line 60 def mark_newlines! value.accept(Newlines.new(Array.new(1 + source.offsets.size, false))) end |
#success? ⇒ Boolean
Returns true if there were no errors during parsing and false if there were.
404 405 406 |
# File 'lib/prism/parse_result.rb', line 404 def success? errors.empty? end |