Class: Macros::Loader

Inherits:
Object
  • Object
show all
Includes:
Sexp
Defined in:
lib/macros/loader.rb

Instance Method Summary collapse

Methods included from Sexp

#node?, #s, #seval, #sfind, #smatch?, #treefilter, #treemap

Constructor Details

#initializeLoader

Returns a new instance of Loader.



5
6
7
8
9
# File 'lib/macros/loader.rb', line 5

def initialize
  @compiler = Macros::Compiler.new
  @macros   = {}
  @expander = Macros::Expander.new(@macros)
end

Instance Method Details

#load(pathname) ⇒ Object



24
25
26
27
28
29
# File 'lib/macros/loader.rb', line 24

def load(pathname)
  ast = Macros.parse pathname.read
  @macros.merge! @compiler.collect_defmacros(ast)
  rest_ast = @compiler.reject_defmacros(ast)
  MAIN.instance_eval Unparser.unparse @expander.macroexpand(rest_ast)
end

#require(name) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/macros/loader.rb', line 11

def require(name)
  $LOAD_PATH.each do |p|
    rb_file = (Pathname(p) + "#{name}.rb")

    if rb_file.file?
      unless $".include? rb_file.to_s
        load(rb_file)
        $" << rb_file.to_s
      end
    end
  end
end