source: trunk/lib/Parser.cc @ 184

Last change on this file since 184 was 184, checked in by Peter Johansson, 15 years ago

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

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.1 KB
Line 
1// $Id: Parser.cc 184 2006-09-05 11:19:53Z peter $
2
3/*
4  Copyright (C) 2006 Peter Johansson
5
6  This file is part of svndigest, http://lev.thep.lu.se/trac/svndigest
7
8  svndigest is free software; you can redistribute it and/or modify it
9  under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 2 of the License, or
11  (at your option) any later version.
12
13  svndigest is distributed in the hope that it will be useful, but
14  WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21  02111-1307, USA.
22*/
23
24#include "Parser.h"
25#include "utility.h"
26
27#include <algorithm>
28#include <functional>
29#include <fstream>
30#include <iostream>
31#include <string>
32
33namespace theplu{
34namespace svndigest{
35
36
37  Parser::Parser(const std::string& path)
38  {
39    std::ifstream is(path.c_str());
40    cc_mode(is);
41    is.close();
42  }
43
44
45  void Parser::cc_mode(std::istream& is)
46  {
47    bool block_com=false;
48    std::string str;
49    while(getline(is,str)) {
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        }
90      }
91      type_.push_back(lt);
92    }
93  }
94
95
96}} // end of namespace svndigest and namespace theplu
Note: See TracBrowser for help on using the repository browser.