Class: YARP::ParseResult

Inherits:
Object
  • Object
show all
Defined in:
lib/yarp.rb,
ext/yarp/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.



171
172
173
174
175
176
177
# File 'lib/yarp.rb', line 171

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.



169
170
171
# File 'lib/yarp.rb', line 169

def comments
  @comments
end

#errorsObject (readonly)

Returns the value of attribute errors.



169
170
171
# File 'lib/yarp.rb', line 169

def errors
  @errors
end

#sourceObject (readonly)

Returns the value of attribute source.



169
170
171
# File 'lib/yarp.rb', line 169

def source
  @source
end

#valueObject (readonly)

Returns the value of attribute value.



169
170
171
# File 'lib/yarp.rb', line 169

def value
  @value
end

#warningsObject (readonly)

Returns the value of attribute warnings.



169
170
171
# File 'lib/yarp.rb', line 169

def warnings
  @warnings
end

Instance Method Details

#deconstruct_keys(keys) ⇒ Object



179
180
181
# File 'lib/yarp.rb', line 179

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

#failure?Boolean

Returns:

  • (Boolean)


187
188
189
# File 'lib/yarp.rb', line 187

def failure?
  !success?
end

#mark_newlinesObject



223
224
225
226
227
228
# File 'lib/yarp.rb', line 223

def mark_newlines
  newline_marked = Array.new(1 + @source.offsets.size, false)
  visitor = MarkNewlinesVisitor.new(newline_marked)
  value.accept(visitor)
  value
end

#success?Boolean

Returns:

  • (Boolean)


183
184
185
# File 'lib/yarp.rb', line 183

def success?
  errors.empty?
end