Boost logo

Boost Users :

Subject: Re: [Boost-users] [spirit] first steps
From: Michael Caisse (boost_at_[hidden])
Date: 2010-02-18 14:06:50


Igor R wrote:
>> qi::string is not a valid parser primitive. What would you expect it to match anyway? You'll have to be a bit more specific about what kind of string you need to parse, for instance:
>>
>> '"' >> ~+char_('"') >> '"'
>>
>
> Ok, I see...
> Actually, I have to parse a list of strings, where every line consists
> of numbers and "strings" delimited by ":" -- where "strings" may be
> empty or may contain virtually any character (except for the
> delimeter), like this:
> 1:23:string#1:optional&string_at_2
> 2:34:string#2:optional.string%3
>
> besides, the last "string" in the line may be absent with the
> preceeding delimeter, i.e. both "1:23:string#1:" and "1:23:string#1"
> are valid (of course, "1:23::" is valid too)
>
> Is it possible with Spirit? Would it be the right tool?
>
> Thanks.
>

Hi Igor -

Spirit has a built-in construct for lists:

   
   ~*char( ':' ) % ':'

If you use attribute parsing you can simply perform the following:

   std::vector< std::string > list_of_strings;

          parse( begin, end,
                 ~*char( ':' ) % ':',
                 list_of_strings
                );

Nice huh?

HTH -
michael

-- 
----------------------------------
Michael Caisse
Object Modeling Designs
www.objectmodelingdesigns.com

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net