可能な順列ごとに具体的なパターンマッチングを行わずに、複数のオプショナルを処理する方法を知りたいです。
以下は、私が直面している問題の簡単な例です。
lexical Int = [0-9]+;
syntax Bool = "True" | "False";
syntax Period = "Day" | "Month" | "Quarter" | "Year";
layout Standard = [\ \t\n\f\r]*;
syntax Optionals = Int? i Bool? b Period? p;
str printOptionals(Optionals opt){
str res = "";
if(!isEmpty("<opt.i>")) { // opt has i is always true (same for opt.i?)
res += printInt(opt.i);
}
if(!isEmpty("<opt.b>")){
res += printBool(opt.b);
}
if(!isEmpty("<opt.p>")) {
res += printPeriod(opt.period);
}
return res;
}
str printInt(Int i) = "<i>";
str printBool(Bool b) = "<b>";
str printPeriod(Period p) = "<p>";
ただし、これによりエラーメッセージが表示されます。
The called signature: printInt(opt(lex("Int"))), does not match the declared signature: str printInt(sort("Int"));
opt 部分があることがわかっている場合、どうすればそれを取り除くことができますか?