/*============================================================================= Copyright (c) 2011 Alex Dubov 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_MAP) #define SPIRIT_MAP #if defined(_MSC_VER) #pragma once #endif #include #include #include #include #include #include #include #include #include #include namespace boost { namespace spirit { namespace repository { BOOST_SPIRIT_DEFINE_TERMINALS_NAME_EX((map, map_type)) } template struct use_directive< qi::domain, terminal_ex > > > : mpl::true_ {}; template <> struct use_lazy_directive : mpl::true_ {}; namespace repository { namespace qi { using repository::map_type; using repository::map; template struct map_parser : spirit::qi::unary_parser > { template struct attribute : mpl::identity {}; map_parser(Subject const& subject, std::map const& lookup) : subject(subject), lookup(lookup) {} template bool parse(Iterator& first, Iterator const& last, Context& context, Skipper const& skipper, Attribute& attr) const { T attr_; Iterator iter = first; typename std::map::const_iterator attr_iter; if (subject.parse(iter, last, context, skipper, attr_)) { attr_iter = lookup.find(attr_); if (attr_iter != lookup.end()) { attr = attr_iter->second; first = iter; return true; } } return false; } template info what(Context const& ctx) const { return info("map", subject.what(ctx)); } Subject subject; std::map lookup; }; }} namespace qi { template struct make_directive< terminal_ex > >, Subject, Modifiers > { typedef repository::qi::map_parser result_type; template result_type operator()( Terminal const& term, Subject const& subject, Modifiers const& modifiers ) const { return result_type(subject, fusion::at_c<0>(term.args)); } }; } namespace traits { template struct has_semantic_action< repository::qi::map_parser > : unary_has_semantic_action {}; }}} #endif