]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | [/============================================================================== |
2 | Copyright (C) 2001-2011 Joel de Guzman | |
3 | Copyright (C) 2001-2011 Hartmut Kaiser | |
4 | ||
5 | Distributed under the Boost Software License, Version 1.0. (See accompanying | |
6 | file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |
7 | ===============================================================================/] | |
8 | ||
9 | This quick reference section is provided for convenience. You can use | |
10 | this section as a sort of a "cheat-sheet" on the most commonly used Lex | |
11 | components. It is not intended to be complete, but should give you an | |
12 | easy way to recall a particular component without having to dig through | |
13 | pages and pages of reference documentation. | |
14 | ||
15 | [/////////////////////////////////////////////////////////////////////////////] | |
16 | [section Common Notation] | |
17 | ||
18 | [variablelist Notation | |
19 | [[`L`] [Lexer type]] | |
20 | [[`l, a, b, c, d`] [Lexer objects]] | |
21 | [[`Iterator`] [The type of an iterator referring to the underlying | |
22 | input sequence]] | |
23 | [[`IdType`] [The token id type]] | |
24 | [[`Context`] [The lexer components `Context` type]] | |
25 | [[`ch`] [Character-class specific character (See __char_class_types__)]] | |
26 | [[`Ch`] [Character-class specific character type (See __char_class_types__)]] | |
27 | [[`str`] [Character-class specific string (See __char_class_types__)]] | |
28 | [[`Str`] [Character-class specific string type (See __char_class_types__)]] | |
29 | [[`Attrib`] [An attribute type]] | |
30 | [[`fa`] [A semantic action function with a signature: | |
31 | `void f(Iterator&, Iterator&, pass_flag&, Idtype&, Context&)`.]] | |
32 | ] | |
33 | ||
34 | [endsect] | |
35 | ||
36 | [/////////////////////////////////////////////////////////////////////////////] | |
37 | [section:lexers Primitive Lexer Components] | |
38 | ||
39 | [table | |
40 | [[Expression] [Attribute] [Description]] | |
41 | [[`ch`] [n/a] [Matches `ch`]] | |
42 | [[`char_(ch)`] [n/a] [Matches `ch`]] | |
43 | [[`str`] [n/a] [Matches regular expression `str`]] | |
44 | [[`string(str)`] [n/a] [Matches regular expression `str`]] | |
45 | [[`token_def<Attrib>`] [`Attrib`] [Matches the immediate argument]] | |
46 | [[`a | b`] [n/a] [Matches any of the expressions `a` or `b`]] | |
47 | [[`l[fa]`] [Attribute of `l`] [Call semantic action `fa` (after matching `l`).]] | |
48 | ] | |
49 | ||
50 | [note The column /Attribute/ in the table above lists the parser attribute | |
51 | exposed by the lexer component if it is used as a parser (see | |
52 | __attribute__). A 'n/a' in this columns means the lexer component is not | |
53 | usable as a parser.] | |
54 | ||
55 | [endsect] | |
56 | ||
57 | [/////////////////////////////////////////////////////////////////////////////] | |
58 | [section Semantic Actions] | |
59 | ||
60 | Has the form: | |
61 | ||
62 | l[f] | |
63 | ||
64 | where `f` is a function with the signatures: | |
65 | ||
66 | void f(); | |
67 | void f(Iterator&, Iterator&); | |
68 | void f(Iterator&, Iterator&, pass_flag&); | |
69 | void f(Iterator&, Iterator&, pass_flag&, Idtype&); | |
70 | void f(Iterator&, Iterator&, pass_flag&, Idtype&, Context&); | |
71 | ||
72 | You can use __boost_bind__ to bind member functions. For function | |
73 | objects, the allowed signatures are: | |
74 | ||
75 | void operator()(unused_type, unused_type, unused_type, unused_type, unused_type) const; | |
76 | void operator()(Iterator&, Iterator&, unused_type, unused_type, unused_type) const; | |
77 | void operator()(Iterator&, Iterator&, pass_flag&, unused_type, unused_type) const; | |
78 | void operator()(Iterator&, Iterator&, pass_flag&, Idtype&, unused_type) const; | |
79 | void operator()(Iterator&, Iterator&, pass_flag&, Idtype&, Context&) const; | |
80 | ||
81 | The `unused_type` is used in the signatures above to signify 'don't | |
82 | care'. | |
83 | ||
84 | For more information see __lex_actions__. | |
85 | ||
86 | [endsect] | |
87 | ||
88 | [/////////////////////////////////////////////////////////////////////////////] | |
89 | [section Phoenix] | |
90 | ||
91 | __boost_phoenix__ makes it easier to attach semantic actions. You just | |
92 | inline your lambda expressions: | |
93 | ||
94 | l[phoenix-lambda-expression] | |
95 | ||
96 | __lex__ provides some __boost_phoenix__ placeholders to access important | |
97 | information from the `Context` that are otherwise difficult to extract. | |
98 | ||
99 | [variablelist Spirit.Lex specific Phoenix placeholders | |
100 | [[`_start, _end`] [Iterators pointing to the begin and the end of the | |
101 | matched input sequence.]] | |
102 | [[`_pass`] [Assign `lex::pass_flags::pass_fail` to `_pass` to force the current match to fail.]] | |
103 | [[`_tokenid`] [The token id of the matched token.]] | |
104 | [[`_val`] [The token value of the matched token.]] | |
105 | [[`_state`] [The lexer state the token has been matched in.]] | |
106 | [[`_eoi`] [Iterator referring to the current end of the input sequence.]] | |
107 | ] | |
108 | ||
109 | [tip All of the placeholders in the list above (except `_eoi`) can be changed | |
110 | from the inside of the semantic action allowing to modify the lexer | |
111 | behavior. They are defined in the namespace `boost::spirit::lex`.] | |
112 | ||
113 | For more information see __lex_actions__. | |
114 | ||
115 | [endsect] | |
116 | ||
117 |