Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 25, 2008, 9:58:14 PM (17 years ago)
Author:
landauf
Message:

finally got a good approach for the CommandExecutor parser. more to come.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/console/src/core/CommandEvaluation.cc

    r1416 r1424  
    4242    {
    4343        this->bNewCommand_ = true;
    44 
     44        this->bCommandChanged_ = false;
    4545        this->originalCommand_ = command;
    4646        this->command_ = command;
     
    7979        }
    8080
    81         COUT(4) << "CE_execute: " << this->command_ << "\n";
    82 
    83         unsigned int startindex = this->getStartindex();
    84         if (this->commandTokens_.size() > startindex)
    85             return this->function_->parse(removeSlashes(this->commandTokens_.subSet(startindex).join() + this->getAdditionalParameter()));
    86         else
    87             return this->function_->parse(removeSlashes(this->additionalParameter_));
    88     }
    89 
    90     std::string CommandEvaluation::complete() const
    91     {
    92         switch (this->state_)
    93         {
    94             case CS_Uninitialized:
    95 std::cout << "complete: state: CS_Uninitialized" << std::endl;
    96             case CS_Empty:
    97 std::cout << "complete: state: CS_Empty" << std::endl;
    98             case CS_ShortcutOrIdentifier:
    99 std::cout << "complete: state: CS_ShortcutOrIdentifier" << std::endl;
    100                 {
    101                     std::list<std::pair<const std::string*, const std::string*> > temp;
    102                     temp.insert(temp.end(), this->listOfPossibleFunctions_.begin(), this->listOfPossibleFunctions_.end());
    103                     temp.insert(temp.end(), this->listOfPossibleIdentifiers_.begin(), this->listOfPossibleIdentifiers_.end());
    104                     if (temp.size() > 0)
    105                     {
    106 std::cout << "complete: temp > 0" << std::endl;
    107                         return (CommandEvaluation::getCommonBegin(temp));
    108                     }
    109                 }
    110                 break;
    111             case CS_Shortcut_Params:
    112 std::cout << "complete: state: CS_Shortcut_Params" << std::endl;
    113                 if (this->function_)
    114                 {
    115 std::cout << "complete: function != 0" << std::endl;
    116                     if (this->commandTokens_.size() > 1)
    117                     {
    118                         if ((this->commandTokens_.size() - 1) >= this->function_->getParamCount())
    119                             return (this->function_->getName() + " " + this->commandTokens_.subSet(1, this->commandTokens_.size()).join());
    120                         else
    121                             return (this->function_->getName() + " " + this->commandTokens_.subSet(1, this->commandTokens_.size()).join() + " " + CommandEvaluation::getCommonBegin(this->listOfPossibleArguments_));
    122                     }
    123                     else
    124                         return (this->function_->getName() + " ");
    125                 }
    126                 break;
    127             case CS_Shortcut_Finished:
    128 std::cout << "complete: state: CS_Shortcut_Finished" << std::endl;
    129                 if (this->function_)
    130                 {
    131 std::cout << "complete: function != 0" << std::endl;
    132                     if (this->commandTokens_.size() > 1)
    133                         return (this->function_->getName() + " " + this->commandTokens_.subSet(1, this->commandTokens_.size()).join());
    134                     else
    135                         return (this->function_->getName());
    136                 }
    137                 break;
    138             case CS_Function:
    139 std::cout << "complete: state: CS_Function" << std::endl;
    140                 if (this->functionclass_)
    141                 {
    142 std::cout << "complete: functionclass != 0" << std::endl;
    143                     return (this->functionclass_->getName() + " " + CommandEvaluation::getCommonBegin(this->listOfPossibleFunctions_));
    144                 }
    145                 break;
    146             case CS_Function_Params:
    147 std::cout << "complete: state: CS_Function_Params" << std::endl;
    148                 if (this->functionclass_ && this->function_)
    149                 {
    150 std::cout << "complete: function und functionclass != 0" << std::endl;
    151                     if (this->commandTokens_.size() > 2)
    152                     {
    153                         if ((this->commandTokens_.size() - 2) >= this->function_->getParamCount())
    154                             return (this->functionclass_->getName() + " " + this->function_->getName() + " " + this->commandTokens_.subSet(2, this->commandTokens_.size()).join());
    155                         else
    156                             return (this->functionclass_->getName() + " " + this->function_->getName() + " " + this->commandTokens_.subSet(2, this->commandTokens_.size()).join() + " " + CommandEvaluation::getCommonBegin(this->listOfPossibleArguments_));
    157                     }
    158                     else
    159                         return (this->functionclass_->getName() + " " + this->function_->getName() + " ");
    160                 }
    161                 break;
    162             case CS_Function_Finished:
    163 std::cout << "complete: state: CS_Function_Finished" << std::endl;
    164                 if (this->functionclass_ && this->function_)
    165                 {
    166 std::cout << "complete: function und functionclass != 0" << std::endl;
    167                     if (this->commandTokens_.size() > 2)
    168                         return (this->functionclass_->getName() + " " + this->function_->getName() + " " + this->commandTokens_.subSet(2, this->commandTokens_.size()).join());
    169                     else
    170                         return (this->functionclass_->getName() + " " + this->function_->getName());
    171                 }
    172                break;
    173             case CS_Error:
    174 std::cout << "complete: state: CS_Error" << std::endl;
    175                 break;
    176         }
    177 
    178         return this->originalCommand_;
     81        if (!this->bCommandChanged_)
     82        {
     83            COUT(4) << "CE_execute: " << this->command_ << "\n";
     84
     85            unsigned int startindex = this->getStartindex();
     86            if (this->commandTokens_.size() > startindex)
     87                return this->function_->parse(removeSlashes(this->commandTokens_.subSet(startindex).join() + this->getAdditionalParameter()));
     88            else
     89                return this->function_->parse(removeSlashes(this->additionalParameter_));
     90        }
     91
     92        return false;
     93    }
     94
     95    std::string CommandEvaluation::complete()
     96    {
     97        if (!this->bNewCommand_)
     98        {
     99std::cout << "ASDF" << std::endl;
     100            switch (this->state_)
     101            {
     102                case CS_Uninitialized:
     103                    break;
     104                case CS_Empty:
     105                    break;
     106                case CS_ShortcutOrIdentifier:
     107                    if (this->function_)
     108                        return CommandExecutor::complete(this->function_->getName() + " ");
     109                    else if (this->functionclass_)
     110                        return CommandExecutor::complete(this->functionclass_->getName() + " ");
     111                    break;
     112                case CS_Function:
     113                    if (this->function_)
     114                        return CommandExecutor::complete(this->functionclass_->getName() + " " + this->function_->getName() + " ");
     115                    break;
     116                case CS_Params:
     117                    break;
     118                case CS_Finished:
     119                    break;
     120                case CS_Error:
     121                    break;
     122            }
     123        }
     124        this->bNewCommand_ = false;
     125        return this->command_;
    179126    }
    180127
     
    197144                return CommandEvaluation::dump(this->listOfPossibleFunctions_);
    198145                break;
    199             case CS_Shortcut_Params:
    200             case CS_Function_Params:
     146            case CS_Params:
    201147                if (this->listOfPossibleArguments_.size() > 0)
    202148                    return CommandEvaluation::dump(this->listOfPossibleArguments_);
    203149                else
    204150                    return CommandEvaluation::dump(this->function_);
    205             case CS_Shortcut_Finished:
    206             case CS_Function_Finished:
     151            case CS_Finished:
    207152                if (this->function_)
    208153                    return CommandEvaluation::dump(this->function_);
     
    273218    unsigned int CommandEvaluation::getStartindex() const
    274219    {
    275         if (this->state_ == CS_Shortcut_Params || this->state_ == CS_Shortcut_Finished)
     220        if (this->functionclass_ && this->function_)
     221            return 2;
     222        else if (this->function_)
    276223            return 1;
    277         else if (this->state_ == CS_Function || this->state_ == CS_Function_Params || this->state_ == CS_Function_Finished)
    278             return 2;
    279224        else
    280225            return 0;
    281226    }
    282227
    283     std::string CommandEvaluation::getCommonBegin(const std::list<std::pair<const std::string*, const std::string*> >& list)
    284     {
    285         if (list.size() == 0)
    286         {
    287             return "";
    288         }
    289         else if (list.size() == 1)
    290         {
    291             return ((*(*list.begin()).first) + " ");
    292         }
    293         else
    294         {
    295             std::string output = "";
    296             for (unsigned int i = 0; true; i++)
    297             {
    298                 char temp = 0;
    299                 for (std::list<std::pair<const std::string*, const std::string*> >::const_iterator it = list.begin(); it != list.end(); ++it)
    300                 {
    301                     if ((*(*it).first).size() > i)
    302                     {
    303                         if (it == list.begin())
    304                         {
    305                             temp = (*(*it).first)[i];
    306                         }
    307                         else
    308                         {
    309                             if (temp != (*(*it).first)[i])
    310                                 return output;
    311                         }
    312                     }
    313                     else
    314                     {
    315                         return output;
    316                     }
    317                 }
    318                 output += temp;
    319             }
    320             return output;
    321         }
    322     }
    323 
    324228    std::string CommandEvaluation::dump(const std::list<std::pair<const std::string*, const std::string*> >& list)
    325229    {
     
    337241    std::string CommandEvaluation::dump(const ConsoleCommand* command)
    338242    {
    339         std::string output = "";
     243        std::string output = command->getName() + ": ";
    340244        for (unsigned int i = 0; i < command->getParamCount(); i++)
    341245        {
Note: See TracChangeset for help on using the changeset viewer.