add Sprout.Weed ->* Attribute-conversion

This commit is contained in:
bolero-MURAKAMI 2012-05-31 22:28:58 +09:00
commit 3a968fa5ac
35 changed files with 369 additions and 112 deletions

View file

@ -7,5 +7,6 @@
#include <sprout/weed/attr_cnv/shift_left.hpp>
#include <sprout/weed/attr_cnv/modulus.hpp>
#include <sprout/weed/attr_cnv/bitwise_or.hpp>
#include <sprout/weed/attr_cnv/mem_ptr.hpp>
#endif // #ifndef SPROUT_WEED_ATTR_CNV_HPP

View file

@ -135,7 +135,7 @@ namespace sprout {
typedef typename sprout::weed::attr_cnv::result_of::bitwise_or<T, U>::type type;
return sprout::make<type>();
}
// unused >> unused -> unused
// unused | unused -> unused
template<typename T, typename U, typename X>
inline SPROUT_CONSTEXPR typename std::enable_if<
sprout::weed::detail::is_both_unused<T, U>::value,

View file

@ -0,0 +1,22 @@
#ifndef SPROUT_WEED_ATTR_CNV_MEM_PTR_HPP
#define SPROUT_WEED_ATTR_CNV_MEM_PTR_HPP
#include <sprout/config.hpp>
#include <sprout/weed/attr_cnv/result_of/mem_ptr.hpp>
namespace sprout {
namespace weed {
namespace attr_cnv {
//
// mem_ptr
//
template<typename T, typename U>
inline SPROUT_CONSTEXPR typename sprout::weed::attr_cnv::result_of::mem_ptr<T, U>::type
mem_ptr(T const& t, U const& u) {
return u(t);
}
} // namespace attr_cnv
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_ATTR_CNV_MEM_PTR_HPP

View file

@ -7,5 +7,6 @@
#include <sprout/weed/attr_cnv/result_of/shift_left.hpp>
#include <sprout/weed/attr_cnv/result_of/modulus.hpp>
#include <sprout/weed/attr_cnv/result_of/bitwise_or.hpp>
#include <sprout/weed/attr_cnv/result_of/mem_ptr.hpp>
#endif // #ifndef SPROUT_WEED_ATTR_CNV_RESULT_OF_HPP

View file

@ -0,0 +1,23 @@
#ifndef SPROUT_WEED_ATTR_CNV_RESULT_OF_MEM_PTR_HPP
#define SPROUT_WEED_ATTR_CNV_RESULT_OF_MEM_PTR_HPP
#include <type_traits>
#include <sprout/config.hpp>
namespace sprout {
namespace weed {
namespace attr_cnv {
namespace result_of {
//
// mem_ptr
//
template<typename T, typename U, typename = void>
struct mem_ptr
: public std::result_of<U(T)>
{};
} // namespace result_of
} // namespace attr_cnv
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_ATTR_CNV_RESULT_OF_MEM_PTR_HPP

View file

@ -11,5 +11,6 @@
#include <sprout/weed/context/parse_context/operator/modulus.hpp>
#include <sprout/weed/context/parse_context/operator/minus.hpp>
#include <sprout/weed/context/parse_context/operator/bitwise_or.hpp>
#include <sprout/weed/context/parse_context/operator/mem_ptr.hpp>
#endif // #ifndef SPROUT_WEED_CONTEXT_PARSE_CONTEXT_OPERATOR_HPP

View file

@ -0,0 +1,81 @@
#ifndef SPROUT_WEED_CONTEXT_PARSE_CONTEXT_TERMINAL_OPERATOR_MEM_PTR_HPP
#define SPROUT_WEED_CONTEXT_PARSE_CONTEXT_TERMINAL_OPERATOR_MEM_PTR_HPP
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/tuple/tuple.hpp>
#include <sprout/weed/eval_result.hpp>
#include <sprout/weed/expr/tag.hpp>
#include <sprout/weed/expr/eval.hpp>
#include <sprout/weed/attr_cnv/result_of/mem_ptr.hpp>
#include <sprout/weed/attr_cnv/mem_ptr.hpp>
#include <sprout/weed/traits/expr/tag_of.hpp>
#include <sprout/weed/traits/parser/attribute_of.hpp>
#include <sprout/weed/context/parse_context_fwd.hpp>
namespace sprout {
namespace weed {
//
// parse_context::eval
//
template<typename Iterator>
template<typename Expr>
struct parse_context<Iterator>::eval<
Expr,
typename std::enable_if<
std::is_same<
typename sprout::weed::traits::tag_of<Expr>::type,
sprout::weed::tag::mem_ptr
>::value
>::type
> {
private:
typedef sprout::weed::parse_context<Iterator> context_type;
typedef typename sprout::tuples::tuple_element<0, typename Expr::args_type>::type expr1_type;
typedef typename sprout::tuples::tuple_element<1, typename Expr::args_type>::type expr2_type;
public:
typedef typename sprout::weed::attr_cnv::result_of::mem_ptr<
typename sprout::weed::traits::attribute_of<expr1_type, Iterator, context_type>::type,
typename sprout::tuples::tuple_element<0, typename expr2_type::args_type>::type
>::type attribute_type;
typedef sprout::weed::eval_result<context_type, Iterator, attribute_type> result_type;
private:
template<typename Result1>
SPROUT_CONSTEXPR result_type call_1(
typename Expr::args_type const& args,
context_type const& ctx,
Result1 const& res
) const
{
return res.success()
? result_type(
true,
res.current(),
sprout::weed::attr_cnv::mem_ptr(
res.attr(), sprout::tuples::get<0>(sprout::tuples::get<1>(args).args())
),
context_type(ctx, res.current())
)
: result_type(false, ctx.begin(), attribute_type(), ctx)
;
}
SPROUT_CONSTEXPR result_type call(
typename Expr::args_type const& args,
context_type const& ctx
) const
{
return call_1(args, ctx, sprout::weed::eval(sprout::tuples::get<0>(args), ctx));
}
public:
SPROUT_CONSTEXPR result_type operator()(
Expr const& expr,
context_type const& ctx
) const
{
return call(expr.args(), ctx);
}
};
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_CONTEXT_PARSE_CONTEXT_TERMINAL_OPERATOR_MEM_PTR_HPP

View file

@ -8,6 +8,7 @@
#include <sprout/weed/expr/tag.hpp>
#include <sprout/weed/traits/type/is_char_type.hpp>
#include <sprout/weed/traits/type/is_string.hpp>
#include <sprout/weed/traits/parser/is_parser.hpp>
#include <sprout/weed/traits/expr/tag_of.hpp>
#include <sprout/weed/traits/parser/attribute_of.hpp>
#include <sprout/weed/context/parse_context_fwd.hpp>
@ -26,6 +27,9 @@ namespace sprout {
typename sprout::weed::traits::tag_of<Expr>::type,
sprout::weed::tag::terminal
>::value
&& sprout::weed::traits::is_parser<
typename sprout::tuples::tuple_element<0, typename Expr::args_type>::type
>::value
&& !sprout::weed::traits::is_char_type<
typename sprout::tuples::tuple_element<0, typename Expr::args_type>::type
>::value

View file

@ -4,6 +4,9 @@
#include <sprout/config.hpp>
#include <sprout/tuple/tuple.hpp>
#include <sprout/utility/forward.hpp>
#include <sprout/weed/expr/expr_fwd.hpp>
#include <sprout/weed/expr/tag.hpp>
#include <sprout/weed/traits/expr/expr_of.hpp>
namespace sprout {
namespace weed {

View file

@ -0,0 +1,16 @@
#ifndef SPROUT_WEED_EXPR_EXPR_FWD_HPP
#define SPROUT_WEED_EXPR_EXPR_FWD_HPP
#include <sprout/config.hpp>
namespace sprout {
namespace weed {
//
// expr
//
template<typename Tag, typename... Args>
class expr;
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_EXPR_EXPR_FWD_HPP

View file

@ -16,6 +16,7 @@ namespace sprout {
struct modulus {};
struct minus {};
struct bitwise_or {};
struct mem_ptr {};
} // namespace tag
} // namespace weed
} // namespace sprout

View file

@ -11,5 +11,6 @@
#include <sprout/weed/operator/modulus.hpp>
#include <sprout/weed/operator/minus.hpp>
#include <sprout/weed/operator/bitwise_or.hpp>
#include <sprout/weed/operator/mem_ptr.hpp>
#endif // #ifndef SPROUT_WEED_OPERATOR_HPP

View file

@ -0,0 +1,40 @@
#ifndef SPROUT_WEED_OPERATOR_MEM_PTR_HPP
#define SPROUT_WEED_OPERATOR_MEM_PTR_HPP
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/utility/forward.hpp>
#include <sprout/weed/expr/tag.hpp>
#include <sprout/weed/expr/make_expr.hpp>
#include <sprout/weed/traits/expr/expr_of.hpp>
#include <sprout/weed/traits/parser/is_parser.hpp>
#include <sprout/weed/detail/uncvref.hpp>
namespace sprout {
namespace weed {
//
// operator->*
//
template<
typename Arg1,
typename Arg2,
typename = typename std::enable_if<
sprout::weed::traits::is_parser<
typename sprout::weed::detail::uncvref<Arg1>::type
>::value
>::type
>
inline SPROUT_CONSTEXPR typename sprout::weed::traits::expr_of<
sprout::weed::tag::mem_ptr,
Arg1,
Arg2
>::type operator->*(Arg1&& arg1, Arg2&& arg2) {
return sprout::weed::make_expr<sprout::weed::tag::mem_ptr>(
sprout::forward<Arg1>(arg1),
sprout::forward<Arg2>(arg2)
);
}
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_OPERATOR_MEM_PTR_HPP

View file

@ -3,7 +3,7 @@
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/weed/expr/expr.hpp>
#include <sprout/weed/expr/expr_fwd.hpp>
#include <sprout/weed/traits/expr/terminal_or_expr_of.hpp>
#include <sprout/weed/detail/uncvref.hpp>

View file

@ -3,7 +3,7 @@
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/weed/expr/expr.hpp>
#include <sprout/weed/expr/expr_fwd.hpp>
namespace sprout {
namespace weed {

View file

@ -3,7 +3,7 @@
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/weed/expr/expr.hpp>
#include <sprout/weed/expr/expr_fwd.hpp>
#include <sprout/weed/expr/tag.hpp>
#include <sprout/weed/traits/type/is_c_str.hpp>
#include <sprout/weed/detail/uncvref.hpp>