--- trunk/src/selection/SelectionCompiler.cpp 2005/02/07 19:13:18 295 +++ 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; } @@ -244,9 +242,7 @@ bool SelectionCompiler::internalCompile(){ previousCharBackslash = ch == '\\' ? !previousCharBackslash : false; } cchToken = ichT - ichToken; - - std::cout << "lookingAtString: encount " << script.substr(ichToken, cchToken) << std::endl; return true; } @@ -344,9 +340,8 @@ bool SelectionCompiler::lookingAtDecimal(bool allowNeg return false; } - // to support 1.ca, let's check the character after the dot - // to determine if it is an alpha - if (ch == '.' && (ichT + 1 < cchScript) && std::isalpha(script[ichT + 1])) { + // to support DMPC.1, let's check the character before the dot + if (ch == '.' && (ichT > 0) && std::isalpha(script[ichT - 1])) { return false; } @@ -389,15 +384,8 @@ bool SelectionCompiler::lookingAtLookupToken() { case '(': case ')': case ',': - case '*': - case '-': case '[': case ']': - case '+': - case ':': - case '@': - case '.': - case '%': break; case '&': case '|': @@ -422,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; } @@ -433,7 +422,6 @@ bool SelectionCompiler::lookingAtLookupToken() { cchToken = ichT - ichToken; - std::cout << "lookingAtLookupToken: encount " << script.substr(ichToken, cchToken) << std::endl; return true; } @@ -657,66 +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; - } - tok = tokPeek(); - 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); + } + } - 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) { - name += boost::any_cast(tokenNext().value); - - 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; - } + case '[' : + ++nbracket; + break; + case ']' : + --nbracket; + break; + case '.' : + ++ndot; + break; } - - }else { - return false; } + //only allow 3 dots at most + return (ndot <=3 && nbracket == 0) ? true : false; } bool SelectionCompiler::clauseIndex(){