Search code examples
c++boostboost-spiritboost-spirit-qi

boost::spirit qi parsing runtime error


why do I have runtime error, while parsing string whith that grammar?

template <typename Iterator, typename Skipper>
struct grammar : qi::grammar<Iterator, QVariant(), Skipper>
{
  grammar() : grammar::base_type(object)
  {
    identifier = qi::raw[qi::lexeme[qi::alpha >> *(qi::alnum | '_' | ('-' >> qi::alnum))]];

    self = (qi::raw[qi::lexeme["self"]]);
    object = (self >> '.' >> identifier)
            |(object >> '.' >> identifier); // there is no runtime error without that line
  }
}

Any other grammatics run good, but I want to parse something like that:

self.foo.bar2.baz

Runtime error throws at

     qi::phrase_parse(it, str.end(), g, ascii::space, v) && it == str.end())

call.


Solution

  • Left recursions like "A = (A >> a ) | b" are unavaible in LL-parsers like boost::spirit. They should be transformed to LL-friendly form: A = bR R = aR | e Where R - new non-terminal and e - epsilon (empty terminal).