quick_reference.qbk 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687
  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. This quick reference section is provided for convenience. You can use
  8. this section as sort of a "cheat-sheet" on the most commonly used Karma
  9. components. It is not intended to be complete, but should give you an
  10. easy way to recall a particular component without having to dig up on
  11. pages upon pages of reference documentation.
  12. [/////////////////////////////////////////////////////////////////////////////]
  13. [section Common Notation]
  14. [variablelist Notation
  15. [[`G`] [Generator type]]
  16. [[`g, a, b, c, d`] [Generator objects]]
  17. [[`A, B, C, D`] [Attribute types of generators `a`, `b`, `c`, and `d`]]
  18. [[`I`] [The iterator type used for generation]]
  19. [[`Unused`] [An `unused_type`]]
  20. [[`Context`] [The enclosing rule's `Context` type]]
  21. [[`attrib`] [An attribute value]]
  22. [[`Attrib`] [An attribute type]]
  23. [[`b`] [A boolean expression]]
  24. [[`B`] [A type to be interpreted in boolean expressions]]
  25. [[`fg`] [A (lazy generator) function with signature `G(Unused, Context)`]]
  26. [[`fa`] [A (semantic action) function with signature `void(Attrib&, Context, bool&)`.
  27. The third parameter is a boolean flag that can be set to false to
  28. force the generator to fail. Both `Context` and the boolean flag are
  29. optional.]]
  30. [[`outiter`] [An output iterator to receive the generated output]]
  31. [[`Ch`] [Character-class specific character type (See __char_class_types__)]]
  32. [[`ch, ch2`] [Character-class specific character (See __char_class_types__)]]
  33. [[`charset`] [Character-set specifier string (example: `"a-z0-9"`)]]
  34. [[`str`] [Character-class specific string (See __char_class_types__)]]
  35. [[`Str`] [Attribute of `str`: `std::basic_string<T>` where `T` is the underlying character type of `str`]]
  36. [[`num`] [Numeric literal, any integer or real number type]]
  37. [[`Num`] [Attribute of `num`: any integer or real number type]]
  38. [[`tuple<>`] [Used as a placeholder for a fusion sequence]]
  39. [[`vector<>`] [Used as a placeholder for an STL container]]
  40. [[`variant<>`] [Used as a placeholder for a boost::variant]]
  41. [[`optional<>`] [Used as a placeholder for a boost::optional]]
  42. ]
  43. [endsect]
  44. [/////////////////////////////////////////////////////////////////////////////]
  45. [section:primitive_generators Karma Generators]
  46. [section:char Character Generators]
  47. See here for more information about __karma_char__.
  48. [table
  49. [[Expression] [Attribute] [Description]]
  50. [[[karma_char `ch`]] [`Unused`] [Generate `ch`]]
  51. [[[karma_char `lit(ch)`]] [`Unused`] [Generate `ch`]]
  52. [[[karma_char `char_`]] [`Ch`] [Generate character supplied as the attribute]]
  53. [[[karma_char `char_(ch)`]] [`Ch`] [Generate `ch`,
  54. if an attribute is supplied it must match]]
  55. [[[karma_char `char_("c")`]] [`Ch`] [Generate a single char string literal, `c`,
  56. if an attribute is supplied it must match]]
  57. [[[karma_char `char_(ch, ch2)`]][`Ch`] [Generate the character supplied as the attribute,
  58. if it belongs to the character range from
  59. `ch` to `ch2`]]
  60. [[[karma_char `char_(charset)`]][`Ch`] [Generate the character supplied as the attribute,
  61. if it belongs to the character set `charset`]]
  62. [[[karma_char_class `alnum`]] [`Ch`] [Generate the character supplied as the attribute
  63. if it satisfies the concept of `std::isalnum` in
  64. the character set defined by `NS`]]
  65. [[[karma_char_class `alpha`]] [`Ch`] [Generate the character supplied as the attribute
  66. if it satisfies the concept of `std::isalpha` in
  67. the character set defined by `NS`]]
  68. [[[karma_char_class `blank`]] [`Ch`] [Generate the character supplied as the attribute
  69. if it satisfies the concept of `std::isblank` in
  70. the character set defined by `NS`]]
  71. [[[karma_char_class `cntrl`]] [`Ch`] [Generate the character supplied as the attribute
  72. if it satisfies the concept of `std::iscntrl` in
  73. the character set defined by `NS`]]
  74. [[[karma_char_class `digit`]] [`Ch`] [Generate the character supplied as the attribute
  75. if it satisfies the concept of `std::isdigit` in
  76. the character set defined by `NS`]]
  77. [[[karma_char_class `graph`]] [`Ch`] [Generate the character supplied as the attribute
  78. if it satisfies the concept of `std::isgraph` in
  79. the character set defined by `NS`]]
  80. [[[karma_char_class `print`]] [`Ch`] [Generate the character supplied as the attribute
  81. if it satisfies the concept of `std::isprint` in
  82. the character set defined by `NS`]]
  83. [[[karma_char_class `punct`]] [`Ch`] [Generate the character supplied as the attribute
  84. if it satisfies the concept of `std::ispunct` in
  85. the character set defined by `NS`]]
  86. [[[karma_char_class `space`]] [`Ch`] [Generate the character supplied as the attribute
  87. if it satisfies the concept of `std::isspace`, or
  88. a single space character in the character set
  89. defined by `NS`]]
  90. [[[karma_char_class `xdigit`]] [`Ch`] [Generate the character supplied as the attribute
  91. if it satisfies the concept of `std::isxdigit` in
  92. the character set defined by `NS`]]
  93. [[[karma_char_class `lower`]] [`Ch`] [Generate the character supplied as the attribute
  94. if it satisfies the concept of `std::islower` in
  95. the character set defined by `NS`]]
  96. [[[karma_char_class `upper`]] [`Ch`] [Generate the character supplied as the attribute
  97. if it satisfies the concept of `std::isupper` in
  98. the character set defined by `NS`]]
  99. ]
  100. [endsect]
  101. [section:string String Generators]
  102. See here for more information about [karma_string String Generators].
  103. [table
  104. [[Expression] [Attribute] [Description]]
  105. [[[karma_string `str`]] [`Unused`] [Generate `str`]]
  106. [[[karma_string `lit(str)`]] [`Unused`] [Generate `str`]]
  107. [[[karma_string `string`]] [`Str`] [Generate string supplied as the attribute]]
  108. [[[karma_string `string(str)`]] [`Str`] [Generate `str`,
  109. if an attribute is supplied it must match]]
  110. [[[karma_symbols `symbols<Attr, T>`]][`Attr`] [Declare a symbol table, `sym`. `Attr` is the
  111. The type of the original attribute to be used
  112. as the key into the symbol generator.
  113. `T` is the data type associated with each key.]]
  114. [[
  115. ``
  116. sym.add
  117. (attr1, val1)
  118. (attr2, val2)
  119. /*...more...*/
  120. ;
  121. ``
  122. ]
  123. [N/A] [Add symbols into a symbol table, `sym`.
  124. val1 and val2 are optional data of type `T`,
  125. the data type associated with each key.]]
  126. [[`sym`] [`T`] [Emits entries in the symbol table, `sym`. If
  127. attribute is found in the symbol table,
  128. the corresponding value is emitted. If `sym`
  129. does not store values, the original attribute
  130. is emitted.]]
  131. ]
  132. [endsect]
  133. [section:real_number Real Number Generators]
  134. See here for more information about __karma_numeric__.
  135. [table
  136. [[Expression] [Attribute] [Description]]
  137. [[[real_number `lit(num)`]] [`Unused`] [Generate `num`]]
  138. [[[real_number `float_`]] [`float`] [Generate a real number from a `float`]]
  139. [[[real_number `float_(num)`]] [`float`] [Generate `num` as a real number from a `float`,
  140. if an attribute is supplied it must match `num`]]
  141. [[[real_number `double_`]] [`double`] [Generate a real number from a `double`]]
  142. [[[real_number `double_(num)`]] [`double`] [Generate a `num` as a real number from a `double`,
  143. if an attribute is supplied it must match `num`]]
  144. [[[real_number `long_double`]] [`long double`] [Generate a real number from a `long double`]]
  145. [[[real_number `long_double(num)`]] [`long double`] [Generate `num` as a real number from a `long double`,
  146. if an attribute is supplied it must match `num`]]
  147. [[[real_number ``real_generator<
  148. Num, Policies
  149. >()``]]
  150. [`Num`] [Generate a real number `Num` using
  151. the supplied real number formatting policies]]
  152. [[[real_number ``real_generator<
  153. Num, Policies
  154. >()(num)``]]
  155. [`Num`] [Generate real number `num` as a `Num`
  156. using the supplied real number formatting
  157. policies, if an attribute is supplied it must
  158. match]]
  159. ]
  160. [endsect]
  161. [section:signed_int Integer Generators]
  162. [table
  163. [[Expression] [Attribute] [Description]]
  164. [[[signed_int `lit(num)`]] [`Unused`] [Generate `num`]]
  165. [[[signed_int `short_`]] [`short`] [Generate a short integer]]
  166. [[[signed_int `short_(num)`]] [`short`] [Generate `num` as a short integer,
  167. if an attribute is supplied it must match]]
  168. [[[signed_int `int_`]] [`int`] [Generate an int]]
  169. [[[signed_int `int_(num)`]] [`int`] [Generate `num` as an int,
  170. if an attribute is supplied it must match]]
  171. [[[signed_int `long_`]] [`long`] [Generate a long integer]]
  172. [[[signed_int `long_(num)`]] [`long`] [Generate `num` as long integer,
  173. if an attribute is supplied it must match]]
  174. [[[signed_int `long_long`]] [`long long`] [Generate a long long]]
  175. [[[signed_int `long_long(num)`]] [`long long`] [Generate `num` as a long long,
  176. if an attribute is supplied it must match]]
  177. [[[signed_int ``int_generator<
  178. Num, Radix, force_sign
  179. >()``]]
  180. [`Num`] [Generate a `Num`]]
  181. [[[signed_int ``int_generator<
  182. Num, Radix, force_sign
  183. >()(num)``]]
  184. [`Num`] [Generate a `num` as a `Num`,
  185. if an attribute is supplied it must match]]
  186. ]
  187. [endsect]
  188. [section:unsigned_int Unsigned Integer Generators]
  189. [table
  190. [[Expression] [Attribute] [Description]]
  191. [[[unsigned_int `lit(num)`]] [`Unused`] [Generate `num`]]
  192. [[[unsigned_int `ushort_`]] [`unsigned short`] [Generate an unsigned short integer]]
  193. [[[unsigned_int `ushort_(num)`]] [`unsigned short`] [Generate `num` as an unsigned short integer,
  194. if an attribute is supplied it must match]]
  195. [[[unsigned_int `uint_`]] [`unsigned int`] [Generate an unsigned int]]
  196. [[[unsigned_int `uint_(num)`]] [`unsigned int`] [Generate `num` as an unsigned int,
  197. if an attribute is supplied it must match]]
  198. [[[unsigned_int `ulong_`]] [`unsigned long`] [Generate an unsigned long integer]]
  199. [[[unsigned_int `ulong_(num)`]] [`unsigned long`] [Generate `num` as an unsigned long integer,
  200. if an attribute is supplied it must match]]
  201. [[[unsigned_int `ulong_long`]] [`unsigned long long`] [Generate an unsigned long long]]
  202. [[[unsigned_int `ulong_long(num)`]] [`unsigned long long`] [Generate `num` as an unsigned long long,
  203. if an attribute is supplied it must match]]
  204. [[[unsigned_int `bin`]] [`unsigned int`] [Generate a binary integer from an `unsigned int`]]
  205. [[[unsigned_int `oct`]] [`unsigned int`] [Generate an octal integer from an `unsigned int`]]
  206. [[[unsigned_int `hex`]] [`unsigned int`] [Generate a hexadecimal integer from an `unsigned int`]]
  207. [[[unsigned_int ``uint_generator<
  208. Num, Radix
  209. >()``]]
  210. [`Num`] [Generate an unsigned `Num`]]
  211. [[[unsigned_int ``uint_generator<
  212. Num, Radix
  213. >()(num)``]]
  214. [`Num`] [Generate an unsigned `num` as a `Num`,
  215. if an attribute is supplied it must match]]
  216. ]
  217. [endsect]
  218. [section:boolean Boolean Generators]
  219. [table
  220. [[Expression] [Attribute] [Description]]
  221. [[[boolean `lit(num)`]] [`Unused`] [Generate `num`]]
  222. [[[boolean `bool_`]] [`bool`] [Generate a boolean]]
  223. [[[boolean `bool_(b)`]] [`bool`] [Generate `b` as a boolean,
  224. if an attribute is supplied it must match]]
  225. [[[boolean ``bool_generator<
  226. B, Policies
  227. >()``]]
  228. [`B`] [Generate a boolean of type `B`]]
  229. [[[boolean ``bool_generator<
  230. B, Policies
  231. >()(b)``]]
  232. [`B`] [Generate a boolean `b` as a `B`,
  233. if an attribute is supplied it must match]]
  234. ]
  235. [endsect]
  236. [section:stream Stream Generators]
  237. See here for more information about [karma_stream Stream Generators].
  238. [table
  239. [[Expression] [Attribute] [Description]]
  240. [[[karma_stream `stream`]] [`hold_any`] [Generate narrow character (`char`) based output
  241. using the matching streaming `operator<<()`]]
  242. [[[karma_stream `stream(s)`]] [`Unused`] [Generate narrow character (`char`) based output
  243. from the immediate argument `s` using the matching
  244. streaming `operator<<()`]]
  245. [[[karma_stream `wstream`]] [`whold_any`] [Generate wide character (`wchar_t`) based output
  246. using the matching streaming `operator<<()`]]
  247. [[[karma_stream `wstream(s)`]] [`Unused`] [Generate wide character (`wchar_t`) based output
  248. from the immediate argument `s` using the matching
  249. streaming `operator<<()`]]
  250. [
  251. [[karma_stream ``stream_generator<
  252. Char
  253. >()``]] [`basic_hold_any<Char>`] [Generate output based on the given character type
  254. (`Char`) using the matching streaming `operator<<()`]]
  255. [
  256. [[karma_stream ``stream_generator<
  257. Char
  258. >()(s)``]] [`Unused`] [Generate output based on the given character type
  259. `Char` from the immediate argument `s` using the
  260. matching streaming `operator<<()`]]
  261. ]
  262. [endsect]
  263. [section:binary Binary Generators]
  264. See here for more information about __karma_binary__.
  265. [table
  266. [[Expression] [Attribute] [Description]]
  267. [[[karma_native_binary `byte_`]] [8 bits native endian] [Generate an 8 bit binary]]
  268. [[[karma_native_binary `word`]] [16 bits native endian] [Generate a 16 bit binary in native endian representation]]
  269. [[[karma_big_binary `big_word`]] [16 bits big endian] [Generate a 16 bit binary in big endian representation]]
  270. [[[karma_little_binary `little_word`]] [16 bits little endian] [Generate a 16 bit binary in little endian representation]]
  271. [[[karma_native_binary `dword`]] [32 bits native endian] [Generate a 32 bit binary in native endian representation]]
  272. [[[karma_big_binary `big_dword`]] [32 bits big endian] [Generate a 32 bit binary in big endian representation]]
  273. [[[karma_little_binary `little_dword`]][32 bits little endian] [Generate a 32 bit binary in little endian representation]]
  274. [[[karma_native_binary `qword`]] [64 bits native endian] [Generate a 64 bit binary in native endian representation]]
  275. [[[karma_big_binary `big_qword`]] [64 bits big endian] [Generate a 64 bit binary in big endian representation]]
  276. [[[karma_little_binary `little_qword`]][64 bits little endian] [Generate a 64 bit binary in little endian representation]]
  277. [[`pad(num)`] [`Unused`] [Generate additional null bytes allowing to align generated
  278. output with memory addresses divisible by `num`.]]
  279. ]
  280. [endsect]
  281. [section:auxiliary Auxiliary Generators]
  282. See here for more information about __karma_auxiliary__.
  283. [table
  284. [[Expression] [Attribute] [Description]]
  285. [[[karma_attr_cast `attr_cast<Exposed>(a)`]] [`Exposed`] [Invoke `a` while supplying an attribute of type `Exposed`.]]
  286. [[__karma_eol__] [`Unused`] [Generate the end of line (`\n`)]]
  287. [[__karma_eps__] [`Unused`] [Generate an empty string]]
  288. [[__karma_feps__] [`Unused`] [If `b` is true, generate an empty string]]
  289. [[[karma_lazy `lazy(fg)`]]
  290. [Attribute of `G` where `G`
  291. is the return type of `fg`] [Invoke `fg` at generation time, returning a generator
  292. `g` which is then called to generate.]]
  293. [[[karma_lazy `fg`]] [see [karma_lazy `lazy(fg)`] above] [Equivalent to [karma_lazy `lazy(fg)`]]]
  294. ]
  295. [endsect]
  296. [section:auto Auto Generators]
  297. See here for more information about [karma_auto Auto Generators].
  298. [table
  299. [[Expression] [Attribute] [Description]]
  300. [[[karma_auto `auto_`]] [`hold_any`] [Generate output using a generator
  301. created from the supplied attribute type
  302. using the __create_generator__ API function.]]
  303. ]
  304. [endsect]
  305. [/////////////////////////////////////////////////////////////////////////////]
  306. [section:operators Generator Operators]
  307. See here for more information about __karma_operator__.
  308. [table
  309. [[Expression] [Attribute] [Description]]
  310. [[[link spirit.karma.reference.operator.not_predicate `!a`]]
  311. [`A`] [Not predicate. Ensure that `a` does not succeed
  312. generating, but don't create any output]]
  313. [[[link spirit.karma.reference.operator.and_predicate `&a`]]
  314. [`A`] [And predicate. Ensure that `a` does succeed
  315. generating, but don't create any output]]
  316. [[[link spirit.karma.reference.operator.optional `-a`]]
  317. [`optional<A>`] [Optional. Generate `a` zero or one time]]
  318. [[[link spirit.karma.reference.operator.kleene `*a`]]
  319. [`vector<A>`] [Kleene. Generate `a` zero or more times]]
  320. [[[link spirit.karma.reference.operator.plus `+a`]]
  321. [`vector<A>`] [Plus. Generate `a` one or more times]]
  322. [[[link spirit.karma.reference.operator.alternative `a | b`]]
  323. [`variant<A, B>`] [Alternative. Generate `a` or `b`]]
  324. [[[link spirit.karma.reference.operator.sequence `a << b`]]
  325. [`tuple<A, B>`] [Sequence. Generate `a` followed by `b`]]
  326. [[[link spirit.karma.reference.operator.list `a % b`]]
  327. [`vector<A>`] [List. Generate `a` delimited `b` one or more times]]
  328. ]
  329. [:For more information about the attribute propagation rules implemented by the
  330. compound generators please see __sec_karma_compound__.]
  331. [endsect]
  332. [/////////////////////////////////////////////////////////////////////////////]
  333. [section:directives Generator Directives]
  334. See here for more information about __karma_directive__.
  335. [table
  336. [[Expression] [Attribute] [Description]]
  337. [[[karma_upperlower `lower`]`[a]`] [`A`] [Generate `a` as lower case]]
  338. [[[karma_upperlower `upper`]`[a]`] [`A`] [Generate `a` as upper case]]
  339. [[[karma_align `left_align`]`[a]`] [`A`] [Generate `a` left aligned in column of width
  340. `BOOST_KARMA_DEFAULT_FIELD_LENGTH`]]
  341. [[[karma_align `left_align`]`(num)[a]`] [`A`] [Generate `a` left aligned in column of width `num`]]
  342. [[[karma_align `left_align`]`(g)[a]`] [`A`] [Generate `a` left aligned in column of width
  343. `BOOST_KARMA_DEFAULT_FIELD_LENGTH` while using `g` to
  344. generate the necessary padding]]
  345. [[[karma_align `left_align`]`(num, g)[a]`][`A`] [Generate `a` left aligned in column of width `num`
  346. while using `g` to generate the necessary
  347. padding]]
  348. [[[karma_align `center`]`[a]`] [`A`] [Generate `a` centered in column of width
  349. `BOOST_KARMA_DEFAULT_FIELD_LENGTH`]]
  350. [[[karma_align `center`]`(num)[a]`] [`A`] [Generate `a` centered in column of width `num`]]
  351. [[[karma_align `center`]`(g)[a]`] [`A`] [Generate `a` centered in column of width
  352. `BOOST_KARMA_DEFAULT_FIELD_LENGTH` while using `g` to
  353. generate the necessary padding]]
  354. [[[karma_align `center`]`(num, g)[a]`] [`A`] [Generate `a` centered in column of width `num`
  355. while using `g` to generate the necessary
  356. padding]]
  357. [[[karma_align `right_align`]`[a]`] [`A`] [Generate `a` right aligned in column of width
  358. `BOOST_KARMA_DEFAULT_FIELD_LENGTH`]]
  359. [[[karma_align `right_align`]`(num)[a]`] [`A`] [Generate `a` right aligned in column of width `num`]]
  360. [[[karma_align `right_align`]`(g)[a]`] [`A`] [Generate `a` right aligned in column of width
  361. `BOOST_KARMA_DEFAULT_FIELD_LENGTH` while using `g` to
  362. generate the necessary padding]]
  363. [[[karma_align `right_align`]`(num, g)[a]`][`A`][Generate `a` right aligned in column of width `num`
  364. while using `g` to generate the necessary
  365. padding]]
  366. [[[karma_maxwidth `maxwidth`]`[a]`] [`A`] [Generate `a` truncated to column of width
  367. `BOOST_KARMA_DEFAULT_FIELD_MAXWIDTH`]]
  368. [[[karma_maxwidth `maxwidth`]`(num)[a]`] [`A`] [Generate `a` truncated to column of width `num`]]
  369. [[[karma_repeat `repeat`]`[a]`] [`vector<A>`] [Repeat `a` zero or more times]]
  370. [[[karma_repeat `repeat`]`(num)[a]`] [`vector<A>`] [Repeat `a` `num` times]]
  371. [[[karma_repeat `repeat`]`(num1, num2)[a]`] [`vector<A>`] [Repeat `a` `num1` to `num2` times]]
  372. [[[karma_repeat `repeat`]`(num, inf)[a]`] [`vector<A>`] [Repeat `a` `num` or more times]]
  373. [[__karma_verbatim__`[a]`][`A`] [Disable delimited generation for `a`. Performs post delimiting.]]
  374. [[[karma_delimit `delimit`]`[a]`] [`A`] [Reestablish the delimiter that got inhibited by verbatim]]
  375. [[[karma_delimit `delimit`]`(d)[a]`] [`A`] [Use `d` as a delimiter for generating `a`]]
  376. [[[karma_no_delimit `no_delimit`]`[a]`] [`A`] [Disable delimited generation for `a`. No post-delimiting step performed.]]
  377. [[__karma_as__`()[a]`] [`A`] [Force atomic output from arbitrary attribute types]]
  378. [[__karma_as_string__`[a]`] [`A`] [Force atomic output from string attributes]]
  379. [[__karma_as_wstring__`[a]`] [`A`] [Force atomic output from wide character string attributes]]
  380. [[__karma_omit__`[a]`] [`A`] [Consume the attribute type of `a` without generating anything.
  381. The embedded generator will be always executed.]]
  382. [[__karma_skip__`[a]`] [`A`] [Consume the attribute type of `a` without generating anything.
  383. The embedded generator will never be executed.]]
  384. [[__karma_duplicate__`[a]`] [`A`] [The supplied attribute will be duplicated and passed unchanged to
  385. all embedded elements of a sequence.]]
  386. [[__karma_buffer__`[a]`][`A`] [Temporarily intercept the output generated by `a`,
  387. flushing it only after `a` succeeded]]
  388. [[[karma_columns `columns`]`[a]`] [`A`] [Generate `a` split into
  389. `BOOST_KARMA_DEFAULT_COLUMNS` number of columns using
  390. `karma::eol` as column delimiter]]
  391. [[[karma_columns `columns`]`(num)[a]`] [`A`] [Generate `a` split into
  392. `num` number of columns using
  393. `karma::eol` as column delimiter]]
  394. [[[karma_columns `columns`]`(g)[a]`] [`A`] [Generate `a` split into
  395. `BOOST_KARMA_DEFAULT_COLUMNS` number of columns using
  396. `g` as column delimiter]]
  397. [[[karma_columns `columns`]`(num, g)[a]`][`A`][Generate `a` split into
  398. `num` number of columns using
  399. `g` as column delimiter]]
  400. ]
  401. [endsect]
  402. [section:action Generator Semantic Actions]
  403. [table
  404. [[Expression] [Attribute] [Description]]
  405. [[`g[fa]`] [Attribute of `g`] [Call semantic action `fa` before invoking `g`]]
  406. ]
  407. [endsect]
  408. [endsect]
  409. [/////////////////////////////////////////////////////////////////////////////]
  410. [section Compound Attribute Rules]
  411. [heading Notation]
  412. The notation we use is of the form:
  413. a: A, b: B, ... --> composite-expression: composite-attribute
  414. `a`, `b`, etc. are the operands. `A`, `B`, etc. are the operand's
  415. attribute types. `composite-expression` is the expression involving the
  416. operands and `composite-attribute` is the resulting attribute type of
  417. the composite expression.
  418. For instance:
  419. a: A, b: B --> (a << b): tuple<A, B>
  420. which reads as: given, `a` and `b` are generators, and `A` is the type
  421. of the attribute of `a`, and `B` is the type of the attribute of `b`, then the
  422. type of the attribute of `a << b` will be `tuple<A, B>`.
  423. [important In the attribute tables, we will use `vector<A>` and
  424. `tuple<A, B...>` as placeholders only. The notation of `vector<A>`
  425. stands for ['any __stl__ container] holding elements of type `A` and the
  426. notation `tuple<A, B...>` stands for ['any __fusion__ sequence] holding
  427. `A`, `B`, ... etc. elements. The notation of `variant<A, B, ...>` stands for
  428. ['a __boost_variant__] capable of holding `A`, `B`, ... etc. elements. Finally,
  429. `Unused` stands for __unused_type__. ]
  430. [heading Compound Generator Attribute Types]
  431. [table
  432. [[Expression] [Attribute]]
  433. [[__karma_sequence__ (`a << b`)]
  434. [``a: A, b: B --> (a << b): tuple<A, B>
  435. a: A, b: Unused --> (a << b): A
  436. a: Unused, b: B --> (a << b): B
  437. a: Unused, b: Unused --> (a << b): Unused
  438. a: A, b: A --> (a << b): vector<A>
  439. a: vector<A>, b: A --> (a << b): vector<A>
  440. a: A, b: vector<A> --> (a << b): vector<A>
  441. a: vector<A>, b: vector<A> --> (a << b): vector<A>``]]
  442. [[__karma_alternative__ (`a | b`)]
  443. [``a: A, b: B --> (a | b): variant<A, B>
  444. a: A, b: Unused --> (a | b): A
  445. a: Unused, b: B --> (a | b): B
  446. a: Unused, b: Unused --> (a | b): Unused
  447. a: A, b: A --> (a | b): A``]]
  448. [[[karma_kleene Kleene (`*a`)]]
  449. [``a: A --> *a: vector<A>
  450. a: Unused --> *a: Unused``]]
  451. [[__karma_plus__ (`+a`)]
  452. [``a: A --> +a: vector<A>
  453. a: Unused --> +a: Unused``]]
  454. [[__karma_list__ (`a % b`)]
  455. [``a: A, b: B --> (a % b): vector<A>
  456. a: Unused, b: B --> (a % b): Unused``]]
  457. [[[karma_repeat Repetition] (`repeat[]`)]
  458. [``a: A --> repeat(...,...)[a]: vector<A>
  459. a: Unused --> repeat(...,...)[a]: Unused``]]
  460. [[__karma_optional__ (`-a`)]
  461. [``a: A --> -a: optional<A>
  462. a: Unused --> -a: Unused``]]
  463. [[__karma_and_predicate__ (`&a`)] [`a: A --> &a: A`]]
  464. [[__karma_not_predicate__ (`!a`)] [`a: A --> !a: A`]]
  465. ]
  466. [endsect]
  467. [/////////////////////////////////////////////////////////////////////////////]
  468. [section:non_terminals Nonterminals]
  469. See here for more information about __karma_nonterminal__.
  470. [variablelist Notation
  471. [[`RT`] [Synthesized attribute. The rule or grammar's return type.]]
  472. [[`Arg1`, `Arg2`, `ArgN`] [Inherited attributes. Zero or more arguments.]]
  473. [[`L1`, `L2`, `LN`] [Zero or more local variables.]]
  474. [[`r, r2`] [Rules]]
  475. [[`g`] [A grammar]]
  476. [[`p`] [A generator expression]]
  477. [[`my_grammar`] [A user defined grammar]]
  478. ]
  479. [variablelist Terminology
  480. [[Signature] [`RT(Arg1, Arg2, ... ,ArgN)`. The signature specifies
  481. the synthesized (return value) and inherited (arguments)
  482. attributes.]]
  483. [[Locals] [`locals<L1, L2, ..., LN>`. The local variables.]]
  484. [[Delimiter] [The delimit-generator type]]
  485. ]
  486. [variablelist Template Arguments
  487. [[`Iterator`] [The iterator type you will use for parsing.]]
  488. [[`A1`, `A2`, `A3`] [Can be one of 1) Signature 2) Locals 3) Delimiter.]]
  489. ]
  490. [table
  491. [[Expression] [Description]]
  492. [[`rule<OutputIterator, A1, A2, A3> r(name);`] [Rule declaration. `OutputIterator` is required.
  493. `A1, A2, A3` are optional and can be specified in any order.
  494. `name` is an optional string that gives the rule
  495. its name, useful for debugging.]]
  496. [[`rule<OutputIterator, A1, A2, A3> r(r2);`] [Copy construct rule `r` from rule `r2`.]]
  497. [[`r = r2;`] [Assign rule `r2` to `r`. `boost::shared_ptr` semantics.]]
  498. [[`r.alias()`] [Return an alias of `r`. The alias is a generator that
  499. holds a reference to `r`. Reference semantics.]]
  500. [[`r.copy()`] [Get a copy of `r`.]]
  501. [[`r.name(name)`] [Set the name of a rule]]
  502. [[`r.name()`] [Get the name of a rule]]
  503. [[debug(r)] [Debug rule `r`]]
  504. [[`r = g;`] [Rule definition]]
  505. [[`r %= g;`] [Auto-rule definition. The attribute of `g` should be
  506. compatible with the synthesized attribute of `r`. When `g`
  507. is successful, its attribute is automatically propagated
  508. to `r`'s synthesized attribute.]]
  509. [[
  510. ``
  511. template <typename OutputIterator>
  512. struct my_grammar : grammar<OutputIterator, A1, A2, A3>
  513. {
  514. my_grammar() : my_grammar::base_type(start, name)
  515. {
  516. // Rule definitions
  517. start = /* ... */;
  518. }
  519. rule<OutputIterator, A1, A2, A3> start;
  520. // more rule declarations...
  521. };
  522. ``
  523. ] [Grammar definition. `name` is an optional string that gives the
  524. grammar its name, useful for debugging.]]
  525. [[my_grammar<OutputIterator> g] [Instantiate a grammar]]
  526. [[`g.name(name)`] [Set the name of a grammar]]
  527. [[`g.name()`] [Get the name of a grammar]]
  528. ]
  529. [endsect]
  530. [/////////////////////////////////////////////////////////////////////////////]
  531. [section:semantic_actions Generator Semantic Actions]
  532. Semantic Actions may be attached to any generator as follows:
  533. g[f]
  534. where `f` is a function with the signatures:
  535. void f(Attrib&);
  536. void f(Attrib&, Context&);
  537. void f(Attrib&, Context&, bool&);
  538. You can use __boost_bind__ to bind member functions. For function
  539. objects, the allowed signatures are:
  540. void operator()(Attrib&, unused_type, unused_type) const;
  541. void operator()(Attrib&, Context&, unused_type) const;
  542. void operator()(Attrib&, Context&, bool&) const;
  543. The `unused_type` is used in the signatures above to signify 'don't
  544. care'.
  545. For more information see __karma_actions__.
  546. [endsect]
  547. [/////////////////////////////////////////////////////////////////////////////]
  548. [section Phoenix]
  549. __phoenix__ makes it easier to attach semantic actions. You just
  550. inline your lambda expressions:
  551. g[phoenix-lambda-expression]
  552. __karma__ provides some __phoenix__ placeholders to access important
  553. information from the `Attrib` and `Context` that are otherwise fiddly to extract.
  554. [variablelist Spirit.Karma specific Phoenix placeholders
  555. [[`_1, _2, ... , _N`] [Nth attribute of `g`]]
  556. [[`_val`] [The enclosing rule's synthesized attribute.]]
  557. [[`_r1, _r2, ... , _rN`] [The enclosing rule's Nth inherited attribute.]]
  558. [[`_a, _b, ... , _j`] [The enclosing rule's local variables (`_a` refers to the first).]]
  559. [[`_pass`] [Assign `false` to `_pass` to force a generator failure.]]
  560. ]
  561. [important All placeholders mentioned above are defined in the namespace
  562. `boost::spirit` and, for your convenience, are available in the
  563. namespace `boost::spirit::karma` as well.]
  564. For more information see __karma_actions__.
  565. [endsect]