#include <boost/xpressive/xpressive.hpp>
#include <boost/xpressive/regex_actions.hpp>
using namespace boost::xpressive;
sregex e_string = as_xpr('"') >> *((as_xpr('//') >> _) | ~(boost::xpressive::set = '//', '"')) >> '"';
sregex e_char = as_xpr('/'') >> *((as_xpr('//') >> _) | ~(boost::xpressive::set = '//', '/'')) >> '/'';
sregex e_normal_comment = ("//" >> -*_ >> before(_ln | eos)) | ("/*" >> -*_>> "*/");
sregex e_if0_start = bol >> *_s >> '#' >> *_s >> "if" >> *_s >> '0' >> +_s;
sregex e_if_start = bol >> *_s >> '#' >> *_s >> "if";
sregex e_if_end = '#' >> *_s >> "endif" >> -*_ >> (_ln | eos);
sregex e_if_secondhalf = -*_ >> (e_if_end | ((e_string | e_char | e_normal_comment | (e_if_start >> self)) >> self));
sregex e_if = e_if_start >> by_ref(e_if_secondhalf);
sregex e_if0_comment = e_if0_start >> by_ref(e_if_secondhalf);
sregex e_comment = e_normal_comment | e_if0_comment;
sregex e_find = e_string | e_char | e_comment[ref(cout) << _ << "/n"];
int main(int argc, char *argv[])
{
string name;
while (cin >> name)
{
ifstream f(name.c_str());
string s((istreambuf_iterator<char>(f)), istreambuf_iterator<char>());
for (sregex_iterator iter(s.begin(), s.end(), e_find); iter != sregex_iterator(); ++iter)
{}
}
system("PAUSE");
return EXIT_SUCCESS;
}
boost xpressive库,介于正则和bnf库之间的混血。显示c/c++代码注释部分。
最新推荐文章于 2023-08-21 10:27:28 发布