Class: RedSnow::ParseResult

Inherits:
Object
  • Object
show all
Defined in:
lib/redsnow/parseresult.rb

Overview

Parse Result

Constant Summary collapse

VERSION_KEY =

Version key

:_version
SUPPORTED_VERSIONS =

Supported version of Api Blueprint

['2.1']

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(report_handle, blueprint_handle, sourcemap_handle) ⇒ ParseResult

Returns a new instance of ParseResult.

Parameters:

  • report_handle (FFI::Pointer)


21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/redsnow/parseresult.rb', line 21

def initialize(report_handle, blueprint_handle, sourcemap_handle)
  @ast = Blueprint.new(blueprint_handle)
  @sourcemap = RedSnow::Sourcemap::Blueprint.new(sourcemap_handle)

  warnings = RedSnow::Binding.sc_warnings_handler(report_handle)
  warnings_size = RedSnow::Binding.sc_warnings_size(warnings)

  @warnings = []

  (0..(warnings_size - 1)).each do |index|
    sc_warning_handler = RedSnow::Binding.sc_warning_handler(warnings, index)

    warning = {}
    warning[:message] = RedSnow::Binding.sc_warning_message(sc_warning_handler)
    warning[:code] = RedSnow::Binding.sc_warning_code(sc_warning_handler)
    warning[:ok] = RedSnow::Binding.sc_warning_ok(sc_warning_handler)

    sc_location_handler = RedSnow::Binding.sc_location_handler(sc_warning_handler)
    sc_location_size = RedSnow::Binding.sc_location_size(sc_location_handler)
    warning[:location] = []

    if sc_location_size > 0
      (0..(sc_location_size - 1)).each do |index_size|
        warning[:location] << Location.new(sc_location_handler, index_size)
      end
    end
    @warnings << warning
  end

  error_handler = RedSnow::Binding.sc_error_handler(report_handle)
  @error = {}
  @error[:message] = RedSnow::Binding.sc_error_message(error_handler)
  @error[:code] = RedSnow::Binding.sc_error_code(error_handler)
  @error[:ok] = RedSnow::Binding.sc_error_ok(error_handler)

  sc_location_handler = RedSnow::Binding.sc_location_handler(error_handler)
  sc_location_size = RedSnow::Binding.sc_location_size(sc_location_handler)
  @error[:location] = []

  return if sc_location_size == 0

  (0..(sc_location_size - 1)).each do |index|
    @error[:location] << Location.new(sc_location_handler, index)
  end
end

Instance Attribute Details

#astObject

Returns the value of attribute ast.



9
10
11
# File 'lib/redsnow/parseresult.rb', line 9

def ast
  @ast
end

#errorObject

Returns the value of attribute error.



10
11
12
# File 'lib/redsnow/parseresult.rb', line 10

def error
  @error
end

#sourcemapObject

Returns the value of attribute sourcemap.



12
13
14
# File 'lib/redsnow/parseresult.rb', line 12

def sourcemap
  @sourcemap
end

#warningsObject

Returns the value of attribute warnings.



11
12
13
# File 'lib/redsnow/parseresult.rb', line 11

def warnings
  @warnings
end