mirror of
https://github.com/bolero-MURAKAMI/Sprout
synced 2025-08-03 12:49:50 +00:00
sprout/weed.hpp 追加
This commit is contained in:
parent
8103682fdb
commit
ecfc2b297a
96 changed files with 5127 additions and 0 deletions
50
sprout/weed/context/parse_context/operator/address_of.hpp
Normal file
50
sprout/weed/context/parse_context/operator/address_of.hpp
Normal file
|
@ -0,0 +1,50 @@
|
|||
#ifndef SPROUT_WEED_CONTEXT_PARSE_CONTEXT_TERMINAL_OPERATOR_ADDRESS_OF_HPP
|
||||
#define SPROUT_WEED_CONTEXT_PARSE_CONTEXT_TERMINAL_OPERATOR_ADDRESS_OF_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/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::address_of
|
||||
>::value
|
||||
>::type
|
||||
> {
|
||||
private:
|
||||
typedef sprout::weed::parse_context<Iterator> context_type;
|
||||
public:
|
||||
typedef typename sprout::weed::traits::attribute_of<Expr, Iterator, context_type>::type attribute_type;
|
||||
typedef sprout::weed::eval_result<context_type, Iterator, attribute_type> result_type;
|
||||
public:
|
||||
SPROUT_CONSTEXPR result_type operator()(
|
||||
Expr const& expr,
|
||||
context_type const& ctx
|
||||
) const
|
||||
{
|
||||
return sprout::weed::eval(sprout::tuples::get<0>(expr.args()), ctx).success()
|
||||
? result_type(true, ctx.begin(), attribute_type(), ctx)
|
||||
: result_type(false, ctx.begin(), attribute_type(), ctx)
|
||||
;
|
||||
}
|
||||
};
|
||||
} // namespace weed
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_WEED_CONTEXT_PARSE_CONTEXT_TERMINAL_OPERATOR_ADDRESS_OF_HPP
|
94
sprout/weed/context/parse_context/operator/bitwise_or.hpp
Normal file
94
sprout/weed/context/parse_context/operator/bitwise_or.hpp
Normal file
|
@ -0,0 +1,94 @@
|
|||
#ifndef SPROUT_WEED_CONTEXT_PARSE_CONTEXT_TERMINAL_OPERATOR_BITWISE_OR_HPP
|
||||
#define SPROUT_WEED_CONTEXT_PARSE_CONTEXT_TERMINAL_OPERATOR_BITWISE_OR_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/bitwise_or.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::bitwise_or
|
||||
>::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;
|
||||
typedef typename sprout::weed::traits::attribute_of<expr1_type, Iterator, context_type>::type attr1_type;
|
||||
typedef typename sprout::weed::traits::attribute_of<expr2_type, Iterator, context_type>::type attr2_type;
|
||||
public:
|
||||
typedef typename sprout::weed::traits::attribute_of<Expr, Iterator, context_type>::type attribute_type;
|
||||
typedef sprout::weed::eval_result<context_type, Iterator, attribute_type> result_type;
|
||||
private:
|
||||
template<typename Result2>
|
||||
SPROUT_CONSTEXPR result_type call_2(
|
||||
typename Expr::args_type const& args,
|
||||
context_type const& ctx,
|
||||
Result2 const& res
|
||||
) const
|
||||
{
|
||||
return res.success()
|
||||
? result_type(
|
||||
true,
|
||||
res.current(),
|
||||
sprout::weed::attr_cnv::bitwise_or<attr1_type, attr2_type>(res.attr()),
|
||||
context_type(ctx, res.current())
|
||||
)
|
||||
: result_type(false, ctx.begin(), attribute_type(), ctx)
|
||||
;
|
||||
}
|
||||
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::bitwise_or<attr1_type, attr2_type>(res.attr()),
|
||||
context_type(ctx, res.current())
|
||||
)
|
||||
: call_2(args, ctx, sprout::weed::eval(sprout::tuples::get<1>(args), 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_BITWISE_OR_HPP
|
214
sprout/weed/context/parse_context/operator/dereference.hpp
Normal file
214
sprout/weed/context/parse_context/operator/dereference.hpp
Normal file
|
@ -0,0 +1,214 @@
|
|||
#ifndef SPROUT_WEED_CONTEXT_PARSE_CONTEXT_TERMINAL_OPERATOR_DEREFERENCE_HPP
|
||||
#define SPROUT_WEED_CONTEXT_PARSE_CONTEXT_TERMINAL_OPERATOR_DEREFERENCE_HPP
|
||||
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/tuple/tuple.hpp>
|
||||
#include <sprout/weed/eval_result.hpp>
|
||||
#include <sprout/weed/limited.hpp>
|
||||
#include <sprout/weed/expr/tag.hpp>
|
||||
#include <sprout/weed/expr/eval.hpp>
|
||||
#include <sprout/weed/attr_cnv/times.hpp>
|
||||
#include <sprout/weed/traits/expr/tag_of.hpp>
|
||||
#include <sprout/weed/traits/parser/attribute_of.hpp>
|
||||
#include <sprout/weed/traits/parser/limit_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::dereference
|
||||
>::value
|
||||
>::type
|
||||
> {
|
||||
private:
|
||||
typedef sprout::weed::parse_context<Iterator> context_type;
|
||||
typedef typename sprout::tuples::tuple_element<0, typename Expr::args_type>::type expr_type;
|
||||
typedef typename sprout::weed::traits::limit_of<expr_type, Iterator, context_type>::type limit;
|
||||
typedef typename sprout::weed::traits::attribute_of<expr_type, Iterator, context_type>::type attr_type;
|
||||
public:
|
||||
typedef typename sprout::weed::traits::attribute_of<Expr, Iterator, context_type>::type attribute_type;
|
||||
typedef sprout::weed::eval_result<context_type, Iterator, attribute_type> result_type;
|
||||
private:
|
||||
template<typename Result, typename Head, typename... Attrs>
|
||||
SPROUT_CONSTEXPR typename std::enable_if<
|
||||
sizeof...(Attrs) + 1 == limit::value,
|
||||
result_type
|
||||
>::type call(
|
||||
expr_type const& expr,
|
||||
context_type const& ctx,
|
||||
sprout::weed::limited::category limited_category,
|
||||
Result const& res,
|
||||
Head const& head,
|
||||
Attrs const&... attrs
|
||||
) const
|
||||
{
|
||||
return res.success()
|
||||
? limited_category == sprout::weed::limited::discard
|
||||
? call(
|
||||
expr,
|
||||
res.ctx(),
|
||||
limited_category,
|
||||
sprout::weed::eval(expr, res.ctx()),
|
||||
head,
|
||||
attrs...
|
||||
)
|
||||
: call(
|
||||
expr,
|
||||
res.ctx(),
|
||||
limited_category,
|
||||
sprout::weed::eval(expr, res.ctx()),
|
||||
attrs...,
|
||||
res.attr()
|
||||
)
|
||||
: result_type(
|
||||
true,
|
||||
ctx.begin(),
|
||||
sprout::weed::attr_cnv::times<limit::value, attr_type>(head, attrs...),
|
||||
ctx
|
||||
)
|
||||
;
|
||||
}
|
||||
template<typename Result, typename Head, typename... Attrs>
|
||||
SPROUT_CONSTEXPR typename std::enable_if<
|
||||
sizeof...(Attrs) + 2 == limit::value,
|
||||
result_type
|
||||
>::type call(
|
||||
expr_type const& expr,
|
||||
context_type const& ctx,
|
||||
sprout::weed::limited::category limited_category,
|
||||
Result const& res,
|
||||
Head const& head,
|
||||
Attrs const&... attrs
|
||||
) const
|
||||
{
|
||||
return res.success()
|
||||
? limited_category != sprout::weed::limited::stopover
|
||||
? call(
|
||||
expr,
|
||||
res.ctx(),
|
||||
limited_category,
|
||||
sprout::weed::eval(expr, res.ctx()),
|
||||
head,
|
||||
attrs...,
|
||||
res.attr()
|
||||
)
|
||||
: result_type(
|
||||
true,
|
||||
res.current(),
|
||||
sprout::weed::attr_cnv::times<limit::value, attr_type>(head, attrs..., res.attr()),
|
||||
res.ctx()
|
||||
)
|
||||
: result_type(
|
||||
true,
|
||||
ctx.begin(),
|
||||
sprout::weed::attr_cnv::times<limit::value, attr_type>(head, attrs...),
|
||||
ctx
|
||||
)
|
||||
;
|
||||
}
|
||||
template<typename Result, typename Head, typename... Attrs>
|
||||
SPROUT_CONSTEXPR typename std::enable_if<
|
||||
(sizeof...(Attrs) + 2 < limit::value),
|
||||
result_type
|
||||
>::type call(
|
||||
expr_type const& expr,
|
||||
context_type const& ctx,
|
||||
sprout::weed::limited::category limited_category,
|
||||
Result const& res,
|
||||
Head const& head,
|
||||
Attrs const&... attrs
|
||||
) const
|
||||
{
|
||||
return res.success()
|
||||
? call(
|
||||
expr,
|
||||
res.ctx(),
|
||||
limited_category,
|
||||
sprout::weed::eval(expr, res.ctx()),
|
||||
head,
|
||||
attrs...,
|
||||
res.attr()
|
||||
)
|
||||
: result_type(
|
||||
true,
|
||||
ctx.begin(),
|
||||
sprout::weed::attr_cnv::times<limit::value, attr_type>(head, attrs...),
|
||||
ctx
|
||||
)
|
||||
;
|
||||
}
|
||||
template<typename Result>
|
||||
SPROUT_CONSTEXPR result_type call_inf(
|
||||
expr_type const& expr,
|
||||
context_type const& ctx,
|
||||
Result const& res
|
||||
) const
|
||||
{
|
||||
return res.success()
|
||||
? call_inf(expr, res.ctx(), sprout::weed::eval(expr, res.ctx()))
|
||||
: result_type(true, ctx.begin(), attribute_type(), ctx)
|
||||
;
|
||||
}
|
||||
template<bool Infinity, typename Result>
|
||||
SPROUT_CONSTEXPR typename std::enable_if<
|
||||
Infinity,
|
||||
result_type
|
||||
>::type call(
|
||||
expr_type const& expr,
|
||||
context_type const& ctx,
|
||||
Result const& res
|
||||
) const
|
||||
{
|
||||
return res.success()
|
||||
? call_inf(expr, res.ctx(), sprout::weed::eval(expr, res.ctx()))
|
||||
: result_type(true, ctx.begin(), attribute_type(), ctx)
|
||||
;
|
||||
}
|
||||
template<bool Infinity, typename Result>
|
||||
SPROUT_CONSTEXPR typename std::enable_if<
|
||||
!Infinity,
|
||||
result_type
|
||||
>::type call(
|
||||
expr_type const& expr,
|
||||
context_type const& ctx,
|
||||
Result const& res
|
||||
) const
|
||||
{
|
||||
return res.success()
|
||||
? call(
|
||||
expr,
|
||||
res.ctx(),
|
||||
sprout::tuples::get<0>(expr.args()).limited_category(),
|
||||
sprout::weed::eval(expr, res.ctx()),
|
||||
res.attr()
|
||||
)
|
||||
: result_type(true, ctx.begin(), attribute_type(), ctx)
|
||||
;
|
||||
}
|
||||
public:
|
||||
SPROUT_CONSTEXPR result_type operator()(
|
||||
Expr const& expr,
|
||||
context_type const& ctx
|
||||
) const
|
||||
{
|
||||
return call<limit::value == std::size_t(-1)>(
|
||||
sprout::tuples::get<0>(expr.args()),
|
||||
ctx,
|
||||
sprout::weed::eval(sprout::tuples::get<0>(expr.args()), ctx)
|
||||
);
|
||||
}
|
||||
};
|
||||
} // namespace weed
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_WEED_CONTEXT_PARSE_CONTEXT_TERMINAL_OPERATOR_DEREFERENCE_HPP
|
50
sprout/weed/context/parse_context/operator/logical_not.hpp
Normal file
50
sprout/weed/context/parse_context/operator/logical_not.hpp
Normal file
|
@ -0,0 +1,50 @@
|
|||
#ifndef SPROUT_WEED_CONTEXT_PARSE_CONTEXT_TERMINAL_OPERATOR_LOGICAL_NOT_HPP
|
||||
#define SPROUT_WEED_CONTEXT_PARSE_CONTEXT_TERMINAL_OPERATOR_LOGICAL_NOT_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/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::logical_not
|
||||
>::value
|
||||
>::type
|
||||
> {
|
||||
private:
|
||||
typedef sprout::weed::parse_context<Iterator> context_type;
|
||||
public:
|
||||
typedef typename sprout::weed::traits::attribute_of<Expr, Iterator, context_type>::type attribute_type;
|
||||
typedef sprout::weed::eval_result<context_type, Iterator, attribute_type> result_type;
|
||||
public:
|
||||
SPROUT_CONSTEXPR result_type operator()(
|
||||
Expr const& expr,
|
||||
context_type const& ctx
|
||||
) const
|
||||
{
|
||||
return !sprout::weed::eval(sprout::tuples::get<0>(expr.args()), ctx).success()
|
||||
? result_type(true, ctx.begin(), attribute_type(), ctx)
|
||||
: result_type(false, ctx.begin(), attribute_type(), ctx)
|
||||
;
|
||||
}
|
||||
};
|
||||
} // namespace weed
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_WEED_CONTEXT_PARSE_CONTEXT_TERMINAL_OPERATOR_LOGICAL_NOT_HPP
|
266
sprout/weed/context/parse_context/operator/modulus.hpp
Normal file
266
sprout/weed/context/parse_context/operator/modulus.hpp
Normal file
|
@ -0,0 +1,266 @@
|
|||
#ifndef SPROUT_WEED_CONTEXT_PARSE_CONTEXT_TERMINAL_OPERATOR_MODULUS_HPP
|
||||
#define SPROUT_WEED_CONTEXT_PARSE_CONTEXT_TERMINAL_OPERATOR_MODULUS_HPP
|
||||
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/tuple/tuple.hpp>
|
||||
#include <sprout/weed/eval_result.hpp>
|
||||
#include <sprout/weed/limited.hpp>
|
||||
#include <sprout/weed/expr/tag.hpp>
|
||||
#include <sprout/weed/expr/eval.hpp>
|
||||
#include <sprout/weed/attr_cnv/modulus.hpp>
|
||||
#include <sprout/weed/traits/expr/tag_of.hpp>
|
||||
#include <sprout/weed/traits/parser/attribute_of.hpp>
|
||||
#include <sprout/weed/traits/parser/limit_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::modulus
|
||||
>::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;
|
||||
typedef typename sprout::weed::traits::limit_of<expr1_type, Iterator, context_type>::type limit;
|
||||
typedef typename sprout::weed::traits::attribute_of<expr1_type, Iterator, context_type>::type attr_type;
|
||||
public:
|
||||
typedef typename sprout::weed::traits::attribute_of<Expr, Iterator, context_type>::type attribute_type;
|
||||
typedef sprout::weed::eval_result<context_type, Iterator, attribute_type> result_type;
|
||||
private:
|
||||
template<typename Result, typename... Attrs>
|
||||
SPROUT_CONSTEXPR result_type call_1(
|
||||
expr1_type const& expr1,
|
||||
expr2_type const& expr2,
|
||||
context_type const& ctx,
|
||||
sprout::weed::limited::category limited_category,
|
||||
Result const& res,
|
||||
Attrs const&... attrs
|
||||
) const
|
||||
{
|
||||
return res.success()
|
||||
? call(
|
||||
expr1,
|
||||
expr2,
|
||||
res.ctx(),
|
||||
limited_category,
|
||||
sprout::weed::eval(expr1, res.ctx()),
|
||||
attrs...
|
||||
)
|
||||
: result_type(
|
||||
true,
|
||||
ctx.begin(),
|
||||
sprout::weed::attr_cnv::modulus<limit::value, attr_type>(attrs...),
|
||||
ctx
|
||||
)
|
||||
;
|
||||
}
|
||||
template<typename Result, typename Head, typename... Attrs>
|
||||
SPROUT_CONSTEXPR typename std::enable_if<
|
||||
sizeof...(Attrs) + 1 == limit::value,
|
||||
result_type
|
||||
>::type call(
|
||||
expr1_type const& expr1,
|
||||
expr2_type const& expr2,
|
||||
context_type const& ctx,
|
||||
sprout::weed::limited::category limited_category,
|
||||
Result const& res,
|
||||
Head const& head,
|
||||
Attrs const&... attrs
|
||||
) const
|
||||
{
|
||||
return res.success()
|
||||
? limited_category == sprout::weed::limited::discard
|
||||
? call_1(
|
||||
expr1,
|
||||
expr2,
|
||||
res.ctx(),
|
||||
limited_category,
|
||||
sprout::weed::eval(expr2, res.ctx()),
|
||||
head,
|
||||
attrs...
|
||||
)
|
||||
: call_1(
|
||||
expr1,
|
||||
expr2,
|
||||
res.ctx(),
|
||||
limited_category,
|
||||
sprout::weed::eval(expr2, res.ctx()),
|
||||
attrs...,
|
||||
res.attr()
|
||||
)
|
||||
: result_type(
|
||||
true,
|
||||
ctx.begin(),
|
||||
sprout::weed::attr_cnv::modulus<limit::value, attr_type>(head, attrs...),
|
||||
ctx
|
||||
)
|
||||
;
|
||||
}
|
||||
template<typename Result, typename Head, typename... Attrs>
|
||||
SPROUT_CONSTEXPR typename std::enable_if<
|
||||
sizeof...(Attrs) + 2 == limit::value,
|
||||
result_type
|
||||
>::type call(
|
||||
expr1_type const& expr1,
|
||||
expr2_type const& expr2,
|
||||
context_type const& ctx,
|
||||
sprout::weed::limited::category limited_category,
|
||||
Result const& res,
|
||||
Head const& head,
|
||||
Attrs const&... attrs
|
||||
) const
|
||||
{
|
||||
return res.success()
|
||||
? limited_category != sprout::weed::limited::stopover
|
||||
? call_1(
|
||||
expr1,
|
||||
expr2,
|
||||
res.ctx(),
|
||||
limited_category,
|
||||
sprout::weed::eval(expr2, res.ctx()),
|
||||
head,
|
||||
attrs...,
|
||||
res.attr()
|
||||
)
|
||||
: result_type(
|
||||
true,
|
||||
res.current(),
|
||||
sprout::weed::attr_cnv::modulus<limit::value, attr_type>(head, attrs..., res.attr()),
|
||||
res.ctx()
|
||||
)
|
||||
: result_type(
|
||||
true,
|
||||
ctx.begin(),
|
||||
sprout::weed::attr_cnv::modulus<limit::value, attr_type>(head, attrs...),
|
||||
ctx
|
||||
)
|
||||
;
|
||||
}
|
||||
template<typename Result, typename Head, typename... Attrs>
|
||||
SPROUT_CONSTEXPR typename std::enable_if<
|
||||
(sizeof...(Attrs) + 2 < limit::value),
|
||||
result_type
|
||||
>::type call(
|
||||
expr1_type const& expr1,
|
||||
expr2_type const& expr2,
|
||||
context_type const& ctx,
|
||||
sprout::weed::limited::category limited_category,
|
||||
Result const& res,
|
||||
Head const& head,
|
||||
Attrs const&... attrs
|
||||
) const
|
||||
{
|
||||
return res.success()
|
||||
? call_1(
|
||||
expr1,
|
||||
expr2,
|
||||
res.ctx(),
|
||||
limited_category,
|
||||
sprout::weed::eval(expr2, res.ctx()),
|
||||
head,
|
||||
attrs...,
|
||||
res.attr()
|
||||
)
|
||||
: result_type(
|
||||
true,
|
||||
ctx.begin(),
|
||||
sprout::weed::attr_cnv::modulus<limit::value, attr_type>(head, attrs...),
|
||||
ctx
|
||||
)
|
||||
;
|
||||
}
|
||||
template<typename Result>
|
||||
SPROUT_CONSTEXPR result_type call_inf_1(
|
||||
expr1_type const& expr1,
|
||||
expr2_type const& expr2,
|
||||
context_type const& ctx,
|
||||
Result const& res
|
||||
) const
|
||||
{
|
||||
return res.success()
|
||||
? call_inf(expr1, expr2, res.ctx(), sprout::weed::eval(expr1, res.ctx()))
|
||||
: result_type(true, ctx.begin(), attribute_type(), ctx)
|
||||
;
|
||||
}
|
||||
template<typename Result>
|
||||
SPROUT_CONSTEXPR result_type call_inf(
|
||||
expr1_type const& expr1,
|
||||
expr2_type const& expr2,
|
||||
context_type const& ctx,
|
||||
Result const& res
|
||||
) const
|
||||
{
|
||||
return res.success()
|
||||
? call_inf_1(expr1, expr2, res.ctx(), sprout::weed::eval(expr2, res.ctx()))
|
||||
: result_type(true, ctx.begin(), attribute_type(), ctx)
|
||||
;
|
||||
}
|
||||
template<bool Infinity, typename Result>
|
||||
SPROUT_CONSTEXPR typename std::enable_if<
|
||||
Infinity,
|
||||
result_type
|
||||
>::type call(
|
||||
expr1_type const& expr1,
|
||||
expr2_type const& expr2,
|
||||
context_type const& ctx,
|
||||
Result const& res
|
||||
) const
|
||||
{
|
||||
return res.success()
|
||||
? call_inf_1(expr1, expr2, res.ctx(), sprout::weed::eval(expr2, res.ctx()))
|
||||
: result_type(false, ctx.begin(), attribute_type(), ctx)
|
||||
;
|
||||
}
|
||||
template<bool Infinity, typename Result>
|
||||
SPROUT_CONSTEXPR typename std::enable_if<
|
||||
!Infinity,
|
||||
result_type
|
||||
>::type call(
|
||||
expr1_type const& expr1,
|
||||
expr2_type const& expr2,
|
||||
context_type const& ctx,
|
||||
Result const& res
|
||||
) const
|
||||
{
|
||||
return res.success()
|
||||
? call_1(
|
||||
expr1,
|
||||
expr2,
|
||||
res.ctx(),
|
||||
sprout::tuples::get<0>(expr1.args()).limited_category(),
|
||||
sprout::weed::eval(expr2, res.ctx()), res.attr()
|
||||
)
|
||||
: result_type(false, ctx.begin(), attribute_type(), ctx)
|
||||
;
|
||||
}
|
||||
public:
|
||||
SPROUT_CONSTEXPR result_type operator()(
|
||||
Expr const& expr,
|
||||
context_type const& ctx
|
||||
) const
|
||||
{
|
||||
return call<limit::value == std::size_t(-1)>(
|
||||
sprout::tuples::get<0>(expr.args()),
|
||||
sprout::tuples::get<1>(expr.args()),
|
||||
ctx,
|
||||
sprout::weed::eval(sprout::tuples::get<0>(expr.args()), ctx)
|
||||
);
|
||||
}
|
||||
};
|
||||
} // namespace weed
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_WEED_CONTEXT_PARSE_CONTEXT_TERMINAL_OPERATOR_MODULUS_HPP
|
91
sprout/weed/context/parse_context/operator/shift_left.hpp
Normal file
91
sprout/weed/context/parse_context/operator/shift_left.hpp
Normal file
|
@ -0,0 +1,91 @@
|
|||
#ifndef SPROUT_WEED_CONTEXT_PARSE_CONTEXT_TERMINAL_OPERATOR_SHIFT_LEFT_HPP
|
||||
#define SPROUT_WEED_CONTEXT_PARSE_CONTEXT_TERMINAL_OPERATOR_SHIFT_LEFT_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/shift_left.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::shift_left
|
||||
>::value
|
||||
>::type
|
||||
> {
|
||||
private:
|
||||
typedef sprout::weed::parse_context<Iterator> context_type;
|
||||
public:
|
||||
typedef typename sprout::weed::traits::attribute_of<Expr, Iterator, context_type>::type attribute_type;
|
||||
typedef sprout::weed::eval_result<context_type, Iterator, attribute_type> result_type;
|
||||
private:
|
||||
template<typename Attr1, typename Result2>
|
||||
SPROUT_CONSTEXPR result_type call_2(
|
||||
typename Expr::args_type const& args,
|
||||
context_type const& ctx,
|
||||
Attr1 const& attr,
|
||||
Result2 const& res
|
||||
) const
|
||||
{
|
||||
return res.success()
|
||||
? result_type(
|
||||
true,
|
||||
res.current(),
|
||||
sprout::weed::attr_cnv::shift_left(attr, res.attr()),
|
||||
context_type(ctx, res.current())
|
||||
)
|
||||
: result_type(false, ctx.begin(), attribute_type(), ctx)
|
||||
;
|
||||
}
|
||||
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()
|
||||
? call_2(
|
||||
args,
|
||||
ctx,
|
||||
res.attr(),
|
||||
sprout::weed::eval(sprout::tuples::get<1>(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_SHIFT_LEFT_HPP
|
214
sprout/weed/context/parse_context/operator/unary_plus.hpp
Normal file
214
sprout/weed/context/parse_context/operator/unary_plus.hpp
Normal file
|
@ -0,0 +1,214 @@
|
|||
#ifndef SPROUT_WEED_CONTEXT_PARSE_CONTEXT_TERMINAL_OPERATOR_UNARY_PLUS_HPP
|
||||
#define SPROUT_WEED_CONTEXT_PARSE_CONTEXT_TERMINAL_OPERATOR_UNARY_PLUS_HPP
|
||||
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/tuple/tuple.hpp>
|
||||
#include <sprout/weed/eval_result.hpp>
|
||||
#include <sprout/weed/limited.hpp>
|
||||
#include <sprout/weed/expr/tag.hpp>
|
||||
#include <sprout/weed/expr/eval.hpp>
|
||||
#include <sprout/weed/attr_cnv/times.hpp>
|
||||
#include <sprout/weed/traits/expr/tag_of.hpp>
|
||||
#include <sprout/weed/traits/parser/attribute_of.hpp>
|
||||
#include <sprout/weed/traits/parser/limit_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::unary_plus
|
||||
>::value
|
||||
>::type
|
||||
> {
|
||||
private:
|
||||
typedef sprout::weed::parse_context<Iterator> context_type;
|
||||
typedef typename sprout::tuples::tuple_element<0, typename Expr::args_type>::type expr_type;
|
||||
typedef typename sprout::weed::traits::limit_of<expr_type, Iterator, context_type>::type limit;
|
||||
typedef typename sprout::weed::traits::attribute_of<expr_type, Iterator, context_type>::type attr_type;
|
||||
public:
|
||||
typedef typename sprout::weed::traits::attribute_of<Expr, Iterator, context_type>::type attribute_type;
|
||||
typedef sprout::weed::eval_result<context_type, Iterator, attribute_type> result_type;
|
||||
private:
|
||||
template<typename Result, typename Head, typename... Attrs>
|
||||
SPROUT_CONSTEXPR typename std::enable_if<
|
||||
sizeof...(Attrs) + 1 == limit::value,
|
||||
result_type
|
||||
>::type call(
|
||||
expr_type const& expr,
|
||||
context_type const& ctx,
|
||||
sprout::weed::limited::category limited_category,
|
||||
Result const& res,
|
||||
Head const& head,
|
||||
Attrs const&... attrs
|
||||
) const
|
||||
{
|
||||
return res.success()
|
||||
? limited_category == sprout::weed::limited::discard
|
||||
? call(
|
||||
expr,
|
||||
res.ctx(),
|
||||
limited_category,
|
||||
sprout::weed::eval(expr, res.ctx()),
|
||||
head,
|
||||
attrs...
|
||||
)
|
||||
: call(
|
||||
expr,
|
||||
res.ctx(),
|
||||
limited_category,
|
||||
sprout::weed::eval(expr, res.ctx()),
|
||||
attrs...,
|
||||
res.attr()
|
||||
)
|
||||
: result_type(
|
||||
true,
|
||||
ctx.begin(),
|
||||
sprout::weed::attr_cnv::times<limit::value, attr_type>(head, attrs...),
|
||||
ctx
|
||||
)
|
||||
;
|
||||
}
|
||||
template<typename Result, typename Head, typename... Attrs>
|
||||
SPROUT_CONSTEXPR typename std::enable_if<
|
||||
sizeof...(Attrs) + 2 == limit::value,
|
||||
result_type
|
||||
>::type call(
|
||||
expr_type const& expr,
|
||||
context_type const& ctx,
|
||||
sprout::weed::limited::category limited_category,
|
||||
Result const& res,
|
||||
Head const& head,
|
||||
Attrs const&... attrs
|
||||
) const
|
||||
{
|
||||
return res.success()
|
||||
? limited_category != sprout::weed::limited::stopover
|
||||
? call(
|
||||
expr,
|
||||
res.ctx(),
|
||||
limited_category,
|
||||
sprout::weed::eval(expr, res.ctx()),
|
||||
head,
|
||||
attrs...,
|
||||
res.attr()
|
||||
)
|
||||
: result_type(
|
||||
true,
|
||||
res.current(),
|
||||
sprout::weed::attr_cnv::times<limit::value, attr_type>(head, attrs..., res.attr()),
|
||||
res.ctx()
|
||||
)
|
||||
: result_type(
|
||||
true,
|
||||
ctx.begin(),
|
||||
sprout::weed::attr_cnv::times<limit::value, attr_type>(head, attrs...),
|
||||
ctx
|
||||
)
|
||||
;
|
||||
}
|
||||
template<typename Result, typename Head, typename... Attrs>
|
||||
SPROUT_CONSTEXPR typename std::enable_if<
|
||||
(sizeof...(Attrs) + 2 < limit::value),
|
||||
result_type
|
||||
>::type call(
|
||||
expr_type const& expr,
|
||||
context_type const& ctx,
|
||||
sprout::weed::limited::category limited_category,
|
||||
Result const& res,
|
||||
Head const& head,
|
||||
Attrs const&... attrs
|
||||
) const
|
||||
{
|
||||
return res.success()
|
||||
? call(
|
||||
expr,
|
||||
res.ctx(),
|
||||
limited_category,
|
||||
sprout::weed::eval(expr, res.ctx()),
|
||||
head,
|
||||
attrs...,
|
||||
res.attr()
|
||||
)
|
||||
: result_type(
|
||||
true,
|
||||
ctx.begin(),
|
||||
sprout::weed::attr_cnv::times<limit::value, attr_type>(head, attrs...),
|
||||
ctx
|
||||
)
|
||||
;
|
||||
}
|
||||
template<typename Result>
|
||||
SPROUT_CONSTEXPR result_type call_inf(
|
||||
expr_type const& expr,
|
||||
context_type const& ctx,
|
||||
Result const& res
|
||||
) const
|
||||
{
|
||||
return res.success()
|
||||
? call_inf(expr, res.ctx(), sprout::weed::eval(expr, res.ctx()))
|
||||
: result_type(true, ctx.begin(), attribute_type(), ctx)
|
||||
;
|
||||
}
|
||||
template<bool Infinity, typename Result>
|
||||
SPROUT_CONSTEXPR typename std::enable_if<
|
||||
Infinity,
|
||||
result_type
|
||||
>::type call(
|
||||
expr_type const& expr,
|
||||
context_type const& ctx,
|
||||
Result const& res
|
||||
) const
|
||||
{
|
||||
return res.success()
|
||||
? call_inf(expr, res.ctx(), sprout::weed::eval(expr, res.ctx()))
|
||||
: result_type(false, ctx.begin(), attribute_type(), ctx)
|
||||
;
|
||||
}
|
||||
template<bool Infinity, typename Result>
|
||||
SPROUT_CONSTEXPR typename std::enable_if<
|
||||
!Infinity,
|
||||
result_type
|
||||
>::type call(
|
||||
expr_type const& expr,
|
||||
context_type const& ctx,
|
||||
Result const& res
|
||||
) const
|
||||
{
|
||||
return res.success()
|
||||
? call(
|
||||
expr,
|
||||
res.ctx(),
|
||||
sprout::tuples::get<0>(expr.args()).limited_category(),
|
||||
sprout::weed::eval(expr, res.ctx()),
|
||||
res.attr()
|
||||
)
|
||||
: result_type(false, ctx.begin(), attribute_type(), ctx)
|
||||
;
|
||||
}
|
||||
public:
|
||||
SPROUT_CONSTEXPR result_type operator()(
|
||||
Expr const& expr,
|
||||
context_type const& ctx
|
||||
) const
|
||||
{
|
||||
return call<limit::value == std::size_t(-1)>(
|
||||
sprout::tuples::get<0>(expr.args()),
|
||||
ctx,
|
||||
sprout::weed::eval(sprout::tuples::get<0>(expr.args()), ctx)
|
||||
);
|
||||
}
|
||||
};
|
||||
} // namespace weed
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_WEED_CONTEXT_PARSE_CONTEXT_TERMINAL_OPERATOR_UNARY_PLUS_HPP
|
Loading…
Add table
Add a link
Reference in a new issue