Created
September 20, 2016 05:36
-
-
Save jefftrull/983d783cf508249e5352de8e844a27cb to your computer and use it in GitHub Desktop.
Interesting (possibly wrong) synthesized attribute behavior
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <boost/spirit/include/qi.hpp> | |
#include <boost/optional.hpp> | |
#include <boost/optional/optional_io.hpp> | |
int main() { | |
using namespace std; | |
// parsing parentheses that may or may not contain integers | |
string in("(10) () (20)"); | |
vector<boost::optional<int>> result; | |
auto beg = in.begin(); | |
auto end = in.end(); | |
using namespace boost::spirit::qi; | |
phrase_parse(beg, end, | |
*('(' > ((int_|eps) ^ eps) > ')'), // <<<< second in sequence uninit instead of "not present" | |
ascii::space, | |
result); | |
copy(result.begin(), result.end(), | |
ostream_iterator<boost::optional<int>>(cout, " ")); | |
cout << "\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment