auxiliary.qbk 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523
  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:auxiliary Auxiliary Parsers]
  8. This module includes different auxiliary parsers not fitting into any of the
  9. other categories. This module includes the `attr`, `attr_cast`, `eoi`, `eol`,
  10. `eps`, and `lazy` parsers.
  11. [heading Module Header]
  12. // forwards to <boost/spirit/home/qi/auxiliary.hpp>
  13. #include <boost/spirit/include/qi_auxiliary.hpp>
  14. Also, see __include_structure__.
  15. [/------------------------------------------------------------------------------]
  16. [section:attr Attribute Parser (`attr`)]
  17. [heading Description]
  18. The Attribute parser does not consume any input, for this reason it
  19. always matches an empty string and always succeeds. It's purpose is to
  20. expose its specified parameter as an attribute.
  21. [heading Header]
  22. // forwards to <boost/spirit/home/qi/auxiliary/attr.hpp>
  23. #include <boost/spirit/include/qi_attr.hpp>
  24. Also, see __include_structure__.
  25. [heading Namespace]
  26. [table
  27. [[Name]]
  28. [[`boost::spirit::attr // alias: boost::spirit::qi::attr`]]
  29. ]
  30. [heading Model of]
  31. [:__primitive_parser_concept__]
  32. [variablelist Notation
  33. [[`a`] [A arbitrary typed constant value, e.g. 0.0, "Hello", or a
  34. variable of arbitrary type or a __qi_lazy_argument__ that evaluates
  35. to an arbitrary type.]]
  36. [[`A`] [The type of `a` or if it is a __qi_lazy_argument__, its
  37. return type.]]
  38. ]
  39. [heading Expression Semantics]
  40. Semantics of an expression is defined only where it differs from, or is
  41. not defined in __primitive_parser_concept__.
  42. [table
  43. [[Expression] [Semantics]]
  44. [[`attr(a)`] [Create a pseudo parser exposing the current value of
  45. `a` as its attribute without consuming any input
  46. at parse time.]]
  47. ]
  48. [heading Attributes]
  49. [table
  50. [[Expression] [Attribute]]
  51. [[`attr(a)`] [`A`]]
  52. ]
  53. [heading Complexity]
  54. [:O(1)]
  55. The complexity is constant as no input is consumed and no matching is done.
  56. [heading Example]
  57. [note The test harness for the example(s) below is presented in the
  58. __qi_basics_examples__ section.]
  59. Some using declarations:
  60. [reference_using_declarations_attr]
  61. Using `attr` with literals:
  62. [reference_attr]
  63. Using `attr` with __phoenix__ function objects:
  64. [reference_attr_phoenix]
  65. [endsect] [/ attr]
  66. [/------------------------------------------------------------------------------]
  67. [section:attr_cast Attribute Transformation Pseudo Parser (`attr_cast`)]
  68. [heading Description]
  69. The `attr_cast<Exposed, Transformed>()` component invokes the embedded parser
  70. while supplying an attribute of type `Transformed`. The supplied attribute gets created
  71. from the original attribute (of type `Exposed`) passed to this component using the
  72. customization point __customize_transform_attribute__.
  73. [heading Header]
  74. // forwards to <boost/spirit/home/qi/auxiliary/attr_cast.hpp>
  75. #include <boost/spirit/include/qi_attr_cast.hpp>
  76. Also, see __include_structure__.
  77. [heading Namespace]
  78. [table
  79. [[Name]]
  80. [[`boost::spirit::attr_cast // alias: boost::spirit::qi::attr_cast`]]
  81. ]
  82. [heading Synopsis]
  83. template <Exposed, Transformed>
  84. <unspecified> attr_cast(<unspecified>);
  85. [heading Template parameters]
  86. [table
  87. [[Parameter] [Description] [Default]]
  88. [[`Exposed`] [The type of the attribute supplied to the `attr_cast`.] [__unused_type__]]
  89. [[`Transformed`][The type of the attribute expected by the embedded
  90. parser `p`.] [__unused_type__]]
  91. ]
  92. The `attr_cast` is a function template. It is possible to invoke it using the
  93. following schemes:
  94. attr_cast(p)
  95. attr_cast<Exposed>(p)
  96. attr_cast<Exposed, Transformed>(p)
  97. depending on which of the attribute types can be deduced properly if not
  98. explicitly specified.
  99. [heading Model of]
  100. [:__unary_parser_concept__]
  101. [variablelist Notation
  102. [[`p`] [A parser object.]]
  103. ]
  104. [heading Expression Semantics]
  105. Semantics of an expression is defined only where it differs from, or is
  106. not defined in __unary_parser_concept__.
  107. [table
  108. [[Expression] [Semantics]]
  109. [[`attr_cast(p)`] [Create a component invoking the
  110. parser `p` while passing an attribute of the type
  111. as normally expected by `p`. The type of the supplied
  112. attribute will be transformed to the type
  113. `p` exposes as its attribute type (by using the
  114. attribute customization point __customize_transform_attribute__).]]
  115. [[`attr_cast<Exposed>(p)`] [Create a component invoking the
  116. parser `p` while passing an attribute of the type
  117. as normally expected by `p`. The supplied attribute
  118. is expected to be of the type `Exposed`, it will be
  119. transformed to the type `p` exposes as its attribute type
  120. (using the attribute customization point
  121. __customize_transform_attribute__).]]
  122. [[`attr_cast<Exposed, Transformed>(p)`] [Create a component invoking the
  123. parser `p` while passing an attribute of type
  124. `Transformed`. The supplied attribute is expected
  125. to be of the type `Exposed`, it will be transformed
  126. to the type `Transformed` (using the attribute
  127. customization point __customize_transform_attribute__).]]
  128. ]
  129. [heading Attributes]
  130. [table
  131. [[Expression] [Attribute]]
  132. [[`attr_cast(p)`] [`p: A --> attr_cast(p): A`]]
  133. [[`attr_cast<Exposed>(p)`] [`p: A --> attr_cast<Exposed>(p): Exposed`]]
  134. [[`attr_cast<Exposed, Transformed>(p)`]
  135. [`p: A --> attr_cast<Exposed, Transformed>(p): Exposed`]]
  136. ]
  137. [heading Complexity]
  138. [:The complexity of this component is fully defined by the complexity of the
  139. embedded parser `p`.]
  140. [heading Example]
  141. [note The test harness for the example(s) below is presented in the
  142. __qi_basics_examples__ section.]
  143. Some using declarations:
  144. [reference_qi_using_declarations_attr_cast]
  145. The example references data structure `int_data` which needs a specialization of
  146. the customization point __customize_transform_attribute__:
  147. [reference_qi_auxiliary_attr_cast_data1]
  148. Now we use the `attr_cast` pseudo parser to invoke the attribute
  149. transformation:
  150. [reference_qi_attr_cast1]
  151. [endsect]
  152. [/------------------------------------------------------------------------------]
  153. [section:eol End of Line Parser (`eol`)]
  154. [heading Description]
  155. The `eol` parser matches the end of line (CR/LF and combinations
  156. thereof).
  157. [heading Header]
  158. // forwards to <boost/spirit/home/qi/auxiliary/eol.hpp>
  159. #include <boost/spirit/include/qi_eol.hpp>
  160. Also, see __include_structure__.
  161. [heading Namespace]
  162. [table
  163. [[Name]]
  164. [[`boost::spirit::eol // alias: boost::spirit::qi::eol`]]
  165. ]
  166. [heading Model of]
  167. [:__primitive_parser_concept__]
  168. [heading Expression Semantics]
  169. Semantics of an expression is defined only where it differs from, or is
  170. not defined in __primitive_parser_concept__.
  171. [table
  172. [[Expression] [Semantics]]
  173. [[`eol`] [Create a parser that matches the end of line.]]
  174. ]
  175. [heading Attributes]
  176. [table
  177. [[Expression] [Attribute]]
  178. [[`eol`] [__unused__]]
  179. ]
  180. [heading Complexity]
  181. [:O(1)]
  182. [heading Example]
  183. [note The test harness for the example(s) below is presented in the
  184. __qi_basics_examples__ section.]
  185. Some using declarations:
  186. [reference_using_declarations_eol]
  187. Using `eol`:
  188. [reference_eol]
  189. [endsect] [/ End of Line]
  190. [/------------------------------------------------------------------------------]
  191. [section:eoi End of Input Parser (`eoi`)]
  192. [heading Description]
  193. The `eoi` parser matches the end of input (returns a successful match
  194. with 0 length when the input is exhausted)
  195. [heading Header]
  196. // forwards to <boost/spirit/home/qi/auxiliary/eoi.hpp>
  197. #include <boost/spirit/include/qi_eoi.hpp>
  198. Also, see __include_structure__.
  199. [heading Namespace]
  200. [table
  201. [[Name]]
  202. [[`boost::spirit::eoi // alias: boost::spirit::qi::eoi`]]
  203. ]
  204. [heading Model of]
  205. [:__primitive_parser_concept__]
  206. [heading Expression Semantics]
  207. Semantics of an expression is defined only where it differs from, or is
  208. not defined in __primitive_parser_concept__.
  209. [table
  210. [[Expression] [Semantics]]
  211. [[`eoi`] [Create a parser that matches the end of input.]]
  212. ]
  213. [heading Attributes]
  214. [table
  215. [[Expression] [Attribute]]
  216. [[`eoi`] [__unused__]]
  217. ]
  218. [heading Complexity]
  219. [:O(1)]
  220. [heading Example]
  221. [note The test harness for the example(s) below is presented in the
  222. __qi_basics_examples__ section.]
  223. Some using declarations:
  224. [reference_using_declarations_eoi]
  225. Using `eoi`:
  226. [reference_eoi]
  227. [endsect] [/ End of Input]
  228. [/------------------------------------------------------------------------------]
  229. [section:eps Epsilon Parser (`eps`)]
  230. [heading Description]
  231. The Epsilon (`eps`) is a multi-purpose parser that returns a zero length
  232. match.
  233. [heading Simple Form]
  234. In its simplest form, `eps` matches the null string and always returns a
  235. match of zero length:
  236. eps // always returns a zero-length match
  237. This form is usually used to trigger a semantic action unconditionally.
  238. For example, it is useful in triggering error messages when a set of
  239. alternatives fail:
  240. r = a | b | c | eps[error()]; // Call error if a, b, and c fail to match
  241. [heading Semantic Predicate]
  242. Semantic predicates allow you to attach a conditional function anywhere
  243. in the grammar. In this role, the epsilon takes a __qi_lazy_argument__ that
  244. returns `true` or `false`. The __qi_lazy_argument__ is typically a test
  245. that is called to resolve ambiguity in the grammar. A parse failure will
  246. be reported when the __qi_lazy_argument__ result evaluates to `false`.
  247. Otherwise an empty match will be reported. The general form is:
  248. eps(f) >> rest;
  249. The __qi_lazy_argument__ `f` is called to do a semantic test (say, checking
  250. if a symbol is in the symbol table). If test returns true, `rest` will
  251. be evaluated. Otherwise, the production will return early with a
  252. no-match without ever touching rest.
  253. [heading Header]
  254. // forwards to <boost/spirit/home/qi/auxiliary/eps.hpp>
  255. #include <boost/spirit/include/qi_eps.hpp>
  256. Also, see __include_structure__.
  257. [heading Namespace]
  258. [table
  259. [[Name]]
  260. [[`boost::spirit::eps // alias: boost::spirit::qi::eps`]]
  261. ]
  262. [heading Model of]
  263. [:__primitive_parser_concept__]
  264. [variablelist Notation
  265. [[`f`] [A __qi_lazy_argument__ that evaluates `bool`.]]
  266. ]
  267. [heading Expression Semantics]
  268. Semantics of an expression is defined only where it differs from, or is
  269. not defined in __primitive_parser_concept__.
  270. [table
  271. [[Expression] [Semantics]]
  272. [[`eps`] [Match an empty string (always matches).]]
  273. [[`eps(f)`] [If `f` evaluates to `true`, return a zero length match.]]
  274. ]
  275. [heading Attributes]
  276. [table
  277. [[Expression] [Attribute]]
  278. [[`eps`] [__unused__]]
  279. ]
  280. [heading Complexity]
  281. [:For plain (`eps`) the complexity is O(1). For Semantic predicates
  282. (`eps(f)`) the complexity is defined by the function `f`.]
  283. [heading Example]
  284. [note The test harness for the example(s) below is presented in the
  285. __qi_basics_examples__ section.]
  286. Some using declarations:
  287. [reference_using_declarations_eps]
  288. [reference_eps]
  289. [reference_eps_if]
  290. [reference_eps_while]
  291. [endsect] [/Epsilon]
  292. [/------------------------------------------------------------------------------]
  293. [section:lazy Lazy Parser (`lazy`)]
  294. [heading Description]
  295. The `lazy` parser, as its name suggests, invokes a lazy __phoenix__
  296. function that returns a parser at parse time. This parser will be
  297. used once it is created to continue the parse.
  298. [heading Header]
  299. // forwards to <boost/spirit/home/qi/auxiliary/lazy.hpp>
  300. #include <boost/spirit/include/qi_lazy.hpp>
  301. Also, see __include_structure__.
  302. [heading Namespace]
  303. [table
  304. [[Name]]
  305. [[`boost::spirit::lazy // alias: boost::spirit::qi::lazy`]]
  306. ]
  307. [heading Model of]
  308. [:__parser_concept__]
  309. [variablelist Notation
  310. [[`fp`] [A __qi_lazy_argument__ that evaluates to a
  311. __parser_concept__.]]
  312. ]
  313. [heading Expression Semantics]
  314. Semantics of an expression is defined only where it differs from, or is
  315. not defined in __parser_concept__.
  316. [table
  317. [[Expression] [Semantics]]
  318. [[`fp`] [Create a lazy-parser from a __qi_lazy_argument__, `fp`.
  319. `fp` will be invoked at parse time. `fp` is expected to
  320. return a __parser_concept__ object. This parser is then
  321. invoked in order to parse the input.]]
  322. [[`lazy(fp)`] [Create a lazy-parser from a __qi_lazy_argument__, `fp`.
  323. `fp` will be invoked at parse time. `fp` is expected to
  324. return a __parser_concept__ object. This parser is then
  325. invoked in order to parse the input.]]
  326. ]
  327. [heading Attributes]
  328. [table
  329. [[Expression] [Attribute]]
  330. [[`fp`] [The attribute type of the return type of `fp`.]]
  331. [[`lazy(fp)`] [The attribute type of the return type of `fp`.]]
  332. ]
  333. [heading Complexity]
  334. The complexity of the `lazy` parser is determined by the complexity of
  335. the parser returned from `fp`.
  336. [heading Example]
  337. [note The test harness for the example(s) below is presented in the
  338. __qi_basics_examples__ section.]
  339. Some using declarations:
  340. [reference_using_declarations_lazy]
  341. Using `lazy`:
  342. [reference_lazy]
  343. [endsect] [/ Lazy]
  344. [endsect] [/ Auxiliary]