1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-23 22:37:55 +02:00

Interactive mode for ERM interpreter.

This commit is contained in:
Michał W. Urbańczyk
2011-06-23 21:42:30 +00:00
parent 3f85ca4504
commit d88b6b1bb3
5 changed files with 40 additions and 5 deletions

View File

@@ -1470,7 +1470,12 @@ struct LineExec : boost::static_visitor<>
void ERMInterpreter::executeLine( const LinePointer & lp ) void ERMInterpreter::executeLine( const LinePointer & lp )
{ {
tlog0 << "Executing line nr " << getRealLine(lp.lineNum) << " (internal " << lp.lineNum << ") from " << lp.file->filename << std::endl; 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 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) void ERMInterpreter::executeUserCommand(const std::string &cmd)
{ {
tlog0 << "ERM here: received command: " << cmd << std::endl; 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) void ERMInterpreter::giveInfoCB(CPrivilagedInfoCallback *cb)

View File

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

View File

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

View File

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

View File

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