I am trying to use the on_error Boost :: Spirit :: qi mechanism to find out why the parsing failed.
I set a breakpoint in the on_error function, and the function is called, but there is no output (nada, nothing, void, ...).
Simple on_error :
on_error<fail>(level1, boost::phoenix::ref(std::cout) << "I've failed.\n" );
Complex on_error (from different sites):
on_error<fail> ( start, boost::phoenix::ref(std::cout) << val("Error! Expecting ") << _4 << val(" here: \"") << construct<std::string>(qi::_3, qi::_2) << val("\"") << std::endl );
Here is my class containing a simple on_error :
template <typename Iterator, typename Skipper> struct Event_Compound : qi::grammar<Iterator, Skipper> { Event_Compound () : Event_Compound::base_type(start, "Compound-Event") { using qi::lexeme; using qi::lit; using namespace qi; using boost::spirit::ascii::char_; relational_operator = lit("&&")[Matched_Relational_AND] || lit("||")[Matched_Relational_OR] ; compound = level1[Matched_Nested_Level1_Begin] >> relational_operator[Matched_Relational_Operator] >> level1[Matched_Nested_Level1_End] ; compare_or_compound = compound[Matched_Compound] | grammar_comparison_event[Matched_Comparison_Event] ; level1 = grammar_boolean_event[Matched_Boolean_Event] | ( char_('(')[Matched_Open_Paren] >> compare_or_compound[Matched_Compare_Or] >> char_(')')[Matched_Close_Paren] ) ; start = level1[Matched_Level1_Begin] >> relational_operator[Matched_Relational_Operator] >> level1[Matched_Level1_End] ; on_error<fail>(level1, boost::phoenix::ref(std::cout) << "I've failed.\n" ); } Event_Boolean<Iterator, Skipper> grammar_boolean_event; Event_Comparison<Iterator, Skipper> grammar_comparison_event; qi::rule<Iterator, Skipper> level1; qi::rule<Iterator, Skipper> compound; qi::rule<Iterator, Skipper> compare_or_compound; qi::rule<Iterator, Skipper> relational_operator; qi::rule<Iterator, Skipper> start; };
Is there a simple method for tracking parser behavior or thinking patterns? (For example, specifying a preprocessor macro or some flag variable)
Why is there no output from on_error ?
Also, what do _1, _2, _3 and _4 link do?
I am trying to debug a grammar, and I have a conclusion about the rules that were mapped, but when the rule is not mapped, I want to know which rule and why.
I use:
- Boost 1.57.0
- Visual studio 2010
- Windows 7
Investigated: