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.



181
182
183
184
185
186
187
# File 'lib/yarp.rb', line 181

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.



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

def comments
  @comments
end

#errorsObject (readonly)

Returns the value of attribute errors.



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

def errors
  @errors
end

#sourceObject (readonly)

Returns the value of attribute source.



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

def source
  @source
end

#valueObject (readonly)

Returns the value of attribute value.



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

def value
  @value
end

#warningsObject (readonly)

Returns the value of attribute warnings.



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

def warnings
  @warnings
end

Instance Method Details

#deconstruct_keys(keys) ⇒ Object



189
190
191
# File 'lib/yarp.rb', line 189

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

#failure?Boolean

Returns:

  • (Boolean)


197
198
199
# File 'lib/yarp.rb', line 197

def failure?
  !success?
end

#mark_newlinesObject



233
234
235
236
237
238
# File 'lib/yarp.rb', line 233

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)


193
194
195
# File 'lib/yarp.rb', line 193

def success?
  errors.empty?
end

#with_source(source) ⇒ Object

Construct a new ParseResult with the same internal values, but with the given source.



242
243
244
# File 'lib/yarp.rb', line 242

def with_source(source)
  ParseResult.new(value, comments, errors, warnings, source)
end