File: basics.qbk

package info (click to toggle)
boost1.74 1.74.0-9
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 464,084 kB
  • sloc: cpp: 3,338,324; xml: 131,293; python: 33,088; ansic: 14,336; asm: 4,034; sh: 3,351; makefile: 1,193; perl: 1,036; yacc: 478; php: 212; ruby: 102; lisp: 24; sql: 13; csh: 6
file content (124 lines) | stat: -rw-r--r-- 4,449 bytes parent folder | download | duplicates (13)
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
[/==============================================================================
    Copyright (C) 2001-2008 Joel de Guzman
    Copyright (C) 2001-2008 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)
===============================================================================/]
[section:basics Parser Basics]

[heading Lazy Argument]

Some parsers (e.g. primitives and non-terminals) may take in additional
attributes. Such parsers take the form:

    p(a1, a2,..., aN)

where `p` is a parser. Each of the arguments (a1 ... aN) can either be an
immediate value, or a function, `f`, with signature:

    T f(Unused, Context)

where `T`, the function's return value, is compatible with the argument
type expected and `Context` is the parser's __context__ type (The first
argument is __unused__ to make the `Context` the second argument. This
is done for uniformity with __actions__).

[heading Character Encoding Namespace]

Some parsers need to know which character set a `char` or `wchar_t` is
operating on. For example, the `alnum` parser works differently with
ISO8859.1 and ASCII encodings. Where necessary, Spirit encodes (tags)
the parser with the character set. 

We have a namespace for each character set Spirit will be supporting.
That includes `ascii`, `iso8859_1`, `standard` and `standard_wide` (and
in the future, `unicode`). In each of the character encoding namespaces,
we place tagged versions of parsers such as `alnum`, `space` etc. 

Example:

    using boost::spirit::ascii::space; // use the ASCII space parser
    
Namespaces:

* boost::spirit::ascii
* boost::spirit::iso8859_1
* boost::spirit::standard
* boost::spirit::standard_wide

For ease of use, the components in this namespaces are also brought into
the qi sub-namespaces with the same names:

* boost::spirit::qi::ascii
* boost::spirit::qi::iso8859_1
* boost::spirit::qi::standard
* boost::spirit::qi::standard_wide

[heading Examples]

All sections in the reference present some real world examples. The
examples use a common test harness to keep the example code as minimal
and direct to the point as possible. The test harness is presented
below.

Some includes:

[reference_includes]

Our test functions:

These functions test the parsers without attributes.

[reference_test]

These functions test the parsers with user supplied attributes.

[reference_test_attr]

The `print_info` utility function prints information contained in the
__info__ class.

[reference_print_info]

[heading String]

[heading Header]

    // forwards to <boost/spirit/home/support/string_traits.hpp>
    #include <boost/spirit/support_string_traits.hpp>

A string can be any object `s`, of type, `S`, that satisfies the
following expression traits:

[table
    [[Expression]                               [Semantics]]
    [[`boost::spirit::traits::is_string<S>`]    [Metafunction that evaluates to `mpl::true_` if 
                                                a certain type, `S` is a string, `mpl::false_`  
                                                otherwise (See __mpl_boolean_constant__).]]
    [[`boost::spirit::traits::char_type_of<S>`] [Metafunction that returns the underlying 
                                                char type of a string type, `S`.]]
    [[`boost::spirit::traits::get_c_string(s)`] [Function that returns the underlying 
                                                raw C-string from `s`.]]
    [[`boost::spirit::traits::get_begin(s)`]    [Function that returns an __stl__ iterator from `s`
                                                that points to the beginning the string.]]                                                
    [[`boost::spirit::traits::get_end(s)`]      [Function that returns an __stl__ iterator from `s`
                                                that points to the end of the string.]]
                                                
]

[heading Models]

Predefined models include:

* any literal string, e.g. "Hello, World", 
* a pointer/reference to a null-terminated array of characters
* a `std::basic_string<Char>`

The namespace `boost::spirit::traits` is open for users to provide their
own specializations. The customization points implemented by __qi__ usable
to customize the behavior of parsers are described in the section 
__sec_customization_points__.

[endsect]