1 /*============================================================================= 2 Copyright (c) 2001-2011 Joel de Guzman 3 4 Distributed under the Boost Software License, Version 1.0. (See accompanying 5 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 ==============================================================================*/ 7 #if !defined(BOOST_SPIRIT_EPS_MARCH_23_2007_0454PM) 8 #define BOOST_SPIRIT_EPS_MARCH_23_2007_0454PM 9 10 #if defined(_MSC_VER) 11 #pragma once 12 #endif 13 14 #include <boost/spirit/home/qi/domain.hpp> 15 #include <boost/spirit/home/qi/skip_over.hpp> 16 #include <boost/spirit/home/qi/meta_compiler.hpp> 17 #include <boost/spirit/home/support/unused.hpp> 18 #include <boost/spirit/home/support/info.hpp> 19 #include <boost/spirit/home/support/common_terminals.hpp> 20 #include <boost/fusion/include/at.hpp> 21 #include <boost/type_traits/is_convertible.hpp> 22 23 namespace boost { namespace spirit 24 { 25 /////////////////////////////////////////////////////////////////////////// 26 // Enablers 27 /////////////////////////////////////////////////////////////////////////// 28 template <> 29 struct use_terminal<qi::domain, tag::eps> // enables eps 30 : mpl::true_ {}; 31 32 template <typename A0> 33 struct use_terminal<qi::domain 34 , terminal_ex<tag::eps, fusion::vector1<A0> > // enables eps(bool-condition) 35 > : is_convertible<A0, bool> {}; 36 37 template <> // enables eps(f) 38 struct use_lazy_terminal< 39 qi::domain, tag::eps, 1 /*arity*/ 40 > : mpl::true_ {}; 41 }} 42 43 namespace boost { namespace spirit { namespace qi 44 { 45 #ifndef BOOST_SPIRIT_NO_PREDEFINED_TERMINALS 46 using spirit::eps; 47 #endif 48 using spirit::eps_type; 49 50 struct eps_parser : primitive_parser<eps_parser> 51 { 52 template <typename Context, typename Iterator> 53 struct attribute 54 { 55 typedef unused_type type; 56 }; 57 58 template <typename Iterator, typename Context 59 , typename Skipper, typename Attribute> parseboost::spirit::qi::eps_parser60 bool parse(Iterator& first, Iterator const& last 61 , Context& /*context*/, Skipper const& skipper 62 , Attribute& /*attr*/) const 63 { 64 qi::skip_over(first, last, skipper); 65 return true; 66 } 67 68 template <typename Context> whatboost::spirit::qi::eps_parser69 info what(Context& /*context*/) const 70 { 71 return info("eps"); 72 } 73 }; 74 75 struct semantic_predicate : primitive_parser<semantic_predicate> 76 { 77 template <typename Context, typename Iterator> 78 struct attribute 79 { 80 typedef unused_type type; 81 }; 82 semantic_predicateboost::spirit::qi::semantic_predicate83 semantic_predicate(bool predicate_) 84 : predicate(predicate_) {} 85 86 template <typename Iterator, typename Context 87 , typename Skipper, typename Attribute> parseboost::spirit::qi::semantic_predicate88 bool parse(Iterator& first, Iterator const& last 89 , Context& /*context*/, Skipper const& skipper 90 , Attribute& /*attr*/) const 91 { 92 qi::skip_over(first, last, skipper); 93 return predicate; 94 } 95 96 template <typename Context> whatboost::spirit::qi::semantic_predicate97 info what(Context& /*context*/) const 98 { 99 return info("semantic-predicate"); 100 } 101 102 bool predicate; 103 }; 104 105 /////////////////////////////////////////////////////////////////////////// 106 // Parser generators: make_xxx function (objects) 107 /////////////////////////////////////////////////////////////////////////// 108 template <typename Modifiers> 109 struct make_primitive<tag::eps, Modifiers> 110 { 111 typedef eps_parser result_type; operator ()boost::spirit::qi::make_primitive112 result_type operator()(unused_type, unused_type) const 113 { 114 return result_type(); 115 } 116 }; 117 118 template <typename Modifiers, typename A0> 119 struct make_primitive< 120 terminal_ex<tag::eps, fusion::vector1<A0> > 121 , Modifiers> 122 { 123 typedef semantic_predicate result_type; 124 template <typename Terminal> operator ()boost::spirit::qi::make_primitive125 result_type operator()(Terminal const& term, unused_type) const 126 { 127 return result_type(fusion::at_c<0>(term.args) ? true : false); 128 } 129 }; 130 }}} 131 132 #endif 133