Created
March 28, 2016 22:31
-
-
Save Ragmaanir/e58c4092486bc15e81f7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
puts `crystal eval "#{ARGV[0]}"` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Makrokode | |
macro crystal_macro(*args, &block) | |
{% arr = "" %} | |
{% for a,i in args %} | |
{% arr += "#{a.id}" %} | |
{% arr += "," if i < args.size-1 %} | |
{% end %} | |
{% arr += "" %} | |
{% | |
body = "#{yield}".id | |
str = "def m(*args); #{body.id}; end; m(#{arr.id})".gsub(/"/, "\\\"") | |
x = run("./makrokode/eval_macro.cr", str) | |
%} | |
puts {{str}} | |
{{x}} | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "./spec_helper" | |
describe Makrokode do | |
it "works" do | |
f = Makrokode.crystal_macro({1,2,{"3",{4}}}) do | |
#puts "{"+args[0].to_s.gsub("{", "").gsub("}", "")+"}" | |
puts args[0] | |
end | |
p typeof(f) | |
p f | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment