Module: Qrb::Syntax::AdType

Includes:
Support
Defined in:
lib/qrb/syntax/ad_type.rb

Instance Method Summary collapse

Methods included from Support

#resolve_ruby_const

Instance Method Details

#compile(factory) ⇒ Object



6
7
8
9
10
# File 'lib/qrb/syntax/ad_type.rb', line 6

def compile(factory)
  name  = builtin_type_name
  clazz = name ? resolve_ruby_const(name.to_s) : nil
  factory.adt(clazz, compile_contracts(factory, clazz))
end

#compile_contracts(factory, clazz) ⇒ Object



12
13
14
15
16
17
18
19
20
21
# File 'lib/qrb/syntax/ad_type.rb', line 12

def compile_contracts(factory, clazz)
  contracts = {}
  captures[:contract].each do |node|
    contract = node.compile(factory, clazz)
    contracts.merge!(contract) do |k,_,_|
      raise Error, "Duplicate contract name `#{k}`"
    end
  end
  contracts
end

#to_astObject



23
24
25
26
27
28
# File 'lib/qrb/syntax/ad_type.rb', line 23

def to_ast
  [ 
    :ad_type,
    builtin_type_name ? builtin_type_name.to_s : nil
  ] + captures[:contract].map(&:to_ast)
end