There’s no way for the parser to know that the argument to introspect is supposed to be evaluated in the type grammar. It’s just parsed as a call to method Bool.| with argument String.
As a workaround, you can use Union(String, Int32) to express that it’s a type. Even Union(String | Int32) works. You could even use that to wrap the macro argument (Union({{ klass }})) and thus allow introspect Bool | String.
So one final issue that is eluding me, I’m trying to parse JSON::Serializable objects
{% properties = {} of Nil => Nil %}
{% for ivar in klass.instance_vars %}
{% ann = ivar.annotation(::JSON::Field) %}
{% unless ann && (ann[:ignore] || ann[:ignore_deserialize]) %}
{% properties[((ann && ann[:key]) || ivar).id] = ivar.type %}
{% end %}
{% end %}
{% if properties.empty? %}
{ type: "object" }
{% else %}
{type: "object", properties: {
{% for key, ivar in properties %}
{{key}}: introspect({{ivar}}),
{% end %}
}, required: [
{% for key, ivar in properties %}
{% if !ivar.type.nilable? %}
{{key.stringify}},
{% end %}
{% end %}
] of String}
{% end %}
module ::Introspect
def __generate_json_schema__
{% begin %}
{% puts "\n\nprocessing JSON::Serializable for #{@type.name}" %}
{% puts "Class: #{@type.instance_vars.map(&.name.stringify)}" %}
{% puts "Instance: #{@type.instance.instance_vars.map(&.name)}\n" %}
{% end %}
end
end
module JSON::Serializable
macro included
extend Introspect
end
end