
hi all, i'm trying to ignore unecognized lines of input (so following lines can be processed without the parse failing). eg: very simple scenario as follows: ///=================================================== { using namespace boost::spirit; typedef file_iterator<char> iterator_t; typedef scanner<iterator_t, scanner_policies_t> scanner_t; typedef rule<scanner_t> rule_t; int red=0, green=0, blue=0; rule_t option = (str_p("red") >> '=' >> int_p[assign(red)]) | (str_p("green") >> '=' >> int_p[assign(green)]) | (str_p("blue") >> '=' >> int_p[assign(blue)]) | ; iterator_t first(filename.c_str()); if (!first) return; iterator_t last = first.make_end(); parse(first, last, *option, space_p); } ///=================================================== wiw is a parser that will skip over the unrecognized line with input like this: ------------------ red = 255 kermit = green green = 128 blue = 128 ------------------ and correctly interpret the green and blue values.. i played around with eol_p as i want to skip whole lines of unrecognized content. i thought it would be easy, but i can't seem to get it right. can anybody do my job for me? cheers Jono

AMDG jono wrote:
i'm trying to ignore unecognized lines of input (so following lines can be processed without the parse failing).
eg: very simple scenario as follows: <snip>
i played around with eol_p as i want to skip whole lines of unrecognized content. i thought it would be easy, but i can't seem to get it right.
can anybody do my job for me?
For something this simple, it might be easier to process line by line. rule_t option = ...; std::ifstream input(filename.c_str()); std::string current_line; while(std::getline(input, current_line)) { parse(current_line, option, space_p); } In Christ, Steven Watanabe
participants (2)
-
jono
-
Steven Watanabe