1 // Copyright (c) 2001-2011 Hartmut Kaiser 2 // 3 // Distributed under the Boost Software License, Version 1.0. (See accompanying 4 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 5 6 #if !defined(BOOST_SPIRIT_QI_AUTO_NOV_29_2009_0336PM) 7 #define BOOST_SPIRIT_QI_AUTO_NOV_29_2009_0336PM 8 9 #if defined(_MSC_VER) 10 #pragma once 11 #endif 12 13 #include <boost/spirit/home/support/common_terminals.hpp> 14 #include <boost/spirit/home/support/info.hpp> 15 #include <boost/spirit/home/support/container.hpp> 16 #include <boost/spirit/home/support/detail/hold_any.hpp> 17 #include <boost/spirit/home/qi/domain.hpp> 18 #include <boost/spirit/home/qi/meta_compiler.hpp> 19 #include <boost/spirit/home/qi/skip_over.hpp> 20 #include <boost/spirit/home/qi/parser.hpp> 21 #include <boost/spirit/home/qi/auto/create_parser.hpp> 22 #include <boost/mpl/bool.hpp> 23 24 /////////////////////////////////////////////////////////////////////////////// 25 namespace boost { namespace spirit 26 { 27 /////////////////////////////////////////////////////////////////////////// 28 // Enablers 29 /////////////////////////////////////////////////////////////////////////// 30 template <> 31 struct use_terminal<qi::domain, tag::auto_> // enables auto_ 32 : mpl::true_ {}; 33 }} 34 35 /////////////////////////////////////////////////////////////////////////////// 36 namespace boost { namespace spirit { namespace qi 37 { 38 #ifndef BOOST_SPIRIT_NO_PREDEFINED_TERMINALS 39 using spirit::auto_; 40 #endif 41 using spirit::auto_type; 42 43 /////////////////////////////////////////////////////////////////////////// 44 template <typename Modifiers> 45 struct auto_parser 46 : parser<auto_parser<Modifiers> > 47 { 48 template <typename Context, typename Iterator> 49 struct attribute 50 { 51 typedef spirit::hold_any type; 52 }; 53 auto_parserboost::spirit::qi::auto_parser54 auto_parser(Modifiers const& modifiers) 55 : modifiers_(modifiers) {} 56 57 template <typename Iterator, typename Context, typename Skipper 58 , typename Attribute> parseboost::spirit::qi::auto_parser59 bool parse(Iterator& first, Iterator const& last 60 , Context& context, Skipper const& skipper, Attribute& attr) const 61 { 62 return compile<qi::domain>(create_parser<Attribute>(), modifiers_) 63 .parse(first, last, context, skipper, attr); 64 } 65 66 template <typename Context> whatboost::spirit::qi::auto_parser67 info what(Context& /*context*/) const 68 { 69 return info("auto_"); 70 } 71 72 Modifiers modifiers_; 73 }; 74 75 /////////////////////////////////////////////////////////////////////////// 76 // Generator generators: make_xxx function (objects) 77 /////////////////////////////////////////////////////////////////////////// 78 template <typename Modifiers> 79 struct make_primitive<tag::auto_, Modifiers> 80 { 81 typedef auto_parser<Modifiers> result_type; 82 operator ()boost::spirit::qi::make_primitive83 result_type operator()(unused_type, Modifiers const& modifiers) const 84 { 85 return result_type(modifiers); 86 } 87 }; 88 }}} 89 90 #endif 91