quick_reference.qbk 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513
  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 a sort of a "cheat-sheet" on the most commonly used Qi
  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 and pages of reference documentation.
  12. [section Common Notation]
  13. [variablelist Notation
  14. [[`P`] [Parser type]]
  15. [[`p, a, b, c`] [Parser objects]]
  16. [[`A, B, C`] [Attribute types of parsers `a`, `b` and `c`]]
  17. [[`I`] [The iterator type used for parsing]]
  18. [[`Unused`] [An `unused_type`]]
  19. [[`Context`] [The enclosing rule's `Context` type]]
  20. [[`attrib`] [An attribute value]]
  21. [[`Attrib`] [An attribute type]]
  22. [[`b`] [A boolean expression]]
  23. [[`fp`] [A (lazy parser) function with signature `P(Unused, Context)`]]
  24. [[`fa`] [A (semantic action) function with signature `void(Attrib, Context, bool&)`.
  25. The third parameter is a boolean flag that can be set to false to
  26. force the parse to fail. Both `Context` and the boolean flag are
  27. optional.]]
  28. [[`first`] [An iterator pointing to the start of input]]
  29. [[`last`] [An iterator pointing to the end of input]]
  30. [[`Ch`] [Character-class specific character type (See __char_class_types__)]]
  31. [[`ch`] [Character-class specific character (See __char_class_types__)]]
  32. [[`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. [[`tuple<>`] [Used as a placeholder for a fusion sequence]]
  37. [[`vector<>`] [Used as a placeholder for an STL container]]
  38. [[`variant<>`] [Used as a placeholder for a boost::variant]]
  39. [[`optional<>`] [Used as a placeholder for a boost::optional]]
  40. ]
  41. [endsect]
  42. [section:qi_parsers Qi Parsers]
  43. [section:char Character Parsers]
  44. [table
  45. [[Expression] [Attribute] [Description]]
  46. [[[qi_char `ch`]] [`Unused`] [Matches `ch`]]
  47. [[[qi_char `lit(ch)`]] [`Unused`] [Matches `ch`]]
  48. [[[qi_char `char_`]] [`Ch`] [Matches any character]]
  49. [[[qi_char `char_(ch)`]] [`Ch`] [Matches `ch`]]
  50. [[[qi_char `char_("c")`]] [`Ch`] [Matches a single char string literal, `c`]]
  51. [[[qi_char `char_(ch, ch2)`]][`Ch`] [Matches a range of chars from `ch` to `ch2` (inclusive)]]
  52. [[[qi_char `char_(charset)`]][`Ch`] [Matches a character set `charset`]]
  53. [[[qi_char_class `alnum`]] [`Ch`] [Matches a character based on the equivalent of
  54. `std::isalnum` in the current character set]]
  55. [[[qi_char_class `alpha`]] [`Ch`] [Matches a character based on the equivalent of
  56. `std::isalpha` in the current character set]]
  57. [[[qi_char_class `blank`]] [`Ch`] [Matches a character based on the equivalent of
  58. `std::isblank` in the current character set]]
  59. [[[qi_char_class `cntrl`]] [`Ch`] [Matches a character based on the equivalent of
  60. `std::iscntrl` in the current character set]]
  61. [[[qi_char_class `digit`]] [`Ch`] [Matches a character based on the equivalent of
  62. `std::isdigit` in the current character set]]
  63. [[[qi_char_class `graph`]] [`Ch`] [Matches a character based on the equivalent of
  64. `std::isgraph` in the current character set]]
  65. [[[qi_char_class `print`]] [`Ch`] [Matches a character based on the equivalent of
  66. `std::isprint` in the current character set]]
  67. [[[qi_char_class `punct`]] [`Ch`] [Matches a character based on the equivalent of
  68. `std::ispunct` in the current character set]]
  69. [[[qi_char_class `space`]] [`Ch`] [Matches a character based on the equivalent of
  70. `std::isspace` in the current character set]]
  71. [[[qi_char_class `xdigit`]] [`Ch`] [Matches a character based on the equivalent of
  72. `std::isxdigit` in the current character set]]
  73. [[[qi_char_class `lower`]] [`Ch`] [Matches a character based on the equivalent of
  74. `std::islower` in the current character set]]
  75. [[[qi_char_class `upper`]] [`Ch`] [Matches a character based on the equivalent of
  76. `std::isupper` in the current character set]]
  77. ]
  78. [endsect]
  79. [section:numeric Numeric Parsers]
  80. [table
  81. [[Expression] [Attribute] [Description]]
  82. [[[qi_real_number `float_`]] [`float`] [Parse a floating point number into a `float`]]
  83. [[[qi_real_number `float_(num)`]] [`float`] [Parse a floating point number into a `float`,
  84. a number is matched only if it's `num`]]
  85. [[[qi_real_number `double_`]] [`double`] [Parse a floating point number into a `double`]]
  86. [[[qi_real_number `double_(num)`]] [`double`] [Parse a floating point number into a `double`,
  87. a number is matched only if it's `num`]]
  88. [[[qi_real_number `long_double`]] [`long double`] [Parse a floating point number into a `long double`]]
  89. [[[qi_real_number `long_double(num)`]] [`long double`] [Parse a floating point number into a `long double`,
  90. a number is matched only if it's `num`]]
  91. [[[qi_unsigned_int `bin`]] [`unsigned`] [Parse a binary integer into an `unsigned`]]
  92. [[[qi_unsigned_int `oct`]] [`unsigned`] [Parse an octal integer into an `unsigned`]]
  93. [[[qi_unsigned_int `hex`]] [`unsigned`] [Parse a hexadecimal integer into an `unsigned`]]
  94. [[[qi_unsigned_int `ushort_`]] [`unsigned short`] [Parse an unsigned short integer]]
  95. [[[qi_unsigned_int `ushort_(num)`]] [`unsigned short`] [Parse an unsigned short integer,
  96. a number is matched only if it's `num`]]
  97. [[[qi_unsigned_int `ulong_`]] [`unsigned long`] [Parse an unsigned long integer]]
  98. [[[qi_unsigned_int `ulong_(num)`]] [`unsigned long`] [Parse an unsigned long integer,
  99. a number is matched only if it's `num`]]
  100. [[[qi_unsigned_int `uint_`]] [`unsigned int`] [Parse an unsigned int]]
  101. [[[qi_unsigned_int `uint_(num)`]] [`unsigned int`] [Parse an unsigned int,
  102. a number is matched only if it's `num`]]
  103. [[[qi_unsigned_int `ulong_long`]] [`unsigned long long`] [Parse an unsigned long long]]
  104. [[[qi_unsigned_int `ulong_long(num)`]] [`unsigned long long`] [Parse an unsigned long long,
  105. a number is matched only if it's `num`]]
  106. [[[qi_signed_int `short_`]] [`short`] [Parse a short integer]]
  107. [[[qi_signed_int `short_(num)`]] [`short`] [Parse a short integer,
  108. a number is matched only if it's `num`]]
  109. [[[qi_signed_int `long_`]] [`long`] [Parse a long integer]]
  110. [[[qi_signed_int `long_(num)`]] [`long`] [Parse a long integer,
  111. a number is matched only if it's `num`]]
  112. [[[qi_signed_int `int_`]] [`int`] [Parse an int]]
  113. [[[qi_signed_int `int_(num)`]] [`int`] [Parse an int,
  114. a number is matched only if it's `num`]]
  115. [[[qi_signed_int `long_long`]] [`long long`] [Parse a long long]]
  116. [[[qi_signed_int `long_long(num)`]] [`long long`] [Parse a long long,
  117. a number is matched only if it's `num`]]
  118. ]
  119. [endsect]
  120. [section:string String Parsers]
  121. [table
  122. [[Expression] [Attribute] [Description]]
  123. [[[qi_lit_string `str`]] [`Unused`] [Matches `str`]]
  124. [[[qi_lit_string `lit(str)`]] [`Unused`] [Matches `str`]]
  125. [[[qi_lit_string `string(str)`]] [`Str`] [Matches `str`]]
  126. [[__qi_symbols__] [N/A] [Declare a symbol table, `sym`. `Ch` is the
  127. underlying char type of the symbol table keys.
  128. `T` is the data type associated with each key.]]
  129. [[
  130. ``
  131. sym.add
  132. (str1, val1)
  133. (str2, val2)
  134. /*...more...*/
  135. ;
  136. ``
  137. ]
  138. [N/A] [Add symbols into a symbol table, `sym`.
  139. val1 and val2 are optional data of type `T`,
  140. the data type associated with each key.]]
  141. [[`sym`] [`T`] [Matches entries in the symbol table, `sym`. If
  142. successful, returns the data associated with
  143. the key]]
  144. ]
  145. [endsect]
  146. [section:auxiliary Auxiliary Parsers]
  147. [table
  148. [[Expression] [Attribute] [Description]]
  149. [[__qi_eol__] [`Unused`] [Matches the end of line (`\r` or `\n` or `\r\n`)]]
  150. [[__qi_eoi__] [`Unused`] [Matches the end of input (first == last)]]
  151. [[__qi_eps__] [`Unused`] [Match an empty string]]
  152. [[__qi_eps__`(b)`] [`Unused`] [If `b` is true, match an empty string]]
  153. [[__qi_lazy__`(fp)`] [Attribute of `P` where `P`
  154. is the return type of `fp`] [Invoke `fp` at parse time, returning a parser
  155. `p` which is then called to parse.]]
  156. [[`fp`] [see `lazy(fp)` above] [Equivalent to `lazy(fp)`]]
  157. [[__qi_attr__] [`Attrib`] [Doesn't consume/parse any input, but exposes the
  158. argument `attrib` as its attribute.]]
  159. ]
  160. [endsect]
  161. [section:binary Binary Parsers]
  162. [table
  163. [[Expression] [Attribute] [Description]]
  164. [[[qi_native_binary `byte_`]] [8 bits native endian] [Matches an 8 bit binary in native endian representation]]
  165. [[[qi_native_binary `word`]] [16 bits native endian] [Matches a 16 bit binary in native endian representation]]
  166. [[[qi_big_binary `big_word`]] [16 bits big endian] [Matches a 16 bit binary in big endian representation]]
  167. [[[qi_little_binary `little_word`]] [16 bits little endian][Matches a 16 bit binary in little endian representation]]
  168. [[[qi_native_binary `dword`]] [32 bits native endian] [Matches a 32 bit binary in native endian representation]]
  169. [[[qi_big_binary `big_dword`]] [32 bits big endian] [Matches a 32 bit binary in big endian representation]]
  170. [[[qi_little_binary `little_dword`]] [32 bits little endian][Matches a 32 bit binary in little endian representation]]
  171. [[[qi_native_binary `qword`]] [64 bits native endian] [Matches a 64 bit binary in native endian representation]]
  172. [[[qi_big_binary `big_qword`]] [64 bits big endian] [Matches a 64 bit binary in big endian representation]]
  173. [[[qi_little_binary `little_qword`]] [64 bits little endian][Matches a 64 bit binary in little endian representation]]
  174. ]
  175. [endsect]
  176. [section:auto Auto Parsers]
  177. See here for more information about [qi_auto Auto Parsers].
  178. [table
  179. [[Expression] [Attribute] [Description]]
  180. [[[qi_auto `auto_`]] [`hold_any`] [Parse input using a parser
  181. created from the supplied attribute type
  182. using the __create_parser__ API function.]]
  183. ]
  184. [endsect]
  185. [section:directive Parser Directives]
  186. [table
  187. [[Expression] [Attribute] [Description]]
  188. [[__qi_lexeme__`[a]`] [`A`] [Disable skip parsing for `a`, does pre-skipping]]
  189. [[[qi_no_skip `no_skip[a]`]] [`A`] [Disable skip parsing for `a`, no pre-skipping]]
  190. [[__qi_no_case__`[a]`] [`A`] [Inhibits case-sensitivity for `a`]]
  191. [[__qi_omit__`[a]`] [`Unused`] [Ignores the attribute type of `a`]]
  192. [[__qi_matches__`[a]`] [`bool`] [Return if the embedded parser `a` matched its input]]
  193. [[__qi_as__`()[a]`] [`A`] [Force atomic assignment for arbitrary attribute types]]
  194. [[__qi_as_string__`[a]`] [`A`] [Force atomic assignment for string attributes]]
  195. [[__qi_as_wstring__`[a]`] [`A`] [Force atomic assignment for wide character string attributes]]
  196. [[__qi_raw__`[a]`] [__boost_iterator_range__`<I>`] [Presents the transduction of `a` as an iterator range]]
  197. [[__qi_expectd__`[a]`] [`A`] [Throw an exception if parsing `a` fails]]
  198. [[[qi_repeat `repeat[a]`]] [`vector<A>`] [Repeat `a` zero or more times]]
  199. [[[qi_repeat `repeat(N)[a]`]] [`vector<A>`] [Repeat `a` `N` times]]
  200. [[[qi_repeat `repeat(N, M)[a]`]] [`vector<A>`] [Repeat `a` `N` to `M` times]]
  201. [[[qi_repeat `repeat(N, inf)[a]`]] [`vector<A>`] [Repeat `a` `N` or more times]]
  202. [[__qi_skip__`[a]`] [`A`] [Re-establish the skipper that got inhibited by lexeme or no_skip.]]
  203. [[__qi_skip__`(p)[a]`] [`A`] [Use `p` as a skipper for parsing `a`]]
  204. ]
  205. ]
  206. [endsect]
  207. [section:operator Parser Operators]
  208. [table
  209. [[Expression] [Attribute] [Description]]
  210. [[[link spirit.qi.reference.operator.not_predicate `!a`]]
  211. [`Unused`] [Not predicate. If the predicate `a` matches,
  212. fail. Otherwise, return a zero length match.]]
  213. [[[link spirit.qi.reference.operator.and_predicate `&a`]]
  214. [`Unused`] [And predicate. If the predicate `a` matches,
  215. return a zero length match. Otherwise, fail.]]
  216. [[[link spirit.qi.reference.operator.optional `-a`]]
  217. [`optional<A>`] [Optional. Parse `a` zero or one time]]
  218. [[[link spirit.qi.reference.operator.kleene `*a`]]
  219. [`vector<A>`] [Kleene. Parse `a` zero or more times]]
  220. [[[link spirit.qi.reference.operator.plus `+a`]]
  221. [`vector<A>`] [Plus. Parse `a` one or more times]]
  222. [[[link spirit.qi.reference.operator.alternative `a | b`]]
  223. [`variant<A, B>`] [Alternative. Parse `a` or `b`]]
  224. [[[link spirit.qi.reference.operator.sequence `a >> b`]]
  225. [`tuple<A, B>`] [Sequence. Parse `a` followed by `b`]]
  226. [[[link spirit.qi.reference.operator.expect `a > b`]]
  227. [`tuple<A, B>`] [Expect. Parse `a` followed by `b`. `b` is
  228. expected to match when `a` matches, otherwise,
  229. an `expectation_failure` is thrown.]]
  230. [[[link spirit.qi.reference.operator.difference `a - b`]]
  231. [`A`] [Difference. Parse `a` but not `b`]]
  232. [[[link spirit.qi.reference.operator.sequential_or `a || b`]]
  233. [`tuple<`
  234. `optional<A>,`
  235. `optional<B> >`
  236. ] [Sequential Or. Parse `a` or `b` or `a` followed by `b`]]
  237. [[[link spirit.qi.reference.operator.list `a % b`]]
  238. [`vector<A>`] [List. Parse `a` delimited `b` one or more times]]
  239. [[[link spirit.qi.reference.operator.permutation `a ^ b`]]
  240. [`tuple<`
  241. `optional<A>,`
  242. `optional<B> >`
  243. ] [Permutation. Parse `a` or `b` or `a` followed by `b` or `b` followed by `a`.]]
  244. ]
  245. [endsect]
  246. [section:action Parser Semantic Actions]
  247. [table
  248. [[Expression] [Attribute] [Description]]
  249. [[`p[fa]`] [Attribute of `p`] [Call semantic action, `fa` if p succeeds.]]
  250. ]
  251. [endsect]
  252. [endsect]
  253. [section Compound Attribute Rules]
  254. [heading Notation]
  255. The notation we will use will be of the form:
  256. a: A, b: B, ... --> composite-expression: composite-attribute
  257. `a`, `b`, etc. are the operands. `A`, `B`, etc. are the operand's
  258. attribute types. `composite-expression` is the expression involving the
  259. operands and `composite-attribute` is the resulting attribute type of
  260. the composite expression.
  261. For instance:
  262. a: A, b: B --> (a >> b): tuple<A, B>
  263. reads as: given, `a` and `b` are parsers, and `A` is the type of the
  264. attribute of `a`, and `B` is the type of the attribute of `b`, then the
  265. type of the attribute of `a >> b` will be `tuple<A, B>`.
  266. [important In the attribute tables, we will use `vector<A>` and
  267. `tuple<A, B...>` as placeholders only. The notation of `vector<A>`
  268. stands for ['any __stl__ container] holding elements of type `A` and the
  269. notation `tuple<A, B...>` stands for ['any __fusion__ sequence] holding
  270. `A`, `B`, ... etc. elements. Finally, `Unused` stands for
  271. __unused_type__. ]
  272. [heading Compound Parser Attribute Types]
  273. [table
  274. [[Expression] [Attribute]]
  275. [[__qi_sequence__ (`a >> b`)]
  276. [``a: A, b: B --> (a >> b): tuple<A, B>
  277. a: A, b: Unused --> (a >> b): A
  278. a: Unused, b: B --> (a >> b): B
  279. a: Unused, b: Unused --> (a >> b): Unused
  280. a: A, b: A --> (a >> b): vector<A>
  281. a: vector<A>, b: A --> (a >> b): vector<A>
  282. a: A, b: vector<A> --> (a >> b): vector<A>
  283. a: vector<A>, b: vector<A> --> (a >> b): vector<A>``]]
  284. [[__qi_expect__ (`a > b`)]
  285. [``a: A, b: B --> (a > b): tuple<A, B>
  286. a: A, b: Unused --> (a > b): A
  287. a: Unused, b: B --> (a > b): B
  288. a: Unused, b: Unused --> (a > b): Unused
  289. a: A, b: A --> (a > b): vector<A>
  290. a: vector<A>, b: A --> (a > b): vector<A>
  291. a: A, b: vector<A> --> (a > b): vector<A>
  292. a: vector<A>, b: vector<A> --> (a > b): vector<A>``]]
  293. [[__qi_alternative__ (`a | b`)]
  294. [``a: A, b: B --> (a | b): variant<A, B>
  295. a: A, b: Unused --> (a | b): optional<A>
  296. a: A, b: B, c: Unused --> (a | b | c): optional<variant<A, B> >
  297. a: Unused, b: B --> (a | b): optional<B>
  298. a: Unused, b: Unused --> (a | b): Unused
  299. a: A, b: A --> (a | b): A``]]
  300. [[__qi_difference__ (`a - b`)]
  301. [``a: A, b: B --> (a - b): A
  302. a: Unused, b: B --> (a - b): Unused``]]
  303. [[__qi_kleene__ (`*a`)]
  304. [``a: A --> *a: vector<A>
  305. a: Unused --> *a: Unused``]]
  306. [[__qi_plus__ (`+a`)]
  307. [``a: A --> +a: vector<A>
  308. a: Unused --> +a: Unused``]]
  309. [[__qi_list__ (`a % b`)]
  310. [``a: A, b: B --> (a % b): vector<A>
  311. a: Unused, b: B --> (a % b): Unused``]]
  312. [[[link spirit.qi.reference.directive.repeat `repeat(...,...)[a]`]]
  313. [``a: A --> repeat(...,...)[a]: vector<A>
  314. a: Unused --> repeat(...,...)[a]: Unused``]]
  315. [[__qi_sequential_or__ (`a || b`)]
  316. [``a: A, b: B --> (a || b): tuple<optional<A>, optional<B> >
  317. a: A, b: Unused --> (a || b): optional<A>
  318. a: Unused, b: B --> (a || b): optional<B>
  319. a: Unused, b: Unused --> (a || b): Unused
  320. a: A, b: A --> (a || b): vector<optional<A> >``]]
  321. [[__qi_optional__ (`-a`)]
  322. [``a: A --> -a: optional<A>
  323. a: Unused --> -a: Unused``]]
  324. [[`&a`] [`a: A --> &a: Unused`]]
  325. [[`!b`] [`a: A --> !a: Unused`]]
  326. [[__qi_permutation__ (`a ^ b`)]
  327. [``a: A, b: B --> (a ^ b): tuple<optional<A>, optional<B> >
  328. a: A, b: Unused --> (a ^ b): optional<A>
  329. a: Unused, b: B --> (a ^ b): optional<B>
  330. a: Unused, b: Unused --> (a ^ b): Unused``]]
  331. ]
  332. [endsect]
  333. [section:non_terminals Nonterminals]
  334. [variablelist Notation
  335. [[`RT`] [Synthesized attribute. The rule or grammar's return type.]]
  336. [[`Arg1`, `Arg2`, `ArgN`] [Inherited attributes. Zero or more arguments.]]
  337. [[`L1`, `L2`, `LN`] [Zero or more local variables.]]
  338. [[`r, r2`] [Rules]]
  339. [[`g`] [A grammar]]
  340. [[`p`] [A parser expression]]
  341. [[`my_grammar`] [A user defined grammar]]
  342. ]
  343. [variablelist Terminology
  344. [[Signature] [`RT(Arg1, Arg2 ... ,ArgN)`. The signature specifies
  345. the synthesized (return value) and inherited (arguments)
  346. attributes.]]
  347. [[Locals] [`locals<L1, L2 ..., LN>`. The local variables.]]
  348. [[Skipper] [The skip-parser type]]
  349. ]
  350. [variablelist Template Arguments
  351. [[`Iterator`] [The iterator type you will use for parsing.]]
  352. [[`A1`, `A2`, `A3`] [Can be one of 1) Signature 2) Locals 3) Skipper.]]
  353. ]
  354. [table
  355. [[Expression] [Description]]
  356. [[`rule<Iterator, A1, A2, A3> r(name);`] [Rule declaration. `Iterator` is required.
  357. `A1, A2, A3` are optional and can be specified in any order.
  358. `name` is an optional string that gives the rule
  359. its name, useful for debugging and error handling.]]
  360. [[`rule<Iterator, A1, A2, A3> r(r2);`] [Copy construct rule `r` from rule `r2`.]]
  361. [[`r = r2;`] [Assign rule `r2` to `r`.]]
  362. [[`r.alias()`] [return an alias of `r`. The alias is a parser that
  363. holds a reference to `r`. Reference semantics.]]
  364. [[`r.copy()`] [Get a copy of `r`.]]
  365. [[`r.name(name)`] [Naming a rule]]
  366. [[`r.name()`] [Getting the name of a rule]]
  367. [[debug(r)] [Debug rule `r`]]
  368. [[`r = p;`] [Rule definition]]
  369. [[`r %= p;`] [Auto-rule definition. The attribute of `p` must be
  370. compatible with the synthesized attribute of `r`. If `p`
  371. is successful, its attribute is automatically propagated
  372. to `r`'s synthesized attribute. Semantic actions, if present,
  373. may not change the attribute's type.]]
  374. [[
  375. ``
  376. template <typename Iterator>
  377. struct my_grammar : grammar<Iterator, A1, A2, A3>
  378. {
  379. my_grammar() : my_grammar::base_type(start, name)
  380. {
  381. // Rule definitions
  382. start = /* ... */;
  383. }
  384. rule<Iterator, A1, A2, A3> start;
  385. // more rule declarations...
  386. };
  387. ``
  388. ] [Grammar definition. `name` is an optional string that gives the
  389. grammar its name, useful for debugging and error handling.]]
  390. [[`g.name(name)`] [Naming a grammar]]
  391. [[`g.name()`] [Getting the name of a grammar]]
  392. ]
  393. [endsect]
  394. [section:semantic_actions Parser Semantic Actions]
  395. Has the form:
  396. p[f]
  397. where `f` is a function with the signatures:
  398. void f(Attrib const&);
  399. void f(Attrib const&, Context&);
  400. void f(Attrib const&, Context&, bool&);
  401. You can use __boost_bind__ to bind member functions. For function
  402. objects, the allowed signatures are:
  403. void operator()(Attrib const&, unused_type, unused_type) const;
  404. void operator()(Attrib const&, Context&, unused_type) const;
  405. void operator()(Attrib const&, Context&, bool&) const;
  406. The `unused_type` is used in the signatures above to signify 'don't
  407. care'.
  408. For more detailed information about semantic actions see:
  409. [link spirit.qi.tutorials.semantic_actions here].
  410. [endsect]
  411. [section Phoenix]
  412. __phoenix__ makes it easier to attach semantic actions. You just
  413. inline your lambda expressions:
  414. p[phoenix-lambda-expression]
  415. Spirit.Qi provides some __phoenix__ placeholders to important
  416. information from the `Attrib` and `Context` that are otherwise fiddly to extract.
  417. [variablelist Spirit.Qi specific Phoenix placeholders
  418. [[`_1, _2... , _N`] [Nth attribute of `p`]]
  419. [[`_val`] [The enclosing rule's synthesized attribute.]]
  420. [[`_r1, _r2... , _rN`] [The enclosing rule's Nth inherited attribute.]]
  421. [[`_a, _b... , _j`] [The enclosing rule's local variables (`_a` refers to the first).]]
  422. [[`_pass`] [Assign `false` to `_pass` to force a parser failure.]]
  423. ]
  424. [important All placeholders mentioned above are defined in the namespace
  425. `boost::spirit` and, for your convenience, are available in the
  426. namespace `boost::spirit::qi` as well.]
  427. For more detailed information about semantic actions see:
  428. [link spirit.qi.tutorials.semantic_actions here].
  429. [endsect]