// Copyright (c) 2001-2007 Joel de Guzman // 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_21_2007_0742AM) #define BOOST_SPIRIT_KARMA_META_GRAMMAR_FEB_21_2007_0742AM #if defined(_MSC_VER) && (_MSC_VER >= 1020) #pragma once // MS compatible compilers support #pragma once #endif #include #include #include #include #include #include namespace boost { namespace spirit { /////////////////////////////////////////////////////////////////////////// // test if a tag is a character literal type /////////////////////////////////////////////////////////////////////////// template struct is_char_tag< spirit::char_class::key, karma::domain > : mpl::true_ {}; }} namespace boost { namespace spirit { namespace karma { /////////////////////////////////////////////////////////////////////////// // forward declarations /////////////////////////////////////////////////////////////////////////// template struct any_char; template struct literal_char; struct lazy_char; template struct any_space_char; template struct literal_space_char; struct char_meta_grammar; template struct is_valid_expr; template struct expr_transform; /////////////////////////////////////////////////////////////////////////// // get the director of a character literal type /////////////////////////////////////////////////////////////////////////// template struct extract_literal_char_director; template struct extract_literal_char_director { typedef literal_char type; }; template struct extract_literal_char_director { typedef literal_char type; }; template struct extract_literal_char_director { typedef literal_char type; }; template struct extract_literal_char_director { typedef literal_char type; }; template struct extract_literal_char_director< spirit::char_class::key, T > { typedef spirit::char_class::key key_type; typedef literal_space_char type; }; /////////////////////////////////////////////////////////////////////////// // get the director of a plain character type /////////////////////////////////////////////////////////////////////////// template struct extract_any_char_director; template <> struct extract_any_char_director { typedef any_char type; }; template <> struct extract_any_char_director { typedef any_char type; }; template struct extract_any_char_director< spirit::char_class::key > { typedef typename CharSet::char_type char_type; typedef spirit::char_class::key key_type; typedef any_space_char type; }; /////////////////////////////////////////////////////////////////////////// // char generator meta-grammars /////////////////////////////////////////////////////////////////////////// // literals: 'x', L'x' struct char_literal_meta_grammar : proto::or_< meta_grammar::terminal_rule< karma::domain, char, literal_char >, meta_grammar::terminal_rule< karma::domain, wchar_t, literal_char > > { }; // literals: 'x', L'x' struct basic_char_literal_meta_grammar : proto::or_< proto::terminal, proto::terminal > { }; // char_, wchar, space // char_('x'), char_(L'x'), wchar('x'), wchar(L'x'), space(' ') struct char_meta_grammar1 : proto::or_< // char_, wchar, space meta_grammar::compose_empty< proto::if_< is_char_tag() >, karma::domain, mpl::identity > >, // char_('x'), wchar(L'x'), space(' ') meta_grammar::compose_function1_eval< proto::function< proto::if_< is_char_tag() >, basic_char_literal_meta_grammar >, karma::domain, mpl::identity > >, // lit('x'), wlit('x') meta_grammar::compose_function1_eval< proto::function< proto::if_< is_lit_tag() >, basic_char_literal_meta_grammar >, karma::domain, mpl::identity > >, // char_(val('y')) meta_grammar::function1_rule< karma::domain, tag::char_, lazy_char > > { }; // main char_meta_grammar struct char_meta_grammar : proto::or_< char_literal_meta_grammar, char_meta_grammar1 > { }; /////////////////////////////////////////////////////////////////////////// // These specializations non-intrusively hook 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