# encoding: utf-8 # frozen_string_literal: true module Carbon module Compiler class Directive ATTACHING = %w(doc extern).freeze def self.handlers @_handlers ||= {} end def self.handle(name, &block) handlers[name.to_s] = block end require "carbon/compiler/directive/import" def initialize(node, file, index) @node = node @file = file @index = index end def call instance_exec(&self.class.handlers.fetch(name.to_s)) end def name @node.value end def attach? ATTACHING.include?(name) end private def error_excessive_parameters(node, expected) @file.emit("Directive/Parameter/Excessive", node.location, [expected, node.parameters.size]) end def error_invalid_parameter(parameter) @file.emit("Directive/Parameter/Invalid", parameter.location) end end end end