--- trunk/src/selection/SelectionCompiler.cpp 2005/02/07 22:36:32 303 +++ trunk/src/selection/SelectionCompiler.cpp 2005/04/05 23:09:48 452 @@ -119,14 +119,12 @@ bool SelectionCompiler::internalCompile(){ //} if (lookingAtDecimal((tokCommand & Token::negnums) != 0)) { float value = lexi_cast(script.substr(ichToken, cchToken)); - std::cout << "encount an decimal: " << value << std::endl; ltoken.push_back(Token(Token::decimal, boost::any(value))); continue; } if (lookingAtInteger((tokCommand & Token::negnums) != 0)) { int val = lexi_cast(script.substr(ichToken, cchToken)); - std::cout << "encount an integer: " << val << std::endl; ltoken.push_back(Token(Token::integer, boost::any(val))); continue; } @@ -245,8 +243,6 @@ bool SelectionCompiler::internalCompile(){ } cchToken = ichT - ichToken; - - std::cout << "lookingAtString: encount " << script.substr(ichToken, cchToken) << std::endl; return true; } @@ -388,15 +384,8 @@ bool SelectionCompiler::lookingAtLookupToken() { case '(': case ')': case ',': - case '*': - case '-': case '[': case ']': - case '+': - case ':': - case '@': - case '.': - case '%': break; case '&': case '|': @@ -421,9 +410,10 @@ bool SelectionCompiler::lookingAtLookupToken() { if ((ch < 'a' || ch > 'z') && (ch < 'A' && ch > 'Z') && ch != '_') { return false; } + case '*': case '?': // include question marks in identifier for atom expressions - while (ichT < cchScript && !std::isspace(ch = script[ichT]) && (std::isalpha(ch) ||std::isdigit(ch) || - ch == '_' || ch == '?') ) { + while (ichT < cchScript && !std::isspace(ch = script[ichT]) && + (std::isalpha(ch) ||std::isdigit(ch) || ch == '_' || ch == '.' || ch == '*' || ch == '?' || ch == '+' || ch == '-' || ch == '[' || ch == ']') ){ ++ichT; } @@ -432,7 +422,6 @@ bool SelectionCompiler::lookingAtLookupToken() { cchToken = ichT - ichToken; - std::cout << "lookingAtLookupToken: encount " << script.substr(ichToken, cchToken) << std::endl; return true; } @@ -656,75 +645,41 @@ bool SelectionCompiler::clauseChemObjName() { } bool SelectionCompiler::clauseChemObjName() { - std::string chemObjName; - int tok = tokPeek(); - if (!clauseName(chemObjName)){ - return false; - } + Token token = tokenNext(); + if (token.tok == Token::identifier && token.value.type() == typeid(std::string)) { - - tok = tokPeek(); - //allow two dot at most - if (tok == Token::dot) { - tokenNext(); - chemObjName += "."; - if (!clauseName(chemObjName)) { - return false; + std::string name = boost::any_cast(token.value); + if (isNameValid(name)) { + return addTokenToPostfix(Token(Token::name, name)); + } else { + return compileError("invalid name: " + name); } - tok = tokPeek(); - if (tok == Token::dot) { - tokenNext(); - chemObjName += "."; + } - if (!clauseName(chemObjName)) { - return false; - } - } - } - - return addTokenToPostfix(Token(Token::name, chemObjName)); + return false; + } -bool SelectionCompiler:: clauseName(std::string& name) { +bool SelectionCompiler::isNameValid(const std::string& name) { + int nbracket = 0; + int ndot = 0; + for (int i =0 ; i < name.size(); ++i) { + switch(name[i]) { - int tok = tokPeek(); - - if (tok == Token::asterisk || tok == Token::identifier || tok == Token::integer) { - - Token token = tokenNext(); - if (token.value.type() == typeid(std::string)) { - name += boost::any_cast(token.value); - } else if (token.value.type() == typeid(int)){ - int intVal = boost::any_cast(token.value); - char buffer[255]; - sprintf(buffer,"%d", intVal); - name += buffer; /** @todo */ - //name += toString(intVal); + case '[' : + ++nbracket; + break; + case ']' : + --nbracket; + break; + case '.' : + ++ndot; + break; } - while(true){ - tok = tokPeek(); - switch (tok) { - case Token::asterisk : - name += "*"; - tokenNext(); - break; - case Token::identifier : - name += boost::any_cast(tokenNext().value); - break; - case Token::integer : - name += toString(boost::any_cast(tokenNext().value)); - break; - case Token::dot : - return true; - default : - return true; - } - } - - }else { - return false; } + //only allow 3 dots at most + return (ndot <=3 && nbracket == 0) ? true : false; } bool SelectionCompiler::clauseIndex(){