簡単なパーサーを書いているとします。入力式のタイプに応じて、対応する解析関数を呼び出すディスパッチャがあります。
def dispatcher(expression):
m = pattern1.match(expression):
if m is not None:
handle_type1(expression, m)
# ... other types
私の質問は、マッチングとチェックを組み合わせる方法はありNone
ますか? つまり、次の C コードのようなものです。
void dispatcher(char *expression)
{
if ((m = pattern1.match(expression)) != NULL) {
// ... handle expression type 1
}
else if ((m = pattern2.match(expression)) != NULL) {
// ... handle expression type 2
}
// ... other cases
}
ありがとう!