operator.qbk 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816
  1. [/==============================================================================
  2. Copyright (C) 2001-2011 Hartmut Kaiser
  3. Copyright (C) 2001-2011 Joel de Guzman
  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:operator Generator Operators]
  8. Operators are used as a means for object composition and embedding.
  9. Simple generators may be composed to form composites through operator
  10. overloading, crafted to approximate the syntax of __peg__ (PEG). An
  11. expression such as:
  12. a | b
  13. yields a new generator type which is a composite of its operands, `a` and
  14. `b`.
  15. This module includes different generators which get instantiated if one of the
  16. overloaded operators is used with more primitive generator constructs. It
  17. includes sequences (`a << b`), alternatives (`a | b`), Kleene star (unary `*`),
  18. plus (unary `+`), optional (unary `-`), lists (`a % b`), and the two predicates, the
  19. /and/ predicate (unary `&`) and the /not/ predicate (unary `!`).
  20. [heading Module Header]
  21. // forwards to <boost/spirit/home/karma/operator.hpp>
  22. #include <boost/spirit/include/karma_operator.hpp>
  23. Also, see __include_structure__.
  24. [/////////////////////////////////////////////////////////////////////////////]
  25. [section:sequence Sequence Generator (`a << b`)]
  26. [heading Description]
  27. Generator sequences are used to consecutively combine different, more primitive
  28. generators. All generators in a sequence are invoked from left to right as long
  29. as they succeed.
  30. [heading Header]
  31. // forwards to <boost/spirit/home/karma/operator/sequence.hpp>
  32. #include <boost/spirit/include/karma_sequence.hpp>
  33. Also, see __include_structure__.
  34. [heading Model of]
  35. [:__nary_generator_concept__]
  36. [heading Expression Semantics]
  37. Semantics of an expression is defined only where it differs from, or is not
  38. defined in __nary_generator_concept__.
  39. [table
  40. [[Expression] [Semantics]]
  41. [[`a << b`] [The generators `a` and `b` are executed sequentially
  42. from left to right and as long as they succeed. A
  43. failed generator stops the execution of the entire
  44. sequence and makes the sequence fail as well.]]
  45. ]
  46. It is important to note, that sequences don't perform any buffering of the
  47. output generated by its elements. That means that any failing sequence might
  48. have already generated some output, which is /not/ rolled back.
  49. [tip The simplest way to force a sequence to behave as if it did buffering
  50. is to wrap it into a buffering directive (see __karma_buffer__):
  51. ``buffer[a << b << c]``
  52. which will /not/ generate any output in case of a failing sequence.]
  53. [heading Attributes]
  54. See __karma_comp_attr_notation__.
  55. [table
  56. [[Expression] [Attribute]]
  57. [[`a << b` (sequence)]
  58. [``a: A, b: B --> (a << b): tuple<A, B>
  59. a: A, b: Unused --> (a << b): A
  60. a: Unused, b: B --> (a << b): B
  61. a: Unused, b: Unused --> (a << b): Unused
  62. a: A, b: A --> (a << b): vector<A>
  63. a: vector<A>, b: A --> (a << b): vector<A>
  64. a: A, b: vector<A> --> (a << b): vector<A>
  65. a: vector<A>, b: vector<A> --> (a << b): vector<A>``]]
  66. ]
  67. [important The table above uses `tuple<A, B>` and `vector<A>` as placeholders
  68. only.
  69. The notation `tuple<A, B>` stands for /any fusion sequence of two
  70. elements/, where `A` is the type of its first element and `B` is the
  71. type of its second element.
  72. The notation of `vector<A>` stands for /any STL container/ holding
  73. elements of type `A`.]
  74. The attribute composition and propagation rules as shown in the table above make
  75. sequences somewhat special as they can operate in two modes if all elements have
  76. the same attribute type: consuming fusion sequences and consuming STL
  77. containers. The selected mode depends on the type of the attribute supplied.
  78. [heading Complexity]
  79. [:The overall complexity of the sequence generator is defined by the sum of the
  80. complexities of its elements. The complexity of the sequence itself is O(N),
  81. where N is the number of elements in the sequence.]
  82. [heading Example]
  83. [note The test harness for the example(s) below is presented in the
  84. __karma_basics_examples__ section.]
  85. Some includes:
  86. [reference_karma_includes]
  87. Some using declarations:
  88. [reference_karma_using_declarations_sequence]
  89. Basic usage of a sequence:
  90. [reference_karma_sequence]
  91. [endsect]
  92. [/////////////////////////////////////////////////////////////////////////////]
  93. [section:alternative Alternative Generator (`a | b`)]
  94. [heading Description]
  95. Generator alternatives are used to combine different, more primitive generators
  96. into alternatives. All generators in an alternative are invoked from left to
  97. right until one of them succeeds.
  98. [heading Header]
  99. // forwards to <boost/spirit/home/karma/operator/alternative.hpp>
  100. #include <boost/spirit/include/karma_alternative.hpp>
  101. Also, see __include_structure__.
  102. [heading Model of]
  103. [:__nary_generator_concept__]
  104. [heading Expression Semantics]
  105. Semantics of an expression is defined only where it differs from, or is not
  106. defined in __nary_generator_concept__.
  107. [table
  108. [[Expression] [Semantics]]
  109. [[`a | b`] [The generators `a` and `b` are executed sequentially
  110. from left to right until one of them succeeds. A
  111. failed generator forces the alternative generator to
  112. try the next one. The alternative fails as a whole
  113. only if all elements of the alternative fail. Each
  114. element of the alternative gets passed the whole
  115. attribute of the alternative.]]
  116. ]
  117. Alternatives intercept and buffer the output of the currently executed element.
  118. This allows to avoid partial outputs from failing elements as the buffered
  119. content will be forwarded to the actual output only after an element succeeded.
  120. [heading Attributes]
  121. See __karma_comp_attr_notation__.
  122. [table
  123. [[Expression] [Attribute]]
  124. [[`a | b` (alternative)]
  125. [``a: A, b: B --> (a | b): variant<A, B>
  126. a: A, b: Unused --> (a | b): A
  127. a: Unused, b: B --> (a | b): B
  128. a: Unused, b: Unused --> (a | b): Unused
  129. a: A, b: A --> (a | b): A``]]
  130. ]
  131. [important The table above uses `variant<A, B>` as a placeholder only. The
  132. notation `variant<A, B>` stands for the type `boost::variant<A, B>`.
  133. ]
  134. The attribute handling of Alternatives is special as their behavior is
  135. not completely defined at compile time. First of all the selected alternative
  136. element depends on the actual type of the attribute supplied to the alternative
  137. generator (i.e. what is stored in the variant). The attribute type supplied at
  138. /runtime/ narrows the set of considered alternatives to those being compatible
  139. attribute wise. The remaining alternatives are tried sequentially until the
  140. first of them succeeds. See below for an example of this behavior.
  141. [heading Complexity]
  142. [:The overall complexity of the alternative generator is defined by the sum of
  143. the complexities of its elements. The complexity of the alternative itself is
  144. O(N), where N is the number of elements in the alternative.]
  145. [heading Example]
  146. [note The test harness for the example(s) below is presented in the
  147. __karma_basics_examples__ section.]
  148. Some includes:
  149. [reference_karma_includes]
  150. Some using declarations:
  151. [reference_karma_using_declarations_alternative]
  152. Basic usage of an alternative. While being only the second alternative, the
  153. `double_` generator is chosen for output formatting because the supplied
  154. attribute type is not compatible (i.e. not convertible) to the attribute type
  155. of the `string` alternative.
  156. [reference_karma_alternative1]
  157. The same formatting rules may be used to output a string. This time we supply
  158. the string `"example"`, resulting in the first alternative to be chosen for the
  159. generated output.
  160. [reference_karma_alternative2]
  161. [endsect]
  162. [/////////////////////////////////////////////////////////////////////////////]
  163. [section:kleene Kleene Star Generator (`*a`)]
  164. [heading Description]
  165. Kleene star generators are used to repeat the execution of an embedded generator
  166. zero or more times. Regardless of the success of the embedded generator, the
  167. Kleene star generator always succeeds.
  168. [heading Header]
  169. // forwards to <boost/spirit/home/karma/operator/kleene.hpp>
  170. #include <boost/spirit/include/karma_kleene.hpp>
  171. Also, see __include_structure__.
  172. [heading Model of]
  173. [:__unary_generator_concept__]
  174. [heading Expression Semantics]
  175. Semantics of an expression is defined only where it differs from, or is not
  176. defined in __unary_generator_concept__.
  177. [table
  178. [[Expression] [Semantics]]
  179. [[`*a`] [The generator `a` is executed zero or more times
  180. depending on the availability of an attribute. The
  181. execution of `a` stops after the attribute values
  182. passed to the Kleene star generator are exhausted.
  183. The Kleene star always succeeds (unless the
  184. underlying output stream reports an error).]]
  185. ]
  186. [note All failing iterations of the embedded generator will consume one element
  187. from the supplied attribute.]
  188. [heading Attributes]
  189. See __karma_comp_attr_notation__.
  190. [table
  191. [[Expression] [Attribute]]
  192. [[`*a` (Kleene star, unary `*`)]
  193. [``a: A --> *a: vector<A>
  194. a: Unused --> *a: Unused``]]
  195. ]
  196. [important The table above uses `vector<A>` as a placeholder only. The notation
  197. of `vector<A>` stands for /any STL container/ holding elements of
  198. type `A`.]
  199. The Kleene star generator will execute its embedded generator once for each
  200. element in the provided container attribute as long as the embedded
  201. generator succeeds. On each iteration it will pass the next consecutive element
  202. from the container attribute to the embedded generator. Therefore the number of
  203. iterations will not be larger than the number of elements in the container
  204. passed as its attribute. An empty container will make the Kleene star
  205. generate no output at all.
  206. It is important to note, that the Kleene star does not perform any buffering
  207. of the output generated by its embedded elements. That means that any failing
  208. element generator might have already generated some output, which is /not/
  209. rolled back.
  210. [tip The simplest way to force a Kleene star to behave as if it did
  211. buffering is to wrap it into a buffering directive (see
  212. __karma_buffer__):
  213. ``buffer[*a]``
  214. which will /not/ generate any output in case of a failing generator `*a`.
  215. The expression:
  216. ``*(buffer[a])``
  217. will not generate any partial output from a generator `a` if it fails
  218. generating in the middle of its output. The overall expression will
  219. still generate the output as produced by all successful invocations of
  220. the generator `a`.]
  221. [heading Complexity]
  222. [:The overall complexity of the Kleene star generator is defined by the
  223. complexity of its embedded generator multiplied by the number of executed
  224. iterations. The complexity of the Kleene star itself is O(N), where N is the
  225. number of elements in the container passed as its attribute.]
  226. [heading Example]
  227. [note The test harness for the example(s) below is presented in the
  228. __karma_basics_examples__ section.]
  229. Some includes:
  230. [reference_karma_includes]
  231. Some using declarations:
  232. [reference_karma_using_declarations_kleene]
  233. Basic usage of a Kleene star generator:
  234. [reference_karma_kleene]
  235. [endsect]
  236. [/////////////////////////////////////////////////////////////////////////////]
  237. [section:plus Plus Generator (`+a`)]
  238. [heading Description]
  239. The Plus generator is used to repeat the execution of an embedded generator
  240. one or more times. It succeeds if the embedded generator has been successfully
  241. executed at least once.
  242. [heading Header]
  243. // forwards to <boost/spirit/home/karma/operator/plus.hpp>
  244. #include <boost/spirit/include/karma_plus.hpp>
  245. Also, see __include_structure__.
  246. [heading Model of]
  247. [:__unary_generator_concept__]
  248. [heading Expression Semantics]
  249. Semantics of an expression is defined only where it differs from, or is not
  250. defined in __unary_generator_concept__.
  251. [table
  252. [[Expression] [Semantics]]
  253. [[`+a`] [The generator `a` is executed one or more times
  254. depending on the availability of an attribute. The
  255. execution of `a` stops after the attribute values
  256. passed to the plus generator are exhausted.
  257. The plus generator succeeds as long as its embedded
  258. generator has been successfully executed at least once
  259. (unless the underlying output stream reports an
  260. error).]]
  261. ]
  262. [note All failing iterations of the embedded generator will consume one element
  263. from the supplied attribute. The overall `+a` will succeed as long as at
  264. least one invocation of the embedded generator will succeed (unless the
  265. underlying output stream reports an error).]
  266. [heading Attributes]
  267. See __karma_comp_attr_notation__.
  268. [table
  269. [[Expression] [Attribute]]
  270. [[`+a` (unary `+`)]
  271. [``a: A --> +a: vector<A>
  272. a: Unused --> +a: Unused``]]
  273. ]
  274. [important The table above uses `vector<A>` as a placeholder only. The notation
  275. of `vector<A>` stands for /any STL container/ holding elements of
  276. type `A`.]
  277. The Plus generator will execute its embedded generator once for each
  278. element in the provided container attribute as long as the embedded
  279. generator succeeds. On each iteration it will pass the next consecutive element
  280. from the container attribute to the embedded generator. Therefore the number of
  281. iterations will not be larger than the number of elements in the container
  282. passed as its attribute. An empty container will make the plus generator fail.
  283. It is important to note, that the plus generator does not perform any buffering
  284. of the output generated by its embedded elements. That means that any failing
  285. element generator might have already generated some output, which is /not/
  286. rolled back.
  287. [tip The simplest way to force a plus generator to behave as if it did
  288. buffering is to wrap it into a buffering directive (see
  289. __karma_buffer__):
  290. ``buffer[+a]``
  291. which will /not/ generate any output in case of a failing generator `+a`.
  292. The expression:
  293. ``+(buffer[a])``
  294. will not generate any partial output from a generator `a` if it fails
  295. generating in the middle of its output. The overall expression will
  296. still generate the output as produced by all successful invocations of
  297. the generator `a`.]
  298. [heading Complexity]
  299. [:The overall complexity of the plus generator is defined by the
  300. complexity of its embedded generator multiplied by the number of executed
  301. iterations. The complexity of the plus generator itself is O(N), where N is
  302. the number of elements in the container passed as its attribute.]
  303. [heading Example]
  304. [note The test harness for the example(s) below is presented in the
  305. __karma_basics_examples__ section.]
  306. Some includes:
  307. [reference_karma_includes]
  308. Some using declarations:
  309. [reference_karma_using_declarations_plus]
  310. Basic usage of a plus generator:
  311. [reference_karma_plus1]
  312. A more sophisticated use case showing how to leverage the fact that plus is
  313. failing for empty containers passed as its attribute:
  314. [reference_karma_plus2]
  315. [endsect]
  316. [/////////////////////////////////////////////////////////////////////////////]
  317. [section:list List Generator (`a % b`)]
  318. [heading Description]
  319. The list generator is used to repeat the execution of an embedded generator
  320. and intersperse it with the output of another generator one or more times.
  321. It succeeds if the embedded generator has been successfully executed at least
  322. once.
  323. [heading Header]
  324. // forwards to <boost/spirit/home/karma/operator/list.hpp>
  325. #include <boost/spirit/include/karma_list.hpp>
  326. Also, see __include_structure__.
  327. [heading Model of]
  328. [:__binary_generator_concept__]
  329. [heading Expression Semantics]
  330. Semantics of an expression is defined only where it differs from, or is not
  331. defined in __binary_generator_concept__.
  332. [table
  333. [[Expression] [Semantics]]
  334. [[`a % b`] [The generator `a` is executed one or more times
  335. depending on the availability of an attribute. The
  336. output generated by `a` is interspersed with the output
  337. generated by `b`. The list generator succeeds if
  338. its first embedded generator has been
  339. successfully executed at least once (unless the
  340. underlying output stream reports an error).]]
  341. ]
  342. The list expression `a % b` is a shortcut for `a << *(b << a)`. It is almost
  343. semantically equivalent, except for the attribute of `b`, which gets ignored
  344. in the case of the list generator.
  345. [note All failing iterations of the embedded generator will consume one element
  346. from the supplied attribute. The overall `a % b` will succeed as long as at
  347. least one invocation of the embedded generator, `a`, will succeed (unless
  348. the underlying output stream reports an error).]
  349. [heading Attributes]
  350. See __karma_comp_attr_notation__.
  351. [table
  352. [[Expression] [Attribute]]
  353. [[`a % b` (list)]
  354. [``a: A, b: B --> (a % b): vector<A>
  355. a: Unused, b: B --> (a % b): Unused``]]
  356. ]
  357. [important The table above uses `vector<A>` as a placeholder only. The notation
  358. of `vector<A>` stands for /any STL container/ holding elements of
  359. type `A`.]
  360. The list generator will execute its embedded generator once for each
  361. element in the provided container attribute and as long as the embedded
  362. generator succeeds. The output generated by its first generator will be
  363. interspersed by the output generated by the second generator. On each iteration
  364. it will pass the next consecutive element from the container attribute to the
  365. first embedded generator. The second embedded generator does not get passed
  366. any attributes (it gets invoked using an `unused_type` as its attribute).
  367. Therefore the number of iterations will not be larger than the number of
  368. elements in the container passed as its attribute. An empty container will make
  369. the list generator fail.
  370. [tip If you want to use the list generator and still allow for an empty
  371. attribute, you can use the optional operator (see __karma_optional__):
  372. ``-(a % b)``
  373. which will succeed even if the provided container attribute does not
  374. contain any elements.
  375. ]
  376. [heading Complexity]
  377. [:The overall complexity of the list generator is defined by the
  378. complexity of its embedded generators multiplied by the number of executed
  379. iterations. The complexity of the list generator itself is O(N), where N is
  380. the number of elements in the container passed as its attribute.]
  381. [heading Example]
  382. [note The test harness for the example(s) below is presented in the
  383. __karma_basics_examples__ section.]
  384. Some includes:
  385. [reference_karma_includes]
  386. Some using declarations:
  387. [reference_karma_using_declarations_list]
  388. Basic usage of a list generator:
  389. [reference_karma_list]
  390. [endsect]
  391. [/////////////////////////////////////////////////////////////////////////////]
  392. [section:optional Optional Generator (`-a`)]
  393. [heading Description]
  394. The optional generator is used to conditionally execute an embedded generator.
  395. It succeeds always.
  396. [heading Header]
  397. // forwards to <boost/spirit/home/karma/operator/optional.hpp>
  398. #include <boost/spirit/include/karma_optional.hpp>
  399. Also, see __include_structure__.
  400. [heading Model of]
  401. [:__unary_generator_concept__]
  402. [heading Expression Semantics]
  403. Semantics of an expression is defined only where it differs from, or is not
  404. defined in __unary_generator_concept__.
  405. [table
  406. [[Expression] [Semantics]]
  407. [[`-a`] [The generator `a` is executed depending on the
  408. availability of an attribute. The optional generator
  409. succeeds if its embedded generator succeeds
  410. (unless the underlying output stream reports an
  411. error).]]
  412. ]
  413. [heading Attributes]
  414. See __karma_comp_attr_notation__.
  415. [table
  416. [[Expression] [Attribute]]
  417. [[`-a` (optional, unary `-`)]
  418. [``a: A --> -a: optional<A>
  419. a: Unused --> -a: Unused``]]
  420. ]
  421. [important The table above uses `optional<A>` as a placeholder only. The
  422. notation of `optional<A>` stands for the data type
  423. `boost::optional<A>`.]
  424. The optional generator will execute its embedded generator once if the provided
  425. attribute holds a valid value. It forwards the value held in its attribute
  426. to the embedded generator.
  427. It is important to note, that the optional generator does not perform any
  428. buffering of the output generated by its embedded elements. That means that any
  429. failing element might have already generated some output, which is /not/
  430. rolled back.
  431. [tip The simplest way to force a optional generator to behave as if it did
  432. buffering is to wrap it into a buffering directive (see
  433. __karma_buffer__):
  434. ``buffer[-a]``
  435. which will /not/ generate any output in case of a failing generator `-a`.
  436. ]
  437. [heading Complexity]
  438. [:The overall complexity of the optional generator is defined by the
  439. complexity of its embedded generator. The complexity of the optional
  440. generator itself is O(1).]
  441. [heading Example]
  442. [note The test harness for the example(s) below is presented in the
  443. __karma_basics_examples__ section.]
  444. Some includes:
  445. [reference_karma_includes]
  446. Some using declarations:
  447. [reference_karma_using_declarations_optional]
  448. Basic usage of an optional generator:
  449. [reference_karma_optional1]
  450. Usage and result of an empty optional generator:
  451. [reference_karma_optional2]
  452. [endsect]
  453. [/////////////////////////////////////////////////////////////////////////////]
  454. [section:and_predicate And-Predicate Generator (`&a`)]
  455. [heading Description]
  456. The and-predicate generator is used to test, whether the embedded generator
  457. succeeds without generating any output. It succeeds if the embedded generator
  458. succeeds.
  459. [heading Header]
  460. // forwards to <boost/spirit/home/karma/operator/and_predicate.hpp>
  461. #include <boost/spirit/include/karma_and_predicate.hpp>
  462. Also, see __include_structure__.
  463. [heading Model of]
  464. [:__unary_generator_concept__]
  465. [heading Expression Semantics]
  466. Semantics of an expression is defined only where it differs from, or is not
  467. defined in __unary_generator_concept__.
  468. [table
  469. [[Expression] [Semantics]]
  470. [[`&a`] [The generator `a` is executed for the sole purpose of
  471. testing whether it succeeds. The and-predicate
  472. generator succeeds if its embedded generator
  473. succeeds (unless the underlying output stream
  474. reports an error). The and-predicate never produces
  475. any output.]]
  476. ]
  477. The and generator is implemented by redirecting all output produced by its
  478. embedded generator into a discarding device.
  479. [heading Attributes]
  480. See __karma_comp_attr_notation__.
  481. [table
  482. [[Expression] [Attribute]]
  483. [[`&a` (and-predicate, unary `&`)] [`a: A --> &a: A`]]
  484. ]
  485. [note The attribute of the and-predicate is not always `unused_type`, which is
  486. different from Qi's and-predicate. This is necessary as the generator the
  487. and predicate is attached to most of the time needs an attribute.
  488. ]
  489. [heading Complexity]
  490. [:The overall complexity of the and-predicate generator is defined by the
  491. complexity of its embedded generator. The complexity of the and-predicate
  492. generator itself is O(1).]
  493. [heading Example]
  494. [note The test harness for the example(s) below is presented in the
  495. __karma_basics_examples__ section.]
  496. Some includes:
  497. [reference_karma_includes]
  498. Some using declarations:
  499. [reference_karma_using_declarations_and_predicate]
  500. Basic usage of an and predicate generator:
  501. [reference_karma_and_predicate]
  502. [endsect]
  503. [/////////////////////////////////////////////////////////////////////////////]
  504. [section:not_predicate Not-Predicate Generator (`!a`)]
  505. [heading Description]
  506. The not-predicate generator is used to test, whether the embedded generator
  507. fails, without generating any output. It succeeds if the embedded generator
  508. fails.
  509. [heading Header]
  510. // forwards to <boost/spirit/home/karma/operator/not_predicate.hpp>
  511. #include <boost/spirit/include/karma_not_predicate.hpp>
  512. Also, see __include_structure__.
  513. [heading Model of]
  514. [:__unary_generator_concept__]
  515. [heading Expression Semantics]
  516. Semantics of an expression is defined only where it differs from, or is not
  517. defined in __unary_generator_concept__.
  518. [table
  519. [[Expression] [Semantics]]
  520. [[`!a`] [The generator `a` is executed for the sole purpose of
  521. testing whether it succeeds. The not-predicate
  522. generator succeeds if its embedded generator
  523. fails (unless the underlying output stream
  524. reports an error). The not-predicate never produces
  525. any output.]]
  526. ]
  527. The not generator is implemented by redirecting all output produced by its
  528. embedded generator into a discarding device.
  529. [heading Attributes]
  530. See __karma_comp_attr_notation__.
  531. [table
  532. [[Expression] [Attribute]]
  533. [[`!a` (not-predicate, unary `!`)] [`a: A --> !a: A`]]
  534. ]
  535. [note The attribute of the not-predicate is not always `unused_type`, which is
  536. different from Qi's not-predicate. This is necessary as the generator the
  537. and-predicate is attached to most of the time needs an attribute.
  538. ]
  539. [heading Complexity]
  540. [:The overall complexity of the not-predicate generator is defined by the
  541. complexity of its embedded generator. The complexity of the not-predicate
  542. generator itself is O(1).]
  543. [heading Example]
  544. [note The test harness for the example(s) below is presented in the
  545. __karma_basics_examples__ section.]
  546. Some includes:
  547. [reference_karma_includes]
  548. Some using declarations:
  549. [reference_karma_using_declarations_not_predicate]
  550. Basic usage of a not predicate generator:
  551. [reference_karma_not_predicate]
  552. [endsect]
  553. [endsect]