Class: Prism::ParseResult

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

Instance Method Summary collapse

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

#commentsObject (readonly)

Returns the value of attribute comments.



209
210
211
# File 'lib/prism/parse_result.rb', line 209

def comments
  @comments
end

#errorsObject (readonly)

Returns the value of attribute errors.



209
210
211
# File 'lib/prism/parse_result.rb', line 209

def errors
  @errors
end

#sourceObject (readonly)

Returns the value of attribute source.



209
210
211
# File 'lib/prism/parse_result.rb', line 209

def source
  @source
end

#valueObject (readonly)

Returns the value of attribute value.



209
210
211
# File 'lib/prism/parse_result.rb', line 209

def value
  @value
end

#warningsObject (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

Returns:

  • (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

Returns:

  • (Boolean)


223
224
225
# File 'lib/prism/parse_result.rb', line 223

def success?
  errors.empty?
end