| 13 | namespace bp = boost::parser; |
| 14 | |
| 15 | int main() |
| 16 | { |
| 17 | std::cout << "Enter a list of doubles, separated by commas. "; |
| 18 | std::string input; |
| 19 | std::getline(std::cin, input); |
| 20 | |
| 21 | std::vector<double> result; |
| 22 | //[ semantic_action_example_lambda |
| 23 | auto const action = [&result](auto & ctx) { |
| 24 | std::cout << "Got one!\n"; |
| 25 | result.push_back(_attr(ctx)); |
| 26 | }; |
| 27 | //] |
| 28 | auto const action_parser = bp::double_[action]; |
| 29 | auto const success = bp::parse(input, action_parser % ',', bp::ws); |
| 30 | |
| 31 | if (success) { |
| 32 | std::cout << "You entered:\n"; |
| 33 | for (double x : result) { |
| 34 | std::cout << x << "\n"; |
| 35 | } |
| 36 | } else { |
| 37 | std::cout << "Parse failure.\n"; |
| 38 | } |
| 39 | } |
| 40 | //] |