Class: Prism::Result

Inherits:
Object
  • Object
show all
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.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(comments, magic_comments, data_loc, errors, warnings, source) ⇒ Result

Create a new result object with the given values.


701
702
703
704
705
706
707
708
# File 'lib/prism/parse_result.rb', line 701

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

#commentsObject (readonly)

The list of comments that were encountered during parsing.


681
682
683
# File 'lib/prism/parse_result.rb', line 681

def comments
  @comments
end

#data_locObject (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.


689
690
691
# File 'lib/prism/parse_result.rb', line 689

def data_loc
  @data_loc
end

#errorsObject (readonly)

The list of errors that were generated during parsing.


692
693
694
# File 'lib/prism/parse_result.rb', line 692

def errors
  @errors
end

#magic_commentsObject (readonly)

The list of magic comments that were encountered during parsing.


684
685
686
# File 'lib/prism/parse_result.rb', line 684

def magic_comments
  @magic_comments
end

#sourceObject (readonly)

A Source instance that represents the source code that was parsed.


698
699
700
# File 'lib/prism/parse_result.rb', line 698

def source
  @source
end

#warningsObject (readonly)

The list of warnings that were generated during parsing.


695
696
697
# File 'lib/prism/parse_result.rb', line 695

def warnings
  @warnings
end

Instance Method Details

#code_units_cache(encoding) ⇒ Object

Create a code units cache for the given encoding.


733
734
735
# File 'lib/prism/parse_result.rb', line 733

def code_units_cache(encoding)
  source.code_units_cache(encoding)
end

#deconstruct_keys(keys) ⇒ Object

Implement the hash pattern matching interface for Result.


711
712
713
# File 'lib/prism/parse_result.rb', line 711

def deconstruct_keys(keys)
  { comments: comments, magic_comments: magic_comments, data_loc: data_loc, errors: errors, warnings: warnings }
end

#encodingObject

Returns the encoding of the source code that was parsed.


716
717
718
# File 'lib/prism/parse_result.rb', line 716

def encoding
  source.encoding
end

#failure?Boolean

Returns true if there were errors during parsing and false if there were not.

Returns:

  • (Boolean)

728
729
730
# File 'lib/prism/parse_result.rb', line 728

def failure?
  !success?
end

#success?Boolean

Returns true if there were no errors during parsing and false if there were.

Returns:

  • (Boolean)

722
723
724
# File 'lib/prism/parse_result.rb', line 722

def success?
  errors.empty?
end