File: quick_reference.qbk

package info (click to toggle)
boost1.88 1.88.0-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 576,932 kB
  • sloc: cpp: 4,149,234; xml: 136,789; ansic: 35,092; python: 33,910; asm: 5,698; sh: 4,604; ada: 1,681; makefile: 1,633; pascal: 1,139; perl: 1,124; sql: 640; yacc: 478; ruby: 271; java: 77; lisp: 24; csh: 6
file content (372 lines) | stat: -rw-r--r-- 20,170 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
[/==============================================================================
    Copyright (C) 2001-2011 Joel de Guzman
    Copyright (C) 2001-2011 Hartmut Kaiser

    Distributed under the Boost Software License, Version 1.0. (See accompanying
    file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
===============================================================================/]

This quick reference section is provided for convenience. You can use
this section as a sort of a "cheat-sheet" on the most commonly used X3
components. It is not intended to be complete, but should give you an
easy way to recall a particular component without having to dig up on
pages and pages of reference documentation.

[section Common Notation]

[variablelist Notation
    [[`P`]              [Parser type]]
    [[`p, a, b, c`]     [Parser objects]]
    [[`A, B, C`]        [Attribute types of parsers `a`, `b` and `c`]]
    [[`I`]              [The iterator type used for parsing]]
    [[`Unused`]         [An `unused_type`]]
    [[`Context`]        [The enclosing rule's `Context` type]]
    [[`attrib`]         [An attribute value]]
    [[`Attrib`]         [An attribute type]]
    [[`b`]              [A boolean expression]]
    [[`fp`]             [A (lazy parser) function with signature `P(Unused, Context)`]]
    [[`fa`]             [A (semantic action) function with signature `void(Context&)`.]]
    [[`first`]          [An iterator pointing to the start of input]]
    [[`last`]           [An iterator pointing to the end of input]]
    [[`Ch`]             [Character-class specific character type (See __char_class_types__)]]
    [[`ch`]             [Character-class specific character (See __char_class_types__)]]
    [[`ch2`]            [Character-class specific character (See __char_class_types__)]]
    [[`charset`]        [Character-set specifier string (example: "a-z0-9")]]
    [[`str`]            [Character-class specific string (See __char_class_types__)]]
    [[`Str`]            [Attribute of `str`: `std::basic_string<T>` where `T` is the underlying character type of `str`]]
    [[`tuple<>`]        [Used as a placeholder for a fusion sequence]]
    [[`vector<>`]       [Used as a placeholder for an STL container]]
    [[`variant<>`]      [Used as a placeholder for a boost::variant]]
    [[`optional<>`]     [Used as a placeholder for a boost::optional]]
]

[endsect]
[section:char Character Parsers]

[table
    [[Expression]                [Attribute]       [Description]]
    [[[x3_char `ch`]]            [`Unused`]        [Matches `ch`]]
    [[[x3_char `lit(ch)`]]       [`Unused`]        [Matches `ch`]]
    [[[x3_char `char_`]]         [`Ch`]            [Matches any character]]
    [[[x3_char `char_(ch)`]]     [`Ch`]            [Matches `ch`]]
    [[[x3_char `char_("c")`]]    [`Ch`]            [Matches a single char string literal, `c`]]
    [[[x3_char `char_(ch, ch2)`]][`Ch`]            [Matches a range of chars from `ch` to `ch2` (inclusive)]]
    [[[x3_char `char_(charset)`]][`Ch`]            [Matches a character set `charset`]]

    [[[x3_char_class `alnum`]]   [`Ch`]            [Matches a character based on the equivalent of
                                   `std::isalnum` in the current character set]]
    [[[x3_char_class `alpha`]]   [`Ch`]            [Matches a character based on the equivalent of
                                   `std::isalpha` in the current character set]]
    [[[x3_char_class `blank`]]   [`Ch`]            [Matches a character based on the equivalent of
                                   `std::isblank` in the current character set]]
    [[[x3_char_class `cntrl`]]   [`Ch`]            [Matches a character based on the equivalent of
                                   `std::iscntrl` in the current character set]]
    [[[x3_char_class `digit`]]   [`Ch`]            [Matches a character based on the equivalent of
                                   `std::isdigit` in the current character set]]
    [[[x3_char_class `graph`]]   [`Ch`]            [Matches a character based on the equivalent of
                                   `std::isgraph` in the current character set]]
    [[[x3_char_class `print`]]   [`Ch`]            [Matches a character based on the equivalent of
                                   `std::isprint` in the current character set]]
    [[[x3_char_class `punct`]]   [`Ch`]            [Matches a character based on the equivalent of
                                   `std::ispunct` in the current character set]]
    [[[x3_char_class `space`]]   [`Ch`]            [Matches a character based on the equivalent of
                                   `std::isspace` in the current character set]]
    [[[x3_char_class `xdigit`]]  [`Ch`]            [Matches a character based on the equivalent of
                                   `std::isxdigit` in the current character set]]
    [[[x3_char_class `lower`]]   [`Ch`]            [Matches a character based on the equivalent of
                                   `std::islower` in the current character set]]
    [[[x3_char_class `upper`]]   [`Ch`]            [Matches a character based on the equivalent of
                                   `std::isupper` in the current character set]]
]

[endsect]
[section:numeric Numeric Parsers]

[table
    [[Expression]                 [Attribute]           [Description]]
    [[[x3_real_number `float_`]]  [`float`]             [Parse a floating point number into a `float`]]
    [[[x3_real_number `float_(num)`]]  [`float`]        [Parse a floating point number into a `float`,
                                                            a number is matched only if it's `num`]]
    [[[x3_real_number `double_`]] [`double`]            [Parse a floating point number into a `double`]]
    [[[x3_real_number `double_(num)`]] [`double`]            [Parse a floating point number into a `double`,
                                                            a number is matched only if it's `num`]]
    [[[x3_real_number `long_double`]] [`long double`]   [Parse a floating point number into a `long double`]]
    [[[x3_real_number `long_double(num)`]] [`long double`]   [Parse a floating point number into a `long double`,
                                                            a number is matched only if it's `num`]]

    [[[x3_unsigned_int `bin`]]     [`unsigned`]                [Parse a binary integer into an `unsigned`]]
    [[[x3_unsigned_int `oct`]]     [`unsigned`]                [Parse an octal integer into an `unsigned`]]
    [[[x3_unsigned_int `hex`]]     [`unsigned`]                [Parse a hexadecimal integer into an `unsigned`]]
    [[[x3_unsigned_int `ushort_`]] [`unsigned short`]          [Parse an unsigned short integer]]
    [[[x3_unsigned_int `ushort_(num)`]] [`unsigned short`]     [Parse an unsigned short integer,
                                                            a number is matched only if it's `num`]]
    [[[x3_unsigned_int `ulong_`]]  [`unsigned long`]           [Parse an unsigned long integer]]
    [[[x3_unsigned_int `ulong_(num)`]]  [`unsigned long`]      [Parse an unsigned long integer,
                                                            a number is matched only if it's `num`]]
    [[[x3_unsigned_int `uint_`]]   [`unsigned int`]            [Parse an unsigned int]]
    [[[x3_unsigned_int `uint_(num)`]]   [`unsigned int`]       [Parse an unsigned int,
                                                            a number is matched only if it's `num`]]
    [[[x3_unsigned_int `ulong_long`]] [`unsigned long long`]   [Parse an unsigned long long]]
    [[[x3_unsigned_int `ulong_long(num)`]] [`unsigned long long`]   [Parse an unsigned long long,
                                                            a number is matched only if it's `num`]]
    [[[x3_signed_int `short_`]]    [`short`]                   [Parse a short integer]]
    [[[x3_signed_int `short_(num)`]]    [`short`]              [Parse a short integer,
                                                            a number is matched only if it's `num`]]
    [[[x3_signed_int `long_`]]     [`long`]                    [Parse a long integer]]
    [[[x3_signed_int `long_(num)`]]     [`long`]               [Parse a long integer,
                                                            a number is matched only if it's `num`]]
    [[[x3_signed_int `int_`]]      [`int`]                     [Parse an int]]
    [[[x3_signed_int `int_(num)`]]      [`int`]                [Parse an int,
                                                            a number is matched only if it's `num`]]
    [[[x3_signed_int `long_long`]] [`long long`]               [Parse a long long]]
    [[[x3_signed_int `long_long(num)`]] [`long long`]          [Parse a long long,
                                                            a number is matched only if it's `num`]]
]

[endsect]
[section:string String Parsers]

[table
    [[Expression]           [Attribute]                 [Description]]
    [[[x3_lit_string `str`]]          [`Unused`]    [Matches `str`]]
    [[[x3_lit_string `lit(str)`]]     [`Unused`]    [Matches `str`]]
    [[[x3_lit_string `string(str)`]]  [`Str`]       [Matches `str`]]

    [[__x3_symbols__]       [N/A]                       [Declare a symbol table, `sym`. `T` is the
                                                        data type associated with each key.]]
    [[
``
    sym.add
        (str1, val1)
        (str2, val2)
        /*...more...*/
    ;
``
    ]
    [N/A]                                               [Add symbols into a symbol table, `sym`.
                                                        val1 and val2 are optional data of type `T`,
                                                        the data type associated with each key.]]
    [[`sym`]                [`T`]                       [Matches entries in the symbol table, `sym`. If
                                                        successful, returns the data associated with
                                                        the key]]
]

[endsect]
[section:auxiliary Auxiliary Parsers]

[table
    [[Expression]           [Attribute]                 [Description]]
    [[__x3_eol__]           [`Unused`]                  [Matches the end of line (`\r` or `\n` or `\r\n`)]]
    [[__x3_eoi__]           [`Unused`]                  [Matches the end of input (first == last)]]
    [[__x3_eps__]           [`Unused`]                  [Match an empty string]]
    [[__x3_eps__`(b)`]      [`Unused`]                  [If `b` is true, match an empty string]]
    [[__x3_lazy__`(fp)`]    [Attribute of `P` where `P`
                            is the return type of `fp`] [Invoke `fp` at parse time, returning a parser
                                                        `p` which is then called to parse.]]
    [[`fp`]                 [see `lazy(fp)` above]      [Equivalent to `lazy(fp)`]]
    [[__x3_attr__]          [`Attrib`]                  [Doesn't consume/parse any input, but exposes the
                                                         argument `attrib` as its attribute.]]
]

[endsect]
[section:binary Binary Parsers]

[table
    [[Expression]                   [Attribute]                 [Description]]
    [[[x3_native_binary `byte_`]]   [8 bits native endian]      [Matches an 8 bit binary in native endian representation]]
    [[[x3_native_binary `word`]]    [16 bits native endian]     [Matches a 16 bit binary in native endian representation]]
    [[[x3_big_binary `big_word`]]   [16 bits big endian]        [Matches a 16 bit binary in big endian representation]]
    [[[x3_little_binary `little_word`]]  [16 bits little endian][Matches a 16 bit binary in little endian representation]]
    [[[x3_native_binary `dword`]]   [32 bits native endian]     [Matches a 32 bit binary in native endian representation]]
    [[[x3_big_binary `big_dword`]]  [32 bits big endian]        [Matches a 32 bit binary in big endian representation]]
    [[[x3_little_binary `little_dword`]] [32 bits little endian][Matches a 32 bit binary in little endian representation]]
    [[[x3_native_binary `qword`]]   [64 bits native endian]     [Matches a 64 bit binary in native endian representation]]
    [[[x3_big_binary `big_qword`]]  [64 bits big endian]        [Matches a 64 bit binary in big endian representation]]
    [[[x3_little_binary `little_qword`]] [64 bits little endian][Matches a 64 bit binary in little endian representation]]
]

[endsect]

[section:directive Parser Directives]

[table
    [[Expression]                   [Attribute]                     [Description]]
    [[__x3_lexeme__`[a]`]           [`A`]                           [Disable skip parsing for `a`, does pre-skipping]]
    [[[x3_no_skip `no_skip[a]`]]    [`A`]                           [Disable skip parsing for `a`, no pre-skipping]]
    [[__x3_no_case__`[a]`]          [`A`]                           [Inhibits case-sensitivity for `a`]]
    [[__x3_omit__`[a]`]             [`Unused`]                      [Ignores the attribute type of `a`]]
    [[__x3_matches__`[a]`]          [`bool`]                        [Return if the embedded parser `a` matched its input]]

    [[__x3_raw__`[a]`]              [__boost_iterator_range__`<I>`] [Presents the transduction of `a` as an iterator range]]

    [[__x3_expectd__`[a]`]          [`A`]                           [Throw an exception if parsing `a` fails]]

    [[[x3_repeat `repeat[a]`]]      [`vector<A>`]                   [Repeat `a` zero or more times]]
    [[[x3_repeat `repeat(N)[a]`]]         [`vector<A>`]             [Repeat `a` `N` times]]
    [[[x3_repeat `repeat(N, M)[a]`]]      [`vector<A>`]             [Repeat `a` `N` to `M` times]]
    [[[x3_repeat `repeat(N, inf)[a]`]]    [`vector<A>`]             [Repeat `a` `N` or more times]]

    [[__x3_skip__`[a]`]             [`A`]                           [Re-establish the skipper that got inhibited by lexeme or no_skip.]]
    [[__x3_skip__`(p)[a]`]          [`A`]                           [Use `p` as a skipper for parsing `a`]]
]

[endsect]
[section:operator Parser Operators]

[table
    [[Expression]           [Attribute]                 [Description]]
    [[__x3_not_predicate__] [`Unused`]                  [Not predicate. If the predicate `a` matches,
                                                        fail. Otherwise, return a zero length match.]]
    [[__x3_and_predicate__] [`Unused`]                  [And predicate. If the predicate `a` matches,
                                                        return a zero length match. Otherwise, fail.]]
    [[__x3_optional__]      [`optional<A>`]             [Optional. Parse `a` zero or one time]]
    [[__x3_kleene__]        [`vector<A>`]               [Kleene. Parse `a` zero or more times]]
    [[__x3_plus__]          [`vector<A>`]               [Plus. Parse `a` one or more times]]
    [[__x3_alternative__]   [`variant<A, B>`]           [Alternative. Parse `a` or `b`]]
    [[__x3_sequence__]      [`tuple<A, B>`]             [Sequence. Parse `a` followed by `b`]]
    [[__x3_expect__]        [`tuple<A, B>`]             [Expect. Parse `a` followed by `b`. `b` is
                                                        expected to match when `a` matches, otherwise,
                                                        an `expectation_failure` is thrown.]]
    [[__x3_difference__]    [`A`]                       [Difference. Parse `a` but not `b`]]
    [[__x3_list__]          [`vector<A>`]               [List. Parse `a` delimited `b` one or more times]]
]

[endsect]
[section:action Parser Semantic Actions]

[table
    [[Expression]           [Attribute]                 [Description]]
    [[`p[fa]`]              [Attribute of `p`]          [Call semantic action, `fa` if p succeeds.]]
]

[endsect]
[section Compound Attribute Rules]

[heading Notation]

The notation we will use will be of the form:

    a: A, b: B, ... --> composite-expression: composite-attribute

`a`, `b`, etc. are the operands. `A`, `B`, etc. are the operand's
attribute types. `composite-expression` is the expression involving the
operands and `composite-attribute` is the resulting attribute type of
the composite expression.

For instance:

    a: A, b: B --> (a >> b): tuple<A, B>

reads as: given, `a` and `b` are parsers, and `A` is the type of the
attribute of `a`, and `B` is the type of the attribute of `b`, then the
type of the attribute of `a >> b` will be `tuple<A, B>`.

[important In the attribute tables, we will use `vector<A>` and
`tuple<A, B...>` as placeholders only. The notation of `vector<A>`
stands for ['any __stl__ container] holding elements of type `A` and the
notation `tuple<A, B...>` stands for ['any __fusion__ sequence] holding
`A`, `B`, ... etc. elements. Finally, `Unused` stands for
__unused_type__. ]

[heading Compound Parser Attribute Types]

[table
    [[Expression]           [Attribute]]

    [[__x3_sequence__ (`a >> b`)]
[``a: A, b: B --> (a >> b): tuple<A, B>
a: A, b: Unused --> (a >> b): A
a: Unused, b: B --> (a >> b): B
a: Unused, b: Unused --> (a >> b): Unused

a: A, b: A --> (a >> b): vector<A>
a: vector<A>, b: A --> (a >> b): vector<A>
a: A, b: vector<A> --> (a >> b): vector<A>
a: vector<A>, b: vector<A> --> (a >> b): vector<A>``]]

    [[__x3_expect__ (`a > b`)]
[``a: A, b: B --> (a > b): tuple<A, B>
a: A, b: Unused --> (a > b): A
a: Unused, b: B --> (a > b): B
a: Unused, b: Unused --> (a > b): Unused

a: A, b: A --> (a > b): vector<A>
a: vector<A>, b: A --> (a > b): vector<A>
a: A, b: vector<A> --> (a > b): vector<A>
a: vector<A>, b: vector<A> --> (a > b): vector<A>``]]

    [[__x3_alternative__ (`a | b`)]
[``a: A, b: B --> (a | b): variant<A, B>
a: A, b: Unused --> (a | b): optional<A>
a: A, b: B, c: Unused --> (a | b | c): optional<variant<A, B> >
a: Unused, b: B --> (a | b): optional<B>
a: Unused, b: Unused --> (a | b): Unused
a: A, b: A --> (a | b): A``]]

    [[__x3_difference__ (`a - b`)]
[``a: A, b: B --> (a - b): A
a: Unused, b: B --> (a - b): Unused``]]

    [[__x3_kleene__ (`*a`)]
[``a: A --> *a: vector<A>
a: Unused --> *a: Unused``]]
    [[__x3_plus__ (`+a`)]
[``a: A --> +a: vector<A>
a: Unused --> +a: Unused``]]

    [[__x3_list__ (`a % b`)]
[``a: A, b: B --> (a % b): vector<A>
a: Unused, b: B --> (a % b): Unused``]]

    [[[/ $$$ FIXME $$$ link spirit.x3.reference.directive.repeat] `repeat(...,...)[a]`]
[``a: A --> repeat(...,...)[a]: vector<A>
a: Unused --> repeat(...,...)[a]: Unused``]]

    [[__x3_optional__ (`-a`)]
[``a: A --> -a: optional<A>
a: Unused --> -a: Unused``]]

    [[`&a`]  [`a: A --> &a: Unused`]]
    [[`!b`]  [`a: A --> !a: Unused`]]

]

[endsect]

[section:non_terminals Nonterminals]

[variablelist Notation
    [[`Attr`]                   [Synthesized attribute. The rule return type.]]
    [[`ID`]                     [The rule ID]]
    [[`r, r2`]                  [Rules]]
    [[`r_def, r2_def`]          [A rule definition. By convention a rule named `r` should
                                have corresponding rule definition named `r_def`]]
    [[`p`]                      [A parser expression]]
]

[table
    [[Expression]                               [Description]]
    [[`rule<ID, Attr> const r = name;`]         [Rule declaration. `ID` is required.
                                                `Attr` is optional and defaults to __unused_type__.
                                                `name` is an optional string that gives the rule
                                                its name, useful for debugging and error handling.]]
    [[`r.name()`]                               [Getting the name of a rule]]
    [[`auto const r_def = p;`]                  [Rule definition]]
    [[`BOOST_SPIRIT_DEFINE(r, r2, ...)`]        [Links one or more rules (`r, r2, ...`)  with
                                                their definitions (`r_def, r2_def, ...`)]]
]

[endsect]
[section:semantic_actions Parser Semantic Actions]

Has the form:

    p[f]

where `f` is a function with the signatures:

    void f(Context&);

[/ $$$ TODO $$$ Fix this link: For more detailed information about semantic actions see:]

[endsect]