Template Toolkit

Template Toolkit

[3] Template Toolkit (TT) は、 Perl で使われているテンプレートエンジンです。

メモ

[4] かつては大人気でしたが、今は他のエンジンに押されて下火のようです。

[1] Template Toolkit における演算子の優先順位を調べる TT テンプレート。微妙に結果が変だったり、 < とか > とか <= とか != とかがなぜか機能しませんが、大体正しい結果がでてくるっぽいです。

<http://suika.fam.cx/~wakaba/-temp/test/tt/tools/live?s=%5B%25-+MACRO+cmp%28x%2Cy%29+BLOCK+-%25%5D%0D%0A++%5B%25-+v1+%3D+%22%5B%25+a+%24x+b+%24y+c+%25%22+_+%22%5D%22+%7C+eval+-%25%5D%0D%0A++%5B%25-+v2+%3D+%22%5B%25+t+%3D+a+%24x+b%3B+t+%24y+c+%25%22+_+%22%5D%22+%7C+eval+-%25%5D%0D%0A++%5B%25-+v3+%3D+%22%5B%25+t+%3D+b+%24y+c%3B+a+%24x+t+%25%22+_+%22%5D%22+%7C+eval+-%25%5D%0D%0A++%5B%25-+IF+v1+%3D%3D+v2+AND+v1+%3D%3D+v3+-%25%5D%0D%0A++++%5B%25-+0+-%25%5D%0D%0A++%5B%25-+ELSE+-%25%5D%0D%0A++++%5B%25-+IF+v1+%3D%3D+v2+-%25%5D%0D%0A++++++%5B%25-+1+-%25%5D%0D%0A++++%5B%25-+END+-%25%5D%0D%0A++++%5B%25-+IF+v1+%3D%3D+v3+-%25%5D%0D%0A++++++%5B%25-+-1+-%25%5D%0D%0A++++%5B%25-+END+-%25%5D%0D%0A++%5B%25-+END+-%25%5D%0D%0A%5B%25-+END+-%25%5D%0D%0A%5B%25-+MACRO+result%28r%2C+x%2C+y%29+BLOCK+-%25%5D%0D%0A++%5B%25-+r+%3D%3D+-1+%3F+%22%24x+%3C+%24y%22+%3A+r+%3D%3D+1+%3F+%22%24x+%3E+%24y%22+%3A+%22%24x+%3D%3D+%24y%22+-%25%5D%0D%0A%5B%25-+END+-%25%5D%0D%0A%5B%25-+MACRO+resultdir+%28r%2C+x%2C+y%29+BLOCK+-%25%5D%0D%0A++%5B%25-+r+%3D%3D+-1+%3F+%27%3C%27+%3A+r+%3D%3D+1+%3F+%27%3E%27+%3A+%27%3D%3D%27+-%25%5D%0D%0A%5B%25-+END+-%25%5D%0D%0A%5B%25-+MACRO+opcmp%28x%2C+y%29+BLOCK+-%25%5D%0D%0A++%5B%25-+a+%3D+7%3B+b+%3D+213%3B+c+%3D+18.9+-%25%5D%0D%0A++%5B%25-+r1+%3D+cmp%28x%2C+y%29%3B+r2+%3D+cmp%28y%2C+x%29+-%25%5D%0D%0A++%5B%25-+IF+r1+%3D%3D+-1+*+r2+-%25%5D%0D%0A++++%5B%25-+r1+-%25%5D%0D%0A++%5B%25-+ELSE+-%25%5D%0D%0A++++%5B%25-+IF+r1+*+r2+%3D%3D+0+-%25%5D%0D%0A++++++%5B%25-+0+-%25%5D%0D%0A++++%5B%25-+ELSE+-%25%5D%0D%0A++++++%5B%25-+%22%21%21+can%27t+determine+precedence+of+%24r1+and+%24r2%22+-%25%5D%0D%0A++++%5B%25-+END+-%25%5D%0D%0A++%5B%25-+END+-%25%5D%0D%0A%5B%25-+END+-%25%5D%0D%0A%5B%25-+MACRO+insert%28l%2C+newOp%29+BLOCK+-%25%5D%0D%0A++%5B%25-+inserted+%3D+0+-%25%5D%0D%0A++%5B%25-+iMax+%3D+l.size+-+1+-%25%5D%0D%0A++%5B%25-+FOREACH+i+IN+%5B0..iMax%5D+-%25%5D%0D%0A++++%5B%25-+item+%3D+l.%24i+-%25%5D%0D%0A++++%5B%25-+IF+opcmp%28item%2C+newOp%29+%3E+0+-%25%5D%0D%0A++++++%5B%25-+undef+%3D+list.splice%28i%2C+0%2C+newOp%29+-%25%5D%0D%0A++++++%5B%25-+inserted+%3D+1+-%25%5D%0D%0A++++++%5B%25-+LAST+-%25%5D%0D%0A++++%5B%25-+END+-%25%5D%0D%0A++%5B%25-+END+-%25%5D%0D%0A++%5B%25-+UNLESS+inserted+-%25%5D%0D%0A++++%5B%25-+list.push+%28newOp%29+-%25%5D%0D%0A++%5B%25-+END+-%25%5D%0D%0A%5B%25-+END+-%25%5D%0D%0A%5B%25-+MACRO+print_list+%28l%29+BLOCK+-%25%5D%0D%0A++%5B%25-+iMax+%3D+l.size+-+1+-%25%5D%0D%0A++%5B%25-+%27%22%27+_+l.0+_+%27%22%27+-%25%5D%0D%0A++%5B%25-+FOREACH+i+IN+%5B1..iMax%5D+-%25%5D%0D%0A++++%5B%25-+h+%3D+i+-+1+-%25%5D%0D%0A++++%5B%25-+%27+%27%3B+resultdir%28opcmp%28l.%24h%2C+l.%24i%29%2C+l.%24h%2C+l.%24i%29%3B+%27+%22%27%3B+l.%24i%3B+%27%22%27+-%25%5D%0D%0A++%5B%25-+END+-%25%5D%0D%0A%5B%25-+END+-%25%5D%0D%0A%5B%25-+%23result%28r%2C+x%2C+y%29+-%25%5D%0D%0A%0D%0A%5B%25-+list+%3D+%5B%5D+-%25%5D%0D%0A%5B%25-+ops+%3D+%27%26%26+%7C%7C+and+or+%2B+-+*+%2F+%25+div+mod+%26%26+%7C%7C+and+or+_+%3D%3D+%3C%3D+or+%7C%7C+_+%2B%27+-%25%5D%0D%0A%5B%25-+FOREACH+op+IN+ops.split%28%27+%27%29+-%25%5D%0D%0A++%5B%25-+insert+%28list%2C+op%29+-%25%5D%0D%0A%5B%25-+END+-%25%5D%0D%0A%5B%25-+print_list+%28list%29+-%25%5D%0D%0A>

"&&" == "||" == "and" == "or" == "or" == "||" < "==" == "<=" < "+" == "-" == "_" == "_" == "+" < "*" == "/" == "%" == "||" == "or" < "div" == "mod" == "&&" == "and"

[2] Input:

[%!1+1%]

Result:

1