// Copyright (c) 2001-2008 Hartmut Kaiser // Copyright (c) 2001-2007 Joel de Guzman // // 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(BOOST_SPIRIT_KARMA_META_GRAMMAR_FEB_23_2007_0505PM) #define BOOST_SPIRIT_KARMA_META_GRAMMAR_FEB_23_2007_0505PM #if defined(_MSC_VER) && (_MSC_VER >= 1020) #pragma once // MS compatible compilers support #pragma once #endif #include #include #include #include #include #include #include namespace boost { namespace spirit { namespace karma { template struct is_valid_expr; template struct expr_transform; /////////////////////////////////////////////////////////////////////////// // numeric tags /////////////////////////////////////////////////////////////////////////// template struct int_tag {}; template struct uint_tag {}; template struct real_tag { RealPolicies policies; }; /////////////////////////////////////////////////////////////////////////// // numeric specs /////////////////////////////////////////////////////////////////////////// template struct int_spec : proto::terminal >::type {}; template struct uint_spec : proto::terminal >::type {}; /////////////////////////////////////////////////////////////////////////// template struct real_spec : proto::terminal >::type { private: typedef typename proto::terminal >::type base_type; base_type make_tag(RealPolicies const& p) const { base_type xpr = {{p}}; return xpr; } public: real_spec(RealPolicies const& p = RealPolicies()) : base_type(make_tag(p)) {} }; /////////////////////////////////////////////////////////////////////////// namespace detail { template struct real_policy { template static RealPolicies get(Tag) { return RealPolicies(); } template static RealPolicies const& get(real_tag const& p) { return p.policies; } }; } }}} // namespace boost::spirit::karma namespace boost { namespace spirit { /////////////////////////////////////////////////////////////////////////// // test if a tag is an int tag (the basic specializations are defined in // the file support/placeholders.hpp) /////////////////////////////////////////////////////////////////////////// template struct is_int_tag, karma::domain> : mpl::true_ {}; template struct is_int_tag, karma::domain> : mpl::true_ {}; /////////////////////////////////////////////////////////////////////////// // test if a tag is a real tag (the basic specializations are defined in // the file support/placeholders.hpp) /////////////////////////////////////////////////////////////////////////// template struct is_real_tag, karma::domain> : mpl::true_ {}; }} // namespace boost::spirit namespace boost { namespace spirit { namespace karma { /////////////////////////////////////////////////////////////////////////// // get the director of an int tag /////////////////////////////////////////////////////////////////////////// template struct extract_int_director; template struct extract_int_director { typedef uint_generator type; }; template struct extract_int_director { typedef uint_generator type; }; template struct extract_int_director { typedef uint_generator type; }; template struct extract_int_director { typedef uint_generator type; }; template struct extract_int_director { typedef uint_generator type; }; template struct extract_int_director { typedef uint_generator type; }; template struct extract_int_director { typedef int_generator type; }; template struct extract_int_director { typedef int_generator type; }; template struct extract_int_director { typedef int_generator type; }; #ifdef BOOST_HAS_LONG_LONG template struct extract_int_director { typedef uint_generator type; }; template struct extract_int_director { typedef int_generator type; }; #endif template struct extract_int_director, IsLiteral> { typedef int_generator type; }; template struct extract_int_director, IsLiteral> { typedef uint_generator type; }; template struct extract_int_director_lit : extract_int_director {}; template struct extract_int_director_plain : extract_int_director {}; /////////////////////////////////////////////////////////////////////////// // get the director of a floating point literal type /////////////////////////////////////////////////////////////////////////// template struct extract_literal_real_director; template <> struct extract_literal_real_director { typedef real_generator > type; }; template <> struct extract_literal_real_director { typedef real_generator > type; }; template <> struct extract_literal_real_director { typedef real_generator< true, long double, real_generator_policies > type; }; /////////////////////////////////////////////////////////////////////////// // get the director of a floating point tag /////////////////////////////////////////////////////////////////////////// template struct extract_real_director; template struct extract_real_director { typedef real_generator > type; }; template struct extract_real_director { typedef real_generator > type; }; template struct extract_real_director { typedef real_generator< IsLiteral, long double, real_generator_policies > type; }; template struct extract_real_director, IsLiteral> { typedef real_generator type; }; /////////////////////////////////////////////////////////////////////////// template struct extract_real_director_lit : extract_real_director {}; template struct extract_real_director_plain : extract_real_director {}; /////////////////////////////////////////////////////////////////////////// // get the director of an integer literal type /////////////////////////////////////////////////////////////////////////// template struct extract_literal_int_director; template <> struct extract_literal_int_director { typedef int_generator type; }; template <> struct extract_literal_int_director { typedef uint_generator type; }; template <> struct extract_literal_int_director { typedef int_generator type; }; template <> struct extract_literal_int_director { typedef uint_generator type; }; template <> struct extract_literal_int_director { typedef int_generator type; }; template <> struct extract_literal_int_director { typedef uint_generator type; }; #ifdef BOOST_HAS_LONG_LONG template <> struct extract_literal_int_director { typedef int_generator type; }; template <> struct extract_literal_int_director { typedef uint_generator type; }; #endif /////////////////////////////////////////////////////////////////////////// // numeric parser meta-grammar /////////////////////////////////////////////////////////////////////////// // literals: 10, 10L, 10LL struct int_literal_meta_grammar : meta_grammar::compose_empty< proto::if_< is_int_lit_tag() >, karma::domain, mpl::identity > > {}; // all the different integer's as int_, uint, bin, oct, dec, hex, etc. // and the corresponding int_(10), uint(10), etc. struct int_meta_grammar : proto::or_< meta_grammar::compose_empty< proto::if_< is_int_tag() >, karma::domain, mpl::identity > >, meta_grammar::compose_function1_eval< proto::function< proto::if_< is_int_tag() >, int_literal_meta_grammar >, karma::domain, mpl::identity > > > {}; // floating point literals: 1.0, 1.0f, 10.1e2 etc. struct real_literal_meta_grammar : meta_grammar::compose_empty< proto::if_< is_real_lit_tag() >, karma::domain, mpl::identity > > {}; struct real_meta_grammar : proto::or_< meta_grammar::compose_single< proto::if_< is_real_tag() >, karma::domain, mpl::identity > >, meta_grammar::compose_function1_full< proto::function< proto::if_< is_real_tag() >, real_literal_meta_grammar >, karma::domain, mpl::identity > > > {}; /////////////////////////////////////////////////////////////////////////// struct numeric_meta_grammar : proto::or_< int_meta_grammar, real_meta_grammar > {}; /////////////////////////////////////////////////////////////////////////// // These specializations non-intrusively hooks into the RD meta-grammar. // (see qi/meta_grammar.hpp) /////////////////////////////////////////////////////////////////////////// template struct is_valid_expr >::type> : mpl::true_ {}; template struct expr_transform >::type> : mpl::identity {}; }}} #endif