Skip to content

Instantly share code, notes, and snippets.

@Ragmaanir
Created March 28, 2016 22:31
Show Gist options
  • Save Ragmaanir/e58c4092486bc15e81f7 to your computer and use it in GitHub Desktop.
Save Ragmaanir/e58c4092486bc15e81f7 to your computer and use it in GitHub Desktop.
puts `crystal eval "#{ARGV[0]}"`
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
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