--- trunk/src/selection/SelectionCompiler.cpp 2005/02/02 23:13:11 281 +++ trunk/src/selection/SelectionCompiler.cpp 2005/02/04 22:39:26 288 @@ -82,8 +82,8 @@ bool SelectionCompiler::internalCompile(){ for ( ; true; ichToken += cchToken) { if (lookingAtLeadingWhitespace()) continue; - if (lookingAtComment()) - continue; + //if (lookingAtComment()) + // continue; bool endOfLine = lookingAtEndOfLine(); if (endOfLine || lookingAtEndOfStatement()) { if (tokCommand != Token::nada) { @@ -131,8 +131,7 @@ bool SelectionCompiler::internalCompile(){ } if (lookingAtLookupToken()) { - std::string ident = script.substr(ichToken, ichToken + cchToken); - + std::string ident = script.substr(ichToken, cchToken); Token token; Token* pToken = TokenMap::getInstance()->getToken(ident); if (pToken != NULL) { @@ -419,10 +418,9 @@ bool SelectionCompiler::lookingAtLookupToken() { return false; } case '?': // include question marks in identifier for atom expressions - while (ichT < cchScript && (std::isalpha(ch = script[ichT]) ||std::isdigit(ch) || - ch == '_' || ch == '?') ||(ch == '^' && ichT > ichToken && std::isdigit(script[ichT - 1]))) { - // hack for insertion codes embedded in an atom expression :-( - // select c3^a + while (ichT < cchScript && !std::isspace(ch = script[ichT]) && (std::isalpha(ch) ||std::isdigit(ch) || + ch == '_' || ch == '?') ) { + ++ichT; } break; @@ -560,15 +558,11 @@ bool SelectionCompiler::clausePrimitive() { switch (tok) { case Token::within: return clauseWithin(); - case Token::name : - return clauseName(Token::name); - case Token::index : - return clauseIndex(Token::index); - case Token::molname : - return clauseName(Token::molname); - case Token::molindex : - return clauseIndex(Token::molindex); - + + case Token::asterisk: + case Token::identifier: + return clauseChemObjName(); + default: if ((tok & Token::atomproperty) == Token::atomproperty) { return clauseComparator(); @@ -601,14 +595,19 @@ bool SelectionCompiler::clauseComparator() { } Token tokenValue = tokenNext(); - if (tokenValue.tok != Token::integer) { - return integerExpected(); + if (tokenValue.tok != Token::integer && tokenValue.tok != Token::decimal) { + return numberExpected(); } - int val = tokenValue.intValue; - // note that a comparator instruction is a complicated instruction - // int intValue is the tok of the property you are comparing - // the value against which you are comparing is stored as an Integer - // in the object value + + float val; + if (tokenValue.value.type() == typeid(int)) { + val = boost::any_cast(tokenValue.value); + } else if (tokenValue.value.type() == typeid(float)) { + val = boost::any_cast(tokenValue.value); + } else { + return false; + } + return addTokenToPostfix(Token(tokenComparator.tok, tokenAtomProperty.tok, boost::any(val))); } @@ -647,17 +646,68 @@ bool SelectionCompiler::clauseWithin() { return addTokenToPostfix(Token(Token::within, distance)); } +bool SelectionCompiler::clauseChemObjName() { + std::string chemObjName; + int tok = tokPeek(); + if (!clauseName(chemObjName)){ + return false; + } -bool SelectionCompiler:: clauseName(int tok) { - Token tokenName = tokenNext(); - std::string name = boost::any_cast(tokenName.value); - return addTokenToPostfix(Token(tok, name)); /**@todo */ + + 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; + } + } + } + + return addTokenToPostfix(Token(Token::name, chemObjName)); } -bool SelectionCompiler:: clauseIndex(int tok) { - //return addTokenToPostfix(Token(tok, )); /**@todo*/ - return true; +bool SelectionCompiler:: clauseName(std::string& name) { + + 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; + } + } + + }else { + return false; + } + } + }