1 /*=============================================================================
2 Copyright (c) 2001-2011 Hartmut Kaiser
3 Copyright (c) 2001-2011 Joel de Guzman
5 Distributed under the Boost Software License, Version 1.0. (See accompanying
6 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 ==============================================================================*/
8 #if !defined(BOOST_SPIRIT_ATTR_JUL_23_2008_0956AM)
9 #define BOOST_SPIRIT_ATTR_JUL_23_2008_0956AM
15 #include <boost/mpl/bool.hpp>
16 #include <boost/spirit/home/qi/domain.hpp>
17 #include <boost/spirit/home/qi/parser.hpp>
18 #include <boost/spirit/home/qi/detail/assign_to.hpp>
19 #include <boost/spirit/home/qi/meta_compiler.hpp>
20 #include <boost/spirit/home/support/common_terminals.hpp>
21 #include <boost/spirit/home/support/handles_container.hpp>
22 #include <boost/type_traits/add_reference.hpp>
23 #include <boost/type_traits/add_const.hpp>
24 #include <boost/type_traits/remove_const.hpp>
26 namespace boost { namespace spirit
28 ///////////////////////////////////////////////////////////////////////////
30 ///////////////////////////////////////////////////////////////////////////
31 template <typename A0> // enables attr()
33 qi::domain, terminal_ex<tag::attr, fusion::vector1<A0> > >
36 template <> // enables *lazy* attr()
37 struct use_lazy_terminal<qi::domain, tag::attr, 1>
42 namespace boost { namespace spirit { namespace qi
44 #ifndef BOOST_SPIRIT_NO_PREDEFINED_TERMINALS
47 using spirit::attr_type;
49 template <typename Value>
50 struct attr_parser : primitive_parser<attr_parser<Value> >
52 template <typename Context, typename Iterator>
53 struct attribute : remove_const<Value> {};
55 attr_parser(typename add_reference<Value>::type value)
58 template <typename Iterator, typename Context
59 , typename Skipper, typename Attribute>
60 bool parse(Iterator& /*first*/, Iterator const& /*last*/
61 , Context& /*context*/, Skipper const& /*skipper*/
62 , Attribute& attr_) const
64 spirit::traits::assign_to(value_, attr_);
65 return true; // never consume any input, succeed always
68 template <typename Context>
69 info what(Context& /*context*/) const
77 // silence MSVC warning C4512: assignment operator could not be generated
78 attr_parser& operator= (attr_parser const&);
81 ///////////////////////////////////////////////////////////////////////////
82 // Parser generators: make_xxx function (objects)
83 ///////////////////////////////////////////////////////////////////////////
84 template <typename Modifiers, typename A0>
85 struct make_primitive<
86 terminal_ex<tag::attr, fusion::vector1<A0> >
89 typedef typename add_const<A0>::type const_value;
90 typedef attr_parser<const_value> result_type;
92 template <typename Terminal>
93 result_type operator()(Terminal const& term, unused_type) const
95 return result_type(fusion::at_c<0>(term.args));
100 namespace boost { namespace spirit { namespace traits
102 ///////////////////////////////////////////////////////////////////////////
103 template <typename T, typename Attr, typename Context, typename Iterator>
104 struct handles_container<qi::attr_parser<T>, Attr, Context, Iterator>
105 : traits::is_container<Attr> {};