| 1 | // test case demonstrating change in results of "distinct" repo parser
|
|---|
| 2 |
|
|---|
| 3 | #include <boost/spirit/include/qi.hpp>
|
|---|
| 4 | #include <boost/spirit/repository/include/qi_distinct.hpp>
|
|---|
| 5 | #include <boost/spirit/include/qi_attr.hpp>
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 | int main(int argc, char **argv) {
|
|---|
| 9 | using boost::spirit::repository::distinct;
|
|---|
| 10 | using namespace boost::spirit::qi;
|
|---|
| 11 | typedef std::string::iterator iterator;
|
|---|
| 12 | using boost::spirit::ascii::space_type;
|
|---|
| 13 | using boost::spirit::attr;
|
|---|
| 14 | using boost::spirit::ascii::string;
|
|---|
| 15 |
|
|---|
| 16 | boost::spirit::qi::rule<iterator, std::string(), space_type> string_keyword;
|
|---|
| 17 | // removing the preamble "+" from the rule and the input data causes this to pass
|
|---|
| 18 | string_keyword %= '+' >> (distinct("0-9a-zA-Z_")[string("ALPHA")] |
|
|---|
| 19 | distinct("0-9a-zA-Z_")[string("BETA")]);
|
|---|
| 20 |
|
|---|
| 21 | using boost::spirit::qi::phrase_parse;
|
|---|
| 22 | using boost::spirit::qi::ascii::space;
|
|---|
| 23 |
|
|---|
| 24 | std::string inputdata("+ BETA");
|
|---|
| 25 | std::string result;
|
|---|
| 26 | std::string::iterator input_it = inputdata.begin();
|
|---|
| 27 | if (!phrase_parse(input_it, inputdata.end(), string_keyword, space, result) ||
|
|---|
| 28 | (input_it != inputdata.end())) {
|
|---|
| 29 | std::cerr << "parse failed\n";
|
|---|
| 30 | return 1;
|
|---|
| 31 | }
|
|---|
| 32 | if (result != "BETA") {
|
|---|
| 33 | // beginning with Boost 1.46, the result value is "B"
|
|---|
| 34 | std::cerr << "keyword parse produced incorrect result " << result;
|
|---|
| 35 | std::cerr << " vs. expected value BETA\n";
|
|---|
| 36 | return 1;
|
|---|
| 37 | }
|
|---|
| 38 | return 0;
|
|---|
| 39 | }
|
|---|