このメソッドを実行するたびに、出力されたエラー メッセージが返され続けます。例: ユーザー入力:
display <table.txt> sortedby <ID>
これは、表示関数を呼び出すときにユーザーに使用してもらいたい正しい構文です。しかし、ユーザーが正しい構文を使用して表示すると、指定したエラー メッセージが出力されます。
Syntax error: display <intable> sortedby <col_name>
全体として、この方法では、テーブルをきれいな形式で表示したいと考えています。しかし、if ステートメントを通過しません。error_message を返す可能性のある見落としがあるかどうか疑問に思っていました。
void display(Lexer lexer) {
Table table; // create a table from the created table class
vector<Token> tokvec = lexer.tokenize();
// expect [IDENT | STRING] sortedby IDENT
if (tokvec.size() != 4 ||
(tokvec[0].type != IDENT && tokvec[1].type != STRING) ||
tokvec[2].value != "sortedby" || tokvec[3].type != IDENT){
error_return("Syntax error: display <intable> sortedby <col_name>");
return;
}
string fn = tokvec[1].value; // name of the file
string col_name = tokvec[3].value;
table.set_input(fn);
table.scan_input();
table.set_index(col_name);
table.sort();
table.display();
}