Re: Parsing data using istream_iterator
From: Jeff F (not_at_anywhere.com)
Date: 10/29/04
- Next message: Ravi Ambros Wallau: "Re: How can I add a alredy existing project to a workspace"
- Previous message: Jeff Partch [MVP]: "Re: _CLSID_ADSystemInfo link error."
- In reply to: Daniel Lidström: "Re: Parsing data using istream_iterator"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 29 Oct 2004 08:18:04 -0400
Daniel,
Parsing tasks are best done with parsers. See
http://www.boost.org/libs/spirit/index.html for an embedded C++ parser
framework. There was also an article on www.codeproject.com, IIRC.
"Daniel Lidström" <someone@microsoft.com> wrote in message
news:1svdm5o1477u4$.18g82c87qj5hg$.dlg@40tude.net...
> On Fri, 29 Oct 2004 10:51:25 +0200, Daniel Lidström wrote:
>
> > Hi,
> >
> > I'm writing routines for parsing data that comes in this form:
> >
> > string 3d {
> > z 10
> > colour "white"
> > data {
> > x-value y-value z-value
> > . . .
> > . . .
> > }
> > }
The corresponding spirit parser could be defined _approximately_ like:
using boost::spirit;
file_iterator beg( "mydatafile" ), end;
point pt;
std::vector<point> points;
rule<> rPoint = real_p[assign(pt.x)] >> real_p[assign(pt.y)] >>
real_p[assign(pt.z)];
rule<> rData = str_p("data") >> '{' >> +rPoint[Append(points,point)] >>
'}';
rule<> rColor = str_p("colour") >> '"' >> +alpha_p >> '"';
rule<> rZ = chr_p('z') >> uint_p;
rule<> r3d = str_p("string") >> "3d" >> '{' >> rZ >> rColor >>
rData>> '}';
parse( beg, end, r3d, space_p );
This is just meant to give you a flavor of what you can do. The details are
slightly more involved. You can read up on spirit at the links above.
Jeff F
- Next message: Ravi Ambros Wallau: "Re: How can I add a alredy existing project to a workspace"
- Previous message: Jeff Partch [MVP]: "Re: _CLSID_ADSystemInfo link error."
- In reply to: Daniel Lidström: "Re: Parsing data using istream_iterator"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|