Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

missing expectation errors for program fragments #2363

Closed
bob-carpenter opened this issue Jul 25, 2017 · 3 comments
Closed

missing expectation errors for program fragments #2363

bob-carpenter opened this issue Jul 25, 2017 · 3 comments
Assignees

Comments

@bob-carpenter
Copy link
Contributor

bob-carpenter commented Jul 25, 2017

Summary:

When the program ends in the middle of a Boost Spirit Qi parser expectation, the error doesn't get reported.

Reproducible Steps:

This program triggers the problem.

oneliner.stan

data {

Current Output:

From CmdStan:

Model name=oneliner_model
Input file=/Users/carp/temp2/oneliner.stan
Output file=/Users/carp/temp2/oneliner.hpp

PROGRAM ERROR, MESSAGE(S) FROM PARSER:


make: *** [/Users/carp/temp2/oneliner.hpp] Error 253

Expected Output:

Expectation error indicating a missing }.

Additional Information:

I tried to ask on StackOverflow and got scolded and downvoted.

https://stackoverflow.com/questions/45307175/expectation-failure-not-triggered-if-file-ends-with-boost-spirit-qi-parser/45307497#45307497

I've gotten this far in trying to replicate with no luck, so I'm going to punt on this for the time being.

#include <boost/spirit/home/support/iterators/line_pos_iterator.hpp>
#include <boost/spirit/include/qi.hpp>
#include <string>
#include <iostream>

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

  typedef std::string::const_iterator input_iterator;
  typedef boost::spirit::line_pos_iterator<input_iterator> lp_iterator;

  struct whitespace_grammar : public boost::spirit::qi::grammar<lp_iterator> {
    boost::spirit::qi::rule<lp_iterator> whitespace;
    whitespace_grammar() : whitespace_grammar::base_type(whitespace) {
      whitespace = ((omit["/*"] >> *(char_ - "*/")) > omit["*/"])
        | (omit["//"] >> *(char_ - eol))
        | boost::spirit::ascii::space_type();
    }
  };

  rule<lp_iterator, std::string(), whitespace_grammar> rule
  = (lit("data") > lit('{')) > string("foo") > lit('}');


}

int main() {
  using test::lp_iterator;
  std::string in("data { foo");
  lp_iterator begin = lp_iterator(in.begin());
  lp_iterator end = lp_iterator(in.end());
  test::whitespace_grammar white_gram;
  std::string result;
  try {
    phrase_parse(begin, end, test::rule, white_gram, result);
  } catch (const test::expectation_failure<lp_iterator>& e) {
    std::cout << e.what_ << std::endl;
  }
}
$ ./a.out
"}"

There's a ton of other logic floating around in our grammars, so I'm guessing the error's getting thrown and then ignored by one of the many layers we have in place.

Current Version:

v2.16.0

@bob-carpenter bob-carpenter added this to the v3 milestone Jul 25, 2017
@bob-carpenter bob-carpenter self-assigned this Jul 25, 2017
@mitzimorris mitzimorris self-assigned this Jul 31, 2017
@mitzimorris
Copy link
Member

now that feature #2280 has been merged into develop via PR #2357, given program fragment data {, the parser generates the following error:

PARSER EXPECTED: whitespace to end of file.
FOUND AT line 12: 
data {





make: *** [foo.hpp] Error 253

@mitzimorris
Copy link
Member

not a great error message - for that we have issue: #2367

@bob-carpenter
Copy link
Contributor Author

OK, closing.

@mcol mcol removed this from the v3 milestone Feb 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants