Class: Prism::Result
- Inherits:
-
Object
- Object
- Prism::Result
- Defined in:
- lib/prism/parse_result.rb,
ext/prism/extension.c
Overview
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.
Direct Known Subclasses
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 __END__ marker and the rest of the content of the file.
-
#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.
-
#warnings ⇒ Object
readonly
The list of warnings that were generated during parsing.
Instance Method Summary collapse
-
#code_units_cache(encoding) ⇒ Object
Create a code units cache for the given encoding.
-
#deconstruct_keys(keys) ⇒ Object
Implement the hash pattern matching interface for Result.
-
#encoding ⇒ Object
Returns the encoding of the source code that was parsed.
-
#failure? ⇒ Boolean
Returns true if there were errors during parsing and false if there were not.
-
#initialize(comments, magic_comments, data_loc, errors, warnings, source) ⇒ Result
constructor
Create a new result object with the given values.
-
#success? ⇒ Boolean
Returns true if there were no errors during parsing and false if there were.
Constructor Details
#initialize(comments, magic_comments, data_loc, errors, warnings, source) ⇒ Result
Create a new result object with the given values.
702 703 704 705 706 707 708 709 |
# File 'lib/prism/parse_result.rb', line 702 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 |
Instance Attribute Details
#comments ⇒ Object (readonly)
The list of comments that were encountered during parsing.
682 683 684 |
# File 'lib/prism/parse_result.rb', line 682 def comments @comments end |
#data_loc ⇒ Object (readonly)
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.
690 691 692 |
# File 'lib/prism/parse_result.rb', line 690 def data_loc @data_loc end |
#errors ⇒ Object (readonly)
The list of errors that were generated during parsing.
693 694 695 |
# File 'lib/prism/parse_result.rb', line 693 def errors @errors end |
#magic_comments ⇒ Object (readonly)
The list of magic comments that were encountered during parsing.
685 686 687 |
# File 'lib/prism/parse_result.rb', line 685 def magic_comments @magic_comments end |
#source ⇒ Object (readonly)
A Source instance that represents the source code that was parsed.
699 700 701 |
# File 'lib/prism/parse_result.rb', line 699 def source @source end |
#warnings ⇒ Object (readonly)
The list of warnings that were generated during parsing.
696 697 698 |
# File 'lib/prism/parse_result.rb', line 696 def warnings @warnings end |
Instance Method Details
#code_units_cache(encoding) ⇒ Object
Create a code units cache for the given encoding.
734 735 736 |
# File 'lib/prism/parse_result.rb', line 734 def code_units_cache(encoding) source.code_units_cache(encoding) end |
#deconstruct_keys(keys) ⇒ Object
Implement the hash pattern matching interface for Result.
712 713 714 |
# File 'lib/prism/parse_result.rb', line 712 def deconstruct_keys(keys) { comments: comments, magic_comments: magic_comments, data_loc: data_loc, errors: errors, warnings: warnings } end |
#encoding ⇒ Object
Returns the encoding of the source code that was parsed.
717 718 719 |
# File 'lib/prism/parse_result.rb', line 717 def encoding source.encoding end |
#failure? ⇒ Boolean
Returns true if there were errors during parsing and false if there were not.
729 730 731 |
# File 'lib/prism/parse_result.rb', line 729 def failure? !success? end |
#success? ⇒ Boolean
Returns true if there were no errors during parsing and false if there were.
723 724 725 |
# File 'lib/prism/parse_result.rb', line 723 def success? errors.empty? end |