// Copyright (c) 2001-2008 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(BOOST_SPIRIT_KARMA_META_GRAMMAR_FEB_22_2007_0532PM) #define BOOST_SPIRIT_KARMA_META_GRAMMAR_FEB_22_2007_0532PM #if defined(_MSC_VER) && (_MSC_VER >= 1020) #pragma once // MS compatible compilers support #pragma once #endif #include #include #include #include #include #include #include #include namespace boost { namespace spirit { namespace karma { /////////////////////////////////////////////////////////////////////////// // forwards /////////////////////////////////////////////////////////////////////////// template struct any_string; template struct literal_string; struct lazy_string; struct string_meta_grammar; template struct is_valid_expr; template struct expr_transform; /////////////////////////////////////////////////////////////////////////// // /////////////////////////////////////////////////////////////////////////// template struct extract_char; template struct extract_char > { typedef Char type; }; template struct extract_char { typedef typename remove_const::type type; }; template struct extract_char { typedef typename remove_const::type type; }; template struct extract_char { typedef typename remove_const::type type; }; /////////////////////////////////////////////////////////////////////////// // get the director of a string literal type /////////////////////////////////////////////////////////////////////////// template struct extract_lit_director_lit; template struct extract_lit_director_lit { typedef typename extract_char::type char_type; typedef literal_string type; }; template struct extract_lit_director_lit { typedef typename extract_char::type char_type; typedef literal_string type; }; /////////////////////////////////////////////////////////////////////////// template struct extract_lit_director_plain; template <> struct extract_lit_director_plain { typedef any_string type; }; template <> struct extract_lit_director_plain { typedef any_string type; }; /////////////////////////////////////////////////////////////////////////// // string generator meta-grammar /////////////////////////////////////////////////////////////////////////// // literal strings: "hello" struct string_literal_meta_grammar : proto::or_< meta_grammar::terminal_rule< karma::domain, char const*, literal_string >, meta_grammar::terminal_rule< karma::domain, wchar_t const*, literal_string >, meta_grammar::terminal_rule< karma::domain, char*, literal_string >, meta_grammar::terminal_rule< karma::domain, wchar_t*, literal_string > > { }; // literal strings: "hello" struct basic_string_literal_meta_grammar : proto::or_< proto::terminal, proto::terminal > { }; // std::string(s) struct std_string_meta_grammar : proto::or_< meta_grammar::terminal_rule< karma::domain, std::basic_string, literal_string >, meta_grammar::terminal_rule< karma::domain, std::basic_string, literal_string > > { }; // std::string(s) struct basic_std_string_meta_grammar : proto::or_< proto::terminal >, proto::terminal > > { }; namespace detail { // we use this test to detect if the argument to lit is a callable // function or not. Only types convertible to int or function/ // function objects are allowed. Therefore, if T is not convertible // to an int, then we have a function/function object. template struct is_not_convertible_to_int : mpl::not_ > { }; } // this is the string literal meta grammar // literal strings: lit, lit("hello") struct string_meta_grammar : proto::or_< string_literal_meta_grammar, std_string_meta_grammar, meta_grammar::compose_empty< proto::if_< is_lit_tag() >, karma::domain, mpl::identity > >, meta_grammar::compose_function1_eval< proto::function< proto::if_< is_lit_tag() >, proto::or_< basic_string_literal_meta_grammar, basic_std_string_meta_grammar > >, karma::domain, mpl::identity > >, meta_grammar::function1_rule< karma::domain, tag::lit, lazy_string, proto::if_< detail::is_not_convertible_to_int() > > > { }; /////////////////////////////////////////////////////////////////////////// // These specializations non-intrusively hooks into the Karma meta-grammar. // (see karma/meta_grammar.hpp) /////////////////////////////////////////////////////////////////////////// template struct is_valid_expr >::type> : mpl::true_ { }; template struct expr_transform >::type> : mpl::identity { }; }}} #endif