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