/*============================================================================= 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_META_GRAMMAR_FEB_03_2007_0356PM) #define BOOST_SPIRIT_META_GRAMMAR_FEB_03_2007_0356PM #include #include #include #include #include #include #include namespace boost { namespace spirit { namespace qi { /////////////////////////////////////////////////////////////////////////// // forwards /////////////////////////////////////////////////////////////////////////// template struct literal_string; struct lazy_string; template struct symbols_director; struct string_meta_grammar; template struct is_valid_expr; template struct expr_transform; template struct symbols_lookup; /////////////////////////////////////////////////////////////////////////// // get the director of a string literal type /////////////////////////////////////////////////////////////////////////// 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; }; template struct extract_lit_director; template struct extract_lit_director { typedef typename extract_char::type char_type; typedef literal_string type; }; template struct extract_lit_director { typedef typename extract_char::type char_type; typedef literal_string type; }; /////////////////////////////////////////////////////////////////////////// // string parser meta-grammars /////////////////////////////////////////////////////////////////////////// // literal strings: "hello" struct string_literal_meta_grammar : proto::or_< meta_grammar::terminal_rule< qi::domain, char const*, literal_string > , meta_grammar::terminal_rule< qi::domain, char*, literal_string > , meta_grammar::terminal_rule< qi::domain, wchar_t const*, literal_string > , meta_grammar::terminal_rule< qi::domain, wchar_t*, literal_string > > { }; // literal strings: "hello" struct basic_string_literal_meta_grammar : proto::or_< proto::terminal , proto::terminal > { }; // std::string(s) struct basic_std_string_meta_grammar : proto::or_< proto::terminal > , proto::terminal > > { }; // std::string(s) struct std_string_meta_grammar : proto::or_< meta_grammar::terminal_rule< qi::domain , std::basic_string , literal_string > , meta_grammar::terminal_rule< qi::domain , std::basic_string , literal_string > > { }; 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_ > {}; } // strings: "hello", lit("hello"), lit(str), lit(f), symbols struct string_meta_grammar : proto::or_< string_literal_meta_grammar , std_string_meta_grammar , meta_grammar::compose_function1_eval< proto::function< proto::if_< is_lit_tag()> , proto::or_ > , qi::domain , mpl::identity > > , meta_grammar::function1_rule< qi::domain , tag::lit , lazy_string , proto::if_< detail::is_not_convertible_to_int() > > , meta_grammar::terminal_rule< qi::domain , symbols_lookup , symbols_director<> > > { }; /////////////////////////////////////////////////////////////////////////// // 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