/*============================================================================= Copyright (c) 2001-2010 Hartmut Kaiser Distributed under 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) ==============================================================================*/ #if !defined(SPIRIT_QI_BOOL_SEP_29_2009_0709AM) #define SPIRIT_QI_BOOL_SEP_29_2009_0709AM #if defined(_MSC_VER) #pragma once #endif #include #include #include #include #include #include #include #include namespace boost { namespace spirit { /////////////////////////////////////////////////////////////////////////// // Enablers /////////////////////////////////////////////////////////////////////////// template <> struct use_terminal // enables bool_ : mpl::true_ {}; template <> struct use_terminal // enables true_ : mpl::true_ {}; template <> struct use_terminal // enables false_ : mpl::true_ {}; }} namespace boost { namespace spirit { namespace qi { using spirit::bool_; using spirit::bool__type; using spirit::true_; using spirit::true__type; using spirit::false_; using spirit::false__type; namespace detail { template struct bool_impl { template static bool parse(Iterator& first, Iterator const& last , Attribute& attr, Policies const& p, bool allow_true = true , bool disallow_false = false) { if (first == last) return false; #if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1600)) p; // suppresses warning: C4100: 'p' : unreferenced formal parameter #endif return (allow_true && p.parse_true(first, last, attr)) || (!disallow_false && p.parse_false(first, last, attr)); } }; } /////////////////////////////////////////////////////////////////////////// // This actual boolean parser /////////////////////////////////////////////////////////////////////////// template < typename T = bool , typename Policies = bool_policies > struct bool_parser_impl : primitive_parser > { template struct attribute { typedef T type; }; template bool parse(Iterator& first, Iterator const& last , Context& /*context*/, Skipper const& skipper , Attribute& attr) const { qi::skip_over(first, last, skipper); return detail::bool_impl:: parse(first, last, attr, Policies()); } template info what(Context& /*context*/) const { return info("boolean"); } }; template < typename T = bool , typename Policies = bool_policies > struct bool_parser_literal_impl : primitive_parser > { template struct attribute { typedef T type; }; bool_parser_literal_impl(typename add_const::type n) : n_(n) {} template bool parse(Iterator& first, Iterator const& last , Context& /*context*/, Skipper const& skipper , Attribute& attr) const { qi::skip_over(first, last, skipper); return detail::bool_impl:: parse(first, last, attr, Policies(), n_, n_); } template info what(Context& /*context*/) const { return info("boolean"); } T n_; }; /////////////////////////////////////////////////////////////////////////// // bool_parser is the class that the user can instantiate directly /////////////////////////////////////////////////////////////////////////// template < typename T , typename Policies = bool_policies > struct bool_parser : proto::terminal >::type {}; /////////////////////////////////////////////////////////////////////////// // Parser generators: make_xxx function (objects) /////////////////////////////////////////////////////////////////////////// template struct make_primitive { typedef has_modifier > no_case; typedef typename mpl::if_< no_case , bool_parser_impl > , bool_parser_impl<> >::type result_type; result_type operator()(unused_type, unused_type) const { return result_type(); } }; namespace detail { template struct make_literal_bool { typedef has_modifier > no_case; typedef typename mpl::if_< no_case , bool_parser_literal_impl > , bool_parser_literal_impl<> >::type result_type; result_type operator()(unused_type, unused_type) const { return result_type(b); } }; } template struct make_primitive : detail::make_literal_bool {}; template struct make_primitive : detail::make_literal_bool {}; }}} #endif