[spirit] working with end_p

From: Neil Hunt
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.
Indeed. You can fix it by adjusting your grammar thus: line = sensible_line >> (ending >> comment)* >> ending; sensible_line ... as before comment = !( ch_p(';') >> ( anychar_p - eol_p ) ); ending ... as before - James Jones Administrative Data Mgmt. Webmaster 375 Raritan Center Pkwy, Suite A Data Architect Edison, NJ 08837
participants (1)
-
james.jonesīŧ firstinvestors.com