解析制表符分隔的文件,Boost.Spirit哪里条目可包含在空白 [英] Parse tab delimited file with Boost.Spirit where entries may contain whitespace in

查看:217
本文介绍了解析制表符分隔的文件,Boost.Spirit哪里条目可包含在空白的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想分析使用Boost.Spirit(齐)制表符分隔的文件。我的文件看起来是这样的:

 李四\\踏歌23 \\ TMEMBER
李四\\踏歌25 \\ TMEMBER
...

有没有可能用的跳过解析器的解析这个?我现在的问题是,的boost ::精神:: ASCII:空间也跳过了人的姓名中的空白。怎么会在 phrase_parse(...)叫什么样子的?

我也是用的Boost.Fusion元组在一个结构的结果存储无限便捷:

 人员结构
{
    字符串名称;
    INT年龄;
    字符串状态;
};

这似乎为名称工作:

 字符串%=语义[+(字符_-'\\ t')];

它匹配的一切字符不是一个标签。然后,它被用作更大规则的一部分:

 启动(%)=名称>>年龄>>状态;


解决方案

  

Q值。是否有可能带有跳跃解析器解析这个?


一个。不,这是不可能的解析与跳读分析器什么。船长达到相反:他们不顾某些输入信息

不过,你似乎在寻找这样的事情黑客什么:(我不推荐)

现在,你可以看看我其他的答案正确的方式来解析CSV / TSV处理嵌入空白,引用的值,转义引号等等。(我相信有人甚至显示续行字符)

I want to parse a tab delimited file using Boost.Spirit (Qi). My file looks something like this:

John Doe\tAge 23\tMember
Jane Doe\tAge 25\tMember
...

Is it possible to parse this with a skip parser? The problem I have right now is, that boost::spirit::ascii:space also skips the whitespace within the name of the person. How would the phrase_parse(...) call look like?

I am also using the Boost.Fusion tuples for convient storing of the results in a struct:

struct Person
{
    string name;
    int age;
    string status;
};

This seems to work for the name:

String %= lexeme[+(char_-'\t')];

It matches everything char that is not a tab. It is then used as part of the bigger rule:

Start %= Name >> Age >> Status;  

解决方案

Q. Is it possible to parse this with a skip parser?

A. No, it's not possible to parse anything with the skip parser. Skippers achieve the opposite: they disregard certain input information.

However, what you seem to be looking for something like this hack: (I don't recommend it)

Now, you could look at my other answers for proper ways to parse CSV/TSV dealing with embedded whitespace, quoted values, escaped quotes etc. (I believe one even shows line-continuation characters)

这篇关于解析制表符分隔的文件,Boost.Spirit哪里条目可包含在空白的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆