forked from boostorg/spirit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
directive.qbk
1307 lines (975 loc) · 48.6 KB
/
directive.qbk
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
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
[/==============================================================================
Copyright (C) 2001-2011 Hartmut Kaiser
Copyright (C) 2001-2011 Joel de Guzman
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)
===============================================================================/]
[section:directive Generator Directives]
This module includes different generator directives. It includes alignment
directives (`left_align[]`, `center[]`, and `right_align[]`), repetition
(`repeat[]`), directives controlling automatic delimiting (`verbatim[]`,
`no_delimit[]`, and `delimit[]`), controlling case sensitivity (`upper[]` and
`lower[]`), field width (`maxwidth[]`), buffering (`buffer[]`), splitting into
columns (`columns[]`) and attribute handling (`duplicate[]`, `omit[]`, and
`skip[]`).
[heading Module Header]
// forwards to <boost/spirit/home/karma/directive.hpp>
#include <boost/spirit/include/karma_directive.hpp>
Also, see __include_structure__.
[/////////////////////////////////////////////////////////////////////////////]
[section:alignment Alignment Generator Directives (`left_align[]`, `center[]`, `right_align[]`)]
[heading Description]
The alignment directives allow to left align, right align or center output
emitted by other generators into columns of a specified width while using
an arbitrary generator to create the padding.
[heading Header]
For the `left_align[]` directive:
// forwards to <boost/spirit/home/karma/directive/left_alignment.hpp>
#include <boost/spirit/include/karma_left_alignment.hpp>
For the `center[]` directive:
// forwards to <boost/spirit/home/karma/directive/center_alignment.hpp>
#include <boost/spirit/include/karma_center_alignment.hpp>
For the `right_align[]` directive:
// forwards to <boost/spirit/home/karma/directive/right_alignment.hpp>
#include <boost/spirit/include/karma_right_alignment.hpp>
Also, see __include_structure__.
[heading Namespace]
[table
[[Name]]
[[`boost::spirit::left_align // alias: boost::spirit::karma::left_align` ]]
[[`boost::spirit::center // alias: boost::spirit::karma::center` ]]
[[`boost::spirit::right_align // alias: boost::spirit::karma::right_align` ]]
]
[heading Model of]
[:__unary_generator_concept__]
[variablelist Notation
[[`a`] [A generator object]]
[[`pad`] [A generator object, or a __karma_lazy_argument__ that
evaluates to a generator object]]
[[`A`, `Pad`] [Attribute types of the generators `a` and `pad`]]
[[`width`] [Numeric literal, any unsigned integer value, or
a __karma_lazy_argument__ that evaluates to an unsigned
integer value]]]
[heading Expression Semantics]
Semantics of an expression is defined only where it differs from, or is not
defined in __unary_generator_concept__.
[table
[[Expression] [Semantics]]
[[`left_align[a]`] [Generate `a` left aligned in a column of
width as defined by the preprocessor constant
`BOOST_KARMA_DEFAULT_FIELD_LENGTH`
(default: 10), while using `space` to emit
the necessary padding. This generator succeeds as
long as its embedded generator `a` does not
fail (unless the underlying output stream
reports an error).]]
[[`left_align(width)[a]`] [Generate `a` left aligned in a column of
the given `width`, while using `space` to emit
the necessary padding. This generator succeeds as
long as its embedded generator `a` does not
fail (unless the underlying output stream
reports an error).]]
[[`left_align(pad)[a]`] [Generate `a` left aligned in a column of
width as defined by the preprocessor constant
`BOOST_KARMA_DEFAULT_FIELD_LENGTH`
(default: 10), while using the generator `pad`
to emit the necessary padding. This generator
succeeds as long as its embedded and padding
generators `a` and `pad` do not fail (except
if the underlying output stream reports an
error).]]
[[`left_align(width, pad)[a]`] [Generate `a` left aligned in a column of
the given `width`, while using the generator
`pad` to emit the necessary padding. This
generator succeeds as long as its embedded
and padding generators `a` and `pad` do not
fail (unless the underlying output stream
reports an error).]]
[[`center[a]`] [Generate `a` centered in a column of
width as defined by the preprocessor constant
`BOOST_KARMA_DEFAULT_FIELD_LENGTH`
(default: 10), while using `space` to emit
the necessary padding. This generator succeeds as
long as its embedded generator `a` does not
fail (unless the underlying output stream
reports an error).]]
[[`center(width)[a]`] [Generate `a` centered in a column of
the given `width`, while using `space` to emit
the necessary padding. This generator succeeds as
long as its embedded generator `a` does not
fail (unless the underlying output stream
reports an error).]]
[[`center(pad)[a]`] [Generate `a` centered in a column of
width as defined by the preprocessor constant
`BOOST_KARMA_DEFAULT_FIELD_LENGTH`
(default: 10), while using the generator `pad`
to emit the necessary padding. This generator
succeeds as long as its embedded and padding
generators `a` and `pad` do not fail (except
if the underlying output stream reports an
error).]]
[[`center(width, pad)[a]`] [Generate `a` centered in a column of
the given `width`, while using the generator
`pad` to emit the necessary padding. This
generator succeeds as long as its embedded
and padding generators `a` and `pad` do not
fail (unless the underlying output stream
reports an error).]]
[[`right_align[a]`] [Generate `a` right aligned in a column of
width as defined by the preprocessor constant
`BOOST_KARMA_DEFAULT_FIELD_LENGTH`
(default: 10), while using `space` to emit
the necessary padding. This generator succeeds as
long as its embedded generator `a` does not
fail (unless the underlying output stream
reports an error).]]
[[`right_align(width)[a]`] [Generate `a` right aligned in a column of
the given `width`, while using `space` to emit
the necessary padding. This generator succeeds as
long as its embedded generator `a` does not
fail (unless the underlying output stream
reports an error).]]
[[`right_align(pad)[a]`] [Generate `a` right aligned in a column of
width as defined by the preprocessor constant
`BOOST_KARMA_DEFAULT_FIELD_LENGTH`
(default: 10), while using the generator `pad`
to emit the necessary padding. This generator
succeeds as long as its embedded and padding
generators `a` and `pad` do not fail (except
if the underlying output stream reports an
error).]]
[[`right_align(width, pad)[a]`] [Generate `a` right aligned in a column of
the given `width`, while using the generator
`pad` to emit the necessary padding. This
generator succeeds as long as its embedded
and padding generators `a` and `pad` do not
fail (unless the underlying output stream
reports an error).]]
]
[note None of the generator directives listed above limits the emitted output
to the respective column width. If the emitted output is longer than
the specified (or implied) column width, the generated output overruns
the column to the right.
If the output needs to be limited to a specified column width, use the
`maxwidth[]` directive, for instance:
``
maxwidth(8)[right_align(12)["1234567890"]]
``
which will output (without the quotes): ``" 123456"``
]
[heading Attributes]
See __karma_comp_attr_notation__.
[table
[[Expression] [Attribute]]
[[`left_align[]`]
[``a: A --> left_align[a]: A
a: Unused --> left_align[a]: Unused``]]
[[`left_align(width)[]`]
[``a: A --> left_align(width)[a]: A
a: Unused --> left_align(width)[a]: Unused``]]
[[`left_align(pad)[]`]
[``a: A, pad: Pad --> left_align(pad)[a]: A
a: Unused, pad: Pad --> left_align(pad)[a]: Unused``]]
[[`left_align(pad, width)[]`]
[``a: A, pad: Pad --> left_align(pad, width)[a]: A
a: Unused, pad: Pad --> left_align(pad, width)[a]: Unused``]]
[[`center[]`]
[``a: A --> center[a]: A
a: Unused --> center[a]: Unused``]]
[[`center(width)[]`]
[``a: A --> center(width)[a]: A
a: Unused --> center(width)[a]: Unused``]]
[[`center(pad)[]`]
[``a: A, pad: Pad --> center(pad)[a]: A
a: Unused, pad: Pad --> center(pad)[a]: Unused``]]
[[`center(pad, width)[]`]
[``a: A, pad: Pad --> center(pad, width)[a]: A
a: Unused, pad: Pad --> center(pad, width)[a]: Unused``]]
[[`right_align[]`]
[``a: A --> right_align[a]: A
a: Unused --> right_align[a]: Unused``]]
[[`right_align(width)[]`]
[``a: A --> right_align(width)[a]: A
a: Unused --> right_align(width)[a]: Unused``]]
[[`right_align(pad)[]`]
[``a: A, pad: Pad --> right_align(pad)[a]: A
a: Unused, pad: Pad --> right_align(pad)[a]: Unused``]]
[[`right_align(pad, width)[]`]
[``a: A, pad: Pad --> right_align(pad, width)[a]: A
a: Unused, pad: Pad --> right_align(pad, width)[a]: Unused``]]
]
[heading Complexity]
[:The overall complexity of an alignment generator directive is defined by
the complexity of its embedded and padding generator. The complexity of the
left alignment directive generator itself is O(1). The complexity of the
center and right alignment directive generators is O(N), where `N` is the
number of characters emitted by the embedded and padding generators.]
[heading Example]
[note The test harness for the example(s) below is presented in the
__karma_basics_examples__ section.]
Some includes:
[reference_karma_includes]
Some using declarations:
[reference_karma_using_declarations_alignment]
Basic usage of the alignment generators:
[reference_karma_alignment]
[endsect] [/ alignment]
[/////////////////////////////////////////////////////////////////////////////]
[section:repeat Repetition Generator Directive (`repeat[]`)]
[heading Description]
The repetition directive allows to repeat an arbitrary generator expression
while optionally specifying the lower and upper repetition counts. It provides
a more powerful and flexible mechanism for repeating a generator. There are
grammars that are impractical and cumbersome, if not impossible, for the basic
EBNF iteration syntax ([karma_kleene unary `'*'`] and the [karma_plus unary `'+'`])
to specify. Examples:
* A file name may have a maximum of 255 characters only.
* A specific bitmap file format has exactly 4096 RGB color information.
* A 256 bit binary string (1..256 1s or 0s).
[heading Header]
// forwards to <boost/spirit/home/karma/directive/repeat.hpp>
#include <boost/spirit/include/karma_repeat.hpp>
Also, see __include_structure__.
[heading Namespace]
[table
[[Name]]
[[`boost::spirit::repeat // alias: boost::spirit::karma::repeat` ]]
[[`boost::spirit::inf // alias: boost::spirit::karma::inf` ]]
]
[heading Model of]
[:__unary_generator_concept__]
[variablelist Notation
[[`a`] [A generator object]]
[[`num, num1, num2`][Numeric literals, any unsigned integer value, or
a __karma_lazy_argument__ that evaluates to an
unsigned integer value]]
[[`inf`] [Placeholder expression standing for 'no upper repeat
limit']]
]
[heading Expression Semantics]
Semantics of an expression is defined only where it differs from, or is not
defined in __unary_generator_concept__.
[table
[[Expression] [Semantics]]
[[`repeat[a]`] [Repeat the generator `a` zero or more times.
This generator succeeds as long as its
embedded generator `a` does not fail (except
if the underlying output stream reports an
error). This variant of `repeat[]` is
semantically equivalent to the
[karma_kleene Kleene Star operator `*a`]]]
[[`repeat(num)[a]`] [Repeat the generator `a` exactly `num`
times. This generator succeeds as long as its
embedded generator `a` does not fail and
as long as the associated attribute
(container) contains at least `num` elements
(unless the underlying output stream
reports an error).]]
[[`repeat(num1, num2)[a]`] [Repeat the generator `a` at least `num1`
times but not more than `num2` times. This
generator succeeds as long as its
embedded generator `a` does not fail and
as long as the associated attribute
(container) contains at least `num1` elements
(unless the underlying output stream
reports an error). If the associated
attribute (container) does contain more
than `num2` elements, this directive
limits the repeat count to `num2`. ]]
[[`repeat(num, inf)[a]`] [Repeat the generator `a` at least `num1`
times. No upper limit for the repeat count
is set. This generator succeeds as long as
its embedded generator `a` does not fail
and as long as the associated attribute
(container) contains at least `num` elements
(unless the underlying output stream
reports an error).]]
]
[note All failing iterations of the embedded generator will consume one element
from the supplied attribute. The overall `repeat[a]` will succeed as long
as the iteration criteria (number of successful invocations of the
embedded generator) is fulfilled (unless the underlying output stream
reports an error).]
[heading Attributes]
See __karma_comp_attr_notation__.
[table
[[Expression] [Attribute]]
[[`repeat[a]`]
[``a: A --> repeat[a]: vector<A>
a: Unused --> repeat[a]: Unused``]]
[[`repeat(num)[a]`]
[``a: A --> repeat(num)[a]: vector<A>
a: Unused --> repeat(num)[a]: Unused``]]
[[`repeat(num1, num2)[a]`]
[``a: A --> repeat(num1, num2)[a]: vector<A>
a: Unused --> repeat(num1, num2)[a]: Unused``]]
[[`repeat(num, inf)[a]`]
[``a: A --> repeat(num, inf)[a]: vector<A>
a: Unused --> repeat(num, inf)[a]: Unused``]]
]
[important The table above uses `vector<A>` as placeholders only.
The notation of `vector<A>` stands for /any STL container/ holding
elements of type `A`.]
It is important to note, that the `repeat[]` directive does not perform any
buffering of the output generated by its embedded elements. That means that
any failing element generator might have already generated some output, which
is /not/ rolled back.
[tip The simplest way to force a `repeat[]` directive to behave as if it did
buffering is to wrap it into a buffering directive (see
__karma_buffer__):
``buffer[repeat[a]]``
which will /not/ generate any output in case of a failing generator
`repeat[a]`. The expression:
``repeat[buffer[a]]``
will not generate any partial output from a generator `a` if it fails
generating in the middle of its output. The overall expression will
still generate the output as produced by all succeeded invocations of
the generator `a`.]
[heading Complexity]
[:The overall complexity of the repetition generator is defined by the
complexity of its embedded generator. The complexity of the repeat itself is
O(N), where N is the number of repetitions to execute.]
[heading Example]
[note The test harness for the example(s) below is presented in the
__karma_basics_examples__ section.]
Some includes:
[reference_karma_includes]
Some using declarations:
[reference_karma_using_declarations_repeat]
Basic usage of `repeat` generator directive:
[reference_karma_repeat]
[endsect] [/ repeat]
[/////////////////////////////////////////////////////////////////////////////]
[section:delimit Generator Directives Controlling Automatic Delimiting (`verbatim[]`, `no_delimit[]`, `delimit[]`)]
[heading Description]
The directives `delimit[]`, `no_delimit[]`, and `verbatim[]` can be used to
control automatic delimiting. The directives `verbatim[]` and `no_delimit[]`
disable any automatic delimiting, while the directive `delimit[]` (re-)enables
automatic delimiting.
[heading Header]
For the `verbatim[]` directive:
// forwards to <boost/spirit/home/karma/directive/verbatim.hpp>
#include <boost/spirit/include/karma_verbatim.hpp>
For the `no_delimit[]` directive:
// forwards to <boost/spirit/home/karma/directive/no_delimit.hpp>
#include <boost/spirit/include/karma_no_delimit.hpp>
For the `delimit[]` directive:
// forwards to <boost/spirit/home/karma/directive/delimit.hpp>
#include <boost/spirit/include/karma_delimit.hpp>
Also, see __include_structure__.
[heading Namespace]
[table
[[Name]]
[[`boost::spirit::verbatim // alias: boost::spirit::karma::verbatim` ]]
[[`boost::spirit::no_delimit // alias: boost::spirit::karma::no_delimit` ]]
[[`boost::spirit::delimit // alias: boost::spirit::karma::delimit` ]]
]
[heading Model of]
[:__unary_generator_concept__]
[variablelist Notation
[[`a`] [A generator object]]
[[`d`] [A generator object, or a __karma_lazy_argument__ that
evaluates to a generator object]]
[[`A`, `D`] [Attribute types of the generators `a` and `d`]]]
[heading Expression Semantics]
Semantics of an expression is defined only where it differs from, or is not
defined in __unary_generator_concept__.
[table
[[Expression] [Semantics]]
[[`delimit[a]`] [Enable automatic delimiting for the embedded generator
`a` while using the `space` generator as the
delimiting generator. If used inside a `verbatim[]`
directive it re-enables the delimiter generator as used
outside of this `verbatim[]` instead. The directive succeeds
as long as the embedded generator succeeded (unless
the underlying output stream reports an error).]]
[[`delimit(d)[a]`] [Enable automatic delimiting for the embedded generator
`a` while using the generator `d` as the
delimiting generator. The directive succeeds
as long as the embedded generator succeeded (unless
the underlying output stream reports an error).]]
[[`verbatim[a]`] [Disable automatic delimiting for the embedded generator
`a`. The directive succeeds
as long as the embedded generator succeeded (unless
the underlying output stream reports an error). This
directive it has no effect if it is used when no
delimiting is active. When delimiting is active this
directive performs a post-delimit step (which is
different from the behavior of `no_delimit[]`).]]
[[`no_delimit[a]`] [Disable automatic delimiting for the embedded generator
`a`. The directive succeeds
as long as the embedded generator succeeded (unless
the underlying output stream reports an error). This
directive it has no effect if it is used when no
delimiting is active. When delimiting is active this
directive does not perform a post-delimit step (which is
different from the behavior of `verbatim[]`.]]
]
[heading Attributes]
See __karma_comp_attr_notation__.
[table
[[Expression] [Attribute]]
[[`delimit[a]`]
[``a: A --> delimit[a]: A
a: Unused --> delimit[a]: Unused``]]
[[`delimit(d)[a]`]
[``a: A, d: D --> delimit(d)[a]: A
a: Unused, d: D --> delimit(d)[a]: Unused``]]
[[`verbatim[a]`]
[``a: A --> verbatim[a]: A
a: Unused --> verbatim[a]: Unused``]]
[[`no_delimit[a]`]
[``a: A --> no_delimit[a]: A
a: Unused --> no_delimit[a]: Unused``]]
]
[heading Complexity]
[:The overall complexity of the generator directives `delimit[]`, `verbatim[]`,
and `no_delimit[]` is defined by the complexity of its embedded generators.
The complexity of the directives themselves is O(1).]
[heading Example]
[note The test harness for the example(s) below is presented in the
__karma_basics_examples__ section.]
Some includes:
[reference_karma_includes_simple]
Some using declarations:
[reference_karma_using_declarations_delimit]
Basic usage of `delimit` generator directive:
[reference_karma_delimit]
[endsect] [/ verbatim/delimit/no_delimit]
[/////////////////////////////////////////////////////////////////////////////]
[section:upperlower Generator Directives Controlling Case Sensitivity (`upper[]`, `lower[]`)]
[heading Description]
The generator directives `ns::lower[]` and `ns::upper[]` force their embedded
generators to emit lower case or upper case only characters based on the
interpretation of the generated characters in the character set defined by
`ns` (see __karma_char_encoding_namespace__).
[heading Header]
// forwards to <boost/spirit/home/karma/directive/upper_lower_case.hpp>
#include <boost/spirit/include/karma_upper_lower_case.hpp>
Also, see __include_structure__.
[heading Namespace]
[table
[[Name]]
[[`ns::lower`]]
[[`ns::upper`]]
]
In the table above, `ns` represents a __karma_char_encoding_namespace__.
[heading Model of]
[:The model of `lower[]` and `upper[]` is the model of its subject generator.]
[variablelist Notation
[[`a`] [A generator object]]
[[`A`] [Attribute type of the generator `a`]]
[[`ns`] [A __karma_char_encoding_namespace__.]]]
[heading Expression Semantics]
The `lower[]` and `upper[]` directives have no special generator semantics.
They are pure modifier directives. They indirectly influence the way all
subject generators work. They add information (the `tag::upper` or `tag::lower`)
to the `Modifier` template parameter used while transforming the `proto::expr`
into the corresponding generator expression. This is achieved by the
following specializations:
namespace boost { namespace spirit
{
template <typename CharEncoding>
struct is_modifier_directive<
karma::domain
, tag::char_code<tag::lower, CharEncoding> >
: mpl::true_
{};
template <typename CharEncoding>
struct is_modifier_directive<
karma::domain
, tag::char_code<tag::upper, CharEncoding> >
: mpl::true_
}}
(for more details see the section describing the compilation process of the
__boost_proto__ expression into the corresponding generator expressions).
[table
[[Expression] [Semantics]]
[[`ns::lower[a]`] [Generate `a` as lower case, interpreted in the
character set defined by `ns`. The directive succeeds
as long as the embedded generator succeeded (unless
the underlying output stream reports an error).]]
[[`ns::upper[a]`] [Generate `a` as upper case, interpreted in the
character set defined by `ns`. The directive succeeds
as long as the embedded generator succeeded (unless
the underlying output stream reports an error).]]
]
[note If both directives are 'active' with regard to a generator, the
innermost of those directives takes precedence. For instance:
``
generate(sink, ascii::lower['A' << ascii::upper['b']])
``
will generate `"aB"` (without the quotes).
Further, the directives will have no effect on generators emitting
characters not having an upper case or lower case equivalent in the
character set defined by `ns`.
]
[heading Attributes]
See __karma_comp_attr_notation__.
[table
[[Expression] [Attribute]]
[[`ns:lower[a]`]
[``a: A --> ns:lower[a]: A
a: Unused --> ns:lower[a]: Unused``]]
[[`ns:upper[a]`]
[``a: A --> ns:upper[a]: A
a: Unused --> ns:upper[a]: Unused``]]
]
[heading Complexity]
[:The overall complexity of the generator directives `ns::lower[]` and `ns::upper[]`
is defined by the complexity of its embedded generators. The directives
themselves are compile time only directives, having no impact on runtime
performance.]
[heading Example]
[note The test harness for the example(s) below is presented in the
__karma_basics_examples__ section.]
Some includes:
[reference_karma_includes_simple]
Some using declarations:
[reference_karma_using_declarations_upperlower]
Basic usage of the `upper` and `lower` generator directives:
[reference_karma_upperlower]
[endsect] [/ upper/lower]
[/////////////////////////////////////////////////////////////////////////////]
[section:maxwidth Generator Directives Controlling the Maximum Field Width (`maxwidth[]`)]
[heading Description]
The `maxwidth[]` directive allows to limit (truncate) the overall length of the
output generated by the embedded generator.
[heading Header]
// forwards to <boost/spirit/home/karma/directive/maxwidth.hpp>
#include <boost/spirit/include/karma_maxwidth.hpp>
Also, see __include_structure__.
[table
[[Name]]
[[`boost::spirit::maxwidth // alias: boost::spirit::karma::maxwidth` ]]
]
[heading Model of]
[:__unary_generator_concept__]
[variablelist Notation
[[`a`] [A generator object]]
[[`A`] [Attribute type of the generator `a`]]
[[`num`] [Numeric literal, any unsigned integer value, or
a __karma_lazy_argument__ that evaluates to an unsigned
integer value]]]
[heading Expression Semantics]
Semantics of an expression is defined only where it differs from, or is not
defined in __unary_generator_concept__.
[table
[[Expression] [Semantics]]
[[`maxwidth[a]`] [Limit the overall length of the emitted output of
the embedded generator (including characters
generated by automatic delimiting) to the number
of characters as defined by the preprocessor constant
`BOOST_KARMA_DEFAULT_FIELD_MAXWIDTH`. Any additional
output is truncated. The directive succeeds as long
as the embedded generator succeeded (unless
the underlying output stream reports an error).]]
[[`maxwidth(num)[a]`] [Limit the overall length of the emitted output of
the embedded generator (including characters
generated by automatic delimiting) to the number
of characters as defined by `num`. Any additional
output is truncated. The directive succeeds as long
as the embedded generator succeeded (unless the
underlying output stream reports an error).]]
]
[note The `maxwidth[]` generator directive does not pad the generated output
to fill the specified column width. If the emitted output is shorter
than the specified (or implied) column width, the generated output will
be more narrow than the column width.
If the output needs to always be equal to a specified column width, use
one of the alignment directives `left-align[]`, `center[]`, or
`right_align[]`, for instance:
``
maxwidth(8)[left_align(8)["1234"]]
``
which will output: `"1234 "` (without the quotes).
]
[heading Attributes]
See __karma_comp_attr_notation__.
[table
[[Expression] [Attribute]]
[[`maxwidth[a]`]
[``a: A --> maxwidth[a]: A
a: Unused --> maxwidth[a]: Unused``]]
[[`maxwidth(num)[a]`]
[``a: A --> maxwidth(num)[a]: A
a: Unused --> maxwidth(num)[a]: Unused``]]
]
[heading Complexity]
[:The overall complexity of the generator directive `maxwidth[]`
is defined by the complexity of its embedded generator. The complexity of the
directive itself is O(N), where `N` is the number of characters generated
by the maxwidth directive.]
[heading Example]
[note The test harness for the example(s) below is presented in the
__karma_basics_examples__ section.]
Some includes:
[reference_karma_includes_simple]
Some using declarations:
[reference_karma_using_declarations_maxwidth]
Basic usage of `maxwidth` generator directive:
[reference_karma_maxwidth]
[endsect] [/ maxwidth]
[/////////////////////////////////////////////////////////////////////////////]
[section:buffer Generator Directive for Temporary Output Buffering (`buffer[]`)]
[heading Description]
All generator components (except the __karma_alternative__ generator) pass
their generated output directly to the underlying output stream. If a generator
fails halfway through, the output generated so far is not 'rolled back'. The
buffering generator directive allows to avoid this unwanted output to be
generated. It temporarily redirects the output produced by the embedded
generator into a buffer. This buffer is flushed to the underlying stream only
after the embedded generator succeeded, but is discarded otherwise.
[heading Header]
// forwards to <boost/spirit/home/karma/directive/buffer.hpp>
#include <boost/spirit/include/karma_buffer.hpp>
Also, see __include_structure__.
[table
[[Name]]
[[`boost::spirit::buffer // alias: boost::spirit::karma::buffer` ]]
]
[heading Model of]
[:__unary_generator_concept__]
[variablelist Notation
[[`a`] [A generator object]]
[[`A`] [Attribute type of generator `a`]]]
[heading Expression Semantics]
Semantics of an expression is defined only where it differs from, or is not
defined in __unary_generator_concept__.
[table
[[Expression] [Semantics]]
[[`buffer[a]`] [The embedded generator `a` is invoked but its output
is temporarily intercepted and stored in an internal
buffer. If `a` succeeds the buffer content is flushed
to the underlying output stream, otherwise the buffer
content is discarded. The buffer directive succeeds
as long as the embedded generator succeeded (unless
the underlying output stream reports an error).]]
]
[tip If you want to make the buffered generator succeed regardless of the
outcome of the embedded generator, simply wrap the `buffer[a]` into an
additional optional: `-buffer[a]` (see __karma_optional__).]
[heading Attributes]
See __karma_comp_attr_notation__.
[table
[[Expression] [Attribute]]
[[`buffer[a]`]
[``a: A --> buffer[a]: A
a: Unused --> buffer[a]: Unused``]]
]
[heading Complexity]
[:The overall complexity of the buffering generator directive is defined by the
complexity of its embedded generator. The complexity of the buffering
directive generator itself is O(N), where N is the number of characters
buffered.]
[heading Example]
[note The test harness for the example(s) below is presented in the
__karma_basics_examples__ section.]
Some includes:
[reference_karma_includes]
Some using declarations:
[reference_karma_using_declarations_buffer]
Basic usage of a buffering generator directive. It shows how the partial
output generated in the first example does not show up in the generated output
as the plus generator fails (no data is available, see __karma_plus__).
[reference_karma_buffer]
[endsect] [/ buffer]
[/////////////////////////////////////////////////////////////////////////////]
[section:omit Generator Directives Consuming Attributes (`omit[]` and `skip[]`)]
[heading Description]
The directives `omit[]` and `skip[]` consumes the attribute type of the
embedded generator without generating any output. The `omit[]` directive
will still execute the embedded generator while discarding the generated output
afterwards. The `skip[]` directive will not execute the embedded generator, but
will use it only to extract the exposed attribute type.
[heading Header]
// forwards to <boost/spirit/home/karma/directive/omit.hpp>
#include <boost/spirit/include/karma_omit.hpp>
Also, see __include_structure__.
[table
[[Name]]
[[`boost::spirit::omit // alias: boost::spirit::karma::omit` ]]
[[`boost::spirit::skip // alias: boost::spirit::karma::skip` ]]
]
[heading Model of]
[:__unary_generator_concept__]
[variablelist Notation
[[`a`] [A generator object]]
[[`A`] [Attribute type of generator `a`]]]
[heading Expression Semantics]
Semantics of an expression is defined only where it differs from, or is not
defined in __unary_generator_concept__.
[table
[[Expression] [Semantics]]
[[`omit[a]`] [The `omit` directive consumes the attribute type of the
embedded generator `A` without generating any output.
It succeeds always. The embedded generator is executed
and any generated output is discarded.]]
[[`skip[a]`] [The `skip` directive consumes the attribute type of the
embedded generator `A` without generating any output.
It succeeds always. The embedded generator is not
executed.]]
]
[heading Attributes]
See __karma_comp_attr_notation__.
[table
[[Expression] [Attribute]]
[[`omit[a]`]
[``a: A --> omit[a]: A
a: Unused --> omit[a]: Unused``]]
[[`skip[a]`]
[``a: A --> skip[a]: A
a: Unused --> skip[a]: Unused``]]
]
[heading Complexity]
[:The overall complexity of the `omit[]` directive depends on the complexity
of the embedded generator. The overall complexity of the `skip[]` generator
directive is O(1) as it does not generate any output.]
[heading Example]
[note The test harness for the example(s) below is presented in the
__karma_basics_examples__ section.]
Some includes:
[reference_karma_includes]
Some using declarations:
[reference_karma_using_declarations_omit]
Basic usage of a `omit` generator directive. It shows how it consumes the first
element of the provided attribute without generating anything, leaving the
second element of the attribute to the non-wrapped `double_` generator.
[reference_karma_omit]
Generally, this directive is helpful in situations, where the attribute type
contains more information (elements) than need to be used to generate the
required output. Normally in such situations we would resolve to use semantic
actions to explicitly pass the correct parts of the overall attribute to the
generators. The `omit` directive helps achieving the same without having to use
semantic actions.
Consider the attribute type:
typedef fusion::vector<int, double, std::string> attribute_type;
where we need to generate output only from the first and last element:
typedef std::back_insert:iterator<std::string> iterator_type;
karma::rule<iterator_type, attribute_type()> r;
r = int_[_1 = phoenix::at_c<0>(_val)] << string[_1 = phoenix::at_c<2>(_val)];
std::string str;
iterator_type sink(str);
generate(sink, r, attribute_type(1, 2.0, "example")); // will generate: '1example'
This is error prone and not really readable. The same can be achieved by using
the `omit` directive:
r = int_ << omit[double_] << string;
which is at the same time more readable and more efficient as we don't have to