]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/spirit/classic/example/fundamental/parser_context.cpp
1 /*=============================================================================
2 Copyright (c) 2003 Vaclav Vesely
3 http://spirit.sourceforge.net/
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 =============================================================================*/
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.
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.
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.
24 //-----------------------------------------------------------------------------
26 #include <boost/cstdlib.hpp>
27 #include <boost/spirit/include/phoenix1.hpp>
28 #include <boost/spirit/include/classic_core.hpp>
31 using namespace boost
;
32 using namespace phoenix
;
33 using namespace BOOST_SPIRIT_CLASSIC_NS
;
35 //-----------------------------------------------------------------------------
39 rule
<parser_context
<int> > int_rule
= int_p
;
43 // Using a returned value in the semantic action
44 int_rule
[cout
<< arg1
<< endl
]
50 //-----------------------------------------------------------------------------