/*============================================================================= Copyright (c) 2011-2013 Bolero MURAKAMI https://github.com/bolero-MURAKAMI/Sprout 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) =============================================================================*/ #ifndef SPROUT_WEED_PARSER_CHAR_CHAR_HPP #define SPROUT_WEED_PARSER_CHAR_CHAR_HPP #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace sprout { namespace weed { // // lit_char_p // template struct lit_char_p : public sprout::weed::parser_base { public: template struct attribute : public sprout::identity {}; template struct result : public sprout::identity::type> > {}; private: T t_; public: lit_char_p() = default; explicit SPROUT_CONSTEXPR lit_char_p(T const& t) : t_(t) {} template SPROUT_CONSTEXPR typename result::type operator()( Iterator first, Iterator last, Context const& ) const { typedef typename result::type result_type; typedef typename attribute::type attribute_type; typedef typename std::iterator_traits::value_type elem_type; return first != last && *first == elem_type(t_) ? result_type(true, sprout::next(first), attribute_type()) : result_type(false, first, typename attribute::type()) ; } }; // // lit_g // template struct lit_g::eval< T, typename std::enable_if< sprout::weed::traits::is_char_type::value >::type > { public: typedef sprout::weed::lit_char_p result_type; public: SPROUT_CONSTEXPR result_type operator()(T const& t) const { return result_type(t); } }; // // char_p // template struct char_p : public sprout::weed::parser_base { public: template struct attribute : public sprout::identity::value_type> {}; template struct result : public sprout::identity::type> > {}; private: T t_; public: char_p() = default; explicit SPROUT_CONSTEXPR char_p(T const& t) : t_(t) {} template SPROUT_CONSTEXPR typename result::type operator()( Iterator first, Iterator last, Context const& ) const { typedef typename result::type result_type; typedef typename attribute::type attribute_type; typedef typename std::iterator_traits::value_type elem_type; return first != last && *first == elem_type(t_) ? result_type(true, sprout::next(first), *first) : result_type(false, first, attribute_type()) ; } }; // // char_range_p // template struct char_range_p : public sprout::weed::parser_base { public: template struct attribute : public sprout::identity::value_type> {}; template struct result : public sprout::identity::type> > {}; private: T f_; T l_; public: char_range_p() = default; SPROUT_CONSTEXPR char_range_p(T const& f, T const& l) : f_(f), l_(l) {} template SPROUT_CONSTEXPR typename result::type operator()( Iterator first, Iterator last, Context const& ) const { typedef typename result::type result_type; typedef typename attribute::type attribute_type; typedef typename std::iterator_traits::value_type elem_type; return first != last && *first >= elem_type(f_) && *first <= elem_type(l_) ? result_type(true, sprout::next(first), *first) : result_type(false, first, attribute_type()) ; } }; // // char_set_p // template struct char_set_p : public sprout::weed::parser_base { public: template struct attribute : public sprout::identity::value_type> {}; template struct result : public sprout::identity::type> > {}; private: T t_; public: char_set_p() = default; explicit SPROUT_CONSTEXPR char_set_p(T const& t) : t_(t) {} template SPROUT_CONSTEXPR typename result::type operator()( Iterator first, Iterator last, Context const& ) const { typedef typename result::type result_type; typedef typename attribute::type attribute_type; return first != last && sprout::weed::detail::find_character_set(sprout::begin(t_), sprout::end(t_), *first) != sprout::end(t_) ? result_type(true, sprout::next(first), *first) : result_type(false, first, attribute_type()) ; } }; // // any_char_p // struct any_char_p : public sprout::weed::parser_base { public: template struct attribute : public sprout::identity::value_type> {}; template struct result : public sprout::identity::type> > {}; public: template SPROUT_CONSTEXPR typename result::type operator()( Iterator first, Iterator last, Context const& ) const { typedef typename result::type result_type; typedef typename attribute::type attribute_type; return first != last ? result_type(true, sprout::next(first), *first) : result_type(false, first, attribute_type()) ; } template SPROUT_CONSTEXPR typename std::enable_if< sprout::weed::traits::is_char_type::value, sprout::weed::char_p >::type operator()(T const& t) const { return sprout::weed::char_p(t); } template SPROUT_CONSTEXPR typename std::enable_if< sprout::weed::traits::is_char_type::value, sprout::weed::char_range_p >::type operator()(T const& f, T const& l) const { return sprout::weed::char_range_p(f, l); } template SPROUT_CONSTEXPR typename std::enable_if< sprout::weed::traits::is_c_str::value, sprout::weed::char_set_p< typename sprout::weed::detail::c_str_as_string::type > >::type operator()(T const& t) const { return sprout::weed::char_set_p< typename sprout::weed::detail::c_str_as_string::type >(sprout::to_string(t)); } template SPROUT_CONSTEXPR typename std::enable_if< sprout::weed::traits::is_string::value, sprout::weed::char_set_p >::type operator()(T const& t) const { return sprout::weed::char_set_p(t); } }; // // char_ // SPROUT_STATIC_CONSTEXPR sprout::weed::any_char_p char_ = sprout::weed::any_char_p(); } // namespace weed } // namespace sprout #endif // #ifndef SPROUT_WEED_PARSER_CHAR_CHAR_HPP