...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
The rule is a polymorphic generator that acts as a named place-holder capturing the behavior of a PEG expression assigned to it. Naming a Parsing Expression Grammar expression allows it to be referenced later and makes it possible for the rule to call itself. This is one of the most important mechanisms and the reason behind the word "recursive" in recursive descent output generation.
// forwards to <boost/spirit/home/karma/nonterminal/rule.hpp> #include <boost/spirit/include/karma_rule.hpp>
Also, see Include Structure.
Name |
---|
|
template <typename OutputIterator, typename A1, typename A2, typename A3> struct rule;
Parameter |
Description |
Default |
---|---|---|
|
The underlying output iterator type that the rule is expected to work on. |
none |
|
Either |
See table below. |
Here is more information about the template parameters:
Parameter |
Description |
Default |
---|---|---|
|
Specifies the rule's consumed (value to output) and inherited
(arguments) attributes. More on this here: |
|
|
Specifies the rule's delimiter generator. Specify this if you want the rule to delimit the generated output. |
|
|
Specifies the rule's local variables. See |
|
Notation
r,
r2
Rules
g
A generator expression
OutputIterator
The underlying output iterator type that the rule is expected to work on.
A1
, A2
, A3
Either Signature
,
Delimiter
or Locals
in any order.
Semantics of an expression is defined only where it differs from, or
is not defined in Nonterminal
.
Expression |
Description |
---|---|
rule<OutputIterator, A1, A2, A3> r(name);
|
Rule declaration. |
rule<OutputIterator, A1, A2, A3> r(r2);
|
Copy construct rule |
|
Assign rule |
|
Return an alias of |
|
Get a copy of |
|
Rule definition |
|
Auto-rule definition. The attribute of |
|
Retrieve the current name of the rule object. |
|
Set the current name of the rule object to be |
The rule's generator attribute is
RT
: The consumed attribute of the rule. SeeAttribute
The complexity is defined by the complexity of the RHS generator,
g
Note | |
---|---|
The test harness for the example(s) below is presented in the Basics Examples section. |
Some using declarations:
using boost::spirit::karma::rule; using boost::spirit::karma::int_; using boost::spirit::ascii::space; using boost::spirit::ascii::space_type;
Basic rule:
rule<output_iterator_type> r; r = int_(123); test_generator("123", r);
Rule with consumed attribute:
rule<output_iterator_type, int()> ra; ra = int_; test_generator_attr("123", ra, 123);
Rule with delimiter and consumed attribute:
rule<output_iterator_type, std::vector<int>(), space_type> rs; rs = *int_; std::vector<int> v; v.push_back(123); v.push_back(456); v.push_back(789); test_generator_attr_delim("123 456 789", rs, space, v);