--- trunk/src/selection/SelectionCompiler.cpp 2005/02/04 22:39:26 288 +++ trunk/src/selection/SelectionCompiler.cpp 2005/02/07 22:36:32 303 @@ -118,14 +118,16 @@ bool SelectionCompiler::internalCompile(){ // continue; //} if (lookingAtDecimal((tokCommand & Token::negnums) != 0)) { - float value = lexi_cast(script.substr(ichToken, ichToken + cchToken)); - ltoken.push_back(Token(Token::decimal, value));/**@todo*/ + 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)) { - std::string intString = script.substr(ichToken, ichToken + cchToken); - int val = lexi_cast(intString); - ltoken.push_back(Token(Token::integer, val, intString));/**@todo*/ + + 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; } } @@ -242,6 +244,9 @@ bool SelectionCompiler::internalCompile(){ previousCharBackslash = ch == '\\' ? !previousCharBackslash : false; } cchToken = ichT - ichToken; + + + std::cout << "lookingAtString: encount " << script.substr(ichToken, cchToken) << std::endl; return true; } @@ -339,9 +344,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; } @@ -425,7 +429,10 @@ bool SelectionCompiler::lookingAtLookupToken() { } break; } + cchToken = ichT - ichToken; + + std::cout << "lookingAtLookupToken: encount " << script.substr(ichToken, cchToken) << std::endl; return true; } @@ -562,7 +569,9 @@ bool SelectionCompiler::clausePrimitive() { case Token::asterisk: case Token::identifier: return clauseChemObjName(); - + + case Token::integer : + return clauseIndex(); default: if ((tok & Token::atomproperty) == Token::atomproperty) { return clauseComparator(); @@ -608,8 +617,10 @@ bool SelectionCompiler::clauseComparator() { return false; } + boost::any floatVal; + floatVal = val; return addTokenToPostfix(Token(tokenComparator.tok, - tokenAtomProperty.tok, boost::any(val))); + tokenAtomProperty.tok, floatVal)); } bool SelectionCompiler::clauseWithin() { @@ -622,8 +633,6 @@ bool SelectionCompiler::clauseWithin() { Token tokenDistance = tokenNext(); // distance switch(tokenDistance.tok) { case Token::integer: - distance = float(tokenDistance.intValue); - break; case Token::decimal: distance = tokenDistance.value; break; @@ -680,9 +689,18 @@ bool SelectionCompiler:: clauseName(std::string& name) int tok = tokPeek(); - if (tok == Token::asterisk || tok == Token::identifier) { - name += boost::any_cast(tokenNext().value); - + 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); + } while(true){ tok = tokPeek(); switch (tok) { @@ -709,5 +727,34 @@ bool SelectionCompiler:: clauseName(std::string& name) } +bool SelectionCompiler::clauseIndex(){ + Token token = tokenNext(); + if (token.tok == Token::integer) { + int index = boost::any_cast(token.value); + int tok = tokPeek(); + std::cout << "Token::to is " << Token::to << ", tok = " << tok << std::endl; + if (tok == Token::to) { + tokenNext(); + tok = tokPeek(); + if (tok != Token::integer) { + return numberExpected(); + } + + boost::any intVal = tokenNext().value; + int first = index; + if (intVal.type() != typeid(int)){ + return false; + } + int second = boost::any_cast(intVal); + return addTokenToPostfix(Token(Token::index, boost::any(std::make_pair(first, second)))); + + }else { + return addTokenToPostfix(Token(Token::index, boost::any(index))); + } + } else { + return numberExpected(); + } } + +}