#ifndef SPROUT_WEED_PARSER_DIRECTIVE_AS_ARRAY_HPP #define SPROUT_WEED_PARSER_DIRECTIVE_AS_ARRAY_HPP #include #include #include #include #include #include #include #include #include #include #include namespace sprout { namespace weed { // // as_array_p // template struct as_array_p : public sprout::weed::parser_base { public: template struct attribute { private: typedef typename sprout::weed::traits::attribute_of::type attr_type; private: static_assert(!sprout::weed::traits::is_unused::value, "invalid attribute : unused"); public: typedef sprout::array type; }; template struct result : public sprout::identity::type> > {}; private: typedef typename sprout::weed::traits::terminal_or_expr_of::type expr_type; private: expr_type expr_; private: template SPROUT_CONSTEXPR typename result::type call( Iterator first, Result const& res ) const { typedef typename result::type result_type; typedef typename attribute::type attribute_type; return res.success() ? result_type(true, res.current(), attribute_type{res.attr()}) : result_type(false, first, attribute_type()) ; } public: as_array_p() = default; explicit SPROUT_CONSTEXPR as_array_p( Parser const& p ) : expr_(sprout::weed::make_terminal_or_expr(p)) {} template SPROUT_CONSTEXPR typename result::type operator()( Iterator first, Iterator last, Context const& ctx ) const { return call(first, sprout::weed::eval(expr_, ctx)); } }; // // as_array_d // struct as_array_d { public: template SPROUT_CONSTEXPR sprout::weed::as_array_p operator[](Parser const& p) const { return sprout::weed::as_array_p(p); } }; // // as_array // SPROUT_CONSTEXPR sprout::weed::as_array_d as_array = sprout::weed::as_array_d(); } // namespace weed } // namespace sprout #endif // #ifndef SPROUT_WEED_PARSER_DIRECTIVE_AS_ARRAY_HPP