0

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;  
fuji
  • 1,173
  • 1
  • 10
  • 27

1 Answers1

0

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)

Community
  • 1
  • 1
sehe
  • 374,641
  • 47
  • 450
  • 633
  • Thank you very much for your answer! My understanding so far was, that I would need a skip parser, that ignores tabs and newlines. This would leave me with only the parts that I am interested in, which could be parsed by rules. Is there a Skipper which does this already, or do I need to roll my own? – fuji Jul 21 '15 at 15:28