Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/libs/spirit/example/techniques/epsilon.cpp @ 69

Last change on this file since 69 was 29, checked in by landauf, 17 years ago

updated boost from 1_33_1 to 1_34_1

File size: 2.2 KB
Line 
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 the behaviour of epsilon_p when used as parser
11//  generator.
12//
13//  The "r" is the rule, which is passed as a subject to the epsilon_p parser
14//  generator. The "r" is the rule with binded semantic actions. But epsilon_p
15//  parser generator is intended for looking forward and we don't want to
16//  invoke semantic actions of subject parser. Hence the epsilon_p uses
17//  the no_actions policy.
18//
19//  Because we want to use the "r" rule both in the epsilon_p and outside of it
20//  we need the "r" to support two differant scanners, one with no_actions
21//  action policy and one with the default action policy. To achieve this
22//  we declare the "r" with the no_actions_scanner_list scanner type.
23//
24//-----------------------------------------------------------------------------
25#define BOOST_SPIRIT_RULE_SCANNERTYPE_LIMIT 2
26
27#include <cassert>
28#include <iostream>
29#include <boost/cstdlib.hpp>
30#include <boost/spirit/core.hpp>
31#include <boost/spirit/phoenix.hpp>
32
33using namespace std;
34using namespace boost;
35using namespace spirit;
36using namespace phoenix;
37
38//-----------------------------------------------------------------------------
39
40int main()
41{
42    rule<
43        // Support both the default phrase_scanner_t and the modified version
44        // with no_actions action_policy
45        no_actions_scanner_list<phrase_scanner_t>::type
46    > r;
47
48    int i(0);
49
50    r = int_p[var(i) += arg1];
51
52    parse_info<> info = parse(
53        "1",
54       
55        // r rule is used twice but the semantic action is invoked only once
56        epsilon_p(r) >> r,
57
58        space_p
59    );
60
61    assert(info.full);
62    // Check, that the semantic action was invoked only once
63    assert(i == 1);
64
65    return exit_success;
66}
67
68//-----------------------------------------------------------------------------
Note: See TracBrowser for help on using the repository browser.