13 void Parser::initParser()
19 void Parser::initAtom()
27 void Parser::parseAtom (QString s)
34 // Strip WS at beginning
35 re.setPattern ("\\w");
39 s=s.right(s.length()-pos);
42 re.setPattern ("\\b(.*)(\\s|\\()");
49 re.setPattern ("\\((.*)\\)");
51 //cout << " s="<<s.ascii()<<endl;
52 //cout << "com="<<com.ascii()<<" pos="<<pos<<endl<<endl;
61 while (pos<s.length())
71 if (s.at(pos)==',' && !inquote)
75 s=s.right(s.length()-pos-1);
86 QString Parser::getAtom()
91 QString Parser::getCommand()
96 QStringList Parser::getParameters()
101 int Parser::parCount()
103 return paramList.count();
107 QString Parser::errorMessage()
112 case NoError: l="No Error";
113 case Warning: l="Warning";
114 case Aborted: l="Aborted";
116 return QString ("Error Level: %1\n Command: %2\nDescription: %3")
117 .arg(l).arg(com).arg(errDescription);
120 QString Parser::errorDescription()
122 return errDescription;
125 ErrorLevel Parser::errorLevel()
130 void Parser::setError(ErrorLevel level, const QString &description)
132 errDescription=description;
136 void Parser::resetError ()
144 bool Parser::checkParCount (QList <int> plist)
148 for (int i=0; i<plist.count();i++)
150 if (checkParCount (plist[i]))
155 expList.append(QString().setNum(plist[i]));
157 expected=expList.join(",");
158 errDescription=QString("Wrong number of parameters: Expected %1, but found %2").arg(expected).arg(paramList.count());
162 bool Parser::checkParCount (const int &expected)
164 if (paramList.count()!=expected)
167 errDescription=QString("Wrong number of parameters: Expected %1, but found %2").arg(expected).arg(paramList.count());
173 bool Parser::checkParIsInt(const int &index)
176 if (index > paramList.count())
179 errDescription=QString("Parameter index %1 is outside of parameter list").arg(index);
183 paramList[index].toInt (&ok, 10);
187 errDescription=QString("Parameter %1 is not an integer").arg(index);
194 int Parser::parInt (bool &ok,const uint &index)
196 if (checkParIsInt (index))
197 return paramList[index].toInt (&ok, 10);
202 QString Parser::parString (bool &ok,const int &index)
204 // return the string at index, this could be also stored in
207 QRegExp re("\"(.*)\"");
208 int pos=re.search (paramList[index]);
217 bool Parser::parBool (bool &ok,const int &index)
219 // return the bool at index, this could be also stored in
223 QString p=paramList[index];
224 if (p=="true" || p=="1")
226 else if (p=="false" || p=="0")
232 QColor Parser::parColor(bool &ok,const int &index)
234 // return the QColor at index
238 QRegExp re("\"(.*)\"");
239 int pos=re.search (paramList[index]);
249 void Parser::setScript(const QString &s)
254 QString Parser::getScript()
259 void Parser::runScript()
267 if (current<0) runScript();
268 if (current>=script.length()-1) return false;
270 bool inBracket=false;
273 //cout <<"current="<<current<< " start="<<start<<" length="<<script.length()<<endl;
275 // Check if we are inside a string
276 if (script.at(current)=='"')
284 // Check if we are in a comment
285 if (!inBracket && script.at(current)=='#')
287 while (script.at(current)!='\n')
290 if (current>=script.length())
296 // Check for end of atom
297 if (!inBracket && script.at(current)==';')
299 atom=script.mid(start,current-start);
304 // Check for end of script
305 if (current==script.length() )
309 setError (Aborted,"Runaway string");
313 atom=script.mid(start);