Changeset 184


Ignore:
Timestamp:
Sep 5, 2006, 1:19:53 PM (17 years ago)
Author:
Peter Johansson
Message:

fixes #68 Parser detects block comments of type /* bla bla */

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/Parser.cc

    r149 r184  
    4545  void Parser::cc_mode(std::istream& is)
    4646  {
     47    bool block_com=false;
    4748    std::string str;
    4849    while(getline(is,str)) {
    49       std::string::iterator where;
    50       where = std::find_if(str.begin(), str.end(), std::not1(WhiteSpace()));
    51       if (where==str.end())
    52         type_.push_back(empty);
    53       else if (match_begin(where, str.end(), "//")) {
    54         where = std::find_if(where, str.end(), AlphaNum());
    55         if (where==str.end())
    56           type_.push_back(empty);
    57         else
    58           type_.push_back(comment);
     50      bool line_com=false;
     51      line_type lt=empty;
     52      for (std::string::iterator iter=str.begin(); iter!=str.end(); ++iter){
     53        if (!block_com && match_begin(iter,str.end(), "/*")){
     54          block_com=true;
     55          continue;
     56        }
     57        if (block_com && match_begin(iter,str.end(), "*/")){
     58          block_com=false;
     59          continue;
     60        }
     61        if (block_com){
     62          if (line_com){
     63            if (lt==empty && isalnum(*iter))
     64              lt = comment;
     65          }
     66          else if (lt==empty) {
     67            if (match_begin(iter, str.end(), "//"))
     68              line_com=true;
     69            else if (isalnum(*iter))
     70              lt = comment;
     71          }
     72        }
     73        else if (lt==empty){
     74          if (isalnum(*iter)){
     75            if (line_com){
     76              lt = comment;
     77            }
     78            else{
     79              lt = code;
     80            }
     81          }
     82          else if (match_begin(iter, str.end(), "//")){
     83            line_com=true;
     84          }
     85          else if (!line_com && !isspace(*iter)){
     86            lt = code;
     87          }
     88
     89        }
    5990      }
    60       else {
    61         type_.push_back(code);
    62       }
     91      type_.push_back(lt);
    6392    }
    6493  }
Note: See TracChangeset for help on using the changeset viewer.