Boost logo

Boost Users :

Subject: [Boost-users] spirit classic - matching end of file space
From: Noah Roberts (roberts.noah_at_[hidden])
Date: 2011-03-07 15:15:05


I have a parser that works great except if there's space at the end of
the stream. I can't seem to come up with a manner to match that space.

The file consists of a header block followed by any number of "shape"
blocks.

I'm calling the parser with: boost::spirit::classic::parse(begin, end,
grammar, boost::spirit::classic::space_p)

My file grammar looks like so:

shape_file =
  !( header[assign_a(self.header_was_read, t)][assign_a
(self.read_header, shape_file_header_grammar::current_header)] )
>> *( shape[push_back_a(self.read_shapes,
shape_grammar::current_shape)] )
;

The parser seems to break down because space at the end of the stream
makes it try to read another shape. My shape grammar looks like so:

shape_block = // := <shape_header> "Begin" <element>* "End"
    (shape_header | shapeheader_error)
>> (as_lower_d["begin"] | begin_error)
>> *element
>> as_lower_d["end"]
;

I've tried adding '*space_p' at the end of both of the above. I've also
tried '*lexeme_p[space_p]' in both. Neither fixes the problem.

I've left out the various other bits of the grammars because it all
works, with this minor issue about end of file space. I'm hoping that
it's irrelevant to the problem.

How might I go about gobbling up any end-of-file spaces in this setup?

-- 
http://crazycpp.wordpress.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