Overhaul of command parsing
This commit is contained in:
@@ -38,6 +38,65 @@ LuaConsole::StringVec LuaConsole::get_command() {
|
||||
return result;
|
||||
}
|
||||
|
||||
void LuaConsole::synerr(const std::string &msg) {
|
||||
words_.clear();
|
||||
words_.push_back("syntax");
|
||||
words_.push_back(msg);
|
||||
}
|
||||
|
||||
void LuaConsole::simplify(const StringVec &words) {
|
||||
words_ = words;
|
||||
if (words.size() == 0) {
|
||||
return;
|
||||
} else if (util::validinteger(words[0])) {
|
||||
if (words.size() == 1) {
|
||||
words_.clear();
|
||||
words_.push_back("choose");
|
||||
words_.push_back(words[0]);
|
||||
} else {
|
||||
synerr("/choose command takes no arguments");
|
||||
}
|
||||
} else if (words[0] == "choose") {
|
||||
if ((words.size() == 2)&&(util::validinteger(words[1]))) {
|
||||
// OK
|
||||
} else {
|
||||
synerr("/choose [menu-line-number]");
|
||||
}
|
||||
} else if (words[0] == "view") {
|
||||
if (words.size() != 1) {
|
||||
synerr("/view takes no arguments");
|
||||
}
|
||||
} else if (words[0] == "menu") {
|
||||
if (words.size() == 1) {
|
||||
words_.push_back("-");
|
||||
} else if ((words.size() == 2)&&(util::validinteger(words[1]))) {
|
||||
// OK
|
||||
} else {
|
||||
synerr("/menu [optional-tangible-id]");
|
||||
}
|
||||
} else if (words[0] == "quit") {
|
||||
if (words.size() != 1) {
|
||||
synerr("/quit takes no arguments");
|
||||
}
|
||||
} else if (words[0] == "snap") {
|
||||
if (words.size() != 1) {
|
||||
synerr("/snap takes no arguments");
|
||||
}
|
||||
} else if (words[0] == "roll") {
|
||||
if (words.size() != 1) {
|
||||
synerr("/roll takes no arguments");
|
||||
}
|
||||
} else if (words[0] == "tick") {
|
||||
if ((words.size() == 2)&&(util::validinteger(words[1]))) {
|
||||
// OK
|
||||
} else {
|
||||
synerr("/tick [optional-timestamp]");
|
||||
}
|
||||
} else {
|
||||
synerr("unrecognized command");
|
||||
}
|
||||
}
|
||||
|
||||
void LuaConsole::clear_raw_input() {
|
||||
raw_input_ = "";
|
||||
lines_ = 0;
|
||||
@@ -52,10 +111,11 @@ void LuaConsole::add(std::string line) {
|
||||
raw_input_ += '\n';
|
||||
lines_ += 1;
|
||||
prompt_ = ">> ";
|
||||
words_.clear();
|
||||
|
||||
// Try to interpret it as a slash-command.
|
||||
if ((lines_ == 1)&&(raw_input_[0] == '/')) {
|
||||
words_ = split_words(raw_input_.substr(1));
|
||||
simplify(split_words(raw_input_.substr(1)));
|
||||
clear_raw_input();
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user