括弧の対応を取るパターンマッチ

toluaのソース読んでいたら"%b"なんてのがあった。入れ子になった括弧の対応を取ってくれるのでこりゃ便利だ。
http://www.lua.org/manual/5.1/manual.html#5.4.1
にはメタ文字の一覧から外れたところに、balanced parenthesesとして書いてある。

local code=[[
class Hoge
{
public:
    Hoge(bool is){
        if(is){
            //
        }
    };
};
]]

print(string.find(code, "(%b())"))
print(string.find(code, "(%b{})"))
30      38      (bool is)

12      89      {
public:
    Hoge(bool is){
        if(is){
            //
        }
    };
}