Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

Attributes of Primitive Components

Parsers in Spirit are fully attributed. Spirit.X3 parsers always expose an attribute specific to their type. This is called synthesized attribute as it is returned from a successful match representing the matched input sequence. For instance, numeric parsers, such as int_ or double_, return the int or double value converted from the matched input sequence. Other primitive parser components have other intuitive attribute types, such as for instance int_ which has int, or ascii::char_ which has char. Primitive parsers apply the normal C++ convertibility rules: you can use any C++ type to receive the parsed value as long as the attribute type of the parser is convertible to the type provided. The following example shows how a synthesized parser attribute (the int value) is extracted by calling the API function x3::parse:

int value = 0;
std::string str("123");
std::string::iterator strbegin = str.begin();
x3::parse(strbegin, str.end(), int_, value);   // value == 123

For a full list of available parser primitives and their attribute types please see the sections X3 Parsers.


PrevUpHomeNext