quick_reference.qbk 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  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 X3
  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(Context&)`.]]
  25. [[`first`] [An iterator pointing to the start of input]]
  26. [[`last`] [An iterator pointing to the end of input]]
  27. [[`Ch`] [Character-class specific character type (See __char_class_types__)]]
  28. [[`ch`] [Character-class specific character (See __char_class_types__)]]
  29. [[`ch2`] [Character-class specific character (See __char_class_types__)]]
  30. [[`charset`] [Character-set specifier string (example: "a-z0-9")]]
  31. [[`str`] [Character-class specific string (See __char_class_types__)]]
  32. [[`Str`] [Attribute of `str`: `std::basic_string<T>` where `T` is the underlying character type of `str`]]
  33. [[`tuple<>`] [Used as a placeholder for a fusion sequence]]
  34. [[`vector<>`] [Used as a placeholder for an STL container]]
  35. [[`variant<>`] [Used as a placeholder for a boost::variant]]
  36. [[`optional<>`] [Used as a placeholder for a boost::optional]]
  37. ]
  38. [endsect]
  39. [section:char Character Parsers]
  40. [table
  41. [[Expression] [Attribute] [Description]]
  42. [[[x3_char `ch`]] [`Unused`] [Matches `ch`]]
  43. [[[x3_char `lit(ch)`]] [`Unused`] [Matches `ch`]]
  44. [[[x3_char `char_`]] [`Ch`] [Matches any character]]
  45. [[[x3_char `char_(ch)`]] [`Ch`] [Matches `ch`]]
  46. [[[x3_char `char_("c")`]] [`Ch`] [Matches a single char string literal, `c`]]
  47. [[[x3_char `char_(ch, ch2)`]][`Ch`] [Matches a range of chars from `ch` to `ch2` (inclusive)]]
  48. [[[x3_char `char_(charset)`]][`Ch`] [Matches a character set `charset`]]
  49. [[[x3_char_class `alnum`]] [`Ch`] [Matches a character based on the equivalent of
  50. `std::isalnum` in the current character set]]
  51. [[[x3_char_class `alpha`]] [`Ch`] [Matches a character based on the equivalent of
  52. `std::isalpha` in the current character set]]
  53. [[[x3_char_class `blank`]] [`Ch`] [Matches a character based on the equivalent of
  54. `std::isblank` in the current character set]]
  55. [[[x3_char_class `cntrl`]] [`Ch`] [Matches a character based on the equivalent of
  56. `std::iscntrl` in the current character set]]
  57. [[[x3_char_class `digit`]] [`Ch`] [Matches a character based on the equivalent of
  58. `std::isdigit` in the current character set]]
  59. [[[x3_char_class `graph`]] [`Ch`] [Matches a character based on the equivalent of
  60. `std::isgraph` in the current character set]]
  61. [[[x3_char_class `print`]] [`Ch`] [Matches a character based on the equivalent of
  62. `std::isprint` in the current character set]]
  63. [[[x3_char_class `punct`]] [`Ch`] [Matches a character based on the equivalent of
  64. `std::ispunct` in the current character set]]
  65. [[[x3_char_class `space`]] [`Ch`] [Matches a character based on the equivalent of
  66. `std::isspace` in the current character set]]
  67. [[[x3_char_class `xdigit`]] [`Ch`] [Matches a character based on the equivalent of
  68. `std::isxdigit` in the current character set]]
  69. [[[x3_char_class `lower`]] [`Ch`] [Matches a character based on the equivalent of
  70. `std::islower` in the current character set]]
  71. [[[x3_char_class `upper`]] [`Ch`] [Matches a character based on the equivalent of
  72. `std::isupper` in the current character set]]
  73. ]
  74. [endsect]
  75. [section:numeric Numeric Parsers]
  76. [table
  77. [[Expression] [Attribute] [Description]]
  78. [[[x3_real_number `float_`]] [`float`] [Parse a floating point number into a `float`]]
  79. [[[x3_real_number `float_(num)`]] [`float`] [Parse a floating point number into a `float`,
  80. a number is matched only if it's `num`]]
  81. [[[x3_real_number `double_`]] [`double`] [Parse a floating point number into a `double`]]
  82. [[[x3_real_number `double_(num)`]] [`double`] [Parse a floating point number into a `double`,
  83. a number is matched only if it's `num`]]
  84. [[[x3_real_number `long_double`]] [`long double`] [Parse a floating point number into a `long double`]]
  85. [[[x3_real_number `long_double(num)`]] [`long double`] [Parse a floating point number into a `long double`,
  86. a number is matched only if it's `num`]]
  87. [[[x3_unsigned_int `bin`]] [`unsigned`] [Parse a binary integer into an `unsigned`]]
  88. [[[x3_unsigned_int `oct`]] [`unsigned`] [Parse an octal integer into an `unsigned`]]
  89. [[[x3_unsigned_int `hex`]] [`unsigned`] [Parse a hexadecimal integer into an `unsigned`]]
  90. [[[x3_unsigned_int `ushort_`]] [`unsigned short`] [Parse an unsigned short integer]]
  91. [[[x3_unsigned_int `ushort_(num)`]] [`unsigned short`] [Parse an unsigned short integer,
  92. a number is matched only if it's `num`]]
  93. [[[x3_unsigned_int `ulong_`]] [`unsigned long`] [Parse an unsigned long integer]]
  94. [[[x3_unsigned_int `ulong_(num)`]] [`unsigned long`] [Parse an unsigned long integer,
  95. a number is matched only if it's `num`]]
  96. [[[x3_unsigned_int `uint_`]] [`unsigned int`] [Parse an unsigned int]]
  97. [[[x3_unsigned_int `uint_(num)`]] [`unsigned int`] [Parse an unsigned int,
  98. a number is matched only if it's `num`]]
  99. [[[x3_unsigned_int `ulong_long`]] [`unsigned long long`] [Parse an unsigned long long]]
  100. [[[x3_unsigned_int `ulong_long(num)`]] [`unsigned long long`] [Parse an unsigned long long,
  101. a number is matched only if it's `num`]]
  102. [[[x3_signed_int `short_`]] [`short`] [Parse a short integer]]
  103. [[[x3_signed_int `short_(num)`]] [`short`] [Parse a short integer,
  104. a number is matched only if it's `num`]]
  105. [[[x3_signed_int `long_`]] [`long`] [Parse a long integer]]
  106. [[[x3_signed_int `long_(num)`]] [`long`] [Parse a long integer,
  107. a number is matched only if it's `num`]]
  108. [[[x3_signed_int `int_`]] [`int`] [Parse an int]]
  109. [[[x3_signed_int `int_(num)`]] [`int`] [Parse an int,
  110. a number is matched only if it's `num`]]
  111. [[[x3_signed_int `long_long`]] [`long long`] [Parse a long long]]
  112. [[[x3_signed_int `long_long(num)`]] [`long long`] [Parse a long long,
  113. a number is matched only if it's `num`]]
  114. ]
  115. [endsect]
  116. [section:string String Parsers]
  117. [table
  118. [[Expression] [Attribute] [Description]]
  119. [[[x3_lit_string `str`]] [`Unused`] [Matches `str`]]
  120. [[[x3_lit_string `lit(str)`]] [`Unused`] [Matches `str`]]
  121. [[[x3_lit_string `string(str)`]] [`Str`] [Matches `str`]]
  122. [[__x3_symbols__] [N/A] [Declare a symbol table, `sym`. `T` is the
  123. data type associated with each key.]]
  124. [[
  125. ``
  126. sym.add
  127. (str1, val1)
  128. (str2, val2)
  129. /*...more...*/
  130. ;
  131. ``
  132. ]
  133. [N/A] [Add symbols into a symbol table, `sym`.
  134. val1 and val2 are optional data of type `T`,
  135. the data type associated with each key.]]
  136. [[`sym`] [`T`] [Matches entries in the symbol table, `sym`. If
  137. successful, returns the data associated with
  138. the key]]
  139. ]
  140. [endsect]
  141. [section:auxiliary Auxiliary Parsers]
  142. [table
  143. [[Expression] [Attribute] [Description]]
  144. [[__x3_eol__] [`Unused`] [Matches the end of line (`\r` or `\n` or `\r\n`)]]
  145. [[__x3_eoi__] [`Unused`] [Matches the end of input (first == last)]]
  146. [[__x3_eps__] [`Unused`] [Match an empty string]]
  147. [[__x3_eps__`(b)`] [`Unused`] [If `b` is true, match an empty string]]
  148. [[__x3_lazy__`(fp)`] [Attribute of `P` where `P`
  149. is the return type of `fp`] [Invoke `fp` at parse time, returning a parser
  150. `p` which is then called to parse.]]
  151. [[`fp`] [see `lazy(fp)` above] [Equivalent to `lazy(fp)`]]
  152. [[__x3_attr__] [`Attrib`] [Doesn't consume/parse any input, but exposes the
  153. argument `attrib` as its attribute.]]
  154. ]
  155. [endsect]
  156. [section:binary Binary Parsers]
  157. [table
  158. [[Expression] [Attribute] [Description]]
  159. [[[x3_native_binary `byte_`]] [8 bits native endian] [Matches an 8 bit binary in native endian representation]]
  160. [[[x3_native_binary `word`]] [16 bits native endian] [Matches a 16 bit binary in native endian representation]]
  161. [[[x3_big_binary `big_word`]] [16 bits big endian] [Matches a 16 bit binary in big endian representation]]
  162. [[[x3_little_binary `little_word`]] [16 bits little endian][Matches a 16 bit binary in little endian representation]]
  163. [[[x3_native_binary `dword`]] [32 bits native endian] [Matches a 32 bit binary in native endian representation]]
  164. [[[x3_big_binary `big_dword`]] [32 bits big endian] [Matches a 32 bit binary in big endian representation]]
  165. [[[x3_little_binary `little_dword`]] [32 bits little endian][Matches a 32 bit binary in little endian representation]]
  166. [[[x3_native_binary `qword`]] [64 bits native endian] [Matches a 64 bit binary in native endian representation]]
  167. [[[x3_big_binary `big_qword`]] [64 bits big endian] [Matches a 64 bit binary in big endian representation]]
  168. [[[x3_little_binary `little_qword`]] [64 bits little endian][Matches a 64 bit binary in little endian representation]]
  169. ]
  170. [endsect]
  171. [section:directive Parser Directives]
  172. [table
  173. [[Expression] [Attribute] [Description]]
  174. [[__x3_lexeme__`[a]`] [`A`] [Disable skip parsing for `a`, does pre-skipping]]
  175. [[[x3_no_skip `no_skip[a]`]] [`A`] [Disable skip parsing for `a`, no pre-skipping]]
  176. [[__x3_no_case__`[a]`] [`A`] [Inhibits case-sensitivity for `a`]]
  177. [[__x3_omit__`[a]`] [`Unused`] [Ignores the attribute type of `a`]]
  178. [[__x3_matches__`[a]`] [`bool`] [Return if the embedded parser `a` matched its input]]
  179. [[__x3_raw__`[a]`] [__boost_iterator_range__`<I>`] [Presents the transduction of `a` as an iterator range]]
  180. [[__x3_expectd__`[a]`] [`A`] [Throw an exception if parsing `a` fails]]
  181. [[[x3_repeat `repeat[a]`]] [`vector<A>`] [Repeat `a` zero or more times]]
  182. [[[x3_repeat `repeat(N)[a]`]] [`vector<A>`] [Repeat `a` `N` times]]
  183. [[[x3_repeat `repeat(N, M)[a]`]] [`vector<A>`] [Repeat `a` `N` to `M` times]]
  184. [[[x3_repeat `repeat(N, inf)[a]`]] [`vector<A>`] [Repeat `a` `N` or more times]]
  185. [[__x3_skip__`[a]`] [`A`] [Re-establish the skipper that got inhibited by lexeme or no_skip.]]
  186. [[__x3_skip__`(p)[a]`] [`A`] [Use `p` as a skipper for parsing `a`]]
  187. ]
  188. [endsect]
  189. [section:operator Parser Operators]
  190. [table
  191. [[Expression] [Attribute] [Description]]
  192. [[__x3_not_predicate__] [`Unused`] [Not predicate. If the predicate `a` matches,
  193. fail. Otherwise, return a zero length match.]]
  194. [[__x3_and_predicate__] [`Unused`] [And predicate. If the predicate `a` matches,
  195. return a zero length match. Otherwise, fail.]]
  196. [[__x3_optional__] [`optional<A>`] [Optional. Parse `a` zero or one time]]
  197. [[__x3_kleene__] [`vector<A>`] [Kleene. Parse `a` zero or more times]]
  198. [[__x3_plus__] [`vector<A>`] [Plus. Parse `a` one or more times]]
  199. [[__x3_alternative__] [`variant<A, B>`] [Alternative. Parse `a` or `b`]]
  200. [[__x3_sequence__] [`tuple<A, B>`] [Sequence. Parse `a` followed by `b`]]
  201. [[__x3_expect__] [`tuple<A, B>`] [Expect. Parse `a` followed by `b`. `b` is
  202. expected to match when `a` matches, otherwise,
  203. an `expectation_failure` is thrown.]]
  204. [[__x3_difference__] [`A`] [Difference. Parse `a` but not `b`]]
  205. [[__x3_list__] [`vector<A>`] [List. Parse `a` delimited `b` one or more times]]
  206. ]
  207. [endsect]
  208. [section:action Parser Semantic Actions]
  209. [table
  210. [[Expression] [Attribute] [Description]]
  211. [[`p[fa]`] [Attribute of `p`] [Call semantic action, `fa` if p succeeds.]]
  212. ]
  213. [endsect]
  214. [section Compound Attribute Rules]
  215. [heading Notation]
  216. The notation we will use will be of the form:
  217. a: A, b: B, ... --> composite-expression: composite-attribute
  218. `a`, `b`, etc. are the operands. `A`, `B`, etc. are the operand's
  219. attribute types. `composite-expression` is the expression involving the
  220. operands and `composite-attribute` is the resulting attribute type of
  221. the composite expression.
  222. For instance:
  223. a: A, b: B --> (a >> b): tuple<A, B>
  224. reads as: given, `a` and `b` are parsers, and `A` is the type of the
  225. attribute of `a`, and `B` is the type of the attribute of `b`, then the
  226. type of the attribute of `a >> b` will be `tuple<A, B>`.
  227. [important In the attribute tables, we will use `vector<A>` and
  228. `tuple<A, B...>` as placeholders only. The notation of `vector<A>`
  229. stands for ['any __stl__ container] holding elements of type `A` and the
  230. notation `tuple<A, B...>` stands for ['any __fusion__ sequence] holding
  231. `A`, `B`, ... etc. elements. Finally, `Unused` stands for
  232. __unused_type__. ]
  233. [heading Compound Parser Attribute Types]
  234. [table
  235. [[Expression] [Attribute]]
  236. [[__x3_sequence__ (`a >> b`)]
  237. [``a: A, b: B --> (a >> b): tuple<A, B>
  238. a: A, b: Unused --> (a >> b): A
  239. a: Unused, b: B --> (a >> b): B
  240. a: Unused, b: Unused --> (a >> b): Unused
  241. a: A, b: A --> (a >> b): vector<A>
  242. a: vector<A>, b: A --> (a >> b): vector<A>
  243. a: A, b: vector<A> --> (a >> b): vector<A>
  244. a: vector<A>, b: vector<A> --> (a >> b): vector<A>``]]
  245. [[__x3_expect__ (`a > b`)]
  246. [``a: A, b: B --> (a > b): tuple<A, B>
  247. a: A, b: Unused --> (a > b): A
  248. a: Unused, b: B --> (a > b): B
  249. a: Unused, b: Unused --> (a > b): Unused
  250. a: A, b: A --> (a > b): vector<A>
  251. a: vector<A>, b: A --> (a > b): vector<A>
  252. a: A, b: vector<A> --> (a > b): vector<A>
  253. a: vector<A>, b: vector<A> --> (a > b): vector<A>``]]
  254. [[__x3_alternative__ (`a | b`)]
  255. [``a: A, b: B --> (a | b): variant<A, B>
  256. a: A, b: Unused --> (a | b): optional<A>
  257. a: A, b: B, c: Unused --> (a | b | c): optional<variant<A, B> >
  258. a: Unused, b: B --> (a | b): optional<B>
  259. a: Unused, b: Unused --> (a | b): Unused
  260. a: A, b: A --> (a | b): A``]]
  261. [[__x3_difference__ (`a - b`)]
  262. [``a: A, b: B --> (a - b): A
  263. a: Unused, b: B --> (a - b): Unused``]]
  264. [[__x3_kleene__ (`*a`)]
  265. [``a: A --> *a: vector<A>
  266. a: Unused --> *a: Unused``]]
  267. [[__x3_plus__ (`+a`)]
  268. [``a: A --> +a: vector<A>
  269. a: Unused --> +a: Unused``]]
  270. [[__x3_list__ (`a % b`)]
  271. [``a: A, b: B --> (a % b): vector<A>
  272. a: Unused, b: B --> (a % b): Unused``]]
  273. [[[/ $$$ FIXME $$$ link spirit.x3.reference.directive.repeat] `repeat(...,...)[a]`]
  274. [``a: A --> repeat(...,...)[a]: vector<A>
  275. a: Unused --> repeat(...,...)[a]: Unused``]]
  276. [[__x3_optional__ (`-a`)]
  277. [``a: A --> -a: optional<A>
  278. a: Unused --> -a: Unused``]]
  279. [[`&a`] [`a: A --> &a: Unused`]]
  280. [[`!b`] [`a: A --> !a: Unused`]]
  281. ]
  282. [endsect]
  283. [section:non_terminals Nonterminals]
  284. [variablelist Notation
  285. [[`Attr`] [Synthesized attribute. The rule return type.]]
  286. [[`ID`] [The rule ID]]
  287. [[`r, r2`] [Rules]]
  288. [[`r_def, r2_def`] [A rule definition. By convention a rule named `r` should
  289. have corresponding rule definition named `r_def`]]
  290. [[`p`] [A parser expression]]
  291. ]
  292. [table
  293. [[Expression] [Description]]
  294. [[`rule<ID, Attr> const r = name;`] [Rule declaration. `ID` is required.
  295. `Attr` is optional and defaults to __unused_type__.
  296. `name` is an optional string that gives the rule
  297. its name, useful for debugging and error handling.]]
  298. [[`r.name()`] [Getting the name of a rule]]
  299. [[`auto const r_def = p;`] [Rule definition]]
  300. [[`BOOST_SPIRIT_DEFINE(r, r2, ...)`] [Links one or more rules (`r, r2, ...`) with
  301. their definitions (`r_def, r2_def, ...`)]]
  302. ]
  303. [endsect]
  304. [section:semantic_actions Parser Semantic Actions]
  305. Has the form:
  306. p[f]
  307. where `f` is a function with the signatures:
  308. void f(Context&);
  309. [/ $$$ TODO $$$ Fix this link: For more detailed information about semantic actions see:]
  310. [endsect]