...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
boost::parser::symbols
// In header: <boost/parser/parser.hpp> template<typename T> struct symbols : public boost::parser::parser_interface< symbol_parser< T > > { // public member functions symbols(); symbols(char const *); symbols(std::initializer_list< std::pair< std::string_view, T > >); symbols(char const *, std::initializer_list< std::pair< std::string_view, T > >); void insert_for_next_parse(std::string_view, T); void erase_for_next_parse(std::string_view); void clear_for_next_parse(); template<typename Context> void insert_for_next_parse(Context const &, std::string_view, T); template<typename Context> void erase_for_next_parse(Context const &, std::string_view); template<typename Context> void clear_for_next_parse(Context const &); template<typename Context> unspecified find(Context const &, std::string_view) const; template<typename Context> void insert(Context const &, std::string_view, T) const; template<typename Context> void erase(Context const &, std::string_view) const; template<typename Context> void clear(Context const &) const; };
A symbols<T>
represents the initial state of a symbol table parser that produces attributes of type T
. The entries in the symbol table can be changed during parsing, but those mutations to not affect the symbols<T>
object itself; all mutations happen to a copy of the symbol table in the parse context. For table entries that should be used during every parse, add entries via add()
or operator()
. For mid-parse mutations, use insert()
and erase()
.
symbols
public member functionssymbols();
symbols(char const * diagnostic_text);
symbols(std::initializer_list< std::pair< std::string_view, T > > il);
symbols(char const * diagnostic_text, std::initializer_list< std::pair< std::string_view, T > > il);
void insert_for_next_parse(std::string_view str, T x);
Inserts an entry consisting of a UTF-8 string str
to match, and an associated attribute x
, to *this
. The entry is added for use in all subsequent top-level parses. Subsequent lookups during the current top-level parse will not necessarily match str
.
void erase_for_next_parse(std::string_view str);
Erases the entry whose UTF-8 match string is str
, from *this
. The entry will no longer be available for use in all subsequent top-level parses. str
will not be removed from the symbols matched in the current top-level parse.
void clear_for_next_parse();
Erases all the entries from the copy of the symbol table inside the parse context context
.
template<typename Context> void insert_for_next_parse(Context const & context, std::string_view str, T x);
Inserts an entry consisting of a UTF-8 string str
to match, and an associated attribute x
, to *this
. The entry is added for use in all subsequent top-level parses. Subsequent lookups during the current top-level parse will not necessarily match str
.
template<typename Context> void erase_for_next_parse(Context const & context, std::string_view str);
Erases the entry whose UTF-8 match string is str
, from *this
. The entry will no longer be available for use in all subsequent top-level parses. str
will not be removed from the symbols matched in the current top-level parse.
template<typename Context> void clear_for_next_parse(Context const & context);
Erases all the entries from the copy of the symbol table inside the parse context context
.
template<typename Context> unspecified find(Context const & context, std::string_view str) const;
Uses UTF-8 string str
to look up an attribute in the table during parsing, returning it as an optional reference. The lookup is done on the copy of the symbol table inside the parse context context
, not *this
.
template<typename Context> void insert(Context const & context, std::string_view str, T x) const;
Inserts an entry consisting of a UTF-8 string to match str
, and an associtated attribute x
, to the copy of the symbol table inside the parse context context
.
template<typename Context> void erase(Context const & context, std::string_view str) const;
Erases the entry whose UTF-8 match string is str
from the copy of the symbol table inside the parse context context
.
template<typename Context> void clear(Context const & context) const;
Erases all the entries from the copy of the symbol table inside the parse context context
.