The Crystal Programming Language Forum

AST Node Interpolation outside of macro's

Considering the following code:

class Foo
  def bar
    {{ @type }}
  end
end

p (Foo.new).bar  # Foo : Class 

All the documentation I can find regarding AST interpolation was related to macros and I was surprised to see the above was valid. Is there any deeper documentation regarding the “{{ }}” syntax?

{{ }} and {% %} syntax are still macros. You do not need to be within a macro def to use it.

Yes, I see that now. I was interested if there were more docs on this than what is provided here?

edit: Additionally,

Macros are methods that receive AST nodes at compile-time and produce code that is pasted into a program.

Does that syntax really match that definition?

No, that description is incorrect. It matches to macro methods.

Yea, that helps. Thanks.