Sha256: 55075074d8a6727f95252ebca334e08e729eab37c846ab44cf96707b54fe9c09

Contents?: true

Size: 862 Bytes

Versions: 12

Compression:

Stored size: 862 Bytes

Contents

# = Macros
#
# A powerfull macro implementation for Ruby. Allows definition
# of new macro.
#
# EXPERIMENTAL, not fully working yet
#
# code: 
# George Moschovitis  <gm@navel.gr>
#
# (c) 2004 Navel, all rights reserved.
# $Id: macro.rb 165 2004-11-18 12:04:04Z gmosx $

$__macros__ = {}
$__required__ = {}

module Kernel

alias_method :old_require, :require
def require(path)
	return if $__required__[path]
	
	source = File.read(path)
	
	# parse macro
	source.gsub!(/defmacro\s*\/(.*?)\/\s(.*?)endmacro/m) {
		$__macros__[Regexp.new($1)] = $2 ; ""
	}
	
	# expand macros	
	$__macros__.each { |match, replace|
		source.gsub!(match, replace)
	}
	
	$__required__[path] = true

	eval(source)
end

end

require "nitro/test1.rb"
require "nitro/test2.rb"

__END__

Examples:

defmacro /my_macro\((.*)\)/
	begin 
		my_function(\1)
	rescue => ex
		puts ex
	end 
endmacro

Version data entries

12 entries across 12 versions & 2 rubygems

Version Path
nitro-0.8.0 lib/glue/macro.rb
nitro-0.9.5 lib/glue/macro.rb
nitro-0.6.0 lib/glue/macro.rb
nitro-0.9.3 lib/glue/macro.rb
nitro-0.5.0 lib/glue/macro.rb
nitro-0.7.0 lib/glue/macro.rb
og-0.6.0 lib/glue/macro.rb
og-0.8.0 lib/glue/macro.rb
og-0.9.3 lib/glue/macro.rb
og-0.9.5 lib/glue/macro.rb
og-0.5.0 lib/glue/macro.rb
og-0.7.0 lib/glue/macro.rb