使用 BOOST 分词器显示分隔符,并且不对引号中的字符串进行分词
Using BOOST Tokenizer to display delimiter and to not tokenize a string in quotes
我正在使用BOOST分词器将字符串分解为脚趾。基本上,令牌将用于创建基于 c/c++ 的 VSL 编译器。我想问的是,是否有可能使用
char_separator<char> sep("; << ");
也显示例如,如果我在字符串上使用 Boost 分词器
string s= "cout<<hello;"
它应该制作以下令牌
cout
<<
hello
;
另外,我如何确保它不会转换引号中的标记化某些内容喜欢
string s= "hello my "name is" Hassan"
应转换为以下令牌
hello
my
name is
Hassan
我建议提升精神:住在科里鲁
编辑 另请参阅 http://www.boost.org/doc/libs/1_55_0/libs/spirit/example/qi/compiler_tutorial
#include <boost/spirit/include/qi.hpp>
namespace qi = boost::spirit::qi;
int main(int argc, char** argv)
{
typedef std::string::const_iterator It;
std::string const input = "cout<<hello;my "name is" Hassan";
qi::rule<It, std::string()> delimiter = qi::char_("; ") | qi::string("<<");
qi::rule<It, std::string()> quoted = '"' >> *~qi::char_('"') > '"';
qi::rule<It, std::string()> word = +((quoted | qi::char_) - delimiter);
std::vector<std::string> tokens;
if (qi::parse(input.begin(), input.end(), *(word >> delimiter), tokens))
{
for(auto& token : tokens)
std::cout << "'" << token << "'n";
}
}
输出:
'cout'
'<<'
'hello'
';'
'my'
' '
'name is'
' '
'Hassan'
相关文章:
- 当我尝试使用 sstream 和分面将 Boost Time_duration转换为字符串时,我没有得到所需的格式
- 将子字符串字符从字符串值转换为 int,然后将其分配给 int 变量
- 将 2 个单词与字符串分隔开
- SymSpellPlusPlus 中的分词
- 使用 C++ 的字符串到分词符
- 将字符分配给 C++ 字符串
- C++ 在 switch 语句中,cin.getline 不会分配给 c 字符串变量
- Qt等效于提升分词器表达式/构造
- 使用 BOOST 分词器显示分隔符,并且不对引号中的字符串进行分词
- 使用 ICU 进行分词
- C++数学分词器/解析器错误
- 访问增强分词器的元素
- 提升分词器以将带引号的字符串视为一个标记
- 当我的分词器识别出令牌时,如何执行其他操作
- 分词器 - 预期聚合对象使用"{...}"进行初始化
- C++ 分词器变量中的错误'std::stringstream mystream'具有初始值设定项但类型不完整
- 错误的分词
- 分词错误-比较不同的单词在c++输入中出现的次数
- OpenCV 3.0分词故障(视觉词袋)
- 可视化 如何在没有正则表达式的情况下实现C++高效的全词字符串替换