nonterminal.qbk 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  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 Parsers]
  8. [heading Module Headers]
  9. // forwards to <boost/spirit/home/qi/nonterminal.hpp>
  10. #include <boost/spirit/include/qi_nonterminal.hpp>
  11. Also, see __include_structure__.
  12. [/------------------------------------------------------------------------------]
  13. [section:rule Parser Rule]
  14. [heading Description]
  15. The rule is a polymorphic parser that acts as a named placeholder
  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 parsing.
  21. [heading Header]
  22. // forwards to <boost/spirit/home/qi/nonterminal/rule.hpp>
  23. #include <boost/spirit/include/qi_rule.hpp>
  24. Also, see __include_structure__.
  25. [heading Namespace]
  26. [table
  27. [[Name]]
  28. [[`boost::spirit::qi::rule`]]
  29. ]
  30. [heading Synopsis]
  31. template <typename Iterator, typename A1, typename A2, typename A3>
  32. struct rule;
  33. [heading Template parameters]
  34. [table
  35. [[Parameter] [Description] [Default]]
  36. [[`Iterator`] [The underlying iterator
  37. type that the rule is
  38. expected to work on.] [none]]
  39. [[`A1`, `A2`, `A3`] [Either `Signature`,
  40. `Skipper` 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 synthesized
  47. (return value) and inherited
  48. attributes (arguments). More on
  49. this here: __qi_nonterminal__.] [__unused_type__.
  50. When `Signature` defaults
  51. to __unused_type__, the effect
  52. is the same as specifying a signature
  53. of `void()` which is also equivalent
  54. to `unused_type()`]]
  55. [[`Skipper`] [Specifies the rule's skipper
  56. parser. Specify this if you
  57. want the rule to skip white
  58. spaces. If this is not specified,
  59. the rule is an "implicit lexeme"
  60. and will not skip spaces.
  61. "implicit lexeme" rules can
  62. still be called with a skipper.
  63. In such a case, the rule does a
  64. pre-skip just as all lexemes
  65. and primitives do.] [__unused_type__]]
  66. [[`Locals`] [Specifies the rule's local
  67. variables.
  68. See __qi_nonterminal__.] [__unused_type__]]
  69. ]
  70. [heading Model of]
  71. [:__qi_nonterminal__]
  72. [variablelist Notation
  73. [[`r, r2`] [Rules]]
  74. [[`p`] [A parser expression]]
  75. [[`Iterator`] [The underlying iterator type that the rule is
  76. expected to work on.]]
  77. [[`A1`, `A2`, `A3`] [Either `Signature`, `Skipper` or `Locals` in
  78. any order.]]
  79. ]
  80. [heading Expression Semantics]
  81. Semantics of an expression is defined only where it differs from, or is
  82. not defined in __qi_nonterminal__.
  83. [table
  84. [[Expression] [Description]]
  85. [[
  86. ``rule<Iterator, A1, A2, A3>
  87. r(name);``] [Rule declaration. `Iterator` is required.
  88. `A1, A2, A3` are optional and can be specified in any order.
  89. `name` is an optional string that gives the rule
  90. its name, useful for debugging and error handling.]]
  91. [[
  92. ``rule<Iterator, A1, A2, A3>
  93. r(r2);``] [Copy construct rule `r` from rule `r2`.]]
  94. [[`r = r2;`] [Assign rule `r2` to `r`.]]
  95. [[`r.alias()`] [return an alias of `r`. The alias is a parser that
  96. holds a reference to `r`.]]
  97. [[`r.copy()`] [Get a copy of `r`.]]
  98. [[`r = p;`] [Rule definition. This is equivalent to `r %= p`
  99. (see below) if there are no semantic actions attached
  100. anywhere in `p`.]]
  101. [[`r %= p;`] [Auto-rule definition. The attribute of `p` must be
  102. compatible with the synthesized attribute of `r`. If `p`
  103. is successful, its attribute is automatically propagated
  104. to `r`'s synthesized attribute. Semantic actions, if present,
  105. may not change the attribute's type.]]
  106. [[`r.name()`] [Retrieve the current name of the rule object.]]
  107. [[`r.name(name)`] [Set the current name of the rule object to be `name`.]]
  108. ]
  109. [heading Attributes]
  110. [:The parser attribute of the rule is `T`, its synthesized attribute. See
  111. __qi_nonterminal_attribute__]
  112. [heading Complexity]
  113. [:The complexity is defined by the complexity of the RHS parser, `p`]
  114. [heading Example]
  115. [note The test harness for the example(s) below is presented in the
  116. __qi_basics_examples__ section.]
  117. [reference_rule]
  118. [endsect] [/ Rule]
  119. [/------------------------------------------------------------------------------]
  120. [section:grammar Parser Grammar]
  121. [heading Description]
  122. The grammar encapsulates a set of __qi_rules__ (as well as primitive
  123. parsers (__primitive_parser_concept__) and sub-grammars). The grammar is
  124. the main mechanism for modularization and composition. Grammars can be
  125. composed to form more complex grammars.
  126. [heading Header]
  127. // forwards to <boost/spirit/home/qi/nonterminal/grammar.hpp>
  128. #include <boost/spirit/include/qi_grammar.hpp>
  129. Also, see __include_structure__.
  130. [heading Namespace]
  131. [table
  132. [[Name]]
  133. [[`boost::spirit::qi::grammar`]]
  134. ]
  135. [heading Synopsis]
  136. template <typename Iterator, typename A1, typename A2, typename A3>
  137. struct grammar;
  138. [heading Template parameters]
  139. [table
  140. [[Parameter] [Description] [Default]]
  141. [[`Iterator`] [The underlying iterator
  142. type that the rule is
  143. expected to work on.] [none]]
  144. [[`A1`, `A2`, `A3`] [Either `Signature`,
  145. `Skipper` or `Locals` in
  146. any order. See table below.] [See table below.]]
  147. ]
  148. Here is more information about the template parameters:
  149. [table
  150. [[Parameter] [Description] [Default]]
  151. [[`Signature`] [Specifies the grammar's synthesized
  152. (return value) and inherited
  153. attributes (arguments). More on
  154. this here: __qi_nonterminal__.] [__unused_type__.
  155. When `Signature` defaults
  156. to __unused_type__, the effect
  157. is the same as specifying a signature
  158. of `void()` which is also equivalent
  159. to `unused_type()`]]
  160. [[`Skipper`] [Specifies the grammar's skipper
  161. parser. Specify this if you
  162. want the grammar to skip white
  163. spaces.] [__unused_type__]]
  164. [[`Locals`] [Specifies the grammar's local
  165. variables. See __qi_nonterminal__.] [__unused_type__]]
  166. ]
  167. [heading Model of]
  168. [:__qi_nonterminal__]
  169. [variablelist Notation
  170. [[`g`] [A grammar]]
  171. ]
  172. [heading Expression Semantics]
  173. Semantics of an expression is defined only where it differs from, or is not
  174. defined in __qi_nonterminal__.
  175. [table
  176. [[Expression] [Semantics]]
  177. [[
  178. ``
  179. template <typename Iterator>
  180. struct my_grammar : grammar<Iterator, A1, A2, A3>
  181. {
  182. my_grammar() : my_grammar::base_type(start, name)
  183. {
  184. // Rule definitions
  185. start = /* ... */;
  186. }
  187. rule<Iterator, A1, A2, A3> start;
  188. // more rule declarations...
  189. };
  190. ``
  191. ] [Grammar definition. `name` is an optional string that gives the
  192. grammar its name, useful for debugging and error handling.]]
  193. ]
  194. [note The template parameters of a grammar and its start rule (the rule passed
  195. to the grammar's base class constructor) must match, otherwise you will
  196. see compilation errors.]
  197. [heading Attributes]
  198. [:The parser attribute of the grammar is `T`, its synthesized attribute. See
  199. __qi_nonterminal_attribute__]
  200. [heading Complexity]
  201. [:The complexity is defined by the complexity of the its definition.]
  202. [heading Example]
  203. [note The test harness for the example(s) below is presented in the
  204. __qi_basics_examples__ section.]
  205. [reference_grammar_using]
  206. [reference_grammar_definition]
  207. [reference_grammar]
  208. [endsect] [/ Grammar]
  209. [endsect] [/ Nonterminal]