sprout/weed.hpp 追加

This commit is contained in:
bolero-MURAKAMI 2011-11-13 17:54:38 +09:00
parent 8103682fdb
commit ecfc2b297a
96 changed files with 5127 additions and 0 deletions

16
sprout/weed.hpp Normal file
View file

@ -0,0 +1,16 @@
#ifndef SPROUT_WEED_HPP
#define SPROUT_WEED_HPP
#include <sprout/weed/expr.hpp>
#include <sprout/weed/operator.hpp>
#include <sprout/weed/attr_cnv.hpp>
#include <sprout/weed/context.hpp>
#include <sprout/weed/parse.hpp>
#include <sprout/weed/unused.hpp>
#include <sprout/weed/limited.hpp>
#include <sprout/weed/eval_result.hpp>
#include <sprout/weed/parser_result.hpp>
#include <sprout/weed/parser.hpp>
#include <sprout/weed/traits.hpp>
#endif // #ifndef SPROUT_WEED_HPP

10
sprout/weed/attr_cnv.hpp Normal file
View file

@ -0,0 +1,10 @@
#ifndef SPROUT_WEED_ATTR_CNV_HPP
#define SPROUT_WEED_ATTR_CNV_HPP
#include <sprout/config.hpp>
#include <sprout/weed/attr_cnv/times.hpp>
#include <sprout/weed/attr_cnv/shift_left.hpp>
#include <sprout/weed/attr_cnv/modulus.hpp>
#include <sprout/weed/attr_cnv/bitwise_or.hpp>
#endif // #ifndef SPROUT_WEED_ATTR_CNV_HPP

View file

@ -0,0 +1,141 @@
#ifndef SPROUT_WEED_ATTR_CNV_BITWISE_OR_HPP
#define SPROUT_WEED_ATTR_CNV_BITWISE_OR_HPP
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/fixed_container/make_clone.hpp>
#include <sprout/operation/fixed/realign_to.hpp>
#include <sprout/tuple/algorithm/copy.hpp>
#include <sprout/weed/unused.hpp>
#include <sprout/weed/traits/type/is_container.hpp>
#include <sprout/weed/detail/is_same_container.hpp>
#include <sprout/weed/detail/is_container_and_elem.hpp>
#include <sprout/weed/detail/is_elem_and_container.hpp>
#include <sprout/weed/detail/is_both_tuple.hpp>
#include <sprout/weed/detail/is_same_elem.hpp>
#include <sprout/weed/detail/is_elem_and_unused.hpp>
#include <sprout/weed/detail/is_unused_and_elem.hpp>
#include <sprout/weed/detail/is_both_unused.hpp>
#include <sprout/weed/attr_cnv/result_of/bitwise_or.hpp>
namespace sprout {
namespace weed {
namespace attr_cnv {
//
// bitwise_or
//
// container<V, N> | container<V, M> -> container<V, max(N, M)>
template<typename T, typename U, typename X>
SPROUT_CONSTEXPR inline typename std::enable_if<
sprout::weed::detail::is_same_container<T, U>::value,
typename sprout::weed::attr_cnv::result_of::bitwise_or<T, U>::type
>::type bitwise_or(X const& x) {
typedef typename sprout::weed::attr_cnv::result_of::bitwise_or<T, U>::type type;
return sprout::fixed::realign_to<type>(x);
}
// container<V, N> | V -> container<V, N ? N : 1>
template<typename T, typename U, typename X>
SPROUT_CONSTEXPR inline typename std::enable_if<
sprout::weed::detail::is_container_and_elem<T, U>::value
&& sprout::weed::traits::is_container<X>::value,
typename sprout::weed::attr_cnv::result_of::bitwise_or<T, U>::type
>::type bitwise_or(X const& x) {
typedef typename sprout::weed::attr_cnv::result_of::bitwise_or<T, U>::type type;
return sprout::fixed::realign_to<type>(x);
}
template<typename T, typename U, typename X>
SPROUT_CONSTEXPR inline typename std::enable_if<
sprout::weed::detail::is_container_and_elem<T, U>::value
&& !sprout::weed::traits::is_container<X>::value,
typename sprout::weed::attr_cnv::result_of::bitwise_or<T, U>::type
>::type bitwise_or(X const& x) {
typedef typename sprout::weed::attr_cnv::result_of::bitwise_or<T, U>::type type;
return sprout::make_clone<type>(x);
}
// V | container<V, N> -> container<V, N ? N : 1>
template<typename T, typename U, typename X>
SPROUT_CONSTEXPR inline typename std::enable_if<
sprout::weed::detail::is_elem_and_container<T, U>::value
&& sprout::weed::traits::is_container<X>::value,
typename sprout::weed::attr_cnv::result_of::bitwise_or<T, U>::type
>::type bitwise_or(X const& x) {
typedef typename sprout::weed::attr_cnv::result_of::bitwise_or<T, U>::type type;
return sprout::fixed::realign_to<type>(x);
}
template<typename T, typename U, typename X>
SPROUT_CONSTEXPR inline typename std::enable_if<
sprout::weed::detail::is_elem_and_container<T, U>::value
&& !sprout::weed::traits::is_container<X>::value,
typename sprout::weed::attr_cnv::result_of::bitwise_or<T, U>::type
>::type bitwise_or(X const& x) {
typedef typename sprout::weed::attr_cnv::result_of::bitwise_or<T, U>::type type;
return sprout::make_clone<type>(x);
}
// tuple<Vs...> | tuple<Ws...> -> tuple<max(Vs..., Ws...)>
template<typename T, typename U, typename X>
SPROUT_CONSTEXPR inline typename std::enable_if<
sprout::weed::detail::is_both_tuple<T, U>::value,
typename sprout::weed::attr_cnv::result_of::bitwise_or<T, U>::type
>::type bitwise_or(X const& x) {
typedef typename sprout::weed::attr_cnv::result_of::bitwise_or<T, U>::type type;
return sprout::tuples::copy(type(), x);
}
// V | V -> V
template<typename T, typename U, typename X>
SPROUT_CONSTEXPR inline typename std::enable_if<
sprout::weed::detail::is_same_elem<T, U>::value,
typename sprout::weed::attr_cnv::result_of::bitwise_or<T, U>::type
>::type bitwise_or(X const& x) {
return x;
}
// V | unused -> container<V, 1>
template<typename T, typename U, typename X>
SPROUT_CONSTEXPR inline typename std::enable_if<
sprout::weed::detail::is_elem_and_unused<T, U>::value
&& !sprout::weed::traits::is_unused<X>::value,
typename sprout::weed::attr_cnv::result_of::bitwise_or<T, U>::type
>::type bitwise_or(X const& x) {
typedef typename sprout::weed::attr_cnv::result_of::bitwise_or<T, U>::type type;
return sprout::make_clone<type>(x);
}
template<typename T, typename U, typename X>
SPROUT_CONSTEXPR inline typename std::enable_if<
sprout::weed::detail::is_elem_and_unused<T, U>::value
&& sprout::weed::traits::is_unused<X>::value,
typename sprout::weed::attr_cnv::result_of::bitwise_or<T, U>::type
>::type bitwise_or(X const& x) {
typedef typename sprout::weed::attr_cnv::result_of::bitwise_or<T, U>::type type;
return sprout::make_clone<type>();
}
// unused | V -> container<V, 1>
template<typename T, typename U, typename X>
SPROUT_CONSTEXPR inline typename std::enable_if<
sprout::weed::detail::is_unused_and_elem<T, U>::value
&& !sprout::weed::traits::is_unused<X>::value,
typename sprout::weed::attr_cnv::result_of::bitwise_or<T, U>::type
>::type bitwise_or(X const& x) {
typedef typename sprout::weed::attr_cnv::result_of::bitwise_or<T, U>::type type;
return sprout::make_clone<type>(x);
}
template<typename T, typename U, typename X>
SPROUT_CONSTEXPR inline typename std::enable_if<
sprout::weed::detail::is_unused_and_elem<T, U>::value
&& sprout::weed::traits::is_unused<X>::value,
typename sprout::weed::attr_cnv::result_of::bitwise_or<T, U>::type
>::type bitwise_or(X const& x) {
typedef typename sprout::weed::attr_cnv::result_of::bitwise_or<T, U>::type type;
return sprout::make_clone<type>();
}
// unused >> unused -> unused
template<typename T, typename U, typename X>
SPROUT_CONSTEXPR inline typename std::enable_if<
sprout::weed::detail::is_both_unused<T, U>::value,
typename sprout::weed::attr_cnv::result_of::bitwise_or<T, U>::type
>::type bitwise_or(X const& x) {
return sprout::weed::unused();
}
} // namespace attr_cnv
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_ATTR_CNV_BITWISE_OR_HPP

View file

@ -0,0 +1,24 @@
#ifndef SPROUT_WEED_ATTR_CNV_MODULUS_HPP
#define SPROUT_WEED_ATTR_CNV_MODULUS_HPP
#include <cstddef>
#include <sprout/config.hpp>
#include <sprout/weed/attr_cnv/result_of/modulus.hpp>
#include <sprout/weed/attr_cnv/times.hpp>
namespace sprout {
namespace weed {
namespace attr_cnv {
//
// modulus
//
template<std::size_t Limit, typename T, typename... Args>
SPROUT_CONSTEXPR inline typename sprout::weed::attr_cnv::result_of::modulus<Limit, T>::type
modulus(Args const&... args) {
return sprout::weed::attr_cnv::times<Limit, T>(args...);
}
} // namespace attr_cnv
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_ATTR_CNV_MODULUS_HPP

View file

@ -0,0 +1,10 @@
#ifndef SPROUT_WEED_ATTR_CNV_RESULT_OF_HPP
#define SPROUT_WEED_ATTR_CNV_RESULT_OF_HPP
#include <sprout/config.hpp>
#include <sprout/weed/attr_cnv/result_of/times.hpp>
#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>
#endif // #ifndef SPROUT_WEED_ATTR_CNV_RESULT_OF_HPP

View file

@ -0,0 +1,154 @@
#ifndef SPROUT_WEED_ATTR_CNV_RESULT_OF_BITWISE_OR_HPP
#define SPROUT_WEED_ATTR_CNV_RESULT_OF_BITWISE_OR_HPP
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/string.hpp>
#include <sprout/array.hpp>
#include <sprout/tuple/tuple.hpp>
#include <sprout/weed/unused.hpp>
#include <sprout/weed/traits/type/is_char_type.hpp>
#include <sprout/weed/detail/is_same_container.hpp>
#include <sprout/weed/detail/is_container_and_elem.hpp>
#include <sprout/weed/detail/is_elem_and_container.hpp>
#include <sprout/weed/detail/is_both_tuple.hpp>
#include <sprout/weed/detail/is_same_elem.hpp>
#include <sprout/weed/detail/is_elem_and_unused.hpp>
#include <sprout/weed/detail/is_unused_and_elem.hpp>
#include <sprout/weed/detail/is_both_unused.hpp>
namespace sprout {
namespace weed {
namespace attr_cnv {
namespace result_of {
//
// bitwise_or
//
template<typename T, typename U, typename = void>
struct bitwise_or;
// container<V, N> | container<V, M> -> container<V, max(N, M)>
template<typename T, typename U>
struct bitwise_or<
T,
U,
typename std::enable_if<
sprout::weed::detail::is_same_container<T, U>::value
>::type
> {
public:
typedef typename std::conditional<
!(sprout::tuples::tuple_size<T>::value < sprout::tuples::tuple_size<U>::value),
T,
U
>::type type;
};
// container<V, N> | V -> container<V, N ? N : 1>
template<typename T, typename U>
struct bitwise_or<
T,
U,
typename std::enable_if<
sprout::weed::detail::is_container_and_elem<T, U>::value
>::type
> {
public:
typedef typename std::conditional<
sprout::fixed_container_traits<T>::fixed_size != 0,
T,
typename sprout::rebind_fixed_size<T>::template apply<1>::type
>::type type;
};
// V | container<V, N> -> container<V, N ? N : 1>
template<typename T, typename U>
struct bitwise_or<
T,
U,
typename std::enable_if<
sprout::weed::detail::is_elem_and_container<T, U>::value
>::type
> {
public:
typedef typename std::conditional<
sprout::fixed_container_traits<T>::fixed_size != 0,
U,
typename sprout::rebind_fixed_size<U>::template apply<1>::type
>::type type;
};
// tuple<Vs...> | tuple<Ws...> -> tuple<max(Vs..., Ws...)>
template<typename T, typename U>
struct bitwise_or<
T,
U,
typename std::enable_if<
sprout::weed::detail::is_both_tuple<T, U>::value
>::type
> {
public:
typedef typename std::conditional<
!(sprout::tuples::tuple_size<T>::value < sprout::tuples::tuple_size<U>::value),
T,
U
>::type type;
};
// V | V -> V
template<typename T, typename U>
struct bitwise_or<
T,
U,
typename std::enable_if<
sprout::weed::detail::is_same_elem<T, U>::value
>::type
> {
public:
typedef T type;
};
// V | unused -> container<V, 1>
template<typename T, typename U>
struct bitwise_or<
T,
U,
typename std::enable_if<
sprout::weed::detail::is_elem_and_unused<T, U>::value
>::type
> {
public:
typedef typename std::conditional<
sprout::weed::traits::is_char_type<T>::value,
sprout::basic_string<T, 1>,
sprout::array<T, 1>
>::type type;
};
// unused | V -> container<V, 1>
template<typename T, typename U>
struct bitwise_or<
T,
U,
typename std::enable_if<
sprout::weed::detail::is_unused_and_elem<T, U>::value
>::type
> {
public:
typedef typename std::conditional<
sprout::weed::traits::is_char_type<U>::value,
sprout::basic_string<U, 1>,
sprout::array<U, 1>
>::type type;
};
// unused | unused -> unused
template<typename T, typename U>
struct bitwise_or<
T,
U,
typename std::enable_if<
sprout::weed::detail::is_both_unused<T, U>::value
>::type
> {
public:
typedef sprout::weed::unused type;
};
} // namespace result_of
} // namespace attr_cnv
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_ATTR_CNV_RESULT_OF_BITWISE_OR_HPP

View file

@ -0,0 +1,24 @@
#ifndef SPROUT_WEED_ATTR_CNV_RESULT_OF_MODULUS_HPP
#define SPROUT_WEED_ATTR_CNV_RESULT_OF_MODULUS_HPP
#include <cstddef>
#include <sprout/config.hpp>
#include <sprout/weed/attr_cnv/result_of/times.hpp>
namespace sprout {
namespace weed {
namespace attr_cnv {
namespace result_of {
//
// modulus
//
template<std::size_t Limit, typename T, typename = void>
struct modulus
: public sprout::weed::attr_cnv::result_of::times<Limit, T>
{};
} // namespace result_of
} // namespace attr_cnv
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_ATTR_CNV_RESULT_OF_MODULUS_HPP

View file

@ -0,0 +1,178 @@
#ifndef SPROUT_WEED_ATTR_CNV_RESULT_OF_SHIFT_LEFT_HPP
#define SPROUT_WEED_ATTR_CNV_RESULT_OF_SHIFT_LEFT_HPP
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/string.hpp>
#include <sprout/array.hpp>
#include <sprout/operation/fixed/append_back.hpp>
#include <sprout/operation/fixed/push_back.hpp>
#include <sprout/operation/fixed/push_front.hpp>
#include <sprout/tuple/operation/append_back.hpp>
#include <sprout/tuple/operation/push_back.hpp>
#include <sprout/tuple/operation/push_front.hpp>
#include <sprout/weed/unused.hpp>
#include <sprout/weed/traits/type/is_char_type.hpp>
#include <sprout/weed/detail/is_same_container.hpp>
#include <sprout/weed/detail/is_container_and_elem.hpp>
#include <sprout/weed/detail/is_elem_and_container.hpp>
#include <sprout/weed/detail/is_both_tuple.hpp>
#include <sprout/weed/detail/is_tuple_and_elem.hpp>
#include <sprout/weed/detail/is_elem_and_tuple.hpp>
#include <sprout/weed/detail/is_same_elem.hpp>
#include <sprout/weed/detail/is_different_elem.hpp>
#include <sprout/weed/detail/is_elem_and_unused.hpp>
#include <sprout/weed/detail/is_unused_and_elem.hpp>
#include <sprout/weed/detail/is_both_unused.hpp>
namespace sprout {
namespace weed {
namespace attr_cnv {
namespace result_of {
//
// shift_left
//
template<typename T, typename U, typename = void>
struct shift_left;
// container<V, N> >> container<V, M> -> container<V, N + M>
template<typename T, typename U>
struct shift_left<
T,
U,
typename std::enable_if<
sprout::weed::detail::is_same_container<T, U>::value
>::type
> {
public:
typedef typename sprout::fixed::result_of::append_back<T, U>::type type;
};
// container<V, N> >> V -> container<V, N + 1>
template<typename T, typename U>
struct shift_left<
T,
U,
typename std::enable_if<
sprout::weed::detail::is_container_and_elem<T, U>::value
>::type
> {
public:
typedef typename sprout::fixed::result_of::push_back<T, U>::type type;
};
// V >> container<V, N> -> container<V, N + 1>
template<typename T, typename U>
struct shift_left<
T,
U,
typename std::enable_if<
sprout::weed::detail::is_elem_and_container<T, U>::value
>::type
> {
public:
typedef typename sprout::fixed::result_of::push_front<T, U>::type type;
};
// tuple<Vs...> >> tuple<Ws...> -> tuple<Vs..., Ws...>
template<typename T, typename U>
struct shift_left<
T,
U,
typename std::enable_if<
sprout::weed::detail::is_both_tuple<T, U>::value
>::type
> {
public:
typedef typename sprout::tuples::result_of::append_back<T, U>::type type;
};
// tuple<Vs...> >> V -> tuple<Vs..., V>
template<typename T, typename U>
struct shift_left<
T,
U,
typename std::enable_if<
sprout::weed::detail::is_tuple_and_elem<T, U>::value
>::type
> {
public:
typedef typename sprout::tuples::result_of::push_back<T, U>::type type;
};
// V >> tuple<Vs...> -> tuple<V, Vs...>
template<typename T, typename U>
struct shift_left<
T,
U,
typename std::enable_if<
sprout::weed::detail::is_elem_and_tuple<T, U>::value
>::type
> {
public:
typedef typename sprout::tuples::result_of::push_front<T, U>::type type;
};
// V >> V -> container<V, 2>
template<typename T, typename U>
struct shift_left<
T,
U,
typename std::enable_if<
sprout::weed::detail::is_same_elem<T, U>::value
>::type
> {
public:
typedef typename std::conditional<
sprout::weed::traits::is_char_type<T>::value,
sprout::basic_string<T, 2>,
sprout::array<T, 2>
>::type type;
};
// V >> W -> tuple<V, W>
template<typename T, typename U>
struct shift_left<
T,
U,
typename std::enable_if<
sprout::weed::detail::is_different_elem<T, U>::value
>::type
> {
public:
typedef sprout::tuples::tuple<T, U> type;
};
// V >> unused -> V
template<typename T, typename U>
struct shift_left<
T,
U,
typename std::enable_if<
sprout::weed::detail::is_elem_and_unused<T, U>::value
>::type
> {
public:
typedef T type;
};
// unused >> V -> V
template<typename T, typename U>
struct shift_left<
T,
U,
typename std::enable_if<
sprout::weed::detail::is_unused_and_elem<T, U>::value
>::type
> {
public:
typedef U type;
};
// unused >> unused -> unused
template<typename T, typename U>
struct shift_left<
T,
U,
typename std::enable_if<
sprout::weed::detail::is_both_unused<T, U>::value
>::type
> {
public:
typedef sprout::weed::unused type;
};
} // namespace result_of
} // namespace attr_cnv
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_ATTR_CNV_RESULT_OF_SHIFT_LEFT_HPP

View file

@ -0,0 +1,74 @@
#ifndef SPROUT_WEED_ATTR_CNV_RESULT_OF_TIMES_HPP
#define SPROUT_WEED_ATTR_CNV_RESULT_OF_TIMES_HPP
#include <cstddef>
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/string.hpp>
#include <sprout/array.hpp>
#include <sprout/algorithm/string/join.hpp>
#include <sprout/weed/unused.hpp>
#include <sprout/weed/traits/type/is_char_type.hpp>
#include <sprout/weed/traits/type/is_container.hpp>
#include <sprout/weed/traits/type/is_unused.hpp>
namespace sprout {
namespace weed {
namespace attr_cnv {
namespace result_of {
//
// times
//
template<std::size_t Limit, typename T, typename = void>
struct times;
// times<N>(container<V, K>) -> container<V, N * K>
template<std::size_t Limit, typename T>
struct times<
Limit,
T,
typename std::enable_if<
Limit != std::size_t(-1)
&& sprout::weed::traits::is_container<T>::value
>::type
> {
public:
typedef typename sprout::algorithm::result_of::join<
sprout::array<T, Limit>
>::type type;
};
// times<N>(V) -> container<V, N>
template<std::size_t Limit, typename T>
struct times<
Limit,
T,
typename std::enable_if<
Limit != std::size_t(-1)
&& !sprout::weed::traits::is_container<T>::value
&& !sprout::weed::traits::is_unused<T>::value
>::type
> {
public:
typedef typename std::conditional<
sprout::weed::traits::is_char_type<T>::value,
sprout::basic_string<T, Limit>,
sprout::array<T, Limit>
>::type type;
};
// times<N>(unused) -> unused
template<std::size_t Limit, typename T>
struct times<
Limit,
T,
typename std::enable_if<
sprout::weed::traits::is_unused<T>::value
>::type
> {
public:
typedef sprout::weed::unused type;
};
} // namespace result_of
} // namespace attr_cnv
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_ATTR_CNV_RESULT_OF_TIMES_HPP

View file

@ -0,0 +1,125 @@
#ifndef SPROUT_WEED_ATTR_CNV_SHIFT_LEFT_HPP
#define SPROUT_WEED_ATTR_CNV_SHIFT_LEFT_HPP
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/operation/fixed/append_back.hpp>
#include <sprout/operation/fixed/push_back.hpp>
#include <sprout/operation/fixed/push_front.hpp>
#include <sprout/tuple/operation/append_back.hpp>
#include <sprout/tuple/operation/push_back.hpp>
#include <sprout/tuple/operation/push_front.hpp>
#include <sprout/weed/unused.hpp>
#include <sprout/weed/detail/is_same_container.hpp>
#include <sprout/weed/detail/is_container_and_elem.hpp>
#include <sprout/weed/detail/is_elem_and_container.hpp>
#include <sprout/weed/detail/is_both_tuple.hpp>
#include <sprout/weed/detail/is_tuple_and_elem.hpp>
#include <sprout/weed/detail/is_elem_and_tuple.hpp>
#include <sprout/weed/detail/is_same_elem.hpp>
#include <sprout/weed/detail/is_different_elem.hpp>
#include <sprout/weed/detail/is_elem_and_unused.hpp>
#include <sprout/weed/detail/is_unused_and_elem.hpp>
#include <sprout/weed/detail/is_both_unused.hpp>
#include <sprout/weed/attr_cnv/result_of/shift_left.hpp>
namespace sprout {
namespace weed {
namespace attr_cnv {
//
// shift_left
//
// container<V, N> >> container<V, M> -> container<V, N + M>
template<typename T, typename U>
SPROUT_CONSTEXPR inline typename std::enable_if<
sprout::weed::detail::is_same_container<T, U>::value,
typename sprout::weed::attr_cnv::result_of::shift_left<T, U>::type
>::type shift_left(T const& t, U const& u) {
return sprout::fixed::append_back(t, u);
}
// container<V, N> >> V -> container<V, N + 1>
template<typename T, typename U>
SPROUT_CONSTEXPR inline typename std::enable_if<
sprout::weed::detail::is_container_and_elem<T, U>::value,
typename sprout::weed::attr_cnv::result_of::shift_left<T, U>::type
>::type shift_left(T const& t, U const& u) {
return sprout::fixed::push_back(t, u);
}
// V >> container<V, N> -> container<V, N + 1>
template<typename T, typename U>
SPROUT_CONSTEXPR inline typename std::enable_if<
sprout::weed::detail::is_elem_and_container<T, U>::value,
typename sprout::weed::attr_cnv::result_of::shift_left<T, U>::type
>::type shift_left(T const& t, U const& u) {
return sprout::fixed::push_front(t, u);
}
// tuple<Vs...> >> tuple<Ws...> -> tuple<Vs..., Ws...>
template<typename T, typename U>
SPROUT_CONSTEXPR inline typename std::enable_if<
sprout::weed::detail::is_both_tuple<T, U>::value,
typename sprout::weed::attr_cnv::result_of::shift_left<T, U>::type
>::type shift_left(T const& t, U const& u) {
return sprout::tuples::append_back(t, u);
}
// tuple<Vs...> >> V -> tuple<Vs..., V>
template<typename T, typename U>
SPROUT_CONSTEXPR inline typename std::enable_if<
sprout::weed::detail::is_tuple_and_elem<T, U>::value,
typename sprout::weed::attr_cnv::result_of::shift_left<T, U>::type
>::type shift_left(T const& t, U const& u) {
return sprout::tuples::push_back(t, u);
}
// V >> tuple<Vs...> -> tuple<V, Vs...>
template<typename T, typename U>
SPROUT_CONSTEXPR inline typename std::enable_if<
sprout::weed::detail::is_elem_and_tuple<T, U>::value,
typename sprout::weed::attr_cnv::result_of::shift_left<T, U>::type
>::type shift_left(T const& t, U const& u) {
return sprout::tuples::push_front(t, u);
}
// V >> V -> container<V, 2>
template<typename T, typename U>
SPROUT_CONSTEXPR inline typename std::enable_if<
sprout::weed::detail::is_same_elem<T, U>::value,
typename sprout::weed::attr_cnv::result_of::shift_left<T, U>::type
>::type shift_left(T const& t, U const& u) {
typedef typename sprout::weed::attr_cnv::result_of::shift_left<T, U>::type type;
return sprout::make_clone<type>(t, u);
}
// V >> W -> tuple<V, W>
template<typename T, typename U>
SPROUT_CONSTEXPR inline typename std::enable_if<
sprout::weed::detail::is_different_elem<T, U>::value,
typename sprout::weed::attr_cnv::result_of::shift_left<T, U>::type
>::type shift_left(T const& t, U const& u) {
return typename sprout::weed::attr_cnv::result_of::shift_left<T, U>::type(t, u);
}
// V >> unused -> V
template<typename T, typename U>
SPROUT_CONSTEXPR inline typename std::enable_if<
sprout::weed::detail::is_elem_and_unused<T, U>::value,
typename sprout::weed::attr_cnv::result_of::shift_left<T, U>::type
>::type shift_left(T const& t, U const& u) {
return t;
}
// unused >> V -> V
template<typename T, typename U>
SPROUT_CONSTEXPR inline typename std::enable_if<
sprout::weed::detail::is_unused_and_elem<T, U>::value,
typename sprout::weed::attr_cnv::result_of::shift_left<T, U>::type
>::type shift_left(T const& t, U const& u) {
return u;
}
// unused >> unused -> unused
template<typename T, typename U>
SPROUT_CONSTEXPR inline typename std::enable_if<
sprout::weed::detail::is_both_unused<T, U>::value,
typename sprout::weed::attr_cnv::result_of::shift_left<T, U>::type
>::type shift_left(T const& t, U const& u) {
return sprout::weed::unused();
}
} // namespace attr_cnv
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_ATTR_CNV_SHIFT_LEFT_HPP

View file

@ -0,0 +1,53 @@
#ifndef SPROUT_WEED_ATTR_CNV_TIMES_HPP
#define SPROUT_WEED_ATTR_CNV_TIMES_HPP
#include <cstddef>
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/array.hpp>
#include <sprout/fixed_container/make_clone.hpp>
#include <sprout/algorithm/string/join.hpp>
#include <sprout/weed/unused.hpp>
#include <sprout/weed/traits/type/is_container.hpp>
#include <sprout/weed/traits/type/is_unused.hpp>
#include <sprout/weed/attr_cnv/result_of/times.hpp>
namespace sprout {
namespace weed {
namespace attr_cnv {
//
// times
//
// times<N>(container<V, K>) -> container<V, N * K>
template<std::size_t Limit, typename T, typename... Args>
static SPROUT_CONSTEXPR typename std::enable_if<
sprout::weed::traits::is_container<T>::value,
typename sprout::weed::attr_cnv::result_of::times<Limit, T>::type
>::type times(Args const&... args) {
return sprout::algorithm::join(
sprout::make_clone<sprout::array<T, Limit> >(args...)
);
}
// times<N>(V) -> container<V, N>
template<std::size_t Limit, typename T, typename... Args>
static SPROUT_CONSTEXPR typename std::enable_if<
!sprout::weed::traits::is_container<T>::value
&& !sprout::weed::traits::is_unused<T>::value,
typename sprout::weed::attr_cnv::result_of::times<Limit, T>::type
>::type times(Args const&... args) {
typedef typename sprout::weed::attr_cnv::result_of::times<Limit, T>::type type;
return sprout::make_clone<type>(args...);
}
// times<N>(unused) -> unused
template<std::size_t Limit, typename T, typename... Args>
static SPROUT_CONSTEXPR typename std::enable_if<
sprout::weed::traits::is_unused<T>::value,
typename sprout::weed::attr_cnv::result_of::times<Limit, T>::type
>::type times(Args const&... args) {
return sprout::weed::unused();
}
} // namespace attr_cnv
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_ATTR_CNV_TIMES_HPP

7
sprout/weed/context.hpp Normal file
View file

@ -0,0 +1,7 @@
#ifndef SPROUT_WEED_CONTEXT_HPP
#define SPROUT_WEED_CONTEXT_HPP
#include <sprout/config.hpp>
#include <sprout/weed/context/parse_context.hpp>
#endif // #ifndef SPROUT_WEED_CONTEXT_HPP

View file

@ -0,0 +1,9 @@
#ifndef SPROUT_WEED_CONTEXT_PARSE_CONTEXT_HPP
#define SPROUT_WEED_CONTEXT_PARSE_CONTEXT_HPP
#include <sprout/config.hpp>
#include <sprout/weed/context/parse_context_fwd.hpp>
#include <sprout/weed/context/parse_context/terminal.hpp>
#include <sprout/weed/context/parse_context/operator.hpp>
#endif // #ifndef SPROUT_WEED_CONTEXT_PARSE_CONTEXT_HPP

View file

@ -0,0 +1,13 @@
#ifndef SPROUT_WEED_CONTEXT_PARSE_CONTEXT_OPERATOR_HPP
#define SPROUT_WEED_CONTEXT_PARSE_CONTEXT_OPERATOR_HPP
#include <sprout/config.hpp>
#include <sprout/weed/context/parse_context/operator/unary_plus.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/bitwise_or.hpp>
#endif // #ifndef SPROUT_WEED_CONTEXT_PARSE_CONTEXT_OPERATOR_HPP

View 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

View 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

View 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

View 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

View 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

View 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

View 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

View file

@ -0,0 +1,9 @@
#ifndef SPROUT_WEED_CONTEXT_PARSE_CONTEXT_TERMINAL_HPP
#define SPROUT_WEED_CONTEXT_PARSE_CONTEXT_TERMINAL_HPP
#include <sprout/config.hpp>
#include <sprout/weed/context/parse_context/terminal/char_type.hpp>
#include <sprout/weed/context/parse_context/terminal/string.hpp>
#include <sprout/weed/context/parse_context/terminal/parser.hpp>
#endif // #ifndef SPROUT_WEED_CONTEXT_PARSE_CONTEXT_TERMINAL_HPP

View file

@ -0,0 +1,62 @@
#ifndef SPROUT_WEED_CONTEXT_PARSE_CONTEXT_TERMINAL_CHAR_TYPE_HPP
#define SPROUT_WEED_CONTEXT_PARSE_CONTEXT_TERMINAL_CHAR_TYPE_HPP
#include <iterator>
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/iterator/next.hpp>
#include <sprout/tuple/tuple.hpp>
#include <sprout/weed/eval_result.hpp>
#include <sprout/weed/expr/tag.hpp>
#include <sprout/weed/traits/type/is_char_type.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::terminal
>::value
&& sprout::weed::traits::is_char_type<
typename sprout::tuples::tuple_element<0, typename Expr::args_type>::type
>::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
{
typedef typename std::iterator_traits<Iterator>::value_type elem_type;
return ctx.begin() != ctx.end()
&& *ctx.begin() == elem_type(sprout::tuples::get<0>(expr.args()))
? result_type(
true,
sprout::next(ctx.begin()),
attribute_type(),
context_type(ctx, sprout::next(ctx.begin()))
)
: result_type(false, ctx.begin(), attribute_type(), ctx)
;
}
};
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_CONTEXT_PARSE_CONTEXT_TERMINAL_CHAR_TYPE_HPP

View file

@ -0,0 +1,68 @@
#ifndef SPROUT_WEED_CONTEXT_PARSE_CONTEXT_TERMINAL_PARSER_HPP
#define SPROUT_WEED_CONTEXT_PARSE_CONTEXT_TERMINAL_PARSER_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/traits/type/is_char_type.hpp>
#include <sprout/weed/traits/type/is_string.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::terminal
>::value
&& !sprout::weed::traits::is_char_type<
typename sprout::tuples::tuple_element<0, typename Expr::args_type>::type
>::value
&& !sprout::weed::traits::is_string<
typename sprout::tuples::tuple_element<0, typename Expr::args_type>::type
>::value
>::type
> {
private:
typedef sprout::weed::parse_context<Iterator> context_type;
typedef typename sprout::tuples::tuple_element<0, typename Expr::args_type>::type parser_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(
Result const& res,
context_type const& ctx
) const
{
return result_type(res, context_type(ctx, res.current()));
}
public:
SPROUT_CONSTEXPR result_type operator()(
Expr const& expr,
context_type const& ctx
) const
{
return call(
sprout::tuples::get<0>(expr.args())
.template operator()(ctx.begin(), ctx.end(), ctx),
ctx
);
}
};
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_CONTEXT_PARSE_CONTEXT_TERMINAL_PARSER_HPP

View file

@ -0,0 +1,75 @@
#ifndef SPROUT_WEED_CONTEXT_PARSE_CONTEXT_TERMINAL_STRING_HPP
#define SPROUT_WEED_CONTEXT_PARSE_CONTEXT_TERMINAL_STRING_HPP
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/fixed_container/begin.hpp>
#include <sprout/fixed_container/end.hpp>
#include <sprout/fixed_container/size.hpp>
#include <sprout/iterator/next.hpp>
#include <sprout/tuple/tuple.hpp>
#include <sprout/weed/eval_result.hpp>
#include <sprout/weed/expr/tag.hpp>
#include <sprout/weed/traits/type/is_string.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>
#include HDR_ALGORITHM_SSCRISK_CEL_OR_SPROUT_DETAIL
#include HDR_ITERATOR_SSCRISK_CEL_OR_SPROUT_DETAIL
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::terminal
>::value
&& sprout::weed::traits::is_string<
typename sprout::tuples::tuple_element<0, typename Expr::args_type>::type
>::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 Arg>
SPROUT_CONSTEXPR result_type call(
Arg const& arg,
context_type const& ctx
) const
{
return NS_SSCRISK_CEL_OR_SPROUT_DETAIL::distance(ctx.begin(), ctx.end()) >= sprout::size(arg)
&&NS_SSCRISK_CEL_OR_SPROUT_DETAIL::equal(sprout::begin(arg), sprout::end(arg), ctx.begin())
? result_type(
true,
sprout::next(ctx.begin(),
sprout::size(arg)),
attribute_type(),
context_type(ctx, sprout::next(ctx.begin(), sprout::size(arg)))
)
: result_type(false, ctx.begin(), attribute_type(), ctx)
;
}
public:
SPROUT_CONSTEXPR result_type operator()(
Expr const& expr,
context_type const& ctx
) const
{
return call(sprout::tuples::get<0>(expr.args()), ctx);
}
};
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_CONTEXT_PARSE_CONTEXT_TERMINAL_STRING_HPP

View file

@ -0,0 +1,41 @@
#ifndef SPROUT_WEED_CONTEXT_PARSE_CONTEXT_FWD_HPP
#define SPROUT_WEED_CONTEXT_PARSE_CONTEXT_FWD_HPP
#include <sprout/config.hpp>
namespace sprout {
namespace weed {
//
// parse_context
//
template<typename Iterator>
class parse_context {
public:
template<typename Expr, typename = void>
struct eval;
private:
Iterator first_;
Iterator last_;
public:
SPROUT_CONSTEXPR parse_context(Iterator first, Iterator last)
: first_(first)
, last_(last)
{}
SPROUT_CONSTEXPR parse_context(parse_context const& other, Iterator current)
: first_(current)
, last_(other.last_)
{}
SPROUT_CONSTEXPR Iterator begin() const {
return first_;
}
SPROUT_CONSTEXPR Iterator end() const {
return last_;
}
SPROUT_CONSTEXPR bool empty() const {
return first_ == last_;
}
};
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_CONTEXT_PARSE_CONTEXT_FWD_HPP

View file

@ -0,0 +1,22 @@
#ifndef SPROUT_WEED_DETAIL_C_STR_AS_STRING_HPP
#define SPROUT_WEED_DETAIL_C_STR_AS_STRING_HPP
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/string.hpp>
namespace sprout {
namespace weed {
namespace detail {
template<typename T>
struct c_str_as_string;
template<typename T, std::size_t N>
struct c_str_as_string<T const[N]> {
public:
typedef sprout::basic_string<T, N - 1> type;
};
} // namespace detail
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_DETAIL_C_STR_AS_STRING_HPP

View file

@ -0,0 +1,30 @@
#ifndef SPROUT_WEED_DETAIL_IS_BOTH_TUPLE_HPP
#define SPROUT_WEED_DETAIL_IS_BOTH_TUPLE_HPP
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/weed/traits/type/is_tuple.hpp>
namespace sprout {
namespace weed {
namespace detail {
template<typename T, typename U, typename = void>
struct is_both_tuple
: public std::false_type
{};
template<typename T, typename U>
struct is_both_tuple<
T,
U,
typename std::enable_if<
sprout::weed::traits::is_tuple<T>::value
&& sprout::weed::traits::is_tuple<U>::value
>::type
>
: public std::true_type
{};
} // namespace detail
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_DETAIL_IS_BOTH_TUPLE_HPP

View file

@ -0,0 +1,30 @@
#ifndef SPROUT_WEED_DETAIL_IS_BOTH_UNUSED_HPP
#define SPROUT_WEED_DETAIL_IS_BOTH_UNUSED_HPP
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/weed/traits/type/is_unused.hpp>
namespace sprout {
namespace weed {
namespace detail {
template<typename T, typename U, typename = void>
struct is_both_unused
: public std::false_type
{};
template<typename T, typename U>
struct is_both_unused<
T,
U,
typename std::enable_if<
sprout::weed::traits::is_unused<T>::value
&& sprout::weed::traits::is_unused<U>::value
>::type
>
: public std::true_type
{};
} // namespace detail
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_DETAIL_IS_BOTH_UNUSED_HPP

View file

@ -0,0 +1,33 @@
#ifndef SPROUT_WEED_DETAIL_IS_CONTAINER_AND_ELEM_HPP
#define SPROUT_WEED_DETAIL_IS_CONTAINER_AND_ELEM_HPP
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/weed/traits/type/is_container.hpp>
namespace sprout {
namespace weed {
namespace detail {
template<typename T, typename U, typename = void>
struct is_container_and_elem
: public std::false_type
{};
template<typename T, typename U>
struct is_container_and_elem<
T,
U,
typename std::enable_if<
sprout::weed::traits::is_container<T>::value
&& std::is_same<
typename T::value_type,
U
>::value
>::type
>
: public std::true_type
{};
} // namespace detail
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_DETAIL_IS_CONTAINER_AND_ELEM_HPP

View file

@ -0,0 +1,43 @@
#ifndef SPROUT_WEED_DETAIL_IS_DIFFERENT_ELEM_HPP
#define SPROUT_WEED_DETAIL_IS_DIFFERENT_ELEM_HPP
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/weed/traits/type/is_unused.hpp>
#include <sprout/weed/detail/is_same_container.hpp>
#include <sprout/weed/detail/is_container_and_elem.hpp>
#include <sprout/weed/detail/is_elem_and_container.hpp>
#include <sprout/weed/detail/is_both_tuple.hpp>
#include <sprout/weed/detail/is_tuple_and_elem.hpp>
#include <sprout/weed/detail/is_elem_and_tuple.hpp>
namespace sprout {
namespace weed {
namespace detail {
template<typename T, typename U, typename = void>
struct is_different_elem
: public std::false_type
{};
template<typename T, typename U>
struct is_different_elem<
T,
U,
typename std::enable_if<
!std::is_same<T, U>::value
&& !is_same_container<T, U>::value
&& !is_container_and_elem<T, U>::value
&& !is_elem_and_container<T, U>::value
&& !is_both_tuple<T, U>::value
&& !is_tuple_and_elem<T, U>::value
&& !is_elem_and_tuple<T, U>::value
&& !sprout::weed::traits::is_unused<T>::value
&& !sprout::weed::traits::is_unused<U>::value
>::type
>
: public std::true_type
{};
} // namespace detail
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_DETAIL_IS_DIFFERENT_ELEM_HPP

View file

@ -0,0 +1,33 @@
#ifndef SPROUT_WEED_DETAIL_IS_ELEM_AND_CONTAINER_HPP
#define SPROUT_WEED_DETAIL_IS_ELEM_AND_CONTAINER_HPP
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/weed/traits/type/is_container.hpp>
namespace sprout {
namespace weed {
namespace detail {
template<typename T, typename U, typename = void>
struct is_elem_and_container
: public std::false_type
{};
template<typename T, typename U>
struct is_elem_and_container<
T,
U,
typename std::enable_if<
sprout::weed::traits::is_container<U>::value
&& std::is_same<
typename U::value_type,
T
>::value
>::type
>
: public std::true_type
{};
} // namespace detail
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_DETAIL_IS_ELEM_AND_CONTAINER_HPP

View file

@ -0,0 +1,32 @@
#ifndef SPROUT_WEED_DETAIL_IS_ELEM_AND_TUPLE_HPP
#define SPROUT_WEED_DETAIL_IS_ELEM_AND_TUPLE_HPP
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/weed/traits/type/is_tuple.hpp>
#include <sprout/weed/traits/type/is_unused.hpp>
namespace sprout {
namespace weed {
namespace detail {
template<typename T, typename U, typename = void>
struct is_elem_and_tuple
: public std::false_type
{};
template<typename T, typename U>
struct is_elem_and_tuple<
T,
U,
typename std::enable_if<
!sprout::weed::traits::is_tuple<T>::value
&& !sprout::weed::traits::is_unused<T>::value
&& sprout::weed::traits::is_tuple<U>::value
>::type
>
: public std::true_type
{};
} // namespace detail
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_DETAIL_IS_ELEM_AND_TUPLE_HPP

View file

@ -0,0 +1,30 @@
#ifndef SPROUT_WEED_DETAIL_IS_ELEM_AND_UNUSED_HPP
#define SPROUT_WEED_DETAIL_IS_ELEM_AND_UNUSED_HPP
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/weed/traits/type/is_unused.hpp>
namespace sprout {
namespace weed {
namespace detail {
template<typename T, typename U, typename = void>
struct is_elem_and_unused
: public std::false_type
{};
template<typename T, typename U>
struct is_elem_and_unused<
T,
U,
typename std::enable_if<
!sprout::weed::traits::is_unused<T>::value
&& sprout::weed::traits::is_unused<U>::value
>::type
>
: public std::true_type
{};
} // namespace detail
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_DETAIL_IS_ELEM_AND_UNUSED_HPP

View file

@ -0,0 +1,34 @@
#ifndef SPROUT_WEED_DETAIL_IS_SAME_CONTAINER_HPP
#define SPROUT_WEED_DETAIL_IS_SAME_CONTAINER_HPP
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/weed/traits/type/is_container.hpp>
namespace sprout {
namespace weed {
namespace detail {
template<typename T, typename U, typename = void>
struct is_same_container
: public std::false_type
{};
template<typename T, typename U>
struct is_same_container<
T,
U,
typename std::enable_if<
sprout::weed::traits::is_container<T>::value
&& sprout::weed::traits::is_container<U>::value
&& std::is_same<
typename T::value_type,
typename U::value_type
>::value
>::type
>
: public std::true_type
{};
} // namespace detail
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_DETAIL_IS_SAME_CONTAINER_HPP

View file

@ -0,0 +1,43 @@
#ifndef SPROUT_WEED_DETAIL_IS_SAME_ELEM_HPP
#define SPROUT_WEED_DETAIL_IS_SAME_ELEM_HPP
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/weed/traits/type/is_unused.hpp>
#include <sprout/weed/detail/is_same_container.hpp>
#include <sprout/weed/detail/is_container_and_elem.hpp>
#include <sprout/weed/detail/is_elem_and_container.hpp>
#include <sprout/weed/detail/is_both_tuple.hpp>
#include <sprout/weed/detail/is_tuple_and_elem.hpp>
#include <sprout/weed/detail/is_elem_and_tuple.hpp>
namespace sprout {
namespace weed {
namespace detail {
template<typename T, typename U, typename = void>
struct is_same_elem
: public std::false_type
{};
template<typename T, typename U>
struct is_same_elem<
T,
U,
typename std::enable_if<
std::is_same<T, U>::value
&& !is_same_container<T, U>::value
&& !is_container_and_elem<T, U>::value
&& !is_elem_and_container<T, U>::value
&& !is_both_tuple<T, U>::value
&& !is_tuple_and_elem<T, U>::value
&& !is_elem_and_tuple<T, U>::value
&& !sprout::weed::traits::is_unused<T>::value
&& !sprout::weed::traits::is_unused<U>::value
>::type
>
: public std::true_type
{};
} // namespace detail
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_DETAIL_IS_SAME_ELEM_HPP

View file

@ -0,0 +1,32 @@
#ifndef SPROUT_WEED_DETAIL_IS_TUPLE_AND_ELEM_HPP
#define SPROUT_WEED_DETAIL_IS_TUPLE_AND_ELEM_HPP
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/weed/traits/type/is_tuple.hpp>
#include <sprout/weed/traits/type/is_unused.hpp>
namespace sprout {
namespace weed {
namespace detail {
template<typename T, typename U, typename = void>
struct is_tuple_and_elem
: public std::false_type
{};
template<typename T, typename U>
struct is_tuple_and_elem<
T,
U,
typename std::enable_if<
sprout::weed::traits::is_tuple<T>::value
&& !sprout::weed::traits::is_tuple<U>::value
&& !sprout::weed::traits::is_unused<U>::value
>::type
>
: public std::true_type
{};
} // namespace detail
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_DETAIL_IS_TUPLE_AND_ELEM_HPP

View file

@ -0,0 +1,30 @@
#ifndef SPROUT_WEED_DETAIL_IS_UNUSED_AND_ELEM_HPP
#define SPROUT_WEED_DETAIL_IS_UNUSED_AND_ELEM_HPP
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/weed/traits/type/is_unused.hpp>
namespace sprout {
namespace weed {
namespace detail {
template<typename T, typename U, typename = void>
struct is_unused_and_elem
: public std::false_type
{};
template<typename T, typename U>
struct is_unused_and_elem<
T,
U,
typename std::enable_if<
sprout::weed::traits::is_unused<T>::value
&& !sprout::weed::traits::is_unused<U>::value
>::type
>
: public std::true_type
{};
} // namespace detail
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_DETAIL_IS_UNUSED_AND_ELEM_HPP

View file

@ -0,0 +1,23 @@
#ifndef SPROUT_WEED_DETAIL_UNCVREF_HPP
#define SPROUT_WEED_DETAIL_UNCVREF_HPP
#include <type_traits>
#include <sprout/config.hpp>
namespace sprout {
namespace weed {
namespace detail {
template<typename T>
struct uncvref
: public std::conditional<
std::is_array<T>::value
|| std::is_array<typename std::remove_reference<T>::type>::value,
typename std::remove_reference<T>::type,
typename std::decay<T>::type
>
{};
} // namespace detail
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_DETAIL_UNCVREF_HPP

View file

@ -0,0 +1,86 @@
#ifndef SPROUT_WEED_DETAIL_XDIGITS_HPP
#define SPROUT_WEED_DETAIL_XDIGITS_HPP
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/string.hpp>
#include <sprout/array.hpp>
#include <sprout/tuple/tuple.hpp>
namespace sprout {
namespace weed {
namespace detail {
template<typename Elem>
struct xdigits;
template<>
struct xdigits<char> {
public:
SPROUT_STATIC_CONSTEXPR sprout::basic_string<char, 22> table = sprout::to_string("0123456789abcdefABCDEF");
};
SPROUT_CONSTEXPR sprout::basic_string<char, 22> sprout::weed::detail::xdigits<char>::table;
template<>
struct xdigits<wchar_t> {
public:
SPROUT_STATIC_CONSTEXPR sprout::basic_string<wchar_t, 22> table = sprout::to_string(L"0123456789abcdefABCDEF");
};
SPROUT_CONSTEXPR sprout::basic_string<wchar_t, 22> sprout::weed::detail::xdigits<wchar_t>::table;
template<>
struct xdigits<char16_t> {
public:
SPROUT_STATIC_CONSTEXPR sprout::basic_string<char16_t, 22> table = sprout::to_string(u"0123456789abcdefABCDEF");
};
SPROUT_CONSTEXPR sprout::basic_string<char16_t, 22> sprout::weed::detail::xdigits<char16_t>::table;
template<>
struct xdigits<char32_t> {
public:
SPROUT_STATIC_CONSTEXPR sprout::basic_string<char32_t, 22> table = sprout::to_string(U"0123456789abcdefABCDEF");
};
SPROUT_CONSTEXPR sprout::basic_string<char32_t, 22> sprout::weed::detail::xdigits<char32_t>::table;
template<typename Dummy>
struct xvalues;
template<>
struct xvalues<void> {
public:
SPROUT_STATIC_CONSTEXPR sprout::array<std::uint8_t, 22> table = sprout::array<std::uint8_t, 22>{
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 10, 11, 12, 13, 14, 15}
};
};
SPROUT_CONSTEXPR sprout::array<std::uint8_t, 22> sprout::weed::detail::xvalues<void>::table;
template<typename IntType>
SPROUT_CONSTEXPR sprout::tuples::tuple<IntType, bool> xvalue_at(std::size_t i) {
return i < 22
? sprout::tuples::tuple<IntType, bool>(
static_cast<IntType>(sprout::weed::detail::xvalues<void>::table[i]),
true
)
: sprout::tuples::tuple<IntType, bool>(
IntType(),
false
)
;
}
template<typename IntType, typename Elem>
SPROUT_CONSTEXPR sprout::tuples::tuple<IntType, bool> from_xdigit(Elem c) {
return sprout::weed::detail::xvalue_at<IntType>(
NS_SSCRISK_CEL_OR_SPROUT_DETAIL::distance(
sprout::weed::detail::xdigits<Elem>::table.begin(),
NS_SSCRISK_CEL_OR_SPROUT_DETAIL::find(
sprout::weed::detail::xdigits<Elem>::table.begin(),
sprout::weed::detail::xdigits<Elem>::table.end(),
c
)
)
);
}
} // namespace detail
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_DETAIL_XDIGITS_HPP

View file

@ -0,0 +1,56 @@
#ifndef SPROUT_WEED_EVAL_RESULT_HPP
#define SPROUT_WEED_EVAL_RESULT_HPP
#include <sprout/config.hpp>
#include <sprout/weed/parser_result.hpp>
namespace sprout {
namespace weed {
//
// eval_result
//
template<typename Context, typename Iterator, typename Attribute>
class eval_result {
public:
typedef sprout::weed::parser_result<Iterator, Attribute> presult_type;
private:
presult_type presult_;
Context ctx_;
public:
eval_result() = default;
SPROUT_CONSTEXPR eval_result(
bool success,
Iterator current,
Attribute const& attr,
Context const& ctx
)
: presult_(success, current, attr)
, ctx_(ctx)
{}
SPROUT_CONSTEXPR eval_result(
presult_type const& presult,
Context const& ctx
)
: presult_(presult)
, ctx_(ctx)
{}
SPROUT_CONSTEXPR presult_type const& presult() const {
return presult_;
}
SPROUT_CONSTEXPR bool success() const {
return presult_.success();
}
SPROUT_CONSTEXPR Iterator current() const {
return presult_.current();
}
SPROUT_CONSTEXPR Attribute const& attr() const {
return presult_.attr();
}
SPROUT_CONSTEXPR Context const& ctx() const {
return ctx_;
}
};
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_EVAL_RESULT_HPP

12
sprout/weed/expr.hpp Normal file
View file

@ -0,0 +1,12 @@
#ifndef SPROUT_WEED_EXPR_HPP
#define SPROUT_WEED_EXPR_HPP
#include <sprout/config.hpp>
#include <sprout/weed/expr/tag.hpp>
#include <sprout/weed/expr/expr.hpp>
#include <sprout/weed/expr/make_terminal.hpp>
#include <sprout/weed/expr/make_terminal_or_expr.hpp>
#include <sprout/weed/expr/make_expr.hpp>
#include <sprout/weed/expr/eval.hpp>
#endif // #ifndef SPROUT_WEED_EXPR_HPP

32
sprout/weed/expr/eval.hpp Normal file
View file

@ -0,0 +1,32 @@
#ifndef SPROUT_WEED_EXPR_EVAL_HPP
#define SPROUT_WEED_EXPR_EVAL_HPP
#include <sprout/config.hpp>
#include <sprout/weed/expr/make_terminal_or_expr.hpp>
#include <sprout/weed/traits/expr/terminal_or_expr_of.hpp>
namespace sprout {
namespace weed {
//
// eval
//
template<typename Expr, typename Context>
SPROUT_CONSTEXPR inline typename Context::template eval<
typename sprout::weed::traits::terminal_or_expr_of<Expr>::type
>::result_type eval(
Expr const& expr,
Context const& ctx
)
{
typedef typename Context::template eval<
typename sprout::weed::traits::terminal_or_expr_of<Expr>::type
> eval_type;
return eval_type()(
sprout::weed::make_terminal_or_expr(expr),
ctx
);
}
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_EXPR_EVAL_HPP

32
sprout/weed/expr/expr.hpp Normal file
View file

@ -0,0 +1,32 @@
#ifndef SPROUT_WEED_EXPR_EXPR_HPP
#define SPROUT_WEED_EXPR_EXPR_HPP
#include <sprout/config.hpp>
#include <sprout/tuple/tuple.hpp>
#include <sprout/utility/forward.hpp>
namespace sprout {
namespace weed {
//
// expr
//
template<typename Tag, typename... Args>
class expr {
public:
typedef Tag expr_tag;
typedef sprout::tuples::tuple<Args...> args_type;
private:
args_type args_;
public:
template<typename... As>
SPROUT_CONSTEXPR explicit expr(As&&... args)
: args_(sprout::forward<As>(args)...)
{}
SPROUT_CONSTEXPR args_type const& args() const {
return args_;
}
};
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_EXPR_EXPR_HPP

View file

@ -0,0 +1,25 @@
#ifndef SPROUT_WEED_EXPR_MAKE_EXPR_HPP
#define SPROUT_WEED_EXPR_MAKE_EXPR_HPP
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/utility/forward.hpp>
#include <sprout/weed/expr/make_terminal_or_expr.hpp>
#include <sprout/weed/traits/expr/expr_of.hpp>
namespace sprout {
namespace weed {
//
// make_expr
//
template<typename Tag, typename... Args>
SPROUT_CONSTEXPR inline typename sprout::weed::traits::expr_of<Tag, Args...>::type
make_expr(Args&&... args) {
return typename sprout::weed::traits::expr_of<Tag, Args...>::type(
sprout::weed::make_terminal_or_expr(sprout::forward<Args>(args))...
);
}
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_EXPR_MAKE_EXPR_HPP

View file

@ -0,0 +1,42 @@
#ifndef SPROUT_WEED_EXPR_MAKE_TERMINAL_HPP
#define SPROUT_WEED_EXPR_MAKE_TERMINAL_HPP
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/string.hpp>
#include <sprout/utility/forward.hpp>
#include <sprout/weed/traits/type/is_c_str.hpp>
#include <sprout/weed/traits/expr/terminal_of.hpp>
#include <sprout/weed/detail/uncvref.hpp>
namespace sprout {
namespace weed {
//
// make_terminal
//
template<typename Arg>
SPROUT_CONSTEXPR inline typename std::enable_if<
!sprout::weed::traits::is_c_str<
typename sprout::weed::detail::uncvref<Arg>::type
>::value,
typename sprout::weed::traits::terminal_of<Arg>::type
>::type make_terminal(Arg&& arg) {
return typename sprout::weed::traits::terminal_of<Arg>::type(
sprout::forward<Arg>(arg)
);
}
template<typename Arg>
SPROUT_CONSTEXPR inline typename std::enable_if<
sprout::weed::traits::is_c_str<
typename sprout::weed::detail::uncvref<Arg>::type
>::value,
typename sprout::weed::traits::terminal_of<Arg>::type
>::type make_terminal(Arg&& arg) {
return typename sprout::weed::traits::terminal_of<Arg>::type(
sprout::to_string(sprout::forward<Arg>(arg))
);
}
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_EXPR_MAKE_TERMINAL_HPP

View file

@ -0,0 +1,38 @@
#ifndef SPROUT_WEED_EXPR_MAKE_TERMINAL_OR_EXPR_HPP
#define SPROUT_WEED_EXPR_MAKE_TERMINAL_OR_EXPR_HPP
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/utility/forward.hpp>
#include <sprout/weed/expr/make_terminal.hpp>
#include <sprout/weed/traits/expr/is_expr.hpp>
#include <sprout/weed/traits/expr/terminal_or_expr_of.hpp>
#include <sprout/weed/detail/uncvref.hpp>
namespace sprout {
namespace weed {
//
// make_terminal_or_expr
//
template<typename Arg>
SPROUT_CONSTEXPR inline typename std::enable_if<
sprout::weed::traits::is_expr<
typename sprout::weed::detail::uncvref<Arg>::type
>::value,
typename sprout::weed::traits::terminal_or_expr_of<Arg>::type
>::type make_terminal_or_expr(Arg&& arg) {
return sprout::forward<Arg>(arg);
}
template<typename Arg>
SPROUT_CONSTEXPR inline typename std::enable_if<
!sprout::weed::traits::is_expr<
typename sprout::weed::detail::uncvref<Arg>::type
>::value,
typename sprout::weed::traits::terminal_or_expr_of<Arg>::type
>::type make_terminal_or_expr(Arg&& arg) {
return sprout::weed::make_terminal(sprout::forward<Arg>(arg));
}
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_EXPR_MAKE_TERMINAL_OR_EXPR_HPP

21
sprout/weed/expr/tag.hpp Normal file
View file

@ -0,0 +1,21 @@
#ifndef SPROUT_WEED_EXPR_TAG_HPP
#define SPROUT_WEED_EXPR_TAG_HPP
#include <sprout/config.hpp>
namespace sprout {
namespace weed {
namespace tag {
struct terminal {};
struct unary_plus {};
struct dereference {};
struct address_of {};
struct logical_not {};
struct shift_left {};
struct modulus {};
struct bitwise_or {};
} // namespace tag
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_EXPR_TAG_HPP

22
sprout/weed/limited.hpp Normal file
View file

@ -0,0 +1,22 @@
#ifndef SPROUT_WEED_LIMITED_HPP
#define SPROUT_WEED_LIMITED_HPP
#include <sprout/config.hpp>
namespace sprout {
namespace weed {
//
// limited
//
struct limited {
public:
enum category {
discard,
circular,
stopover
};
};
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_LIMITED_HPP

13
sprout/weed/operator.hpp Normal file
View file

@ -0,0 +1,13 @@
#ifndef SPROUT_WEED_OPERATOR_HPP
#define SPROUT_WEED_OPERATOR_HPP
#include <sprout/config.hpp>
#include <sprout/weed/operator/unary_plus.hpp>
#include <sprout/weed/operator/dereference.hpp>
#include <sprout/weed/operator/address_of.hpp>
#include <sprout/weed/operator/logical_not.hpp>
#include <sprout/weed/operator/shift_left.hpp>
#include <sprout/weed/operator/modulus.hpp>
#include <sprout/weed/operator/bitwise_or.hpp>
#endif // #ifndef SPROUT_WEED_OPERATOR_HPP

View file

@ -0,0 +1,37 @@
#ifndef SPROUT_WEED_OPERATOR_ADDRESS_OF_HPP
#define SPROUT_WEED_OPERATOR_ADDRESS_OF_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 Arg,
typename = typename std::enable_if<
sprout::weed::traits::is_parser<
typename sprout::weed::detail::uncvref<Arg>::type
>::value
>::type
>
SPROUT_CONSTEXPR inline typename sprout::weed::traits::expr_of<
sprout::weed::tag::address_of,
Arg
>::type operator!(Arg&& arg) {
return sprout::weed::make_expr<sprout::weed::tag::address_of>(
sprout::forward<Arg>(arg)
);
}
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_OPERATOR_ADDRESS_OF_HPP

View file

@ -0,0 +1,43 @@
#ifndef SPROUT_WEED_OPERATOR_BITWISE_OR_HPP
#define SPROUT_WEED_OPERATOR_BITWISE_OR_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
&& sprout::weed::traits::is_parser<
typename sprout::weed::detail::uncvref<Arg2>::type
>::value
>::type
>
SPROUT_CONSTEXPR inline typename sprout::weed::traits::expr_of<
sprout::weed::tag::bitwise_or,
Arg1,
Arg2
>::type operator|(Arg1&& arg1, Arg2&& arg2) {
return sprout::weed::make_expr<sprout::weed::tag::bitwise_or>(
sprout::forward<Arg1>(arg1),
sprout::forward<Arg2>(arg2)
);
}
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_OPERATOR_BITWISE_OR_HPP

View file

@ -0,0 +1,37 @@
#ifndef SPROUT_WEED_OPERATOR_DEREFERENCE_HPP
#define SPROUT_WEED_OPERATOR_DEREFERENCE_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 Arg,
typename = typename std::enable_if<
sprout::weed::traits::is_parser<
typename sprout::weed::detail::uncvref<Arg>::type
>::value
>::type
>
SPROUT_CONSTEXPR inline typename sprout::weed::traits::expr_of<
sprout::weed::tag::dereference,
Arg
>::type operator*(Arg&& arg) {
return sprout::weed::make_expr<sprout::weed::tag::dereference>(
sprout::forward<Arg>(arg)
);
}
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_OPERATOR_DEREFERENCE_HPP

View file

@ -0,0 +1,37 @@
#ifndef SPROUT_WEED_OPERATOR_LOGICAL_NOT_HPP
#define SPROUT_WEED_OPERATOR_LOGICAL_NOT_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 Arg,
typename = typename std::enable_if<
sprout::weed::traits::is_parser<
typename sprout::weed::detail::uncvref<Arg>::type
>::value
>::type
>
SPROUT_CONSTEXPR inline typename sprout::weed::traits::expr_of<
sprout::weed::tag::logical_not,
Arg
>::type operator!(Arg&& arg) {
return sprout::weed::make_expr<sprout::weed::tag::logical_not>(
sprout::forward<Arg>(arg)
);
}
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_OPERATOR_LOGICAL_NOT_HPP

View file

@ -0,0 +1,43 @@
#ifndef SPROUT_WEED_OPERATOR_MODULUS_HPP
#define SPROUT_WEED_OPERATOR_MODULUS_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
&& sprout::weed::traits::is_parser<
typename sprout::weed::detail::uncvref<Arg2>::type
>::value
>::type
>
SPROUT_CONSTEXPR inline typename sprout::weed::traits::expr_of<
sprout::weed::tag::modulus,
Arg1,
Arg2
>::type operator%(Arg1&& arg1, Arg2&& arg2) {
return sprout::weed::make_expr<sprout::weed::tag::modulus>(
sprout::forward<Arg1>(arg1),
sprout::forward<Arg2>(arg2)
);
}
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_OPERATOR_MODULUS_HPP

View file

@ -0,0 +1,43 @@
#ifndef SPROUT_WEED_OPERATOR_SHIFT_LEFT_HPP
#define SPROUT_WEED_OPERATOR_SHIFT_LEFT_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
&& sprout::weed::traits::is_parser<
typename sprout::weed::detail::uncvref<Arg2>::type
>::value
>::type
>
SPROUT_CONSTEXPR inline typename sprout::weed::traits::expr_of<
sprout::weed::tag::shift_left,
Arg1,
Arg2
>::type operator>>(Arg1&& arg1, Arg2&& arg2) {
return sprout::weed::make_expr<sprout::weed::tag::shift_left>(
sprout::forward<Arg1>(arg1),
sprout::forward<Arg2>(arg2)
);
}
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_OPERATOR_SHIFT_LEFT_HPP

View file

@ -0,0 +1,37 @@
#ifndef SPROUT_WEED_OPERATOR_UNARY_PLUS_HPP
#define SPROUT_WEED_OPERATOR_UNARY_PLUS_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 Arg,
typename = typename std::enable_if<
sprout::weed::traits::is_parser<
typename sprout::weed::detail::uncvref<Arg>::type
>::value
>::type
>
SPROUT_CONSTEXPR inline typename sprout::weed::traits::expr_of<
sprout::weed::tag::unary_plus,
Arg
>::type operator+(Arg&& arg) {
return sprout::weed::make_expr<sprout::weed::tag::unary_plus>(
sprout::forward<Arg>(arg)
);
}
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_OPERATOR_UNARY_PLUS_HPP

32
sprout/weed/parse.hpp Normal file
View file

@ -0,0 +1,32 @@
#ifndef SPROUT_WEED_PARSE_HPP
#define SPROUT_WEED_PARSE_HPP
#include <sprout/config.hpp>
#include <sprout/weed/expr/make_terminal_or_expr.hpp>
#include <sprout/weed/context/parse_context.hpp>
#include <sprout/weed/traits/expr/terminal_or_expr_of.hpp>
namespace sprout {
namespace weed {
//
// parse
//
template<typename Iterator, typename Parser>
SPROUT_CONSTEXPR inline typename sprout::weed::parse_context<Iterator>::template eval<
typename sprout::weed::traits::terminal_or_expr_of<Parser>::type
>::result_type::presult_type parse(
Iterator first,
Iterator last,
Parser const& parser
)
{
return sprout::weed::eval(
sprout::weed::make_terminal_or_expr(parser),
sprout::weed::parse_context<Iterator>(first, last)
).presult()
;
}
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_PARSE_HPP

14
sprout/weed/parser.hpp Normal file
View file

@ -0,0 +1,14 @@
#ifndef SPROUT_WEED_PARSER_HPP
#define SPROUT_WEED_PARSER_HPP
#include <sprout/config.hpp>
#include <sprout/weed/parser/parser_base.hpp>
#include <sprout/weed/parser/lit.hpp>
#include <sprout/weed/parser/lim.hpp>
#include <sprout/weed/parser/char.hpp>
#include <sprout/weed/parser/string.hpp>
#include <sprout/weed/parser/numeric.hpp>
#include <sprout/weed/parser/auxiliary.hpp>
#include <sprout/weed/parser/directive.hpp>
#endif // #ifndef SPROUT_WEED_PARSER_HPP

View file

@ -0,0 +1,9 @@
#ifndef SPROUT_WEED_PARSER_AUXILIARY_HPP
#define SPROUT_WEED_PARSER_AUXILIARY_HPP
#include <sprout/config.hpp>
#include <sprout/weed/parser/auxiliary/eol.hpp>
#include <sprout/weed/parser/auxiliary/eoi.hpp>
#include <sprout/weed/parser/auxiliary/eps.hpp>
#endif // #ifndef SPROUT_WEED_PARSER_AUXILIARY_HPP

View file

@ -0,0 +1,49 @@
#ifndef SPROUT_WEED_PARSER_AUXILIARY_EOI_HPP
#define SPROUT_WEED_PARSER_AUXILIARY_EOI_HPP
#include <cstddef>
#include <sprout/config.hpp>
#include <sprout/weed/unused.hpp>
#include <sprout/weed/parser_result.hpp>
#include <sprout/weed/parser/parser_base.hpp>
namespace sprout {
namespace weed {
//
// eoi_p
//
struct eoi_p
: public sprout::weed::parser_base
{
public:
template<typename Context, typename Iterator>
struct attribute {
public:
typedef sprout::weed::unused type;
};
template<typename Context, typename Iterator>
struct result {
public:
typedef sprout::weed::parser_result<Iterator, typename attribute<Context, Iterator>::type> type;
};
public:
template<typename Context, typename Iterator>
SPROUT_CONSTEXPR typename result<Context, Iterator>::type operator()(
Iterator first,
Iterator last,
Context const&
) const
{
typedef typename result<Context, Iterator>::type result_type;
typedef typename attribute<Context, Iterator>::type attribute_type;
return result_type(first == last, first, attribute_type());
}
};
//
// eoi
//
SPROUT_STATIC_CONSTEXPR sprout::weed::eoi_p eoi = sprout::weed::eoi_p();
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_PARSER_AUXILIARY_EOI_HPP

View file

@ -0,0 +1,62 @@
#ifndef SPROUT_WEED_PARSER_AUXILIARY_EOL_HPP
#define SPROUT_WEED_PARSER_AUXILIARY_EOL_HPP
#include <cstddef>
#include <sprout/config.hpp>
#include <sprout/iterator/next.hpp>
#include <sprout/weed/unused.hpp>
#include <sprout/weed/parser_result.hpp>
#include <sprout/weed/parser/parser_base.hpp>
namespace sprout {
namespace weed {
//
// eol_p
//
struct eol_p
: public sprout::weed::parser_base
{
public:
template<typename Context, typename Iterator>
struct attribute {
public:
typedef sprout::weed::unused type;
};
template<typename Context, typename Iterator>
struct result {
public:
typedef sprout::weed::parser_result<Iterator, typename attribute<Context, Iterator>::type> type;
};
public:
template<typename Context, typename Iterator>
SPROUT_CONSTEXPR typename result<Context, Iterator>::type operator()(
Iterator first,
Iterator last,
Context const&
) const
{
typedef typename result<Context, Iterator>::type result_type;
typedef typename attribute<Context, Iterator>::type attribute_type;
typedef typename std::iterator_traits<Iterator>::value_type elem_type;
return first != last
? *first == elem_type('\r')
? sprout::next(first) != last
? *sprout::next(first) == elem_type('\n')
? result_type(true, sprout::next(sprout::next(first)), attribute_type())
: result_type(true, sprout::next(first), attribute_type())
: result_type(true, sprout::next(first), attribute_type())
: *first == elem_type('\n')
? result_type(true, sprout::next(first), attribute_type())
: result_type(false, first, attribute_type())
: result_type(false, first, attribute_type())
;
}
};
//
// eol
//
SPROUT_STATIC_CONSTEXPR sprout::weed::eol_p eol = sprout::weed::eol_p();
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_PARSER_AUXILIARY_EOL_HPP

View file

@ -0,0 +1,49 @@
#ifndef SPROUT_WEED_PARSER_AUXILIARY_EPS_HPP
#define SPROUT_WEED_PARSER_AUXILIARY_EPS_HPP
#include <cstddef>
#include <sprout/config.hpp>
#include <sprout/weed/unused.hpp>
#include <sprout/weed/parser_result.hpp>
#include <sprout/weed/parser/parser_base.hpp>
namespace sprout {
namespace weed {
//
// eps_p
//
struct eps_p
: public sprout::weed::parser_base
{
public:
template<typename Context, typename Iterator>
struct attribute {
public:
typedef sprout::weed::unused type;
};
template<typename Context, typename Iterator>
struct result {
public:
typedef sprout::weed::parser_result<Iterator, typename attribute<Context, Iterator>::type> type;
};
public:
template<typename Context, typename Iterator>
SPROUT_CONSTEXPR typename result<Context, Iterator>::type operator()(
Iterator first,
Iterator last,
Context const&
) const
{
typedef typename result<Context, Iterator>::type result_type;
typedef typename attribute<Context, Iterator>::type attribute_type;
return result_type(true, first, attribute_type());
}
};
//
// eps
//
SPROUT_STATIC_CONSTEXPR sprout::weed::eps_p eps = sprout::weed::eps_p();
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_PARSER_AUXILIARY_EPS_HPP

View file

@ -0,0 +1,8 @@
#ifndef SPROUT_WEED_PARSER_CHAR_HPP
#define SPROUT_WEED_PARSER_CHAR_HPP
#include <sprout/config.hpp>
#include <sprout/weed/parser/char/char.hpp>
#include <sprout/weed/parser/char/char_class.hpp>
#endif // #ifndef SPROUT_WEED_PARSER_CHAR_HPP

View file

@ -0,0 +1,161 @@
#ifndef SPROUT_WEED_PARSER_CHAR_CHAR_HPP
#define SPROUT_WEED_PARSER_CHAR_CHAR_HPP
#include <iterator>
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/iterator/next.hpp>
#include <sprout/weed/unused.hpp>
#include <sprout/weed/parser_result.hpp>
#include <sprout/weed/parser/parser_base.hpp>
#include <sprout/weed/parser/lit.hpp>
#include <sprout/weed/traits/type/is_char_type.hpp>
namespace sprout {
namespace weed {
//
// lit_char_p
//
template<typename T>
struct lit_char_p
: public sprout::weed::parser_base
{
public:
template<typename Context, typename Iterator>
struct attribute {
public:
typedef sprout::weed::unused type;
};
template<typename Context, typename Iterator>
struct result {
public:
typedef sprout::weed::parser_result<Iterator, typename attribute<Context, Iterator>::type> type;
};
private:
T t_;
public:
lit_char_p() = default;
SPROUT_CONSTEXPR explicit lit_char_p(T const& t)
: t_(t)
{}
template<typename Context, typename Iterator>
SPROUT_CONSTEXPR typename result<Context, Iterator>::type operator()(
Iterator first,
Iterator last,
Context const&
) const
{
typedef typename result<Context, Iterator>::type result_type;
typedef typename attribute<Context, Iterator>::type attribute_type;
typedef typename std::iterator_traits<Iterator>::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<Context, Iterator>::type())
;
}
};
//
// lit_g
//
template<typename T>
struct lit_g::eval<
T,
typename std::enable_if<
sprout::weed::traits::is_char_type<T>::value
>::type
> {
public:
typedef sprout::weed::lit_char_p<T> result_type;
public:
SPROUT_CONSTEXPR result_type operator()(T const& t) const {
return result_type(t);
}
};
//
// char_p
//
template<typename T>
struct char_p
: public sprout::weed::parser_base
{
public:
template<typename Context, typename Iterator>
struct attribute {
public:
typedef typename std::iterator_traits<Iterator>::value_type type;
};
template<typename Context, typename Iterator>
struct result {
public:
typedef sprout::weed::parser_result<Iterator, typename attribute<Context, Iterator>::type> type;
};
private:
T t_;
public:
char_p() = default;
SPROUT_CONSTEXPR explicit char_p(T const& t)
: t_(t)
{}
template<typename Context, typename Iterator>
SPROUT_CONSTEXPR typename result<Context, Iterator>::type operator()(
Iterator first,
Iterator last,
Context const&
) const
{
typedef typename result<Context, Iterator>::type result_type;
typedef typename attribute<Context, Iterator>::type attribute_type;
typedef typename std::iterator_traits<Iterator>::value_type elem_type;
return first != last && *first == elem_type(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<typename Context, typename Iterator>
struct attribute {
public:
typedef typename std::iterator_traits<Iterator>::value_type type;
};
template<typename Context, typename Iterator>
struct result {
public:
typedef sprout::weed::parser_result<Iterator, typename attribute<Context, Iterator>::type> type;
};
public:
template<typename Context, typename Iterator>
SPROUT_CONSTEXPR typename result<Context, Iterator>::type operator()(
Iterator first,
Iterator last,
Context const&
) const
{
typedef typename result<Context, Iterator>::type result_type;
typedef typename attribute<Context, Iterator>::type attribute_type;
return first != last
? result_type(true, sprout::next(first), *first)
: result_type(false, first, attribute_type())
;
}
template<typename T>
SPROUT_CONSTEXPR sprout::weed::char_p<T> operator()(T const& t) const {
return sprout::weed::char_p<T>(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

View file

@ -0,0 +1,132 @@
#ifndef SPROUT_WEED_PARSER_CHAR_CHAR_CLASS_HPP
#define SPROUT_WEED_PARSER_CHAR_CHAR_CLASS_HPP
#include <cstddef>
#include <sprout/config.hpp>
#include <sprout/iterator/next.hpp>
#include <sprout/weed/unused.hpp>
#include <sprout/weed/parser_result.hpp>
#include <sprout/weed/parser/parser_base.hpp>
#include <sscrisk/cel/cctype.hpp>
namespace sprout {
namespace weed {
//
// alnum_p
// alpha_p
// blank_p
// cntrl_p
// digit_p
// graph_p
// print_p
// punct_p
// space_p
// xdigit_p
// lower_p
// upper_p
//
#define SPROUT_WEED_DEFINE_CTYPE_P(NAME, ISNAME) \
template<bool Nil = false> \
struct NAME \
: public sprout::weed::parser_base \
{ \
public: \
template<typename Context, typename Iterator> \
struct attribute { \
public: \
typedef typename std::conditional< \
Nil, \
sprout::weed::unused, \
typename std::iterator_traits<Iterator>::value_type \
>::type type; \
}; \
template<typename Context, typename Iterator> \
struct result { \
public: \
typedef sprout::weed::parser_result<Iterator, typename attribute<Context, Iterator>::type> type; \
}; \
public: \
template<typename Context, typename Iterator> \
SPROUT_CONSTEXPR typename result<Context, Iterator>::type operator()( \
Iterator first, \
Iterator last, \
Context const& \
) const \
{ \
typedef typename result<Context, Iterator>::type result_type; \
typedef typename attribute<Context, Iterator>::type attribute_type; \
return first != last && sscrisk::cel::ISNAME(*first) \
? result_type(true, sprout::next(first), *first) \
: result_type(false, first, attribute_type()) \
; \
} \
}
SPROUT_WEED_DEFINE_CTYPE_P(alnum_p, isalnum);
SPROUT_WEED_DEFINE_CTYPE_P(alpha_p, isalpha);
SPROUT_WEED_DEFINE_CTYPE_P(blank_p, isblank);
SPROUT_WEED_DEFINE_CTYPE_P(cntrl_p, iscntrl);
SPROUT_WEED_DEFINE_CTYPE_P(digit_p, isdigit);
SPROUT_WEED_DEFINE_CTYPE_P(graph_p, isgraph);
SPROUT_WEED_DEFINE_CTYPE_P(print_p, isprint);
SPROUT_WEED_DEFINE_CTYPE_P(punct_p, ispunct);
SPROUT_WEED_DEFINE_CTYPE_P(space_p, isspace);
SPROUT_WEED_DEFINE_CTYPE_P(xdigit_p, isxdigit);
SPROUT_WEED_DEFINE_CTYPE_P(lower_p, islower);
SPROUT_WEED_DEFINE_CTYPE_P(upper_p, isupper);
#undef SPROUT_WEED_DEFINE_CTYPE_P
//
// alnum
// alpha
// blank
// cntrl
// digit
// graph
// print
// punct
// space
// xdigit
// lower
// upper
//
SPROUT_STATIC_CONSTEXPR sprout::weed::alnum_p<> alnum = sprout::weed::alnum_p<>();
SPROUT_STATIC_CONSTEXPR sprout::weed::alpha_p<> alpha = sprout::weed::alpha_p<>();
SPROUT_STATIC_CONSTEXPR sprout::weed::blank_p<> blank = sprout::weed::blank_p<>();
SPROUT_STATIC_CONSTEXPR sprout::weed::cntrl_p<> cntrl = sprout::weed::cntrl_p<>();
SPROUT_STATIC_CONSTEXPR sprout::weed::digit_p<> digit = sprout::weed::digit_p<>();
SPROUT_STATIC_CONSTEXPR sprout::weed::graph_p<> graph = sprout::weed::graph_p<>();
SPROUT_STATIC_CONSTEXPR sprout::weed::print_p<> print = sprout::weed::print_p<>();
SPROUT_STATIC_CONSTEXPR sprout::weed::punct_p<> punct = sprout::weed::punct_p<>();
SPROUT_STATIC_CONSTEXPR sprout::weed::space_p<> space = sprout::weed::space_p<>();
SPROUT_STATIC_CONSTEXPR sprout::weed::xdigit_p<> xdigit = sprout::weed::xdigit_p<>();
SPROUT_STATIC_CONSTEXPR sprout::weed::lower_p<> lower = sprout::weed::lower_p<>();
SPROUT_STATIC_CONSTEXPR sprout::weed::upper_p<> upper = sprout::weed::upper_p<>();
//
// alnum_
// alpha_
// blank_
// cntrl_
// digit_
// graph_
// print_
// punct_
// space_
// xdigit_
// lower_
// upper_
//
SPROUT_STATIC_CONSTEXPR sprout::weed::alnum_p<true> alnum_ = sprout::weed::alnum_p<true>();
SPROUT_STATIC_CONSTEXPR sprout::weed::alpha_p<true> alpha_ = sprout::weed::alpha_p<true>();
SPROUT_STATIC_CONSTEXPR sprout::weed::blank_p<true> blank_ = sprout::weed::blank_p<true>();
SPROUT_STATIC_CONSTEXPR sprout::weed::cntrl_p<true> cntrl_ = sprout::weed::cntrl_p<true>();
SPROUT_STATIC_CONSTEXPR sprout::weed::digit_p<true> digit_ = sprout::weed::digit_p<true>();
SPROUT_STATIC_CONSTEXPR sprout::weed::graph_p<true> graph_ = sprout::weed::graph_p<true>();
SPROUT_STATIC_CONSTEXPR sprout::weed::print_p<true> print_ = sprout::weed::print_p<true>();
SPROUT_STATIC_CONSTEXPR sprout::weed::punct_p<true> punct_ = sprout::weed::punct_p<true>();
SPROUT_STATIC_CONSTEXPR sprout::weed::space_p<true> space_ = sprout::weed::space_p<true>();
SPROUT_STATIC_CONSTEXPR sprout::weed::xdigit_p<true> xdigit_ = sprout::weed::xdigit_p<true>();
SPROUT_STATIC_CONSTEXPR sprout::weed::lower_p<true> lower_ = sprout::weed::lower_p<true>();
SPROUT_STATIC_CONSTEXPR sprout::weed::upper_p<true> upper_ = sprout::weed::upper_p<true>();
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_PARSER_CHAR_CHAR_CLASS_HPP

View file

@ -0,0 +1,8 @@
#ifndef SPROUT_WEED_PARSER_DIRECTIVE_HPP
#define SPROUT_WEED_PARSER_DIRECTIVE_HPP
#include <sprout/config.hpp>
#include <sprout/weed/parser/directive/omit.hpp>
#include <sprout/weed/parser/directive/repeat.hpp>
#endif // #ifndef SPROUT_WEED_PARSER_DIRECTIVE_HPP

View file

@ -0,0 +1,86 @@
#ifndef SPROUT_WEED_PARSER_DIRECTIVE_OMIT_HPP
#define SPROUT_WEED_PARSER_DIRECTIVE_OMIT_HPP
#include <cstddef>
#include <sprout/config.hpp>
#include <sprout/weed/unused.hpp>
#include <sprout/weed/parser_result.hpp>
#include <sprout/weed/expr/make_terminal_or_expr.hpp>
#include <sprout/weed/expr/eval.hpp>
#include <sprout/weed/parser/parser_base.hpp>
#include <sprout/weed/traits/expr/terminal_or_expr_of.hpp>
#include <sprout/weed/traits/parser/attribute_of.hpp>
namespace sprout {
namespace weed {
//
// omit_p
//
template<typename Parser>
struct omit_p
: public sprout::weed::parser_base
{
public:
template<typename Context, typename Iterator>
struct attribute {
public:
typedef sprout::weed::unused type;
};
template<typename Context, typename Iterator>
struct result {
public:
typedef sprout::weed::parser_result<Iterator, typename attribute<Context, Iterator>::type> type;
};
private:
typedef typename sprout::weed::traits::terminal_or_expr_of<Parser>::type expr_type;
private:
expr_type expr_;
private:
template<typename Context, typename Iterator, typename Result>
SPROUT_CONSTEXPR typename result<Context, Iterator>::type call(
Iterator first,
Result const& res
) const
{
typedef typename result<Context, Iterator>::type result_type;
typedef typename attribute<Context, Iterator>::type attribute_type;
return res.success()
? result_type(true, res.current(), attribute_type())
: result_type(false, first, attribute_type())
;
}
public:
omit_p() = default;
SPROUT_CONSTEXPR explicit omit_p(
Parser const& p
)
: expr_(sprout::weed::make_terminal_or_expr(p))
{}
template<typename Context, typename Iterator>
SPROUT_CONSTEXPR typename result<Context, Iterator>::type operator()(
Iterator first,
Iterator last,
Context const& ctx
) const
{
return call<Context>(first, sprout::weed::eval(expr_, ctx));
}
};
//
// omit_d
//
struct omit_d {
public:
template<typename Parser>
SPROUT_CONSTEXPR sprout::weed::omit_p<Parser> operator[](Parser const& p) const {
return sprout::weed::omit_p<Parser>(p);
}
};
//
// omit
//
SPROUT_CONSTEXPR sprout::weed::omit_d omit = sprout::weed::omit_d();
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_PARSER_DIRECTIVE_OMIT_HPP

View file

@ -0,0 +1,211 @@
#ifndef SPROUT_WEED_PARSER_DIRECTIVE_REPEAT_HPP
#define SPROUT_WEED_PARSER_DIRECTIVE_REPEAT_HPP
#include <cstddef>
#include <sprout/config.hpp>
#include <sprout/weed/parser_result.hpp>
#include <sprout/weed/expr/make_terminal_or_expr.hpp>
#include <sprout/weed/expr/eval.hpp>
#include <sprout/weed/parser/parser_base.hpp>
#include <sprout/weed/attr_cnv/result_of/times.hpp>
#include <sprout/weed/attr_cnv/times.hpp>
#include <sprout/weed/traits/expr/terminal_or_expr_of.hpp>
#include <sprout/weed/traits/parser/attribute_of.hpp>
#include <sprout/weed/traits/parser/limit_of.hpp>
namespace sprout {
namespace weed {
//
// repeat_p
//
template<typename Parser>
struct repeat_p
: public sprout::weed::parser_base
{
private:
template<typename Context, typename Iterator>
struct eval {
private:
typedef typename sprout::weed::traits::limit_of<Parser, Iterator, Context>::type limit;
typedef typename sprout::weed::traits::attribute_of<Parser, Iterator, Context>::type attr_type;
public:
typedef typename repeat_p::template attribute<Context, Iterator>::type attribute_type;
typedef typename repeat_p::template result<Context, Iterator>::type result_type;
private:
template<typename Result, typename... Attrs>
SPROUT_CONSTEXPR typename std::enable_if<
sizeof...(Attrs) + 1 == limit::value,
result_type
>::type call(
repeat_p const& p,
Iterator first,
Result const& res,
Attrs const&... attrs
) const
{
return res.success()
? result_type(true, res.current(), sprout::weed::attr_cnv::times<limit::value, attr_type>(attrs..., res.attr()))
: p.count_ <= sizeof...(Attrs)
? result_type(true, first, sprout::weed::attr_cnv::times<limit::value, attr_type>(attrs...))
: result_type(false, first, attribute_type())
;
}
template<typename Result, typename... Attrs>
SPROUT_CONSTEXPR typename std::enable_if<
sizeof...(Attrs) + 1 != limit::value,
result_type
>::type call(
repeat_p const& p,
Iterator first,
Result const& res,
Attrs const&... attrs
) const
{
return res.success()
? call(p, p.count_ <= sizeof...(Attrs) ? res.current() : first, sprout::weed::eval(p.expr_, res.ctx()), attrs..., res.attr())
: p.count_ <= sizeof...(Attrs)
? result_type(true, first, sprout::weed::attr_cnv::times<limit::value, attr_type>(attrs...))
: result_type(false, first, attribute_type())
;
}
template<typename Result>
SPROUT_CONSTEXPR result_type call_inf(
repeat_p const& p,
Iterator first,
Result const& res,
std::size_t n
) const
{
return res.success()
? call_inf(p, p.count_ <= n ? res.current() : first, sprout::weed::eval(p.expr_, res.ctx()), n + 1)
: result_type(p.count_ <= n || p.count_ == std::size_t(-1), first, attribute_type())
;
}
template<bool Infinity, typename Result>
SPROUT_CONSTEXPR typename std::enable_if<
Infinity,
result_type
>::type call(
repeat_p const& p,
Iterator first,
Result const& res
) const
{
return res.success()
? call_inf(
p,
p.count_ <= 0 ? res.current() : first,
sprout::weed::eval(p.expr_, res.ctx()),
1
)
: result_type(p.count_ <= 0 || p.count_ == std::size_t(-1), first, attribute_type())
;
}
template<bool Infinity, typename Result>
SPROUT_CONSTEXPR typename std::enable_if<
!Infinity,
result_type
>::type call(
repeat_p const& p,
Iterator first,
Result const& res
) const
{
return res.success()
? call(
p,
p.count_ <= 0 ? res.current() : first,
sprout::weed::eval(p.expr_, res.ctx()),
res.attr()
)
: result_type(p.count_ <= 0, first, attribute_type())
;
}
public:
SPROUT_CONSTEXPR result_type operator()(
repeat_p const& p,
Iterator first,
Context const& ctx
) const
{
return call<limit::value == std::size_t(-1)>(
p,
first,
sprout::weed::eval(p.expr_, ctx)
);
}
};
public:
template<typename Context, typename Iterator>
struct attribute {
public:
typedef typename sprout::weed::attr_cnv::result_of::times<
sprout::weed::traits::limit_of<Parser, Iterator, Context>::value,
typename sprout::weed::traits::attribute_of<Parser, Iterator, Context>::type
>::type type;
};
template<typename Context, typename Iterator>
struct result {
public:
typedef sprout::weed::parser_result<Iterator, typename attribute<Context, Iterator>::type> type;
};
private:
typedef typename sprout::weed::traits::terminal_or_expr_of<Parser>::type expr_type;
private:
expr_type expr_;
std::size_t count_;
public:
repeat_p() = default;
SPROUT_CONSTEXPR explicit repeat_p(Parser const& p, std::size_t count = -1)
: expr_(sprout::weed::make_terminal_or_expr(p))
, count_(count)
{}
template<typename Context, typename Iterator>
SPROUT_CONSTEXPR typename result<Context, Iterator>::type operator()(
Iterator first,
Iterator last,
Context const& ctx
) const
{
return eval<Context, Iterator>()(*this, first, ctx);
}
};
//
// repeat_g
//
struct repeat_g {
private:
std::size_t count_;
public:
SPROUT_CONSTEXPR explicit repeat_g(std::size_t count)
: count_(count)
{}
template<typename Parser>
SPROUT_CONSTEXPR sprout::weed::repeat_p<Parser> operator[](Parser const& p) const {
return sprout::weed::repeat_p<Parser>(p, count_);
}
};
//
// repeat_d
//
struct repeat_d {
public:
template<typename Parser>
SPROUT_CONSTEXPR sprout::weed::repeat_p<Parser> operator[](Parser const& p) const {
return sprout::weed::repeat_p<Parser>(p);
}
SPROUT_CONSTEXPR sprout::weed::repeat_g operator()(std::size_t count) const {
return sprout::weed::repeat_g(count);
}
};
//
// repeat
//
SPROUT_CONSTEXPR sprout::weed::repeat_d repeat = sprout::weed::repeat_d();
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_PARSER_DIRECTIVE_REPEAT_HPP

View file

@ -0,0 +1,95 @@
#ifndef SPROUT_WEED_PARSER_LIM_HPP
#define SPROUT_WEED_PARSER_LIM_HPP
#include <cstddef>
#include <sprout/config.hpp>
#include <sprout/weed/parser_result.hpp>
#include <sprout/weed/limited.hpp>
#include <sprout/weed/expr/make_terminal_or_expr.hpp>
#include <sprout/weed/expr/eval.hpp>
#include <sprout/weed/parser/parser_base.hpp>
#include <sprout/weed/traits/expr/terminal_or_expr_of.hpp>
#include <sprout/weed/traits/parser/attribute_of.hpp>
#include <sprout/weed/traits/parser/limit_of.hpp>
namespace sprout {
namespace weed {
//
// limit_p
//
template<typename Parser, std::size_t Limit>
struct limit_p
: public sprout::weed::parser_base
{
public:
SPROUT_STATIC_CONSTEXPR std::size_t limit = Limit;
public:
template<typename Context, typename Iterator>
struct attribute {
public:
typedef typename sprout::weed::traits::attribute_of<Parser, Iterator, Context>::type type;
};
template<typename Context, typename Iterator>
struct result {
public:
typedef sprout::weed::parser_result<Iterator, typename attribute<Context, Iterator>::type> type;
};
private:
typedef typename sprout::weed::traits::terminal_or_expr_of<Parser>::type expr_type;
private:
expr_type expr_;
sprout::weed::limited::category limited_category_;
public:
limit_p() = default;
SPROUT_CONSTEXPR explicit limit_p(
Parser const& p,
sprout::weed::limited::category limited_category = sprout::weed::limited::discard
)
: expr_(sprout::weed::make_terminal_or_expr(p))
, limited_category_(limited_category)
{}
SPROUT_CONSTEXPR sprout::weed::limited::category limited_category() const {
return limited_category_;
}
template<typename Context, typename Iterator>
SPROUT_CONSTEXPR typename result<Context, Iterator>::type operator()(
Iterator first,
Iterator last,
Context const& ctx
) const
{
return sprout::weed::eval(expr_, ctx).presult();
}
};
template<typename Parser, std::size_t Limit>
SPROUT_CONSTEXPR std::size_t limit_p<Parser, Limit>::limit;
//
// lim
//
template<std::size_t Limit, typename Parser>
SPROUT_CONSTEXPR sprout::weed::limit_p<Parser, Limit> lim(Parser const& p) {
return sprout::weed::limit_p<Parser, Limit>(p);
}
template<std::size_t Limit, typename Parser>
SPROUT_CONSTEXPR sprout::weed::limit_p<Parser, Limit> lim(
Parser const& p,
sprout::weed::limited::category limited_category
)
{
return sprout::weed::limit_p<Parser, Limit>(p, limited_category);
}
namespace traits {
//
// limit_of
//
template<typename Parser, std::size_t Limit, typename Iterator, typename Context>
struct limit_of<sprout::weed::limit_p<Parser, Limit>, Iterator, Context>
: public std::integral_constant<std::size_t, Limit>
{};
} // namespace traits
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_PARSER_LIM_HPP

View file

@ -0,0 +1,33 @@
#ifndef SPROUT_WEED_PARSER_LIT_HPP
#define SPROUT_WEED_PARSER_LIT_HPP
#include <sprout/config.hpp>
#include <sprout/utility/forward.hpp>
#include <sprout/weed/detail/uncvref.hpp>
namespace sprout {
namespace weed {
//
// lit_g
//
struct lit_g {
public:
template<typename T, typename = void>
struct eval;
public:
template<typename T>
SPROUT_CONSTEXPR typename eval<
typename sprout::weed::detail::uncvref<T>::type
>::result_type operator()(T&& t) const {
typedef eval<typename sprout::weed::detail::uncvref<T>::type> eval_type;
return eval_type()(sprout::forward<T>(t));
}
};
//
// lit
//
SPROUT_STATIC_CONSTEXPR sprout::weed::lit_g lit = sprout::weed::lit_g();
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_PARSER_LIT_HPP

View file

@ -0,0 +1,7 @@
#ifndef SPROUT_WEED_PARSER_NUMERIC_HPP
#define SPROUT_WEED_PARSER_NUMERIC_HPP
#include <sprout/config.hpp>
#include <sprout/weed/parser/numeric/hex.hpp>
#endif // #ifndef SPROUT_WEED_PARSER_NUMERIC_HPP

View file

@ -0,0 +1,132 @@
#ifndef SPROUT_WEED_PARSER_NUMERIC_HEX_HPP
#define SPROUT_WEED_PARSER_NUMERIC_HEX_HPP
#include <cstddef>
#include <sprout/config.hpp>
#include <sprout/iterator/next.hpp>
#include <sprout/tuple/tuple.hpp>
#include <sprout/weed/unused.hpp>
#include <sprout/weed/parser_result.hpp>
#include <sprout/weed/parser/parser_base.hpp>
#include <sprout/weed/detail/xdigits.hpp>
namespace sprout {
namespace weed {
//
// hex_p
//
template<typename IntType, std::size_t Min = sizeof(IntType) * 2, std::size_t Max = sizeof(IntType) * 2>
struct hex_p
: public sprout::weed::parser_base
{
public:
template<typename Context, typename Iterator>
struct attribute {
public:
typedef IntType type;
};
template<typename Context, typename Iterator>
struct result {
public:
typedef sprout::weed::parser_result<Iterator, typename attribute<Context, Iterator>::type> type;
};
private:
template<std::size_t N, typename Context, typename Iterator, typename PResult>
SPROUT_CONSTEXPR typename std::enable_if<
N == Max,
typename result<Context, Iterator>::type
>::type call_1(Iterator first, Iterator last, Iterator temp_first, IntType t, PResult const& res) const {
typedef typename result<Context, Iterator>::type result_type;
typedef typename attribute<Context, Iterator>::type attribute_type;
return sprout::tuples::get<1>(res)
? result_type(true, sprout::next(first), static_cast<IntType>(t << 4 | sprout::tuples::get<0>(res)))
: N < Min
? result_type(false, temp_first, attribute_type())
: result_type(true, first, t)
;
}
template<std::size_t N, typename Context, typename Iterator, typename PResult>
SPROUT_CONSTEXPR typename std::enable_if<
N != Max,
typename result<Context, Iterator>::type
>::type call_1(Iterator first, Iterator last, Iterator temp_first, IntType t, PResult const& res) const {
typedef typename result<Context, Iterator>::type result_type;
typedef typename attribute<Context, Iterator>::type attribute_type;
return sprout::tuples::get<1>(res)
? call_0<N, Context>(sprout::next(first), last, temp_first, static_cast<IntType>(t << 4 | sprout::tuples::get<0>(res)))
: N < Min
? result_type(false, temp_first, attribute_type())
: result_type(true, first, t)
;
}
template<std::size_t N, typename Context, typename Iterator>
SPROUT_CONSTEXPR typename result<Context, Iterator>::type call_0(Iterator first, Iterator last, Iterator temp_first, IntType t) const {
typedef typename result<Context, Iterator>::type result_type;
typedef typename attribute<Context, Iterator>::type attribute_type;
return first != last
? call_1<N + 1, Context>(first, last, temp_first, t, sprout::weed::detail::from_xdigit<IntType>(*first))
: N < Min
? result_type(false, temp_first, attribute_type())
: result_type(true, first, t)
;
}
template<typename Context, typename Iterator, typename PResult>
SPROUT_CONSTEXPR typename result<Context, Iterator>::type call(Iterator first, Iterator last, Iterator temp_first, PResult const& res) const {
typedef typename result<Context, Iterator>::type result_type;
typedef typename attribute<Context, Iterator>::type attribute_type;
return sprout::tuples::get<1>(res)
? call_0<1, Context>(sprout::next(first), last, temp_first, sprout::tuples::get<0>(res))
: result_type(false, temp_first, attribute_type())
;
}
public:
template<typename Context, typename Iterator>
SPROUT_CONSTEXPR typename result<Context, Iterator>::type operator()(Iterator first, Iterator last, Context const&) const {
typedef typename result<Context, Iterator>::type result_type;
typedef typename attribute<Context, Iterator>::type attribute_type;
return first != last
? call<Context>(first, last, first, sprout::weed::detail::from_xdigit<IntType>(*first))
: result_type(false, first, attribute_type())
;
}
};
//
// hex8
// hex16
// hex32
// hex64
// uhex8
// uhex16
// uhex32
// uhex64
//
SPROUT_STATIC_CONSTEXPR sprout::weed::hex_p<std::int8_t, 1> hex8 = sprout::weed::hex_p<std::int8_t, 1>();
SPROUT_STATIC_CONSTEXPR sprout::weed::hex_p<std::int16_t, 1> hex16 = sprout::weed::hex_p<std::int16_t, 1>();
SPROUT_STATIC_CONSTEXPR sprout::weed::hex_p<std::int32_t, 1> hex32 = sprout::weed::hex_p<std::int32_t, 1>();
SPROUT_STATIC_CONSTEXPR sprout::weed::hex_p<std::int64_t, 1> hex64 = sprout::weed::hex_p<std::int64_t, 1>();
SPROUT_STATIC_CONSTEXPR sprout::weed::hex_p<std::uint8_t, 1> uhex8 = sprout::weed::hex_p<std::uint8_t, 1>();
SPROUT_STATIC_CONSTEXPR sprout::weed::hex_p<std::uint16_t, 1> uhex16 = sprout::weed::hex_p<std::uint16_t, 1>();
SPROUT_STATIC_CONSTEXPR sprout::weed::hex_p<std::uint32_t, 1> uhex32 = sprout::weed::hex_p<std::uint32_t, 1>();
SPROUT_STATIC_CONSTEXPR sprout::weed::hex_p<std::uint64_t, 1> uhex64 = sprout::weed::hex_p<std::uint64_t, 1>();
//
// hex8f
// hex16f
// hex32f
// hex64f
// uhex8f
// uhex16f
// uhex32f
// uhex64f
//
SPROUT_STATIC_CONSTEXPR sprout::weed::hex_p<std::int8_t> hex8f = sprout::weed::hex_p<std::int8_t>();
SPROUT_STATIC_CONSTEXPR sprout::weed::hex_p<std::int16_t> hex16f = sprout::weed::hex_p<std::int16_t>();
SPROUT_STATIC_CONSTEXPR sprout::weed::hex_p<std::int32_t> hex32f = sprout::weed::hex_p<std::int32_t>();
SPROUT_STATIC_CONSTEXPR sprout::weed::hex_p<std::int64_t> hex64f = sprout::weed::hex_p<std::int64_t>();
SPROUT_STATIC_CONSTEXPR sprout::weed::hex_p<std::uint8_t> uhex8f = sprout::weed::hex_p<std::uint8_t>();
SPROUT_STATIC_CONSTEXPR sprout::weed::hex_p<std::uint16_t> uhex16f = sprout::weed::hex_p<std::uint16_t>();
SPROUT_STATIC_CONSTEXPR sprout::weed::hex_p<std::uint32_t> uhex32f = sprout::weed::hex_p<std::uint32_t>();
SPROUT_STATIC_CONSTEXPR sprout::weed::hex_p<std::uint64_t> uhex64f = sprout::weed::hex_p<std::uint64_t>();
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_PARSER_NUMERIC_HEX_HPP

View file

@ -0,0 +1,15 @@
#ifndef SPROUT_WEED_PARSER_PARSER_BASE_HPP
#define SPROUT_WEED_PARSER_PARSER_BASE_HPP
#include <sprout/config.hpp>
namespace sprout {
namespace weed {
//
// parser_base
//
class parser_base {};
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_PARSER_PARSER_BASE_HPP

View file

@ -0,0 +1,7 @@
#ifndef SPROUT_WEED_PARSER_STRING_HPP
#define SPROUT_WEED_PARSER_STRING_HPP
#include <sprout/config.hpp>
#include <sprout/weed/parser/string/string.hpp>
#endif // #ifndef SPROUT_WEED_PARSER_STRING_HPP

View file

@ -0,0 +1,162 @@
#ifndef SPROUT_WEED_PARSER_STRING_STRING_HPP
#define SPROUT_WEED_PARSER_STRING_STRING_HPP
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/string.hpp>
#include <sprout/fixed_container/begin.hpp>
#include <sprout/fixed_container/end.hpp>
#include <sprout/fixed_container/size.hpp>
#include <sprout/iterator/next.hpp>
#include <sprout/weed/unused.hpp>
#include <sprout/weed/parser_result.hpp>
#include <sprout/weed/parser/parser_base.hpp>
#include <sprout/weed/parser/lit.hpp>
#include <sprout/weed/traits/type/is_c_str.hpp>
#include <sprout/weed/traits/type/is_string.hpp>
#include HDR_ALGORITHM_SSCRISK_CEL_OR_SPROUT_DETAIL
#include HDR_ITERATOR_SSCRISK_CEL_OR_SPROUT_DETAIL
namespace sprout {
namespace weed {
//
// lit_str_p
//
template<typename T>
struct lit_str_p
: public sprout::weed::parser_base
{
public:
template<typename Context, typename Iterator>
struct attribute {
public:
typedef sprout::weed::unused type;
};
template<typename Context, typename Iterator>
struct result {
public:
typedef sprout::weed::parser_result<Iterator, typename attribute<Context, Iterator>::type> type;
};
private:
T t_;
public:
lit_str_p() = default;
SPROUT_CONSTEXPR explicit lit_str_p(T const& t)
: t_(t)
{}
template<typename Context, typename Iterator>
SPROUT_CONSTEXPR typename result<Context, Iterator>::type operator()(
Iterator first,
Iterator last,
Context const&
) const
{
typedef typename result<Context, Iterator>::type result_type;
typedef typename attribute<Context, Iterator>::type attribute_type;
return NS_SSCRISK_CEL_OR_SPROUT_DETAIL::distance(first, last) >= sprout::size(t_)
&&NS_SSCRISK_CEL_OR_SPROUT_DETAIL::equal(sprout::begin(t_), sprout::end(t_), first)
? result_type(true, sprout::next(first, sprout::size(t_)), attribute_type())
: result_type(false, first, typename attribute<Context, Iterator>::type())
;
}
};
//
// lit_g
//
template<typename T>
struct lit_g::eval<
T,
typename std::enable_if<
sprout::weed::traits::is_c_str<T>::value
>::type
> {
public:
typedef sprout::weed::lit_str_p<
typename sprout::weed::detail::c_str_as_string<T const>::type
> result_type;
public:
SPROUT_CONSTEXPR result_type operator()(T const& t) const {
return result_type(sprout::to_string(t));
}
};
template<typename T>
struct lit_g::eval<
T,
typename std::enable_if<
sprout::weed::traits::is_string<T>::value
>::type
> {
public:
typedef sprout::weed::lit_str_p<T> result_type;
public:
SPROUT_CONSTEXPR result_type operator()(T const& t) const {
return result_type(t);
}
};
//
// str_p
//
template<typename T>
struct str_p
: public sprout::weed::parser_base
{
public:
template<typename Context, typename Iterator>
struct attribute {
public:
typedef T type;
};
template<typename Context, typename Iterator>
struct result {
public:
typedef sprout::weed::parser_result<Iterator, typename attribute<Context, Iterator>::type> type;
};
private:
T t_;
public:
str_p() = default;
SPROUT_CONSTEXPR explicit str_p(T const& t)
: t_(t)
{}
template<typename Context, typename Iterator>
SPROUT_CONSTEXPR typename result<Context, Iterator>::type operator()(
Iterator first,
Iterator last,
Context const&
) const
{
typedef typename result<Context, Iterator>::type result_type;
typedef typename attribute<Context, Iterator>::type attribute_type;
return NS_SSCRISK_CEL_OR_SPROUT_DETAIL::distance(first, last) >= sprout::size(t_)
&&NS_SSCRISK_CEL_OR_SPROUT_DETAIL::equal(sprout::begin(t_), sprout::end(t_), first)
? result_type(true, sprout::next(first, sprout::size(t_)), attribute_type())
: result_type(false, first, typename attribute<Context, Iterator>::type())
;
}
};
//
// string
//
template<typename T>
SPROUT_CONSTEXPR inline typename std::enable_if<
sprout::weed::traits::is_c_str<T const>::value,
sprout::weed::str_p<
typename sprout::weed::detail::c_str_as_string<T const>::type
>
>::type string(T const& t) {
return sprout::weed::str_p<
typename sprout::weed::detail::c_str_as_string<T const>::type
>(sprout::to_string(t));
}
template<typename T>
SPROUT_CONSTEXPR inline typename std::enable_if<
sprout::weed::traits::is_string<T>::value,
sprout::weed::str_p<T>
>::type string(T const& t) {
return sprout::weed::str_p<T>(t);
}
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_PARSER_STRING_STRING_HPP

View file

@ -0,0 +1,41 @@
#ifndef SPROUT_WEED_PARSER_RESULT_HPP
#define SPROUT_WEED_PARSER_RESULT_HPP
#include <sprout/config.hpp>
namespace sprout {
namespace weed {
//
// parser_result
//
template<typename Iterator, typename Attribute>
class parser_result {
private:
bool success_;
Iterator current_;
Attribute attr_;
public:
parser_result() = default;
SPROUT_CONSTEXPR parser_result(
bool success,
Iterator current,
Attribute const& attr
)
: success_(success)
, current_(current)
, attr_(attr)
{}
SPROUT_CONSTEXPR bool success() const {
return success_;
}
SPROUT_CONSTEXPR Iterator current() const {
return current_;
}
SPROUT_CONSTEXPR Attribute const& attr() const {
return attr_;
}
};
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_PARSER_RESULT_HPP

9
sprout/weed/traits.hpp Normal file
View file

@ -0,0 +1,9 @@
#ifndef SPROUT_WEED_TRAITS_HPP
#define SPROUT_WEED_TRAITS_HPP
#include <sprout/config.hpp>
#include <sprout/weed/traits/type.hpp>
#include <sprout/weed/traits/expr.hpp>
#include <sprout/weed/traits/parser.hpp>
#endif // #ifndef SPROUT_WEED_TRAITS_HPP

View file

@ -0,0 +1,11 @@
#ifndef SPROUT_WEED_TRAITS_EXPR_HPP
#define SPROUT_WEED_TRAITS_EXPR_HPP
#include <sprout/config.hpp>
#include <sprout/weed/traits/expr/is_expr.hpp>
#include <sprout/weed/traits/expr/tag_of.hpp>
#include <sprout/weed/traits/expr/terminal_of.hpp>
#include <sprout/weed/traits/expr/terminal_or_expr_of.hpp>
#include <sprout/weed/traits/expr/expr_of.hpp>
#endif // #ifndef SPROUT_WEED_TRAITS_EXPR_HPP

View file

@ -0,0 +1,30 @@
#ifndef SPROUT_WEED_TRAITS_EXPR_EXPR_OF_HPP
#define SPROUT_WEED_TRAITS_EXPR_EXPR_OF_HPP
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/weed/expr/expr.hpp>
#include <sprout/weed/traits/expr/terminal_or_expr_of.hpp>
#include <sprout/weed/detail/uncvref.hpp>
namespace sprout {
namespace weed {
namespace traits {
//
// expr_of
//
template<typename Tag, typename... Args>
struct expr_of {
public:
typedef sprout::weed::expr<
Tag,
typename sprout::weed::traits::terminal_or_expr_of<
typename sprout::weed::detail::uncvref<Args>::type
>::type...
> type;
};
} // namespace traits
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_TRAITS_EXPR_EXPR_OF_HPP

View file

@ -0,0 +1,30 @@
#ifndef SPROUT_WEED_TRAITS_EXPR_IS_EXPR_HPP
#define SPROUT_WEED_TRAITS_EXPR_IS_EXPR_HPP
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/weed/expr/expr.hpp>
namespace sprout {
namespace weed {
namespace traits {
//
// is_expr
//
template<typename T>
struct is_expr
: public std::false_type
{};
template<typename T>
struct is_expr<T const>
: public sprout::weed::traits::is_expr<T>
{};
template<typename Tag, typename... Args>
struct is_expr<sprout::weed::expr<Tag, Args...> >
: public std::true_type
{};
} // namespace traits
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_TRAITS_EXPR_IS_EXPR_HPP

View file

@ -0,0 +1,34 @@
#ifndef SPROUT_WEED_TRAITS_EXPR_TAG_OF_HPP
#define SPROUT_WEED_TRAITS_EXPR_TAG_OF_HPP
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/weed/traits/expr/is_expr.hpp>
namespace sprout {
namespace weed {
namespace traits {
//
// tag_of
//
template<typename Expr, typename = void>
struct tag_of;
template<typename Expr>
struct tag_of<Expr const>
: public sprout::weed::traits::tag_of<Expr>
{};
template<typename Expr>
struct tag_of<
Expr,
typename std::enable_if<
sprout::weed::traits::is_expr<Expr>::value
>::type
> {
public:
typedef typename Expr::expr_tag type;
};
} // namespace traits
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_TRAITS_EXPR_TAG_OF_HPP

View file

@ -0,0 +1,56 @@
#ifndef SPROUT_WEED_TRAITS_EXPR_TERMINAL_OF_HPP
#define SPROUT_WEED_TRAITS_EXPR_TERMINAL_OF_HPP
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/weed/expr/expr.hpp>
#include <sprout/weed/expr/tag.hpp>
#include <sprout/weed/traits/type/is_c_str.hpp>
#include <sprout/weed/detail/uncvref.hpp>
#include <sprout/weed/detail/c_str_as_string.hpp>
namespace sprout {
namespace weed {
namespace traits {
//
// terminal_of
//
template<typename Arg, typename = void>
struct terminal_of;
template<typename Arg>
struct terminal_of<
Arg,
typename std::enable_if<
!sprout::weed::traits::is_c_str<
typename sprout::weed::detail::uncvref<Arg>::type
>::value
>::type
> {
public:
typedef sprout::weed::expr<
sprout::weed::tag::terminal,
typename sprout::weed::detail::uncvref<Arg>::type
> type;
};
template<typename Arg>
struct terminal_of<
Arg,
typename std::enable_if<
sprout::weed::traits::is_c_str<
typename sprout::weed::detail::uncvref<Arg>::type
>::value
>::type
> {
public:
typedef sprout::weed::expr<
sprout::weed::tag::terminal,
typename sprout::weed::detail::c_str_as_string<
typename sprout::weed::detail::uncvref<Arg>::type
>::type
> type;
};
} // namespace traits
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_TRAITS_EXPR_TERMINAL_OF_HPP

View file

@ -0,0 +1,31 @@
#ifndef SPROUT_WEED_TRAITS_EXPR_TERMINAL_OR_EXPR_OF_HPP
#define SPROUT_WEED_TRAITS_EXPR_TERMINAL_OR_EXPR_OF_HPP
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/weed/traits/expr/is_expr.hpp>
#include <sprout/weed/traits/expr/terminal_of.hpp>
#include <sprout/weed/detail/uncvref.hpp>
namespace sprout {
namespace weed {
namespace traits {
//
// terminal_or_expr_of
//
template<typename Arg>
struct terminal_or_expr_of {
public:
typedef typename std::conditional<
sprout::weed::traits::is_expr<
typename sprout::weed::detail::uncvref<Arg>::type
>::value,
typename sprout::weed::detail::uncvref<Arg>::type,
typename sprout::weed::traits::terminal_of<Arg>::type
>::type type;
};
} // namespace traits
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_TRAITS_EXPR_TERMINAL_OR_EXPR_OF_HPP

View file

@ -0,0 +1,9 @@
#ifndef SPROUT_WEED_TRAITS_PARSER_HPP
#define SPROUT_WEED_TRAITS_PARSER_HPP
#include <sprout/config.hpp>
#include <sprout/weed/traits/parser/is_parser.hpp>
#include <sprout/weed/traits/parser/attribute_of.hpp>
#include <sprout/weed/traits/parser/limit_of.hpp>
#endif // #ifndef SPROUT_WEED_TRAITS_PARSER_HPP

View file

@ -0,0 +1,115 @@
#ifndef SPROUT_WEED_TRAITS_PARSER_ATTRIBUTE_OF_HPP
#define SPROUT_WEED_TRAITS_PARSER_ATTRIBUTE_OF_HPP
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/weed/unused.hpp>
#include <sprout/weed/expr/expr.hpp>
#include <sprout/weed/expr/tag.hpp>
#include <sprout/weed/traits/type/is_char_type.hpp>
#include <sprout/weed/traits/type/is_c_str.hpp>
#include <sprout/weed/traits/type/is_string.hpp>
#include <sprout/weed/traits/expr/is_expr.hpp>
#include <sprout/weed/traits/parser/is_parser.hpp>
#include <sprout/weed/traits/parser/limit_of.hpp>
#include <sprout/weed/attr_cnv/result_of/times.hpp>
#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>
namespace sprout {
namespace weed {
namespace traits {
//
// attribute_of
//
template<typename T, typename Iterator, typename Context, typename = void>
struct attribute_of;
template<typename T, typename Iterator, typename Context>
struct attribute_of<T const, Iterator, Context>
: public sprout::weed::traits::attribute_of<T, Iterator, Context>
{};
template<typename T, typename Iterator, typename Context>
struct attribute_of<
T,
Iterator,
Context,
typename std::enable_if<
sprout::weed::traits::is_parser<T>::value
&& !sprout::weed::traits::is_expr<T>::value
&& !sprout::weed::traits::is_char_type<T>::value
&& !sprout::weed::traits::is_c_str<T>::value
&& !sprout::weed::traits::is_string<T>::value
>::type
> {
public:
typedef typename T::template attribute<Context, Iterator>::type type;
};
template<typename T, typename Iterator, typename Context>
struct attribute_of<
T,
Iterator,
Context,
typename std::enable_if<
sprout::weed::traits::is_char_type<T>::value
|| sprout::weed::traits::is_c_str<T>::value
|| sprout::weed::traits::is_string<T>::value
>::type
> {
public:
typedef sprout::weed::unused type;
};
template<typename Arg, typename Iterator, typename Context>
struct attribute_of<sprout::weed::expr<sprout::weed::tag::terminal, Arg>, Iterator, Context>
: public sprout::weed::traits::attribute_of<Arg, Iterator, Context>
{};
template<typename Arg, typename Iterator, typename Context>
struct attribute_of<sprout::weed::expr<sprout::weed::tag::unary_plus, Arg>, Iterator, Context>
: public sprout::weed::attr_cnv::result_of::times<
sprout::weed::traits::limit_of<Arg, Iterator, Context>::value,
typename sprout::weed::traits::attribute_of<Arg, Iterator, Context>::type
>
{};
template<typename Arg, typename Iterator, typename Context>
struct attribute_of<sprout::weed::expr<sprout::weed::tag::dereference, Arg>, Iterator, Context>
: public sprout::weed::attr_cnv::result_of::times<
sprout::weed::traits::limit_of<Arg, Iterator, Context>::value,
typename sprout::weed::traits::attribute_of<Arg, Iterator, Context>::type
>
{};
template<typename Arg, typename Iterator, typename Context>
struct attribute_of<sprout::weed::expr<sprout::weed::tag::address_of, Arg>, Iterator, Context> {
public:
typedef sprout::weed::unused type;
};
template<typename Arg, typename Iterator, typename Context>
struct attribute_of<sprout::weed::expr<sprout::weed::tag::logical_not, Arg>, Iterator, Context> {
public:
typedef sprout::weed::unused type;
};
template<typename Arg1, typename Arg2, typename Iterator, typename Context>
struct attribute_of<sprout::weed::expr<sprout::weed::tag::shift_left, Arg1, Arg2>, Iterator, Context>
: public sprout::weed::attr_cnv::result_of::shift_left<
typename sprout::weed::traits::attribute_of<Arg1, Iterator, Context>::type,
typename sprout::weed::traits::attribute_of<Arg2, Iterator, Context>::type
>
{};
template<typename Arg1, typename Arg2, typename Iterator, typename Context>
struct attribute_of<sprout::weed::expr<sprout::weed::tag::modulus, Arg1, Arg2>, Iterator, Context>
: public sprout::weed::attr_cnv::result_of::modulus<
sprout::weed::traits::limit_of<Arg1, Iterator, Context>::value,
typename sprout::weed::traits::attribute_of<Arg1, Iterator, Context>::type
>
{};
template<typename Arg1, typename Arg2, typename Iterator, typename Context>
struct attribute_of<sprout::weed::expr<sprout::weed::tag::bitwise_or, Arg1, Arg2>, Iterator, Context>
: public sprout::weed::attr_cnv::result_of::bitwise_or<
typename sprout::weed::traits::attribute_of<Arg1, Iterator, Context>::type,
typename sprout::weed::traits::attribute_of<Arg2, Iterator, Context>::type
>
{};
} // namespace traits
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_TRAITS_PARSER_ATTRIBUTE_OF_HPP

View file

@ -0,0 +1,75 @@
#ifndef SPROUT_WEED_TRAITS_PARSER_IS_PARSER_HPP
#define SPROUT_WEED_TRAITS_PARSER_IS_PARSER_HPP
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/weed/unused.hpp>
#include <sprout/weed/parser/parser_base.hpp>
#include <sprout/weed/traits/type/is_char_type.hpp>
#include <sprout/weed/traits/type/is_c_str.hpp>
#include <sprout/weed/traits/expr/is_expr.hpp>
namespace sprout {
namespace weed {
namespace traits {
//
// is_parser
//
template<typename T, typename = void>
struct is_parser;
template<typename T>
struct is_parser<
T,
typename std::enable_if<
std::is_const<T>::value
&& !std::is_array<T>::value
>::type
>
: public sprout::weed::traits::is_parser<
typename std::remove_const<T>::type
>
{};
template<typename T>
struct is_parser<
T,
typename std::enable_if<
std::is_base_of<sprout::weed::parser_base, T>::value
&& !std::is_const<T>::value
>::type
>
: public std::true_type
{};
template<typename T>
struct is_parser<
T,
typename std::enable_if<
sprout::weed::traits::is_expr<T>::value
&& !std::is_const<T>::value
>::type
>
: public std::true_type
{};
template<typename T>
struct is_parser<
T,
typename std::enable_if<
sprout::weed::traits::is_char_type<T>::value
&& !std::is_const<T>::value
>::type
>
: public std::true_type
{};
template<typename T>
struct is_parser<
T,
typename std::enable_if<
sprout::weed::traits::is_c_str<T>::value
>::type
>
: public std::true_type
{};
} // namespace traits
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_TRAITS_PARSER_IS_PARSER_HPP

View file

@ -0,0 +1,32 @@
#ifndef SPROUT_WEED_TRAITS_PARSER_LIMIT_OF_HPP
#define SPROUT_WEED_TRAITS_PARSER_LIMIT_OF_HPP
#include <cstddef>
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/weed/expr/expr.hpp>
#include <sprout/weed/expr/tag.hpp>
namespace sprout {
namespace weed {
namespace traits {
//
// limit_of
//
template<typename T, typename Iterator, typename Context, typename = void>
struct limit_of
: public std::integral_constant<std::size_t, -1>
{};
template<typename T, typename Iterator, typename Context>
struct limit_of<T const, Iterator, Context>
: public sprout::weed::traits::limit_of<T, Iterator, Context>
{};
template<typename Arg, typename Iterator, typename Context>
struct limit_of<sprout::weed::expr<sprout::weed::tag::terminal, Arg>, Iterator, Context>
: public sprout::weed::traits::limit_of<Arg, Iterator, Context>
{};
} // namespace traits
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_TRAITS_PARSER_LIMIT_OF_HPP

View file

@ -0,0 +1,12 @@
#ifndef SPROUT_WEED_TRAITS_TYPE_HPP
#define SPROUT_WEED_TRAITS_TYPE_HPP
#include <sprout/config.hpp>
#include <sprout/weed/traits/type/is_char_type.hpp>
#include <sprout/weed/traits/type/is_c_str.hpp>
#include <sprout/weed/traits/type/is_string.hpp>
#include <sprout/weed/traits/type/is_container.hpp>
#include <sprout/weed/traits/type/is_tuple.hpp>
#include <sprout/weed/traits/type/is_unused.hpp>
#endif // #ifndef SPROUT_WEED_TRAITS_TYPE_HPP

View file

@ -0,0 +1,41 @@
#ifndef SPROUT_WEED_TRAITS_TYPE_IS_C_STR_HPP
#define SPROUT_WEED_TRAITS_TYPE_IS_C_STR_HPP
#include <type_traits>
#include <sprout/config.hpp>
namespace sprout {
namespace weed {
namespace traits {
//
// is_c_str
//
template<typename T>
struct is_c_str
: public std::false_type
{};
template<typename T>
struct is_c_str<T const>
: public sprout::weed::traits::is_c_str<T>
{};
template<std::size_t N>
struct is_c_str<char const[N]>
: public std::true_type
{};
template<std::size_t N>
struct is_c_str<wchar_t const[N]>
: public std::true_type
{};
template<std::size_t N>
struct is_c_str<char16_t const[N]>
: public std::true_type
{};
template<std::size_t N>
struct is_c_str<char32_t const[N]>
: public std::true_type
{};
} // namespace traits
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_TRAITS_TYPE_IS_C_STR_HPP

View file

@ -0,0 +1,41 @@
#ifndef SPROUT_WEED_TRAITS_TYPE_IS_CHAR_TYPE_HPP
#define SPROUT_WEED_TRAITS_TYPE_IS_CHAR_TYPE_HPP
#include <type_traits>
#include <sprout/config.hpp>
namespace sprout {
namespace weed {
namespace traits {
//
// is_char_type
//
template<typename T>
struct is_char_type
: public std::false_type
{};
template<typename T>
struct is_char_type<T const>
: public sprout::weed::traits::is_char_type<T>
{};
template<>
struct is_char_type<char>
: public std::true_type
{};
template<>
struct is_char_type<wchar_t>
: public std::true_type
{};
template<>
struct is_char_type<char16_t>
: public std::true_type
{};
template<>
struct is_char_type<char32_t>
: public std::true_type
{};
} // namespace traits
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_TRAITS_TYPE_IS_CHAR_TYPE_HPP

View file

@ -0,0 +1,35 @@
#ifndef SPROUT_WEED_TRAITS_TYPE_IS_CONTAINER_HPP
#define SPROUT_WEED_TRAITS_TYPE_IS_CONTAINER_HPP
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/string.hpp>
#include <sprout/array.hpp>
namespace sprout {
namespace weed {
namespace traits {
//
// is_container
//
template<typename T>
struct is_container
: public std::false_type
{};
template<typename T>
struct is_container<T const>
: public sprout::weed::traits::is_container<T>
{};
template<typename T, std::size_t N>
struct is_container<sprout::array<T, N> >
: public std::true_type
{};
template<typename T, std::size_t N, typename Traits>
struct is_container<sprout::basic_string<T, N, Traits> >
: public std::true_type
{};
} // namespace traits
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_TRAITS_TYPE_IS_CONTAINER_HPP

View file

@ -0,0 +1,30 @@
#ifndef SPROUT_WEED_TRAITS_TYPE_IS_STRING_HPP
#define SPROUT_WEED_TRAITS_TYPE_IS_STRING_HPP
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/string.hpp>
namespace sprout {
namespace weed {
namespace traits {
//
// is_string
//
template<typename T>
struct is_string
: public std::false_type
{};
template<typename T>
struct is_string<T const>
: public sprout::weed::traits::is_string<T>
{};
template<typename T, std::size_t N, typename Traits>
struct is_string<sprout::basic_string<T, N, Traits> >
: public std::true_type
{};
} // namespace traits
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_TRAITS_TYPE_IS_STRING_HPP

View file

@ -0,0 +1,30 @@
#ifndef SPROUT_WEED_TRAITS_TYPE_IS_TUPLE_HPP
#define SPROUT_WEED_TRAITS_TYPE_IS_TUPLE_HPP
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/tuple/tuple.hpp>
namespace sprout {
namespace weed {
namespace traits {
//
// is_tuple
//
template<typename T>
struct is_tuple
: public std::false_type
{};
template<typename T>
struct is_tuple<T const>
: public sprout::weed::traits::is_tuple<T>
{};
template<typename... Types>
struct is_tuple<sprout::tuples::tuple<Types...> >
: public std::true_type
{};
} // namespace traits
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_TRAITS_TYPE_IS_TUPLE_HPP

View file

@ -0,0 +1,26 @@
#ifndef SPROUT_WEED_TRAITS_TYPE_IS_UNUSED_HPP
#define SPROUT_WEED_TRAITS_TYPE_IS_UNUSED_HPP
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/weed/unused.hpp>
namespace sprout {
namespace weed {
namespace traits {
//
// is_unused
//
template<typename T>
struct is_unused
: public std::is_same<T, sprout::weed::unused>
{};
template<typename T>
struct is_unused<T const>
: public sprout::weed::traits::is_unused<T>
{};
} // namespace traits
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_TRAITS_TYPE_IS_UNUSED_HPP

24
sprout/weed/unused.hpp Normal file
View file

@ -0,0 +1,24 @@
#ifndef SPROUT_WEED_UNUSED_HPP
#define SPROUT_WEED_UNUSED_HPP
#include <sprout/config.hpp>
namespace sprout {
namespace weed {
//
// unused
//
struct unused {
public:
unused() = default;
template<typename T>
SPROUT_CONSTEXPR unused(T) {}
template<typename T>
SPROUT_CONSTEXPR operator T() const {
return T();
}
};
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_UNUSED_HPP