Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/Parser.cc
r260 r261 30 30 #include <iostream> 31 31 #include <string> 32 #include <utility> 33 #include <vector> 32 34 33 35 namespace theplu{ … … 38 40 { 39 41 std::ifstream is(path.c_str()); 42 std::vector<std::pair<std::string, std::string> > codon; 40 43 if (match_end(path.rbegin(), path.rend(), ".ac") || 41 44 match_end(path.rbegin(), path.rend(), ".am") || 42 match_end(path.rbegin(), path.rend(), ".pl") || 43 match_end(path.rbegin(), path.rend(), ".pm") || 44 match_end(path.rbegin(), path.rend(), ".sh") || 45 file_name(path)=="Makefile") 46 line_com_mode(is, "#"); 47 else if (match_end(path.rbegin(), path.rend(), ".tex")) 48 line_com_mode(is, "%"); 49 else if (match_end(path.rbegin(), path.rend(), ".m4")) 50 line_com_mode(is, "dnl"); 51 else if (match_end(path.rbegin(), path.rend(), ".txt") || 52 file_name(path)=="AUTHORS" || 53 file_name(path)=="ChangeLog" || 54 file_name(path)=="INSTALL" || 55 file_name(path)=="NEWS" || 56 file_name(path)=="README") 45 match_end(path.rbegin(), path.rend(), ".m4")) { 46 codon.reserve(2); 47 codon.push_back(std::make_pair("#", "\n")); 48 codon.push_back(std::make_pair("dnl", "\n")); 49 parse(is, codon); 50 } 51 else if (match_end(path.rbegin(), path.rend(), ".c") || 52 match_end(path.rbegin(), path.rend(), ".cc") || 53 match_end(path.rbegin(), path.rend(), ".cpp") || 54 match_end(path.rbegin(), path.rend(), ".cxx") || 55 match_end(path.rbegin(), path.rend(), ".h") || 56 match_end(path.rbegin(), path.rend(), ".hh") || 57 match_end(path.rbegin(), path.rend(), ".hpp") || 58 match_end(path.rbegin(), path.rend(), ".java")) { 59 codon.reserve(2); 60 codon.push_back(std::make_pair("//", "\n")); 61 codon.push_back(std::make_pair("/*", "*/")); 62 parse(is, codon); 63 } 64 else if (match_end(path.rbegin(), path.rend(), ".pl") || 65 match_end(path.rbegin(), path.rend(), ".pm") || 66 match_end(path.rbegin(), path.rend(), ".sh") || 67 file_name(path)=="Makefile") { 68 codon.push_back(std::make_pair("#", "\n")); 69 parse(is,codon); 70 } 71 else if (match_end(path.rbegin(), path.rend(), ".tex") || 72 match_end(path.rbegin(), path.rend(), ".m")) { 73 codon.push_back(std::make_pair("%", "\n")); 74 parse(is,codon); 75 } 76 else if (match_end(path.rbegin(), path.rend(), ".jsp")) { 77 codon.reserve(2); 78 codon.push_back(std::make_pair("<!--", "-->")); 79 codon.push_back(std::make_pair("<%--", "--%>")); 80 parse(is,codon); 81 } 82 else if (match_end(path.rbegin(), path.rend(), ".html") || 83 match_end(path.rbegin(), path.rend(), ".xml") || 84 match_end(path.rbegin(), path.rend(), ".xhtml") || 85 match_end(path.rbegin(), path.rend(), ".shtml") || 86 match_end(path.rbegin(), path.rend(), ".xml") || 87 match_end(path.rbegin(), path.rend(), ".css") || 88 match_end(path.rbegin(), path.rend(), ".rss") || 89 match_end(path.rbegin(), path.rend(), ".sgml") ){ 90 codon.push_back(std::make_pair("<!--", "-->")); 91 parse(is,codon); 92 } 93 else 57 94 text_mode(is); 58 else59 cc_mode(is);60 95 is.close(); 61 }62 63 64 void Parser::cc_mode(std::istream& is)65 {66 bool block_com=false;67 std::string str;68 while(getline(is,str)) {69 bool line_com=false;70 line_type lt=empty;71 for (std::string::iterator iter=str.begin(); iter!=str.end(); ++iter){72 if (!block_com && match_begin(iter,str.end(), "/*")){73 block_com=true;74 continue;75 }76 if (block_com && match_begin(iter,str.end(), "*/")){77 block_com=false;78 continue;79 }80 if (block_com){81 if (line_com){82 if (lt==empty && isalnum(*iter))83 lt = comment;84 }85 else if (lt==empty) {86 if (match_begin(iter, str.end(), "//"))87 line_com=true;88 else if (isalnum(*iter))89 lt = comment;90 }91 }92 else if (lt==empty){93 if (isalnum(*iter)){94 if (line_com){95 lt = comment;96 }97 else{98 lt = code;99 }100 }101 else if (match_begin(iter, str.end(), "//")){102 line_com=true;103 }104 else if (!line_com && !isspace(*iter)){105 lt = code;106 }107 108 }109 }110 type_.push_back(lt);111 }112 }113 114 115 void Parser::line_com_mode(std::istream& is, const std::string& com_start)116 {117 std::string str;118 while(getline(is,str)) {119 bool line_com=false;120 line_type lt=empty;121 for (std::string::iterator iter=str.begin(); iter!=str.end(); ++iter){122 if (lt==empty){123 if (isalnum(*iter)){124 if (line_com){125 lt = comment;126 }127 else{128 lt = code;129 }130 }131 else if (match_begin(iter, str.end(), com_start)){132 line_com=true;133 }134 else if (!line_com && !isspace(*iter)){135 lt = code;136 }137 138 }139 }140 type_.push_back(lt);141 }142 }143 144 145 void Parser::markup_mode(std::istream& is)146 {147 bool block_com=false;148 std::string str;149 while(getline(is,str)) {150 line_type lt=empty;151 for (std::string::iterator iter=str.begin(); iter!=str.end(); ++iter){152 if (!block_com && match_begin(iter,str.end(), "<!--")){153 block_com=true;154 continue;155 }156 if (block_com && match_begin(iter,str.end(), "-->")){157 block_com=false;158 continue;159 }160 if (isalnum(*iter))161 if (!block_com)162 lt = code;163 else if (lt==empty)164 lt = comment;165 }166 type_.push_back(lt);167 }168 96 } 169 97 -
trunk/lib/Parser.h
r260 r261 69 69 Parser(const Parser& other); 70 70 71 void cc_mode(std::istream&);72 73 void line_com_mode(std::istream& is, const std::string& com_start);74 75 void markup_mode(std::istream&);76 77 71 void parse(std::istream& is, 78 72 std::vector<std::pair<std::string, std::string> >& codon);
Note: See TracChangeset
for help on using the changeset viewer.