Sha256: 3c84484cbc57c3b36606d69116b4597fe481a70fe7d950ffcc37ede47b6da73c

Contents?: true

Size: 809 Bytes

Versions: 1

Compression:

Stored size: 809 Bytes

Contents

module Qrb
  module Syntax
    module AdType
      include Support

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

      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

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

    end # module AdType
  end # module Syntax
end # module Qrb

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
qrb-0.3.0 lib/qrb/syntax/ad_type.rb