MCPcopy Create free account
hub / github.com/boostorg/parser / main

Function main

example/self_filling_symbol_table.cpp:15–43  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

13namespace bp = boost::parser;
14
15int 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//]

Callers

nothing calls this directly

Calls 3

_attrFunction · 0.85
parseFunction · 0.70
insertMethod · 0.45

Tested by

no test coverage detected