diff -r c2ffbc9b832d -r f867269ab8a1 parser.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/parser.cpp Mon Mar 05 23:22:51 2007 +0000 @@ -0,0 +1,234 @@ +#include "parser.h" + +#include +#include + +using namespace std; + +Parser::Parser() +{ + initCommand(); +} + +void Parser::initCommand() +{ + com=""; + paramList.clear(); + resetError(); +} + +void Parser::parseAtom (const QString &s) +{ + initCommand(); + input=s; + QRegExp re; + int pos; + + // Get command + re.setPattern ("\\b(.*)(\\s|\\()"); + re.setMinimal (true); + pos=re.search (s); + if (pos>=0) + com=re.cap(1); + + // Get parameters + paramList.clear(); + re.setPattern ("\\((.*)\\)"); + pos=re.search (s); + //cout << " s="< plist) +{ + QStringList expList; + QString expected; + for (int i=0; i paramList.count()) + { + errLevel=Aborted; + errDescription=QString("Parameter index %1 is outside of parameter list").arg(index); + return false; + } else + { + paramList[index].toInt (&ok, 10); + if (!ok) + { + errLevel=Aborted; + errDescription=QString("Parameter %1 is not an integer").arg(index); + return false; + } + } + return true; +} + +int Parser::parInt (bool &ok,const uint &index) +{ + if (checkParamIsInt (index)) + return paramList[index].toInt (&ok, 10); + ok=false; + return 0; +} + +QString Parser::parString (bool &ok,const int &index) +{ + // return the string at index, this could be also stored in + // a variable later + QString r; + QRegExp re("\"(.*)\""); + int pos=re.search (paramList[index]); + if (pos>=0) + r=re.cap (1); + else + r=""; + ok=true; + return r; +} + +bool Parser::parBool (bool &ok,const int &index) +{ + // return the bool at index, this could be also stored in + // a variable later + QString r; + ok=true; + QString p=paramList[index]; + if (p=="true" || p=="1") + return true; + else if (p=="false" || p=="0") + return false; + ok=false; + return ok; +} + +QColor Parser::parColor(bool &ok,const int &index) +{ + // return the QColor at index + ok=true; + return QColor (paramList[index]); +} + +void Parser::setScript(const QString &s) +{ + script=s; +} + +QString Parser::getScript() +{ + return script; +} + +void Parser::startScript() +{ +} +