GPL V2. Added settings to documentation
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 bool Parser::checkParIsDouble(const int &index)
197 if (index > paramList.count())
200 errDescription=QString("Parameter index %1 is outside of parameter list").arg(index);
204 paramList[index].toDouble (&ok);
208 errDescription=QString("Parameter %1 is not double").arg(index);
215 int Parser::parInt (bool &ok,const uint &index)
217 if (checkParIsInt (index))
218 return paramList[index].toInt (&ok, 10);
223 QString Parser::parString (bool &ok,const int &index)
225 // return the string at index, this could be also stored in
228 QRegExp re("\"(.*)\"");
229 int pos=re.search (paramList[index]);
238 bool Parser::parBool (bool &ok,const int &index)
240 // return the bool at index, this could be also stored in
244 QString p=paramList[index];
245 if (p=="true" || p=="1")
247 else if (p=="false" || p=="0")
253 QColor Parser::parColor(bool &ok,const int &index)
255 // return the QColor at index
259 QRegExp re("\"(.*)\"");
260 int pos=re.search (paramList[index]);
270 double Parser::parDouble (bool &ok,const int &index)
272 if (checkParIsDouble (index))
273 return paramList[index].toDouble (&ok);
278 void Parser::setScript(const QString &s)
283 QString Parser::getScript()
288 void Parser::runScript()
296 if (current<0) runScript();
297 if (current>=script.length()-1) return false;
299 bool inBracket=false;
302 //cout <<"current="<<current<< " start="<<start<<" length="<<script.length()<<endl;
304 // Check if we are inside a string
305 if (script.at(current)=='"')
313 // Check if we are in a comment
314 if (!inBracket && script.at(current)=='#')
316 while (script.at(current)!='\n')
319 if (current>=script.length())
325 // Check for end of atom
326 if (!inBracket && script.at(current)==';')
328 atom=script.mid(start,current-start);
333 // Check for end of script
334 if (current==script.length() )
338 setError (Aborted,"Runaway string");
342 atom=script.mid(start);