nonterminal.qbk 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. [/==============================================================================
  2. Copyright (C) 2001-2011 Joel de Guzman
  3. Copyright (C) 2001-2011 Hartmut Kaiser
  4. Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. ===============================================================================/]
  7. [section:nonterminal Nonterminal Generators]
  8. [heading Module Headers]
  9. // forwards to <boost/spirit/home/karma/nonterminal.hpp>
  10. #include <boost/spirit/include/karma_nonterminal.hpp>
  11. Also, see __include_structure__.
  12. [//////////////////////////////////////////////////////////////////////////////]
  13. [section:rule Generator Rule]
  14. [heading Description]
  15. The rule is a polymorphic generator that acts as a named place-holder
  16. capturing the behavior of a PEG expression assigned to it. Naming a
  17. __peg__ expression allows it to be referenced later and makes it
  18. possible for the rule to call itself. This is one of the most important
  19. mechanisms and the reason behind the word "recursive" in recursive
  20. descent output generation.
  21. [heading Header]
  22. // forwards to <boost/spirit/home/karma/nonterminal/rule.hpp>
  23. #include <boost/spirit/include/karma_rule.hpp>
  24. Also, see __include_structure__.
  25. [heading Namespace]
  26. [table
  27. [[Name]]
  28. [[`boost::spirit::karma::rule`]]
  29. ]
  30. [heading Synopsis]
  31. template <typename OutputIterator, typename A1, typename A2, typename A3>
  32. struct rule;
  33. [heading Template parameters]
  34. [table
  35. [[Parameter] [Description] [Default]]
  36. [[`OutputIterator`] [The underlying output iterator
  37. type that the rule is
  38. expected to work on.] [none]]
  39. [[`A1`, `A2`, `A3`] [Either `Signature`,
  40. `Delimiter` or `Locals` in
  41. any order. See table below.] [See table below.]]
  42. ]
  43. Here is more information about the template parameters:
  44. [table
  45. [[Parameter] [Description] [Default]]
  46. [[`Signature`] [Specifies the rule's consumed
  47. (value to output) and inherited
  48. (arguments) attributes. More on
  49. this here: __karma_nonterminal_concept__.]
  50. [__unused_type__.
  51. When `Signature` defaults
  52. to __unused_type__, the effect
  53. is the same as specifying a signature
  54. of `void()` which is also equivalent
  55. to `unused_type()`]]
  56. [[`Delimiter`] [Specifies the rule's delimiter
  57. generator. Specify this if you
  58. want the rule to delimit the
  59. generated output.] [__unused_type__]]
  60. [[`Locals`] [Specifies the rule's local
  61. variables. See __karma_nonterminal_concept__.]
  62. [__unused_type__]]
  63. ]
  64. [heading Model of]
  65. [:__karma_nonterminal_concept__]
  66. [variablelist Notation
  67. [[`r, r2`] [Rules]]
  68. [[`g`] [A generator expression]]
  69. [[`OutputIterator`] [The underlying output iterator type that the rule is
  70. expected to work on.]]
  71. [[`A1`, `A2`, `A3`] [Either `Signature`, `Delimiter` or `Locals` in
  72. any order.]]
  73. ]
  74. [heading Expression Semantics]
  75. Semantics of an expression is defined only where it differs from, or is
  76. not defined in __karma_nonterminal_concept__.
  77. [table
  78. [[Expression] [Description]]
  79. [[
  80. ``rule<OutputIterator, A1, A2, A3>
  81. r(name);``]
  82. [Rule declaration. `OutputIterator` is required.
  83. `A1, A2, A3` are optional and can be specified in any order.
  84. `name` is an optional string that gives the rule
  85. its name, useful for debugging.]]
  86. [[
  87. ``rule<OutputIterator, A1, A2, A3>
  88. r(r2);``] [Copy construct rule `r` from rule `r2`.]]
  89. [[`r = r2;`] [Assign rule `r2` to `r`.]]
  90. [[`r.alias()`] [Return an alias of `r`. The alias is a generator that
  91. holds a reference to `r`. Reference semantics.]]
  92. [[`r.copy()`] [Get a copy of `r`.]]
  93. [[`r = g;`] [Rule definition]]
  94. [[`r %= g;`] [Auto-rule definition. The attribute of `g` should be
  95. compatible with the consumed attribute of `r`.]]
  96. [[`r.name()`] [Retrieve the current name of the rule object.]]
  97. [[`r.name(name)`] [Set the current name of the rule object to be `name`.]]
  98. ]
  99. [heading Attributes]
  100. [:The rule's generator attribute is `RT`: The consumed attribute of the
  101. rule. See __karma_nonterminal_attribute__]
  102. [heading Complexity]
  103. [:The complexity is defined by the complexity of the RHS generator, `g`]
  104. [heading Example]
  105. [note The test harness for the example(s) below is presented in the
  106. __karma_basics_examples__ section.]
  107. [karma_reference_rule]
  108. [endsect] [/ Rule]
  109. [////////////////////////////////////////////////////////////////////////////////]
  110. [section:grammar Generator Grammar]
  111. [heading Description]
  112. The grammar encapsulates a set of __karma_rules__ (as well as primitive
  113. generators (__primitive_generator_concept__) and sub-grammars). The grammar is
  114. the main mechanism for modularization and composition. Grammars can be
  115. composed to form more complex grammars.
  116. [heading Header]
  117. // forwards to <boost/spirit/home/karma/nonterminal/grammar.hpp>
  118. #include <boost/spirit/include/karma_grammar.hpp>
  119. Also, see __include_structure__.
  120. [heading Namespace]
  121. [table
  122. [[Name]]
  123. [[`boost::spirit::karma::grammar`]]
  124. ]
  125. [heading Synopsis]
  126. template <typename OutputIterator, typename A1, typename A2, typename A3>
  127. struct grammar;
  128. [heading Template parameters]
  129. [table
  130. [[Parameter] [Description] [Default]]
  131. [[`OutputIterator`] [The underlying output iterator
  132. type that the rule is
  133. expected to work on.] [none]]
  134. [[`A1`, `A2`, `A3`] [Either `Signature`,
  135. `Delimiter` or `Locals` in
  136. any order. See table below.] [See table below.]]
  137. ]
  138. Here is more information about the template parameters:
  139. [table
  140. [[Parameter] [Description] [Default]]
  141. [[`Signature`] [Specifies the grammar's synthesized
  142. (return value) and inherited
  143. attributes (arguments). More on
  144. this here: __karma_nonterminal_concept__.]
  145. [__unused_type__.
  146. When `Signature` defaults
  147. to __unused_type__, the effect
  148. is the same as specifying a signature
  149. of `void()` which is also equivalent
  150. to `unused_type()`]]
  151. [[`Delimiter`] [Specifies the grammar's delimiter
  152. generator. Specify this if you
  153. want the grammar to delimit the
  154. generated output.] [__unused_type__]]
  155. [[`Locals`] [Specifies the grammar's local
  156. variables. See __karma_nonterminal_concept__.]
  157. [__unused_type__]]
  158. ]
  159. [heading Model of]
  160. [:__karma_nonterminal_concept__]
  161. [variablelist Notation
  162. [[`g`] [A grammar]]
  163. ]
  164. [heading Expression Semantics]
  165. Semantics of an expression is defined only where it differs from, or is not
  166. defined in __karma_nonterminal_concept__.
  167. [table
  168. [[Expression] [Semantics]]
  169. [[
  170. ``
  171. template <typename OutputIterator>
  172. struct my_grammar : grammar<OutputIterator, A1, A2, A3>
  173. {
  174. my_grammar() : my_grammar::base_type(start, name)
  175. {
  176. // Rule definitions
  177. start = /* ... */;
  178. }
  179. rule<OutputIterator, A1, A2, A3> start;
  180. // more rule declarations...
  181. };
  182. ``
  183. ] [Grammar definition. `name` is an optional string that gives the
  184. grammar its name, useful for debugging.]]
  185. ]
  186. [note The template parameters of a grammar and its start rule (the rule passed
  187. to the grammar's base class constructor) must match, otherwise you will
  188. see compilation errors.]
  189. [heading Attributes]
  190. [:The generator attribute of the grammar is `RT`, its consumed attribute. See
  191. __karma_nonterminal_attribute__]
  192. [heading Complexity]
  193. [:The complexity is defined by the complexity of the its definition.]
  194. [heading Example]
  195. [note The test harness for the example(s) below is presented in the
  196. __karma_basics_examples__ section.]
  197. [karma_reference_grammar_using]
  198. [karma_reference_grammar_definition]
  199. [karma_reference_grammar]
  200. [endsect] [/ Grammar]
  201. [endsect]