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 (117 lines) | stat: -rw-r--r-- 5,111 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
[/==============================================================================
    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 Lex
components. It is not intended to be complete, but should give you an
easy way to recall a particular component without having to dig through
pages and pages of reference documentation.

[/////////////////////////////////////////////////////////////////////////////]
[section Common Notation]

[variablelist Notation
    [[`L`]              [Lexer type]]
    [[`l, a, b, c, d`]  [Lexer objects]]
    [[`Iterator`]       [The type of an iterator referring to the underlying 
                         input sequence]]
    [[`IdType`]         [The token id type]]
    [[`Context`]        [The lexer components `Context` type]]
    [[`ch`]             [Character-class specific character (See __char_class_types__)]]
    [[`Ch`]             [Character-class specific character type (See __char_class_types__)]]
    [[`str`]            [Character-class specific string (See __char_class_types__)]]
    [[`Str`]            [Character-class specific string type (See __char_class_types__)]]
    [[`Attrib`]         [An attribute type]]
    [[`fa`]             [A semantic action function with a signature: 
                         `void f(Iterator&, Iterator&, pass_flag&, Idtype&, Context&)`.]]
]

[endsect]

[/////////////////////////////////////////////////////////////////////////////]
[section:lexers Primitive Lexer Components]

[table 
    [[Expression]        [Attribute]         [Description]]
    [[`ch`]              [n/a]               [Matches `ch`]]
    [[`char_(ch)`]       [n/a]               [Matches `ch`]]
    [[`str`]             [n/a]               [Matches regular expression `str`]]
    [[`string(str)`]     [n/a]               [Matches regular expression `str`]]
    [[`token_def<Attrib>`] [`Attrib`]        [Matches the immediate argument]]
    [[`a | b`]           [n/a]               [Matches any of the expressions `a` or `b`]]
    [[`l[fa]`]           [Attribute of `l`]  [Call semantic action `fa` (after matching `l`).]]
]

[note  The column /Attribute/ in the table above lists the parser attribute 
       exposed by the lexer component if it is used as a parser (see 
       __attribute__). A 'n/a' in this columns means the lexer component is not
       usable as a parser.]

[endsect]

[/////////////////////////////////////////////////////////////////////////////]
[section Semantic Actions]

Has the form:

    l[f]

where `f` is a function with the signatures:

    void f();
    void f(Iterator&, Iterator&);
    void f(Iterator&, Iterator&, pass_flag&);
    void f(Iterator&, Iterator&, pass_flag&, Idtype&);
    void f(Iterator&, Iterator&, pass_flag&, Idtype&, Context&);

You can use __boost_bind__ to bind member functions. For function
objects, the allowed signatures are:

    void operator()(unused_type, unused_type, unused_type, unused_type, unused_type) const;
    void operator()(Iterator&, Iterator&, unused_type, unused_type, unused_type) const;
    void operator()(Iterator&, Iterator&, pass_flag&, unused_type, unused_type) const;
    void operator()(Iterator&, Iterator&, pass_flag&, Idtype&, unused_type) const;
    void operator()(Iterator&, Iterator&, pass_flag&, Idtype&, Context&) const;

The `unused_type` is used in the signatures above to signify 'don't
care'.

For more information see __lex_actions__.

[endsect]

[/////////////////////////////////////////////////////////////////////////////]
[section Phoenix]

__phoenix__ makes it easier to attach semantic actions. You just
inline your lambda expressions:

    l[phoenix-lambda-expression]

__lex__ provides some __phoenix__ placeholders to access important
information from the `Context` that are otherwise difficult to extract.

[variablelist Spirit.Lex specific Phoenix placeholders
    [[`_start, _end`]          [Iterators pointing to the begin and the end of the
                                matched input sequence.]]
    [[`_pass`]                 [Assign `lex::pass_flags::pass_fail` to `_pass` to force the current match to fail.]]
    [[`_tokenid`]              [The token id of the matched token.]]
    [[`_val`]                  [The token value of the matched token.]]
    [[`_state`]                [The lexer state the token has been matched in.]]
    [[`_eoi`]                  [Iterator referring to the current end of the input sequence.]]
]

[tip  All of the placeholders in the list above (except `_eoi`) can be changed 
      from the inside of the semantic action allowing to modify the lexer 
      behavior. They are defined in the namespace `boost::spirit::lex`.]

For more information see __lex_actions__.

[endsect]