diff -r c56ce5d81cc3 -r 72afe12da1c8 parser.cpp --- a/parser.cpp Tue Apr 10 13:22:51 2007 +0000 +++ b/parser.cpp Tue Apr 10 13:22:52 2007 +0000 @@ -7,26 +7,39 @@ Parser::Parser() { - initCommand(); + initParser(); } -void Parser::initCommand() +void Parser::initParser() { + initAtom(); + current=-1; +} + +void Parser::initAtom() +{ + atom=""; com=""; paramList.clear(); resetError(); } -void Parser::parseAtom (const QString &s) +void Parser::parseAtom (QString s) { - initCommand(); - input=s; + initAtom(); + atom=s; QRegExp re; int pos; + // Strip WS at beginning + re.setPattern ("\\w"); + re.setMinimal (true); + pos=re.search (atom); + if (pos>=0) + s=s.right(s.length()-pos); + // Get command re.setPattern ("\\b(.*)(\\s|\\()"); - re.setMinimal (true); pos=re.search (s); if (pos>=0) com=re.cap(1); @@ -70,12 +83,17 @@ } } -QString Parser::command() +QString Parser::getAtom() +{ + return atom; +} + +QString Parser::getCommand() { return com; } -QStringList Parser::parameters() +QStringList Parser::getParameters() { return paramList; } @@ -240,9 +258,63 @@ void Parser::runScript() { + current=0; } -bool Parser::scriptNextAtom() +bool Parser::next() { + int start=current; + if (current<0) runScript(); + if (current>=script.length()-1) return false; + + bool inBracket=false; + while (true) + { + //cout <<"current="<=script.length()) + return false; + } + start=current; + } + + // Check for end of atom + if (!inBracket && script.at(current)==';') + { + atom=script.mid(start,current-start); + current++; + return true; + } + + // Check for end of script + if (current==script.length() ) + { + if (inBracket) + { + setError (Aborted,"Runaway string"); + return false; + } else + { + atom=script.mid(start); + return true; + } + } + current++; + } }