ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-3.0/src/selection/SelectionCompiler.cpp
(Generate patch)

Comparing trunk/OOPSE-3.0/src/selection/SelectionCompiler.cpp (file contents):
Revision 2099 by tim, Wed Mar 9 18:46:16 2005 UTC vs.
Revision 2147 by tim, Tue Apr 5 23:09:48 2005 UTC

# Line 384 | Line 384 | bool SelectionCompiler::lookingAtLookupToken() {
384          case '(':
385          case ')':
386          case ',':
387        case '*':
388        case '-':
387          case '[':
388          case ']':
391        case '+':
392        case ':':
393        case '@':
394        case '.':
395        case '%':
389          break;
390          case '&':
391          case '|':
# Line 417 | Line 410 | bool SelectionCompiler::lookingAtLookupToken() {
410              if ((ch < 'a' || ch > 'z') && (ch < 'A' && ch > 'Z') && ch != '_') {
411                  return false;
412              }
413 +        case '*':
414          case '?': // include question marks in identifier for atom expressions
415 <            while (ichT < cchScript && !std::isspace(ch = script[ichT]) && (std::isalpha(ch) ||std::isdigit(ch) ||
416 <                ch == '_' || ch == '?') ) {
415 >            while (ichT < cchScript && !std::isspace(ch = script[ichT]) &&
416 >                    (std::isalpha(ch) ||std::isdigit(ch) || ch == '_' || ch == '.' || ch == '*' || ch == '?' || ch == '+' || ch == '-' || ch == '[' || ch == ']') ){
417  
418                  ++ichT;
419              }
# Line 651 | Line 645 | bool SelectionCompiler::clauseChemObjName() {
645   }
646  
647   bool SelectionCompiler::clauseChemObjName() {
648 <    std::string chemObjName;
649 <    int tok = tokPeek();
656 <    if (!clauseName(chemObjName)){
657 <        return false;
658 <    }
648 >    Token token = tokenNext();
649 >    if (token.tok == Token::identifier && token.value.type() == typeid(std::string)) {
650  
651 +        std::string name = boost::any_cast<std::string>(token.value);
652 +        if (isNameValid(name)) {
653 +            return addTokenToPostfix(Token(Token::name, name));
654 +        } else {
655 +            return compileError("invalid name: " + name);
656 +        }
657 +    }
658  
659 <    tok = tokPeek();
660 <    //allow two dot at most
663 <    if (tok == Token::dot) {
664 <        tokenNext();
665 <        chemObjName += ".";
666 <        if (!clauseName(chemObjName)) {
667 <            return false;
668 <        }
669 <        tok = tokPeek();
670 <        if (tok == Token::dot) {
671 <            tokenNext();
672 <            chemObjName += ".";
673 <
674 <            if (!clauseName(chemObjName)) {
675 <                return false;
676 <            }
677 <        }        
678 <    }
679 <
680 <    return addTokenToPostfix(Token(Token::name, chemObjName));
659 >    return false;
660 >        
661   }
662  
663 < bool SelectionCompiler:: clauseName(std::string& name) {
664 <
665 <    int tok = tokPeek();
663 > bool SelectionCompiler::isNameValid(const std::string& name) {
664 >          int nbracket = 0;
665 >    int ndot = 0;
666 >    for (int i =0 ; i < name.size(); ++i) {
667 >        switch(name[i]) {
668  
669 <    if (tok == Token::asterisk || tok == Token::identifier || tok == Token::integer) {
670 <
671 <        Token token = tokenNext();
672 <        if (token.value.type() == typeid(std::string)) {
673 <            name += boost::any_cast<std::string>(token.value);
674 <        } else if (token.value.type() == typeid(int)){
675 <            int intVal = boost::any_cast<int>(token.value);
676 <            char buffer[255];
677 <            sprintf(buffer,"%d", intVal);
696 <            name += buffer; /** @todo */
697 <            //name += toString<int>(intVal);
669 >          case '[' :
670 >              ++nbracket;
671 >              break;
672 >          case ']' :
673 >              --nbracket;
674 >              break;
675 >          case '.' :
676 >              ++ndot;
677 >              break;      
678          }
699        while(true){
700            tok = tokPeek();
701            switch (tok) {
702                case Token::asterisk :
703                    name += "*";
704                    tokenNext();
705                    break;
706                case Token::identifier :
707                    name += boost::any_cast<std::string>(tokenNext().value);
708                    break;
709                case Token::integer :
710                    name += toString(boost::any_cast<int>(tokenNext().value));
711                    break;
712                case Token::dot :
713                    return true;
714                default :
715                    return true;
716            }
717        }
718        
719    }else {
720        return false;
679      }
680  
681 +    //only allow 3 dots at most
682 +    return (ndot <=3 && nbracket == 0) ? true : false;
683   }
684  
685   bool SelectionCompiler::clauseIndex(){

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines