/*============================================================================= Copyright (c) 2004 Martin Wille http://spirit.sourceforge.net/ Use, modification and distribution is subject to 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) =============================================================================*/ #include #include #include #include #include using namespace boost::spirit; int the_var_to_be_tested = 0; namespace local { template struct var_wrapper : public ::boost::reference_wrapper { typedef ::boost::reference_wrapper parent; explicit inline var_wrapper(T& t) : parent(t) {} inline T& operator()() const { return parent::get(); } }; template inline var_wrapper var(T& t) { return var_wrapper(t); } } struct test_grammar : public grammar { template struct definition { rule > test; definition(const test_grammar& self) { test = if_p(local::var(the_var_to_be_tested)) [ real_p ]; } const rule >& start() const {return test;} }; }; int main() { test_grammar gram; tree_parse_info result; //predictably fails the_var_to_be_tested = 0; result = ast_parse("1.50", gram, space_p); std::cout << "Testing if_p against: " << the_var_to_be_tested << std::endl; std::cout << "success: " << result.full << std::endl; BOOST_TEST(!result.full); //predicatably succeeds the_var_to_be_tested = 1; result = ast_parse("1.50", gram, space_p); std::cout << "Testing if_p against: " << the_var_to_be_tested << std::endl; std::cout << "success: " << result.full << std::endl; BOOST_TEST(result.full); //should succeed the_var_to_be_tested = 2; result = ast_parse("1.50", gram, space_p); std::cout << "Testing if_p against: " << the_var_to_be_tested << std::endl; std::cout << "success: " << result.full << std::endl; BOOST_TEST(result.full); return boost::report_errors(); }