]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/spirit/classic/example/fundamental/parser_context.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / spirit / classic / example / fundamental / parser_context.cpp
1 /*=============================================================================
2 Copyright (c) 2003 Vaclav Vesely
3 http://spirit.sourceforge.net/
4
5 Use, modification and distribution is subject to the Boost Software
6 License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
7 http://www.boost.org/LICENSE_1_0.txt)
8 =============================================================================*/
9 //
10 // This example demonstrates usage of the parser_context template with
11 // an explicit argument to declare rules with match results different from
12 // nil_t. For better understanding, you should read the chapter "In-depth:
13 // The Parser Context" in the documentation.
14 //
15 // The default context of non-terminals is the parser_context.
16 // The parser_context is a template with one argument AttrT, which is the type
17 // of match attribute.
18 //
19 // In this example int_rule is declared as rule with int match attribute's
20 // type, so in int_rule variable we can hold any parser, which returns int
21 // value. For example int_p or bin_p. And the most important is that we can
22 // use returned value in the semantic action binded to the int_rule.
23 //
24 //-----------------------------------------------------------------------------
25 #include <iostream>
26 #include <boost/cstdlib.hpp>
27 #include <boost/spirit/include/phoenix1.hpp>
28 #include <boost/spirit/include/classic_core.hpp>
29
30 using namespace std;
31 using namespace boost;
32 using namespace phoenix;
33 using namespace BOOST_SPIRIT_CLASSIC_NS;
34
35 //-----------------------------------------------------------------------------
36
37 int main()
38 {
39 rule<parser_context<int> > int_rule = int_p;
40
41 parse(
42 "123",
43 // Using a returned value in the semantic action
44 int_rule[cout << arg1 << endl]
45 );
46
47 return exit_success;
48 }
49
50 //-----------------------------------------------------------------------------
51