13 void Parser::initParser()
19 void Parser::initAtom()
27 void Parser::parseAtom (QString s)
34 cout << "parseAtom s="<<s.ascii()<<endl;
36 // Strip WS at beginning
37 re.setPattern ("\\w");
41 s=s.right(s.length()-pos);
44 re.setPattern ("\\b(.*)(\\s|\\()");
51 re.setPattern ("\\((.*)\\)");
53 //cout << " s="<<s.ascii()<<endl;
54 //cout << "com="<<com.ascii()<<" pos="<<pos<<endl<<endl;
63 while (pos<s.length())
73 if (s.at(pos)==',' && !inquote)
77 s=s.right(s.length()-pos-1);
88 QString Parser::getAtom()
93 QString Parser::getCommand()
98 QStringList Parser::getParameters()
103 int Parser::parCount()
105 return paramList.count();
109 QString Parser::errorMessage()
114 case NoError: l="No Error";
115 case Warning: l="Warning";
116 case Aborted: l="Aborted";
118 return QString ("Error Level: %1\n Command: %2\nDescription: %3")
119 .arg(l).arg(com).arg(errDescription);
122 QString Parser::errorDescription()
124 return errDescription;
127 ErrorLevel Parser::errorLevel()
132 void Parser::setError(ErrorLevel level, const QString &description)
134 errDescription=description;
138 void Parser::resetError ()
146 bool Parser::checkParCount (QList <int> plist)
150 for (int i=0; i<plist.count();i++)
152 if (checkParCount (plist[i]))
157 expList.append(QString().setNum(plist[i]));
159 expected=expList.join(",");
160 errDescription=QString("Wrong number of parameters: Expected %1, but found %2").arg(expected).arg(paramList.count());
164 bool Parser::checkParCount (const int &expected)
166 if (paramList.count()!=expected)
169 errDescription=QString("Wrong number of parameters: Expected %1, but found %2").arg(expected).arg(paramList.count());
175 bool Parser::checkParIsInt(const int &index)
178 if (index > paramList.count())
181 errDescription=QString("Parameter index %1 is outside of parameter list").arg(index);
185 paramList[index].toInt (&ok, 10);
189 errDescription=QString("Parameter %1 is not an integer").arg(index);
196 int Parser::parInt (bool &ok,const uint &index)
198 if (checkParIsInt (index))
199 return paramList[index].toInt (&ok, 10);
204 QString Parser::parString (bool &ok,const int &index)
206 // return the string at index, this could be also stored in
209 QRegExp re("\"(.*)\"");
210 int pos=re.search (paramList[index]);
219 bool Parser::parBool (bool &ok,const int &index)
221 // return the bool at index, this could be also stored in
225 QString p=paramList[index];
226 if (p=="true" || p=="1")
228 else if (p=="false" || p=="0")
234 QColor Parser::parColor(bool &ok,const int &index)
236 // return the QColor at index
240 QRegExp re("\"(.*)\"");
241 int pos=re.search (paramList[index]);
251 void Parser::setScript(const QString &s)
256 QString Parser::getScript()
261 void Parser::runScript()
269 if (current<0) runScript();
270 if (current>=script.length()-1) return false;
272 bool inBracket=false;
275 //cout <<"current="<<current<< " start="<<start<<" length="<<script.length()<<endl;
277 // Check if we are inside a string
278 if (script.at(current)=='"')
286 // Check if we are in a comment
287 if (!inBracket && script.at(current)=='#')
289 while (script.at(current)!='\n')
292 if (current>=script.length())
298 // Check for end of atom
299 if (!inBracket && script.at(current)==';')
301 atom=script.mid(start,current-start);
306 // Check for end of script
307 if (current==script.length() )
311 setError (Aborted,"Runaway string");
315 atom=script.mid(start);