class Bade::AST::NodeRegistrator

Public Class Methods

create(type, lineno) click to toggle source

Method to create node backing instance

@param [Symbol] type type of the node @param [Fixnum] lineno line number of the node appearance

@return [Bade::AST::Node]

# File lib/bade/ast/node_registrator.rb, line 41
def create(type, lineno)
  klass = registered_types[type]

  raise ::KeyError, "Undefined node type #{type.inspect}" if klass.nil?

  klass.new(type, lineno: lineno)
end
register_type(klass, type) click to toggle source

Method to map some node type to backing node class

@param [Symbol] type type of the node @param [Class] klass registering class

@return [nil]

# File lib/bade/ast/node_registrator.rb, line 28
def register_type(klass, type)
  raise StandardError, "Class #{klass} should be subclass of #{Node}" unless klass <= Node

  registered_types[type] = klass
end
registered_types() click to toggle source

@return [Hash<Symbol, Class>]

# File lib/bade/ast/node_registrator.rb, line 17
def registered_types
  @registered_types ||= {}
end