File indexing completed on 2025-01-31 10:02:17
0001
0002
0003
0004
0005
0006 #if !defined(BOOST_SPIRIT_LEX_PLAIN_TOKENID_MASK_JUN_03_2011_0929PM)
0007 #define BOOST_SPIRIT_LEX_PLAIN_TOKENID_MASK_JUN_03_2011_0929PM
0008
0009 #if defined(_MSC_VER)
0010 #pragma once
0011 #endif
0012
0013 #include <boost/spirit/home/support/info.hpp>
0014 #include <boost/spirit/home/qi/detail/attributes.hpp>
0015 #include <boost/spirit/home/support/common_terminals.hpp>
0016 #include <boost/spirit/home/support/handles_container.hpp>
0017 #include <boost/spirit/home/qi/skip_over.hpp>
0018 #include <boost/spirit/home/qi/domain.hpp>
0019 #include <boost/spirit/home/qi/parser.hpp>
0020 #include <boost/spirit/home/qi/meta_compiler.hpp>
0021 #include <boost/spirit/home/qi/detail/assign_to.hpp>
0022
0023 #include <boost/fusion/include/vector.hpp>
0024 #include <boost/fusion/include/at.hpp>
0025 #include <boost/mpl/or.hpp>
0026 #include <boost/range/iterator_range_core.hpp>
0027 #include <boost/type_traits/is_integral.hpp>
0028 #include <boost/type_traits/is_enum.hpp>
0029 #include <iterator> // for std::iterator_traits
0030 #include <sstream>
0031
0032 namespace boost { namespace spirit
0033 {
0034
0035
0036
0037
0038
0039 template <typename A0>
0040 struct use_terminal<qi::domain
0041 , terminal_ex<tag::tokenid_mask, fusion::vector1<A0> >
0042 > : mpl::or_<is_integral<A0>, is_enum<A0> > {};
0043
0044
0045 template <>
0046 struct use_lazy_terminal<
0047 qi::domain, tag::tokenid_mask, 1
0048 > : mpl::true_ {};
0049 }}
0050
0051 namespace boost { namespace spirit { namespace qi
0052 {
0053 #ifndef BOOST_SPIRIT_NO_PREDEFINED_TERMINALS
0054 using spirit::tokenid_mask;
0055 #endif
0056 using spirit::tokenid_mask_type;
0057
0058
0059
0060
0061
0062
0063 template <typename Mask>
0064 struct plain_tokenid_mask
0065 : primitive_parser<plain_tokenid_mask<Mask> >
0066 {
0067 template <typename Context, typename Iterator>
0068 struct attribute
0069 {
0070 typedef Mask type;
0071 };
0072
0073 plain_tokenid_mask(Mask const& mask)
0074 : mask(mask) {}
0075
0076 template <typename Iterator, typename Context
0077 , typename Skipper, typename Attribute>
0078 bool parse(Iterator& first, Iterator const& last
0079 , Context& , Skipper const& skipper
0080 , Attribute& attr) const
0081 {
0082 qi::skip_over(first, last, skipper);
0083
0084 if (first != last) {
0085
0086
0087
0088 typedef typename
0089 std::iterator_traits<Iterator>::value_type
0090 token_type;
0091 typedef typename token_type::id_type id_type;
0092
0093 token_type const& t = *first;
0094 if ((t.id() & mask) == id_type(mask))
0095 {
0096 spirit::traits::assign_to(t.id(), attr);
0097 ++first;
0098 return true;
0099 }
0100 }
0101 return false;
0102 }
0103
0104 template <typename Context>
0105 info what(Context& ) const
0106 {
0107 std::stringstream ss;
0108 ss << "tokenid_mask(" << mask << ")";
0109 return info("tokenid_mask", ss.str());
0110 }
0111
0112 Mask mask;
0113 };
0114
0115
0116
0117
0118 template <typename Modifiers, typename Mask>
0119 struct make_primitive<terminal_ex<tag::tokenid_mask, fusion::vector1<Mask> >
0120 , Modifiers>
0121 {
0122 typedef plain_tokenid_mask<Mask> result_type;
0123
0124 template <typename Terminal>
0125 result_type operator()(Terminal const& term, unused_type) const
0126 {
0127 return result_type(fusion::at_c<0>(term.args));
0128 }
0129 };
0130 }}}
0131
0132 namespace boost { namespace spirit { namespace traits
0133 {
0134
0135 template<typename Mask, typename Attr, typename Context, typename Iterator>
0136 struct handles_container<qi::plain_tokenid_mask<Mask>, Attr, Context, Iterator>
0137 : mpl::true_
0138 {};
0139 }}}
0140
0141 #endif