| 21 | namespace bp = boost::parser; |
| 22 | |
| 23 | int main() |
| 24 | { |
| 25 | std::cout << "Enter employee record. "; |
| 26 | std::string input; |
| 27 | std::getline(std::cin, input); |
| 28 | |
| 29 | auto quoted_string = bp::lexeme['"' >> +(bp::char_ - '"') >> '"']; |
| 30 | auto employee_p = bp::lit("employee") |
| 31 | >> '{' |
| 32 | >> bp::int_ >> ',' |
| 33 | >> quoted_string >> ',' |
| 34 | >> quoted_string >> ',' |
| 35 | >> bp::double_ |
| 36 | >> '}'; |
| 37 | |
| 38 | employee record; |
| 39 | auto const result = bp::parse(input, employee_p, bp::ws, record); |
| 40 | |
| 41 | if (result) { |
| 42 | std::cout << "You entered:\nage: " << record.age |
| 43 | << "\nsurname: " << record.surname |
| 44 | << "\nforename: " << record.forename |
| 45 | << "\nsalary : " << record.salary << "\n"; |
| 46 | } else { |
| 47 | std::cout << "Parse failure.\n"; |
| 48 | } |
| 49 | } |
| 50 | //] |