mirror of
https://github.com/bolero-MURAKAMI/Sprout
synced 2025-08-03 12:49:50 +00:00
sprout/weed/context/parse_context/operator/minus.hpp 追加
sprout/weed/context/parse_context/operator/negate.hpp 追加
This commit is contained in:
parent
005f8a9a87
commit
a7698fa6e9
13 changed files with 291 additions and 1 deletions
|
@ -3,11 +3,13 @@
|
|||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/weed/context/parse_context/operator/unary_plus.hpp>
|
||||
#include <sprout/weed/context/parse_context/operator/negate.hpp>
|
||||
#include <sprout/weed/context/parse_context/operator/dereference.hpp>
|
||||
#include <sprout/weed/context/parse_context/operator/address_of.hpp>
|
||||
#include <sprout/weed/context/parse_context/operator/logical_not.hpp>
|
||||
#include <sprout/weed/context/parse_context/operator/shift_left.hpp>
|
||||
#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>
|
||||
|
||||
#endif // #ifndef SPROUT_WEED_CONTEXT_PARSE_CONTEXT_OPERATOR_HPP
|
||||
|
|
67
sprout/weed/context/parse_context/operator/minus.hpp
Normal file
67
sprout/weed/context/parse_context/operator/minus.hpp
Normal file
|
@ -0,0 +1,67 @@
|
|||
#ifndef SPROUT_WEED_CONTEXT_PARSE_CONTEXT_TERMINAL_OPERATOR_MINUS_HPP
|
||||
#define SPROUT_WEED_CONTEXT_PARSE_CONTEXT_TERMINAL_OPERATOR_MINUS_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::minus
|
||||
>::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 Result1>
|
||||
SPROUT_CONSTEXPR result_type call_1(
|
||||
typename Expr::args_type const& args,
|
||||
context_type const& ctx,
|
||||
Result1 const& res
|
||||
) const
|
||||
{
|
||||
return res.success() && !sprout::weed::eval(sprout::tuples::get<1>(args), ctx).success()
|
||||
? res
|
||||
: 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_MINUS_HPP
|
62
sprout/weed/context/parse_context/operator/negate.hpp
Normal file
62
sprout/weed/context/parse_context/operator/negate.hpp
Normal file
|
@ -0,0 +1,62 @@
|
|||
#ifndef SPROUT_WEED_CONTEXT_PARSE_CONTEXT_TERMINAL_OPERATOR_NEGATE_HPP
|
||||
#define SPROUT_WEED_CONTEXT_PARSE_CONTEXT_TERMINAL_OPERATOR_NEGATE_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/negate.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::negate
|
||||
>::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 Result>
|
||||
SPROUT_CONSTEXPR result_type call(
|
||||
context_type const& ctx,
|
||||
Result const& res
|
||||
) const
|
||||
{
|
||||
return result_type(
|
||||
true,
|
||||
res.current(),
|
||||
sprout::weed::attr_cnv::negate(res.attr(), res.success()),
|
||||
res.success() ? context_type(ctx, res.current()) : ctx
|
||||
);
|
||||
}
|
||||
public:
|
||||
SPROUT_CONSTEXPR result_type operator()(
|
||||
Expr const& expr,
|
||||
context_type const& ctx
|
||||
) const
|
||||
{
|
||||
return call(ctx, sprout::weed::eval(sprout::tuples::get<0>(expr.args()), ctx));
|
||||
}
|
||||
};
|
||||
} // namespace weed
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_WEED_CONTEXT_PARSE_CONTEXT_TERMINAL_OPERATOR_NEGATE_HPP
|
Loading…
Add table
Add a link
Reference in a new issue