Boost logo

Boost Users :

From: Manfred Doudar (manfred.doudar_at_[hidden])
Date: 2006-07-04 21:27:30


Hi Neil,

Neil Hunt wrote:
> Hello all,
>
> Given a simple spirit grammar (simplified from my real grammer and
> untested) such as:
>
> file = *line;
> line = sensible_line >> ending >> *comment;
> sensible_line = confix_p( '\"', *c_escape_ch_p, '\"' );
> comment = !( ch_p(';') >> ( anychar_p - eol_p ) ) >> ending;
> ending = *blank_p >> ( eol_p | end_p );
>
>
> Note: any given line can be legitimately terminated by the end of the
> file or end of line
>
> And there can be arbitrary numbers of comment lines between sensible lines.
>
> However since 'comment' is terminated with 'ending', the parser ends up
> in an infinite loop matching the kleene star on end_p because it returns
> zero length (doesn't advance the scanner). At least I think this is the
> problem.
>
> By using:
> ending = *blank_p >> eol_p ;
>
> the parser runs to completion, but any given line must be terminated by
> an end of line sequence.
>
> Any suggestions on how to fix this problem?

Not looking to closely at the above code, but you should be specify your
comment parser to be your skip parser:

line = sensible_line >> ending;

and your parse line would look something like:

parse(file_iterator_begin, file_iterator_end, grammar_class_instance,
comment);

Note that 'comment' parser is your _skip_ parser here - so the effect
being is that all comment types are ignored on parsing.

If I have been to succinct, email back and I'll flesh it out a bit more
for you.

Cheers,

-- 
Manfred Doudar
05.07.2006

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