module Macro::DisableMacros

disable macro definitions within classes and modules

Public Instance Methods

macro_expand(macros,session) click to toggle source
# 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