Module: Macro::DisableMacros

Included in:
ClassNode, ModuleNode
Defined in:
lib/macro.rb

Overview

disable macro definitions within classes and modules

Instance Method Summary collapse

Instance Method Details

#macro_expand(macros, session) ⇒ Object



613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
# File 'lib/macro.rb', line 613

def macro_expand(macros,session)
   old_unsure=session[:@modpath_unsure]
   old_namespace_type=session[:@namespace_type]
   session[:@namespace_type]=self.class
   name=self.name.dup
   if Node===name
     case name.first
     when String; #name contains only constant(s), do nothing
     when nil  #name in an absolute namespace
       name.shift
       old_modpath=session[:@modpath]
       session[:@modpath]=[]
     else      #name in a dynamic namespace
       name.shift
       session[:@modpath_unsure]=true
     end
     unwind=name.size
   else
     unwind=1
   end
   session[:@modpath].push( *name )

   map!{|n| 
       case n
       when nil
       when Node; Macro.expand(n,macros,session)
       when Array; n.map!{|nn| Macro.expand(nn,macros,session) }
       else fail
       end
   }

   if old_modpath
     session[:@modpath]=old_modpath
   else
     unwind.times{ session[:@modpath].pop }
   end
   session[:@namespace_type]=old_namespace_type
   session[:@modpath_unsure]=old_unsure

   return nil,false #halt further recursion: already done
end