Bläddra i källkod

Interactive mode for ERM interpreter.

Michał W. Urbańczyk 14 år sedan
förälder
incheckning
d88b6b1bb3

+ 23 - 1
Scripting/ERM/ERMInterpreter.cpp

@@ -1470,7 +1470,12 @@ struct LineExec : boost::static_visitor<>
 void ERMInterpreter::executeLine( const LinePointer & lp )
 {
 	tlog0 << "Executing line nr " << getRealLine(lp.lineNum) << " (internal " << lp.lineNum << ") from " << lp.file->filename << std::endl;
-	boost::apply_visitor(LineExec(), scripts[lp]);
+	executeLine(scripts[lp]);
+}
+
+void ERMInterpreter::executeLine(const ERM::TLine &line)
+{
+	boost::apply_visitor(LineExec(), line);
 }
 
 IexpValStr ERMInterpreter::getVar(std::string toFollow, boost::optional<int> initVal) const
@@ -2739,6 +2744,23 @@ VOptionList ERMInterpreter::evalEach( VermTreeIterator list, Environment * env /
 void ERMInterpreter::executeUserCommand(const std::string &cmd)
 {
 	tlog0 << "ERM here: received command: " << cmd << std::endl;
+	if(cmd.size() < 3)
+	{
+		tlog1 << "That can't be a valid command...\n";
+		return;
+	}
+	try
+	{
+		if(cmd[0] == '!') //should be a neat (V)ERM command
+		{
+			ERM::TLine line = ERMParser::parseLine(cmd);
+			executeLine(line);
+		}
+	}
+	catch(std::exception &e)
+	{
+		tlog1 << "Failed executing user command! Exception info:\n\t" << e.what() << std::endl;
+	}
 }
 
 void ERMInterpreter::giveInfoCB(CPrivilagedInfoCallback *cb)

+ 1 - 0
Scripting/ERM/ERMInterpreter.h

@@ -808,6 +808,7 @@ class ERMInterpreter : public CScriptingModule
 	static const std::string triggerSymbol, postTriggerSymbol, defunSymbol;
 
 	void executeLine(const VERMInterpreter::LinePointer & lp);
+	void executeLine(const ERM::TLine &line);
 	void executeTrigger(VERMInterpreter::Trigger & trig, int funNum = -1, std::vector<int> funParams=std::vector<int>());
 	static bool isCMDATrigger(const ERM::Tcommand & cmd);
 	static bool isATrigger(const ERM::TLine & line);

+ 14 - 2
Scripting/ERM/ERMParser.cpp

@@ -479,6 +479,19 @@ namespace ERM
 };
 
 ERM::TLine ERMParser::parseLine( const std::string & line, int realLineNo )
+{
+	try
+	{
+		return parseLine(line);
+	}
+	catch(...)
+	{
+		tlog1 << "\tParse error occurred in file " << srcFile << " (line " << realLineNo << ") :\n" << line << std::endl;
+		throw;
+	}
+}
+
+ERM::TLine ERMParser::parseLine(const std::string & line)
 {
 	std::string::const_iterator beg = line.begin(),
 		end = line.end();
@@ -489,8 +502,7 @@ ERM::TLine ERMParser::parseLine( const std::string & line, int realLineNo )
 	bool r = qi::phrase_parse(beg, end, ERMgrammar, ascii::space, AST);
 	if(!r || beg != end)
 	{
-		tlog1 << "Parse error in file " << srcFile << " (line " << realLineNo << ") :\n" << line << std::endl;
-		tlog1 << "\tCannot parse: " << std::string(beg, end) << std::endl;
+		tlog1 << "Parse error: cannot parse: " << std::string(beg, end) << std::endl;
 		throw ParseErrorException();
 	}
 	return AST;

+ 1 - 0
Scripting/ERM/ERMParser.h

@@ -265,4 +265,5 @@ private:
 public:
 	ERMParser(std::string file);
 	std::vector<LineInfo> parseFile();
+	static ERM::TLine parseLine(const std::string & line);
 };

+ 1 - 2
client/CMT.cpp

@@ -328,8 +328,7 @@ void processCommand(const std::string &message)
 			tlog0 << "erm>";
 		}
 	}
-
-	if(message==std::string("die, fool"))
+	else if(message==std::string("die, fool"))
 	{
 		exit(EXIT_SUCCESS);
 	}