Class: Blender3d::GenericFieldParser

Inherits:
Object
  • Object
show all
Defined in:
lib/blender-3d/generic_field_parser.rb

Constant Summary collapse

FUNCTION_POINTER =
/^\(\*([^\)]+)\)\(\)$/
POINTER_ARRAY =
/^\*([^\[]+)\[(\d+)\]$/
MULTI_POINTER =
/^\*{2}(.+)$/
POINTER =
/^\*(.+)$/
MULTI_ARRAY =
/^([^\[]+)\[(\d+)\]\[(\d+)\]$/
ARRAY =
/^([^\[]+)\[(\d+)\]$/

Instance Method Summary collapse

Constructor Details

#initialize(type, name) ⇒ GenericFieldParser

Returns a new instance of GenericFieldParser.



10
11
12
# File 'lib/blender-3d/generic_field_parser.rb', line 10

def initialize(type, name)
  @type, @name = type, name
end

Instance Method Details

#parseObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/blender-3d/generic_field_parser.rb', line 14

def parse
  type = case @name
    when FUNCTION_POINTER
      FunctionPointerType.new(@type)

    when POINTER_ARRAY
      array_size = $2.to_i
      ArrayType.new(build_pointer_type, array_size)

    when MULTI_POINTER
      PointerType.new(build_pointer_type)

    when POINTER
      build_pointer_type

    when MULTI_ARRAY
      array1_size, array2_size = $2.to_i, $3.to_i
      ArrayType.new(ArrayType.new(build_simple_type, array2_size), array1_size)

    when ARRAY
      array_size = $2.to_i
      ArrayType.new(build_simple_type, array_size)

    else
      build_simple_type

  end

  name = $1 || @name
  Field.new(type, name)
end