boost xpressive库,介于正则和bnf库之间的混血。显示c/c++代码注释部分。
2009-06-26 15:28
357 查看
#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;
}
#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;
}
相关文章推荐
- 把C/C++程序代码中的注释去掉,并返回结果
- 部分C++代码-耗时统计
- 利用正则表达式统计代码中的(代码行数,注释行数,空白行数)利用正则表达式获取一个网页中所有的邮箱地址
- 崩溃,source Insight显示linux代码中文注释乱码问题,以及很傻很天真的解决方法
- js正则 - 显示或者保存正则表达式匹配的部分内容
- 第16周项目5-编程处理C++代码(输入m、n两个数字,从第m行起的n行代码将作为注释使用)
- 7月_C++_3-->timer部分代码3_双链表
- 解决Eclipse中C++代码显示Symbol 'std' could not be resolved的问题
- php中文乱码问题以及页面显示部分后台代码问题
- php中文乱码问题以及页面显示部分后台代码问题
- java中提供了对正则表达式的支持。 有的时候,恰当地使用正则,可以让我们的工作事半功倍! 如下代码用来检验一个四则运算式中数据项的数目,请填写划线部分缺少的代码。 注意:只填写缺少代码,不要
- VS 2008 实现在C#中调用C++编写的 coin 3d 三位显示部分
- C++文档化代码注释
- 利用unsafe代码在C++和C#之间传递图像
- EtherCAT从站代码注释(部分)
- “机器狗”病毒驱动部分逆向分析注释(C代码)
- vscode打开代码,注释中的中文显示乱码
- c++ setprecision 的是一共显示多少位的意思,包括整数部分,而且是四舍五入
- cocos2d-x CocoStudio中场景触发器(Trigger)的代码部分和触发器之间的互调