| 13 | namespace bp = boost::parser; |
| 14 | |
| 15 | int main() |
| 16 | { |
| 17 | //[ self_filling_symbol_table_table |
| 18 | bp::symbols<int> const symbols = {{"c", 8}}; |
| 19 | assert(parse("c", symbols)); |
| 20 | //] |
| 21 | |
| 22 | //[ self_filling_symbol_table_action |
| 23 | auto const add_symbol = [&symbols](auto & ctx) { |
| 24 | using namespace bp::literals; |
| 25 | // symbols::insert() requires a string, not a single character. |
| 26 | char chars[2] = {_attr(ctx)[0_c], 0}; |
| 27 | symbols.insert(ctx, chars, _attr(ctx)[1_c]); |
| 28 | }; |
| 29 | //] |
| 30 | //[ self_filling_symbol_table_parser |
| 31 | auto const parser = (bp::char_ >> bp::int_)[add_symbol] >> symbols; |
| 32 | //] |
| 33 | |
| 34 | //[ self_filling_symbol_table_parse |
| 35 | auto const result = parse("X 9 X", parser, bp::ws); |
| 36 | assert(result && *result == 9); |
| 37 | //] |
| 38 | (void)result; |
| 39 | |
| 40 | //[ self_filling_symbol_table_after_parse |
| 41 | assert(!parse("X", symbols)); |
| 42 | //] |
| 43 | } |
| 44 | //] |