[spirit] working with end_p

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? Thanks for any help offered, Neil Hunt

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
participants (2)
-
Manfred Doudar
-
Neil Hunt