LoginSignup
2
0

crystal tool expand でCrystalのマクロを展開する

Last updated at Posted at 2023-12-05

はじめに

完全にネタが尽きましたが、なにか書きます。

たとえば、次のようなCrystalのコードがあったとして、

piyo.cr
{% for i in 1..10 %}
  puts {{ i }}
{% end %}

実行すると、以下のように出力されます。

1
2
3
4
5
6
7
8
9
10

このマクロが実際にはどのように展開されているか知りたい場合はどうすればいいでしょうか?

crystal tool expand でマクロを展開する

こんなときには crystal tool expand コマンドを使います。

crystal tool expand -c piyo.cr:2:8 piyo.cr

ここで、 -c オプションで、ファイル名:行:列 を指定するのですが、マクロの範囲を指定しておけばだいたい動く印象です。

1 expansion found
expansion 1:
   {% for i in 1..10 %}
     puts {{ i }}
   {% end %}

~> puts(1)
   puts(2)
   puts(3)
   puts(4)
   puts(5)
   puts(6)
   puts(7)
   puts(8)
   puts(9)
   puts(10)

こんな感じでマクロが展開されました。

この記事は以上です。

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0