Overhaul of command parsing
This commit is contained in:
@@ -8,23 +8,28 @@
|
||||
// 1. Print the prompt suggested by 'get_prompt'.
|
||||
// 2. Read a line of text from stdin.
|
||||
// 3. Add the line to the LuaConsole using 'add'.
|
||||
// 4. Get the command words using 'get_command'.
|
||||
// 4. Get the command word using get_command.
|
||||
// 5. If the command is empty, do nothing.
|
||||
// 6. If the command is nonempty, execute it.
|
||||
// 6. If the command is nonempty, get the args and execute it.
|
||||
//
|
||||
// The LuaConsole expects you to type one of three things:
|
||||
// The LuaConsole expects you to type a lua command, or one
|
||||
// of the following slash-commands:
|
||||
//
|
||||
// * Valid Lua Code.
|
||||
// * Valid Lua Code preceded by '=' as shorthand for 'return'
|
||||
// * A slash-command.
|
||||
// /quit - exit the program
|
||||
// /view - display the nearby tangibles
|
||||
// /menu [tanid] - display the menu for tangible
|
||||
// /snap - snapshot current state
|
||||
// /roll - rollback to previous state
|
||||
// /tick [timevalue] - advance the simulation clock
|
||||
// /1234 - choose menu item 1234
|
||||
//
|
||||
// The 'get_command' returned by the luaconsole can be one of
|
||||
// the following:
|
||||
// If you type anything else, the LuaConsole will generate a
|
||||
// syntax error. Note that not all of the commands above are
|
||||
// supported in all interpreters.
|
||||
//
|
||||
// empty vector - still collecting input: do nothing.
|
||||
// lua <expr> - found a lua command: execute it as lua.
|
||||
// syntax <words> - detected a syntax error: print the error.
|
||||
// word word ... - read a slash-command: execute the command.
|
||||
// Once a command has been typed (or a syntax error has been
|
||||
// typed), the LuaConsole will return the command. The command
|
||||
// can be fetched using command(), int_arg(), and str_arg()
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
|
||||
@@ -42,10 +47,12 @@ private:
|
||||
lua_State *lua_state_;
|
||||
std::string raw_input_;
|
||||
int lines_;
|
||||
StringVec words_;
|
||||
std::string prompt_;
|
||||
StringVec words_;
|
||||
|
||||
void clear_raw_input();
|
||||
void simplify(const StringVec &words);
|
||||
void synerr(const std::string &msg);
|
||||
|
||||
public:
|
||||
LuaConsole();
|
||||
@@ -57,15 +64,14 @@ public:
|
||||
//
|
||||
const std::string &get_prompt() { return prompt_; }
|
||||
|
||||
// Fetch the command to execute.
|
||||
// Get the command words.
|
||||
//
|
||||
// Note that the command words may not be exactly what
|
||||
// the user typed. Typically, the LuaConsole simplifies
|
||||
// the command before returning it to the caller.
|
||||
//
|
||||
// You should fetch the command after calling 'add'.
|
||||
// Returns the empty vector if there is no command.
|
||||
// If there is a command, the first word is the command word.
|
||||
// See the file comment for certain built-in command words.
|
||||
//
|
||||
StringVec get_command();
|
||||
|
||||
|
||||
// Add a line of text that was just read from the console.
|
||||
//
|
||||
void add(std::string line);
|
||||
|
||||
Reference in New Issue
Block a user