| 1 | #include <iostream>
|
|---|
| 2 | #include <boost/spirit/include/qi.hpp>
|
|---|
| 3 | #include <boost/optional.hpp>
|
|---|
| 4 | #include <boost/optional/optional_io.hpp>
|
|---|
| 5 |
|
|---|
| 6 | int main() {
|
|---|
| 7 | using namespace std;
|
|---|
| 8 |
|
|---|
| 9 | // parsing parentheses that may or may contain integers or one of a couple other things
|
|---|
| 10 |
|
|---|
| 11 | using namespace boost::spirit::qi;
|
|---|
| 12 | rule<string::iterator> nulltok = boost::spirit::qi::string("novalue");
|
|---|
| 13 | rule<string::iterator> othertok = boost::spirit::qi::string("somethingelse");
|
|---|
| 14 |
|
|---|
| 15 | boost::optional<int> result;
|
|---|
| 16 | std::string in("(novalue)");
|
|---|
| 17 | auto beg = in.begin();
|
|---|
| 18 | auto end = in.end();
|
|---|
| 19 | phrase_parse(beg, end,
|
|---|
| 20 | '(' > ((int_ | nulltok) ^ othertok) > ')', // <<<< uninit instead of "not present"
|
|---|
| 21 | ascii::space,
|
|---|
| 22 | result);
|
|---|
| 23 | cout << result << "\n";
|
|---|
| 24 | }
|
|---|