I've been playing around with boost::spirit::qi lately and have been trying to write my own (very, very simple) scripting language which it will parse. I've had trouble when I've got to the if statements in the script. I need the parser to skip parts of the input if a function call comes back true.
For example, I have token defined as to accept variable names (a-zA-Z_) and comparison set to accept ">" or "<". An example of the code is below.
comparison_statement = token >> comparison >> token;
statement = lit("if ") >> comparison_statement[&compare] >> "then";
qi::phrase_parse(first, last, script, space); // This call the parser
How would I go about skipping the next section if the function compare comes back true?
A conditional within the parser can be written by using the Epsilon Parser. This will call the function you supply to it and if that function returns false will fail that particular check and go on to the next or.
For example:
qi::rule<Iterator, std::string(), ascii::space_type> rool;
rool = a | b | eps(f) | d