-1

When the file ends in the middle of a rule with remaining expectations, it doesn't trigger an expectation error (it does, of course, fail to parse).

A simplified example that triggers the behavior is this:

data_var_decls_r
  %= (lit("data")
       > lit('{'))
  > lit('}');

If the input is only

data {

then the expectation error for the final expected } isn't triggered.

Is there a way to deal with expectation errors that extend past the end of file?

Bob Carpenter
  • 3,613
  • 1
  • 20
  • 13

1 Answers1

2

Making it into a self-contained example:

See it Live On Wandbox

#include <boost/spirit/include/qi.hpp>

namespace test {
    using namespace boost::spirit::qi;

    rule<std::string::const_iterator> rule = lit("data") > '{' > '}';
}

int main() {
    std::string const input("data{");

    bool ok = parse(input.begin(), input.end(), test::rule);
}

Does throw expectation failure.

Even when using space skipper, it still throws:

See it Live On Wandbox too

#include <boost/spirit/include/qi.hpp>

namespace test {
    using namespace boost::spirit::qi;

    rule<std::string::const_iterator, space_type> rule = lit("data") > '{' > '}';
}

int main() {
    std::string const input("data{");

    bool ok = phrase_parse(input.begin(), input.end(), test::rule, test::space);
}
sehe
  • 374,641
  • 47
  • 450
  • 633
  • Thanks for the simple standalone example. I was hoping it was a known problem with a known solution. I'll try simplifying our dozens of files and grammars into an example that demonstrates the problem. I may not succeed as our grammars are really huge at this point and I have no idea where this problem could be coming from. Are there any general tips for debuggin Spirit Qi grammars somewhere? I wind up just writing a lot of callback semantic actions to print progress, but it's a very time consuming process. – Bob Carpenter Jul 25 '17 at 15:58
  • A lot of them on SO (just search my answers...). A link to a public repo might help. Look at `BOOST_SPIRIT_DEBUG*` macros. And, [don't complicate with semantic actions.. :(](https://stackoverflow.com/questions/8259440/boost-spirit-semantic-actions-are-evil) – sehe Jul 25 '17 at 15:59
  • Also, should I just post a new question or edit? I'm never sure of the protocol on StackOverflow and I see devs yelling at each other all the time over edited questions. I can see that my initial question annoyed someone enough to downvote it and I don't want to keep annoying people who might be able to help me. – Bob Carpenter Jul 25 '17 at 16:00
  • At this stage, I think it's up to you. It's bad etiquette to invalidate existing answers by changing the question, but I don't really mind in this case (because I don't think the question is useful in its current form). OTOH posting a fresh one does give it a fresh chance w.r.t. voting. [The downvote is probably from the same person who upvoted my comment, I suppose.] – sehe Jul 25 '17 at 16:02
  • 1
    I extended the grammar extensively to match what we have and it looks like the problem is somewhere in our results handling code, not in Spirit Qi. Thanks much for the simple example---it was really helpful in debugging. – Bob Carpenter Jul 26 '17 at 16:01
  • Isn't that how it always works. I like to link people to http://kera.name/articles/2013/10/nobody-writes-testcases-any-more/ and similar articles, but it seems not necessary in your case :) Good luck with the project – sehe Jul 26 '17 at 16:02