From ecfc2b297a028bc1efb87e61f0ae41a91aa3968d Mon Sep 17 00:00:00 2001 From: bolero-MURAKAMI Date: Sun, 13 Nov 2011 17:54:38 +0900 Subject: [PATCH] =?UTF-8?q?sprout/weed.hpp=20=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sprout/weed.hpp | 16 ++ sprout/weed/attr_cnv.hpp | 10 + sprout/weed/attr_cnv/bitwise_or.hpp | 141 ++++++++++ sprout/weed/attr_cnv/modulus.hpp | 24 ++ sprout/weed/attr_cnv/result_of.hpp | 10 + sprout/weed/attr_cnv/result_of/bitwise_or.hpp | 154 ++++++++++ sprout/weed/attr_cnv/result_of/modulus.hpp | 24 ++ sprout/weed/attr_cnv/result_of/shift_left.hpp | 178 ++++++++++++ sprout/weed/attr_cnv/result_of/times.hpp | 74 +++++ sprout/weed/attr_cnv/shift_left.hpp | 125 ++++++++ sprout/weed/attr_cnv/times.hpp | 53 ++++ sprout/weed/context.hpp | 7 + sprout/weed/context/parse_context.hpp | 9 + .../weed/context/parse_context/operator.hpp | 13 + .../parse_context/operator/address_of.hpp | 50 ++++ .../parse_context/operator/bitwise_or.hpp | 94 +++++++ .../parse_context/operator/dereference.hpp | 214 ++++++++++++++ .../parse_context/operator/logical_not.hpp | 50 ++++ .../parse_context/operator/modulus.hpp | 266 ++++++++++++++++++ .../parse_context/operator/shift_left.hpp | 91 ++++++ .../parse_context/operator/unary_plus.hpp | 214 ++++++++++++++ .../weed/context/parse_context/terminal.hpp | 9 + .../parse_context/terminal/char_type.hpp | 62 ++++ .../context/parse_context/terminal/parser.hpp | 68 +++++ .../context/parse_context/terminal/string.hpp | 75 +++++ sprout/weed/context/parse_context_fwd.hpp | 41 +++ sprout/weed/detail/c_str_as_string.hpp | 22 ++ sprout/weed/detail/is_both_tuple.hpp | 30 ++ sprout/weed/detail/is_both_unused.hpp | 30 ++ sprout/weed/detail/is_container_and_elem.hpp | 33 +++ sprout/weed/detail/is_different_elem.hpp | 43 +++ sprout/weed/detail/is_elem_and_container.hpp | 33 +++ sprout/weed/detail/is_elem_and_tuple.hpp | 32 +++ sprout/weed/detail/is_elem_and_unused.hpp | 30 ++ sprout/weed/detail/is_same_container.hpp | 34 +++ sprout/weed/detail/is_same_elem.hpp | 43 +++ sprout/weed/detail/is_tuple_and_elem.hpp | 32 +++ sprout/weed/detail/is_unused_and_elem.hpp | 30 ++ sprout/weed/detail/uncvref.hpp | 23 ++ sprout/weed/detail/xdigits.hpp | 86 ++++++ sprout/weed/eval_result.hpp | 56 ++++ sprout/weed/expr.hpp | 12 + sprout/weed/expr/eval.hpp | 32 +++ sprout/weed/expr/expr.hpp | 32 +++ sprout/weed/expr/make_expr.hpp | 25 ++ sprout/weed/expr/make_terminal.hpp | 42 +++ sprout/weed/expr/make_terminal_or_expr.hpp | 38 +++ sprout/weed/expr/tag.hpp | 21 ++ sprout/weed/limited.hpp | 22 ++ sprout/weed/operator.hpp | 13 + sprout/weed/operator/address_of.hpp | 37 +++ sprout/weed/operator/bitwise_or.hpp | 43 +++ sprout/weed/operator/dereference.hpp | 37 +++ sprout/weed/operator/logical_not.hpp | 37 +++ sprout/weed/operator/modulus.hpp | 43 +++ sprout/weed/operator/shift_left.hpp | 43 +++ sprout/weed/operator/unary_plus.hpp | 37 +++ sprout/weed/parse.hpp | 32 +++ sprout/weed/parser.hpp | 14 + sprout/weed/parser/auxiliary.hpp | 9 + sprout/weed/parser/auxiliary/eoi.hpp | 49 ++++ sprout/weed/parser/auxiliary/eol.hpp | 62 ++++ sprout/weed/parser/auxiliary/eps.hpp | 49 ++++ sprout/weed/parser/char.hpp | 8 + sprout/weed/parser/char/char.hpp | 161 +++++++++++ sprout/weed/parser/char/char_class.hpp | 132 +++++++++ sprout/weed/parser/directive.hpp | 8 + sprout/weed/parser/directive/omit.hpp | 86 ++++++ sprout/weed/parser/directive/repeat.hpp | 211 ++++++++++++++ sprout/weed/parser/lim.hpp | 95 +++++++ sprout/weed/parser/lit.hpp | 33 +++ sprout/weed/parser/numeric.hpp | 7 + sprout/weed/parser/numeric/hex.hpp | 132 +++++++++ sprout/weed/parser/parser_base.hpp | 15 + sprout/weed/parser/string.hpp | 7 + sprout/weed/parser/string/string.hpp | 162 +++++++++++ sprout/weed/parser_result.hpp | 41 +++ sprout/weed/traits.hpp | 9 + sprout/weed/traits/expr.hpp | 11 + sprout/weed/traits/expr/expr_of.hpp | 30 ++ sprout/weed/traits/expr/is_expr.hpp | 30 ++ sprout/weed/traits/expr/tag_of.hpp | 34 +++ sprout/weed/traits/expr/terminal_of.hpp | 56 ++++ .../weed/traits/expr/terminal_or_expr_of.hpp | 31 ++ sprout/weed/traits/parser.hpp | 9 + sprout/weed/traits/parser/attribute_of.hpp | 115 ++++++++ sprout/weed/traits/parser/is_parser.hpp | 75 +++++ sprout/weed/traits/parser/limit_of.hpp | 32 +++ sprout/weed/traits/type.hpp | 12 + sprout/weed/traits/type/is_c_str.hpp | 41 +++ sprout/weed/traits/type/is_char_type.hpp | 41 +++ sprout/weed/traits/type/is_container.hpp | 35 +++ sprout/weed/traits/type/is_string.hpp | 30 ++ sprout/weed/traits/type/is_tuple.hpp | 30 ++ sprout/weed/traits/type/is_unused.hpp | 26 ++ sprout/weed/unused.hpp | 24 ++ 96 files changed, 5127 insertions(+) create mode 100644 sprout/weed.hpp create mode 100644 sprout/weed/attr_cnv.hpp create mode 100644 sprout/weed/attr_cnv/bitwise_or.hpp create mode 100644 sprout/weed/attr_cnv/modulus.hpp create mode 100644 sprout/weed/attr_cnv/result_of.hpp create mode 100644 sprout/weed/attr_cnv/result_of/bitwise_or.hpp create mode 100644 sprout/weed/attr_cnv/result_of/modulus.hpp create mode 100644 sprout/weed/attr_cnv/result_of/shift_left.hpp create mode 100644 sprout/weed/attr_cnv/result_of/times.hpp create mode 100644 sprout/weed/attr_cnv/shift_left.hpp create mode 100644 sprout/weed/attr_cnv/times.hpp create mode 100644 sprout/weed/context.hpp create mode 100644 sprout/weed/context/parse_context.hpp create mode 100644 sprout/weed/context/parse_context/operator.hpp create mode 100644 sprout/weed/context/parse_context/operator/address_of.hpp create mode 100644 sprout/weed/context/parse_context/operator/bitwise_or.hpp create mode 100644 sprout/weed/context/parse_context/operator/dereference.hpp create mode 100644 sprout/weed/context/parse_context/operator/logical_not.hpp create mode 100644 sprout/weed/context/parse_context/operator/modulus.hpp create mode 100644 sprout/weed/context/parse_context/operator/shift_left.hpp create mode 100644 sprout/weed/context/parse_context/operator/unary_plus.hpp create mode 100644 sprout/weed/context/parse_context/terminal.hpp create mode 100644 sprout/weed/context/parse_context/terminal/char_type.hpp create mode 100644 sprout/weed/context/parse_context/terminal/parser.hpp create mode 100644 sprout/weed/context/parse_context/terminal/string.hpp create mode 100644 sprout/weed/context/parse_context_fwd.hpp create mode 100644 sprout/weed/detail/c_str_as_string.hpp create mode 100644 sprout/weed/detail/is_both_tuple.hpp create mode 100644 sprout/weed/detail/is_both_unused.hpp create mode 100644 sprout/weed/detail/is_container_and_elem.hpp create mode 100644 sprout/weed/detail/is_different_elem.hpp create mode 100644 sprout/weed/detail/is_elem_and_container.hpp create mode 100644 sprout/weed/detail/is_elem_and_tuple.hpp create mode 100644 sprout/weed/detail/is_elem_and_unused.hpp create mode 100644 sprout/weed/detail/is_same_container.hpp create mode 100644 sprout/weed/detail/is_same_elem.hpp create mode 100644 sprout/weed/detail/is_tuple_and_elem.hpp create mode 100644 sprout/weed/detail/is_unused_and_elem.hpp create mode 100644 sprout/weed/detail/uncvref.hpp create mode 100644 sprout/weed/detail/xdigits.hpp create mode 100644 sprout/weed/eval_result.hpp create mode 100644 sprout/weed/expr.hpp create mode 100644 sprout/weed/expr/eval.hpp create mode 100644 sprout/weed/expr/expr.hpp create mode 100644 sprout/weed/expr/make_expr.hpp create mode 100644 sprout/weed/expr/make_terminal.hpp create mode 100644 sprout/weed/expr/make_terminal_or_expr.hpp create mode 100644 sprout/weed/expr/tag.hpp create mode 100644 sprout/weed/limited.hpp create mode 100644 sprout/weed/operator.hpp create mode 100644 sprout/weed/operator/address_of.hpp create mode 100644 sprout/weed/operator/bitwise_or.hpp create mode 100644 sprout/weed/operator/dereference.hpp create mode 100644 sprout/weed/operator/logical_not.hpp create mode 100644 sprout/weed/operator/modulus.hpp create mode 100644 sprout/weed/operator/shift_left.hpp create mode 100644 sprout/weed/operator/unary_plus.hpp create mode 100644 sprout/weed/parse.hpp create mode 100644 sprout/weed/parser.hpp create mode 100644 sprout/weed/parser/auxiliary.hpp create mode 100644 sprout/weed/parser/auxiliary/eoi.hpp create mode 100644 sprout/weed/parser/auxiliary/eol.hpp create mode 100644 sprout/weed/parser/auxiliary/eps.hpp create mode 100644 sprout/weed/parser/char.hpp create mode 100644 sprout/weed/parser/char/char.hpp create mode 100644 sprout/weed/parser/char/char_class.hpp create mode 100644 sprout/weed/parser/directive.hpp create mode 100644 sprout/weed/parser/directive/omit.hpp create mode 100644 sprout/weed/parser/directive/repeat.hpp create mode 100644 sprout/weed/parser/lim.hpp create mode 100644 sprout/weed/parser/lit.hpp create mode 100644 sprout/weed/parser/numeric.hpp create mode 100644 sprout/weed/parser/numeric/hex.hpp create mode 100644 sprout/weed/parser/parser_base.hpp create mode 100644 sprout/weed/parser/string.hpp create mode 100644 sprout/weed/parser/string/string.hpp create mode 100644 sprout/weed/parser_result.hpp create mode 100644 sprout/weed/traits.hpp create mode 100644 sprout/weed/traits/expr.hpp create mode 100644 sprout/weed/traits/expr/expr_of.hpp create mode 100644 sprout/weed/traits/expr/is_expr.hpp create mode 100644 sprout/weed/traits/expr/tag_of.hpp create mode 100644 sprout/weed/traits/expr/terminal_of.hpp create mode 100644 sprout/weed/traits/expr/terminal_or_expr_of.hpp create mode 100644 sprout/weed/traits/parser.hpp create mode 100644 sprout/weed/traits/parser/attribute_of.hpp create mode 100644 sprout/weed/traits/parser/is_parser.hpp create mode 100644 sprout/weed/traits/parser/limit_of.hpp create mode 100644 sprout/weed/traits/type.hpp create mode 100644 sprout/weed/traits/type/is_c_str.hpp create mode 100644 sprout/weed/traits/type/is_char_type.hpp create mode 100644 sprout/weed/traits/type/is_container.hpp create mode 100644 sprout/weed/traits/type/is_string.hpp create mode 100644 sprout/weed/traits/type/is_tuple.hpp create mode 100644 sprout/weed/traits/type/is_unused.hpp create mode 100644 sprout/weed/unused.hpp diff --git a/sprout/weed.hpp b/sprout/weed.hpp new file mode 100644 index 00000000..a8fe356e --- /dev/null +++ b/sprout/weed.hpp @@ -0,0 +1,16 @@ +#ifndef SPROUT_WEED_HPP +#define SPROUT_WEED_HPP + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#endif // #ifndef SPROUT_WEED_HPP diff --git a/sprout/weed/attr_cnv.hpp b/sprout/weed/attr_cnv.hpp new file mode 100644 index 00000000..2109dbf5 --- /dev/null +++ b/sprout/weed/attr_cnv.hpp @@ -0,0 +1,10 @@ +#ifndef SPROUT_WEED_ATTR_CNV_HPP +#define SPROUT_WEED_ATTR_CNV_HPP + +#include +#include +#include +#include +#include + +#endif // #ifndef SPROUT_WEED_ATTR_CNV_HPP diff --git a/sprout/weed/attr_cnv/bitwise_or.hpp b/sprout/weed/attr_cnv/bitwise_or.hpp new file mode 100644 index 00000000..18b13563 --- /dev/null +++ b/sprout/weed/attr_cnv/bitwise_or.hpp @@ -0,0 +1,141 @@ +#ifndef SPROUT_WEED_ATTR_CNV_BITWISE_OR_HPP +#define SPROUT_WEED_ATTR_CNV_BITWISE_OR_HPP + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace sprout { + namespace weed { + namespace attr_cnv { + // + // bitwise_or + // + // container | container -> container + template + SPROUT_CONSTEXPR inline typename std::enable_if< + sprout::weed::detail::is_same_container::value, + typename sprout::weed::attr_cnv::result_of::bitwise_or::type + >::type bitwise_or(X const& x) { + typedef typename sprout::weed::attr_cnv::result_of::bitwise_or::type type; + return sprout::fixed::realign_to(x); + } + // container | V -> container + template + SPROUT_CONSTEXPR inline typename std::enable_if< + sprout::weed::detail::is_container_and_elem::value + && sprout::weed::traits::is_container::value, + typename sprout::weed::attr_cnv::result_of::bitwise_or::type + >::type bitwise_or(X const& x) { + typedef typename sprout::weed::attr_cnv::result_of::bitwise_or::type type; + return sprout::fixed::realign_to(x); + } + template + SPROUT_CONSTEXPR inline typename std::enable_if< + sprout::weed::detail::is_container_and_elem::value + && !sprout::weed::traits::is_container::value, + typename sprout::weed::attr_cnv::result_of::bitwise_or::type + >::type bitwise_or(X const& x) { + typedef typename sprout::weed::attr_cnv::result_of::bitwise_or::type type; + return sprout::make_clone(x); + } + // V | container -> container + template + SPROUT_CONSTEXPR inline typename std::enable_if< + sprout::weed::detail::is_elem_and_container::value + && sprout::weed::traits::is_container::value, + typename sprout::weed::attr_cnv::result_of::bitwise_or::type + >::type bitwise_or(X const& x) { + typedef typename sprout::weed::attr_cnv::result_of::bitwise_or::type type; + return sprout::fixed::realign_to(x); + } + template + SPROUT_CONSTEXPR inline typename std::enable_if< + sprout::weed::detail::is_elem_and_container::value + && !sprout::weed::traits::is_container::value, + typename sprout::weed::attr_cnv::result_of::bitwise_or::type + >::type bitwise_or(X const& x) { + typedef typename sprout::weed::attr_cnv::result_of::bitwise_or::type type; + return sprout::make_clone(x); + } + // tuple | tuple -> tuple + template + SPROUT_CONSTEXPR inline typename std::enable_if< + sprout::weed::detail::is_both_tuple::value, + typename sprout::weed::attr_cnv::result_of::bitwise_or::type + >::type bitwise_or(X const& x) { + typedef typename sprout::weed::attr_cnv::result_of::bitwise_or::type type; + return sprout::tuples::copy(type(), x); + } + // V | V -> V + template + SPROUT_CONSTEXPR inline typename std::enable_if< + sprout::weed::detail::is_same_elem::value, + typename sprout::weed::attr_cnv::result_of::bitwise_or::type + >::type bitwise_or(X const& x) { + return x; + } + // V | unused -> container + template + SPROUT_CONSTEXPR inline typename std::enable_if< + sprout::weed::detail::is_elem_and_unused::value + && !sprout::weed::traits::is_unused::value, + typename sprout::weed::attr_cnv::result_of::bitwise_or::type + >::type bitwise_or(X const& x) { + typedef typename sprout::weed::attr_cnv::result_of::bitwise_or::type type; + return sprout::make_clone(x); + } + template + SPROUT_CONSTEXPR inline typename std::enable_if< + sprout::weed::detail::is_elem_and_unused::value + && sprout::weed::traits::is_unused::value, + typename sprout::weed::attr_cnv::result_of::bitwise_or::type + >::type bitwise_or(X const& x) { + typedef typename sprout::weed::attr_cnv::result_of::bitwise_or::type type; + return sprout::make_clone(); + } + // unused | V -> container + template + SPROUT_CONSTEXPR inline typename std::enable_if< + sprout::weed::detail::is_unused_and_elem::value + && !sprout::weed::traits::is_unused::value, + typename sprout::weed::attr_cnv::result_of::bitwise_or::type + >::type bitwise_or(X const& x) { + typedef typename sprout::weed::attr_cnv::result_of::bitwise_or::type type; + return sprout::make_clone(x); + } + template + SPROUT_CONSTEXPR inline typename std::enable_if< + sprout::weed::detail::is_unused_and_elem::value + && sprout::weed::traits::is_unused::value, + typename sprout::weed::attr_cnv::result_of::bitwise_or::type + >::type bitwise_or(X const& x) { + typedef typename sprout::weed::attr_cnv::result_of::bitwise_or::type type; + return sprout::make_clone(); + } + // unused >> unused -> unused + template + SPROUT_CONSTEXPR inline typename std::enable_if< + sprout::weed::detail::is_both_unused::value, + typename sprout::weed::attr_cnv::result_of::bitwise_or::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 diff --git a/sprout/weed/attr_cnv/modulus.hpp b/sprout/weed/attr_cnv/modulus.hpp new file mode 100644 index 00000000..bff87383 --- /dev/null +++ b/sprout/weed/attr_cnv/modulus.hpp @@ -0,0 +1,24 @@ +#ifndef SPROUT_WEED_ATTR_CNV_MODULUS_HPP +#define SPROUT_WEED_ATTR_CNV_MODULUS_HPP + +#include +#include +#include +#include + +namespace sprout { + namespace weed { + namespace attr_cnv { + // + // modulus + // + template + SPROUT_CONSTEXPR inline typename sprout::weed::attr_cnv::result_of::modulus::type + modulus(Args const&... args) { + return sprout::weed::attr_cnv::times(args...); + } + } // namespace attr_cnv + } // namespace weed +} // namespace sprout + +#endif // #ifndef SPROUT_WEED_ATTR_CNV_MODULUS_HPP diff --git a/sprout/weed/attr_cnv/result_of.hpp b/sprout/weed/attr_cnv/result_of.hpp new file mode 100644 index 00000000..0e672018 --- /dev/null +++ b/sprout/weed/attr_cnv/result_of.hpp @@ -0,0 +1,10 @@ +#ifndef SPROUT_WEED_ATTR_CNV_RESULT_OF_HPP +#define SPROUT_WEED_ATTR_CNV_RESULT_OF_HPP + +#include +#include +#include +#include +#include + +#endif // #ifndef SPROUT_WEED_ATTR_CNV_RESULT_OF_HPP diff --git a/sprout/weed/attr_cnv/result_of/bitwise_or.hpp b/sprout/weed/attr_cnv/result_of/bitwise_or.hpp new file mode 100644 index 00000000..2bed1931 --- /dev/null +++ b/sprout/weed/attr_cnv/result_of/bitwise_or.hpp @@ -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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace sprout { + namespace weed { + namespace attr_cnv { + namespace result_of { + // + // bitwise_or + // + template + struct bitwise_or; + // container | container -> container + template + struct bitwise_or< + T, + U, + typename std::enable_if< + sprout::weed::detail::is_same_container::value + >::type + > { + public: + typedef typename std::conditional< + !(sprout::tuples::tuple_size::value < sprout::tuples::tuple_size::value), + T, + U + >::type type; + }; + // container | V -> container + template + struct bitwise_or< + T, + U, + typename std::enable_if< + sprout::weed::detail::is_container_and_elem::value + >::type + > { + public: + typedef typename std::conditional< + sprout::fixed_container_traits::fixed_size != 0, + T, + typename sprout::rebind_fixed_size::template apply<1>::type + >::type type; + }; + // V | container -> container + template + struct bitwise_or< + T, + U, + typename std::enable_if< + sprout::weed::detail::is_elem_and_container::value + >::type + > { + public: + typedef typename std::conditional< + sprout::fixed_container_traits::fixed_size != 0, + U, + typename sprout::rebind_fixed_size::template apply<1>::type + >::type type; + }; + // tuple | tuple -> tuple + template + struct bitwise_or< + T, + U, + typename std::enable_if< + sprout::weed::detail::is_both_tuple::value + >::type + > { + public: + typedef typename std::conditional< + !(sprout::tuples::tuple_size::value < sprout::tuples::tuple_size::value), + T, + U + >::type type; + }; + // V | V -> V + template + struct bitwise_or< + T, + U, + typename std::enable_if< + sprout::weed::detail::is_same_elem::value + >::type + > { + public: + typedef T type; + }; + // V | unused -> container + template + struct bitwise_or< + T, + U, + typename std::enable_if< + sprout::weed::detail::is_elem_and_unused::value + >::type + > { + public: + typedef typename std::conditional< + sprout::weed::traits::is_char_type::value, + sprout::basic_string, + sprout::array + >::type type; + }; + // unused | V -> container + template + struct bitwise_or< + T, + U, + typename std::enable_if< + sprout::weed::detail::is_unused_and_elem::value + >::type + > { + public: + typedef typename std::conditional< + sprout::weed::traits::is_char_type::value, + sprout::basic_string, + sprout::array + >::type type; + }; + // unused | unused -> unused + template + struct bitwise_or< + T, + U, + typename std::enable_if< + sprout::weed::detail::is_both_unused::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 diff --git a/sprout/weed/attr_cnv/result_of/modulus.hpp b/sprout/weed/attr_cnv/result_of/modulus.hpp new file mode 100644 index 00000000..be41b5ea --- /dev/null +++ b/sprout/weed/attr_cnv/result_of/modulus.hpp @@ -0,0 +1,24 @@ +#ifndef SPROUT_WEED_ATTR_CNV_RESULT_OF_MODULUS_HPP +#define SPROUT_WEED_ATTR_CNV_RESULT_OF_MODULUS_HPP + +#include +#include +#include + +namespace sprout { + namespace weed { + namespace attr_cnv { + namespace result_of { + // + // modulus + // + template + struct modulus + : public sprout::weed::attr_cnv::result_of::times + {}; + } // namespace result_of + } // namespace attr_cnv + } // namespace weed +} // namespace sprout + +#endif // #ifndef SPROUT_WEED_ATTR_CNV_RESULT_OF_MODULUS_HPP diff --git a/sprout/weed/attr_cnv/result_of/shift_left.hpp b/sprout/weed/attr_cnv/result_of/shift_left.hpp new file mode 100644 index 00000000..16befd6c --- /dev/null +++ b/sprout/weed/attr_cnv/result_of/shift_left.hpp @@ -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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace sprout { + namespace weed { + namespace attr_cnv { + namespace result_of { + // + // shift_left + // + template + struct shift_left; + // container >> container -> container + template + struct shift_left< + T, + U, + typename std::enable_if< + sprout::weed::detail::is_same_container::value + >::type + > { + public: + typedef typename sprout::fixed::result_of::append_back::type type; + }; + // container >> V -> container + template + struct shift_left< + T, + U, + typename std::enable_if< + sprout::weed::detail::is_container_and_elem::value + >::type + > { + public: + typedef typename sprout::fixed::result_of::push_back::type type; + }; + // V >> container -> container + template + struct shift_left< + T, + U, + typename std::enable_if< + sprout::weed::detail::is_elem_and_container::value + >::type + > { + public: + typedef typename sprout::fixed::result_of::push_front::type type; + }; + // tuple >> tuple -> tuple + template + struct shift_left< + T, + U, + typename std::enable_if< + sprout::weed::detail::is_both_tuple::value + >::type + > { + public: + typedef typename sprout::tuples::result_of::append_back::type type; + }; + // tuple >> V -> tuple + template + struct shift_left< + T, + U, + typename std::enable_if< + sprout::weed::detail::is_tuple_and_elem::value + >::type + > { + public: + typedef typename sprout::tuples::result_of::push_back::type type; + }; + // V >> tuple -> tuple + template + struct shift_left< + T, + U, + typename std::enable_if< + sprout::weed::detail::is_elem_and_tuple::value + >::type + > { + public: + typedef typename sprout::tuples::result_of::push_front::type type; + }; + // V >> V -> container + template + struct shift_left< + T, + U, + typename std::enable_if< + sprout::weed::detail::is_same_elem::value + >::type + > { + public: + typedef typename std::conditional< + sprout::weed::traits::is_char_type::value, + sprout::basic_string, + sprout::array + >::type type; + }; + // V >> W -> tuple + template + struct shift_left< + T, + U, + typename std::enable_if< + sprout::weed::detail::is_different_elem::value + >::type + > { + public: + typedef sprout::tuples::tuple type; + }; + // V >> unused -> V + template + struct shift_left< + T, + U, + typename std::enable_if< + sprout::weed::detail::is_elem_and_unused::value + >::type + > { + public: + typedef T type; + }; + // unused >> V -> V + template + struct shift_left< + T, + U, + typename std::enable_if< + sprout::weed::detail::is_unused_and_elem::value + >::type + > { + public: + typedef U type; + }; + // unused >> unused -> unused + template + struct shift_left< + T, + U, + typename std::enable_if< + sprout::weed::detail::is_both_unused::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 diff --git a/sprout/weed/attr_cnv/result_of/times.hpp b/sprout/weed/attr_cnv/result_of/times.hpp new file mode 100644 index 00000000..947d1ae6 --- /dev/null +++ b/sprout/weed/attr_cnv/result_of/times.hpp @@ -0,0 +1,74 @@ +#ifndef SPROUT_WEED_ATTR_CNV_RESULT_OF_TIMES_HPP +#define SPROUT_WEED_ATTR_CNV_RESULT_OF_TIMES_HPP + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace sprout { + namespace weed { + namespace attr_cnv { + namespace result_of { + // + // times + // + template + struct times; + // times(container) -> container + template + struct times< + Limit, + T, + typename std::enable_if< + Limit != std::size_t(-1) + && sprout::weed::traits::is_container::value + >::type + > { + public: + typedef typename sprout::algorithm::result_of::join< + sprout::array + >::type type; + }; + // times(V) -> container + template + struct times< + Limit, + T, + typename std::enable_if< + Limit != std::size_t(-1) + && !sprout::weed::traits::is_container::value + && !sprout::weed::traits::is_unused::value + >::type + > { + public: + typedef typename std::conditional< + sprout::weed::traits::is_char_type::value, + sprout::basic_string, + sprout::array + >::type type; + }; + // times(unused) -> unused + template + struct times< + Limit, + T, + typename std::enable_if< + sprout::weed::traits::is_unused::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 diff --git a/sprout/weed/attr_cnv/shift_left.hpp b/sprout/weed/attr_cnv/shift_left.hpp new file mode 100644 index 00000000..498bf326 --- /dev/null +++ b/sprout/weed/attr_cnv/shift_left.hpp @@ -0,0 +1,125 @@ +#ifndef SPROUT_WEED_ATTR_CNV_SHIFT_LEFT_HPP +#define SPROUT_WEED_ATTR_CNV_SHIFT_LEFT_HPP + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace sprout { + namespace weed { + namespace attr_cnv { + // + // shift_left + // + // container >> container -> container + template + SPROUT_CONSTEXPR inline typename std::enable_if< + sprout::weed::detail::is_same_container::value, + typename sprout::weed::attr_cnv::result_of::shift_left::type + >::type shift_left(T const& t, U const& u) { + return sprout::fixed::append_back(t, u); + } + // container >> V -> container + template + SPROUT_CONSTEXPR inline typename std::enable_if< + sprout::weed::detail::is_container_and_elem::value, + typename sprout::weed::attr_cnv::result_of::shift_left::type + >::type shift_left(T const& t, U const& u) { + return sprout::fixed::push_back(t, u); + } + // V >> container -> container + template + SPROUT_CONSTEXPR inline typename std::enable_if< + sprout::weed::detail::is_elem_and_container::value, + typename sprout::weed::attr_cnv::result_of::shift_left::type + >::type shift_left(T const& t, U const& u) { + return sprout::fixed::push_front(t, u); + } + // tuple >> tuple -> tuple + template + SPROUT_CONSTEXPR inline typename std::enable_if< + sprout::weed::detail::is_both_tuple::value, + typename sprout::weed::attr_cnv::result_of::shift_left::type + >::type shift_left(T const& t, U const& u) { + return sprout::tuples::append_back(t, u); + } + // tuple >> V -> tuple + template + SPROUT_CONSTEXPR inline typename std::enable_if< + sprout::weed::detail::is_tuple_and_elem::value, + typename sprout::weed::attr_cnv::result_of::shift_left::type + >::type shift_left(T const& t, U const& u) { + return sprout::tuples::push_back(t, u); + } + // V >> tuple -> tuple + template + SPROUT_CONSTEXPR inline typename std::enable_if< + sprout::weed::detail::is_elem_and_tuple::value, + typename sprout::weed::attr_cnv::result_of::shift_left::type + >::type shift_left(T const& t, U const& u) { + return sprout::tuples::push_front(t, u); + } + // V >> V -> container + template + SPROUT_CONSTEXPR inline typename std::enable_if< + sprout::weed::detail::is_same_elem::value, + typename sprout::weed::attr_cnv::result_of::shift_left::type + >::type shift_left(T const& t, U const& u) { + typedef typename sprout::weed::attr_cnv::result_of::shift_left::type type; + return sprout::make_clone(t, u); + } + // V >> W -> tuple + template + SPROUT_CONSTEXPR inline typename std::enable_if< + sprout::weed::detail::is_different_elem::value, + typename sprout::weed::attr_cnv::result_of::shift_left::type + >::type shift_left(T const& t, U const& u) { + return typename sprout::weed::attr_cnv::result_of::shift_left::type(t, u); + } + // V >> unused -> V + template + SPROUT_CONSTEXPR inline typename std::enable_if< + sprout::weed::detail::is_elem_and_unused::value, + typename sprout::weed::attr_cnv::result_of::shift_left::type + >::type shift_left(T const& t, U const& u) { + return t; + } + // unused >> V -> V + template + SPROUT_CONSTEXPR inline typename std::enable_if< + sprout::weed::detail::is_unused_and_elem::value, + typename sprout::weed::attr_cnv::result_of::shift_left::type + >::type shift_left(T const& t, U const& u) { + return u; + } + // unused >> unused -> unused + template + SPROUT_CONSTEXPR inline typename std::enable_if< + sprout::weed::detail::is_both_unused::value, + typename sprout::weed::attr_cnv::result_of::shift_left::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 diff --git a/sprout/weed/attr_cnv/times.hpp b/sprout/weed/attr_cnv/times.hpp new file mode 100644 index 00000000..ee86eeed --- /dev/null +++ b/sprout/weed/attr_cnv/times.hpp @@ -0,0 +1,53 @@ +#ifndef SPROUT_WEED_ATTR_CNV_TIMES_HPP +#define SPROUT_WEED_ATTR_CNV_TIMES_HPP + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace sprout { + namespace weed { + namespace attr_cnv { + // + // times + // + // times(container) -> container + template + static SPROUT_CONSTEXPR typename std::enable_if< + sprout::weed::traits::is_container::value, + typename sprout::weed::attr_cnv::result_of::times::type + >::type times(Args const&... args) { + return sprout::algorithm::join( + sprout::make_clone >(args...) + ); + } + // times(V) -> container + template + static SPROUT_CONSTEXPR typename std::enable_if< + !sprout::weed::traits::is_container::value + && !sprout::weed::traits::is_unused::value, + typename sprout::weed::attr_cnv::result_of::times::type + >::type times(Args const&... args) { + typedef typename sprout::weed::attr_cnv::result_of::times::type type; + return sprout::make_clone(args...); + } + // times(unused) -> unused + template + static SPROUT_CONSTEXPR typename std::enable_if< + sprout::weed::traits::is_unused::value, + typename sprout::weed::attr_cnv::result_of::times::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 diff --git a/sprout/weed/context.hpp b/sprout/weed/context.hpp new file mode 100644 index 00000000..ed9b8bd1 --- /dev/null +++ b/sprout/weed/context.hpp @@ -0,0 +1,7 @@ +#ifndef SPROUT_WEED_CONTEXT_HPP +#define SPROUT_WEED_CONTEXT_HPP + +#include +#include + +#endif // #ifndef SPROUT_WEED_CONTEXT_HPP diff --git a/sprout/weed/context/parse_context.hpp b/sprout/weed/context/parse_context.hpp new file mode 100644 index 00000000..5478eb80 --- /dev/null +++ b/sprout/weed/context/parse_context.hpp @@ -0,0 +1,9 @@ +#ifndef SPROUT_WEED_CONTEXT_PARSE_CONTEXT_HPP +#define SPROUT_WEED_CONTEXT_PARSE_CONTEXT_HPP + +#include +#include +#include +#include + +#endif // #ifndef SPROUT_WEED_CONTEXT_PARSE_CONTEXT_HPP diff --git a/sprout/weed/context/parse_context/operator.hpp b/sprout/weed/context/parse_context/operator.hpp new file mode 100644 index 00000000..e2b4ce25 --- /dev/null +++ b/sprout/weed/context/parse_context/operator.hpp @@ -0,0 +1,13 @@ +#ifndef SPROUT_WEED_CONTEXT_PARSE_CONTEXT_OPERATOR_HPP +#define SPROUT_WEED_CONTEXT_PARSE_CONTEXT_OPERATOR_HPP + +#include +#include +#include +#include +#include +#include +#include +#include + +#endif // #ifndef SPROUT_WEED_CONTEXT_PARSE_CONTEXT_OPERATOR_HPP diff --git a/sprout/weed/context/parse_context/operator/address_of.hpp b/sprout/weed/context/parse_context/operator/address_of.hpp new file mode 100644 index 00000000..5a021fb3 --- /dev/null +++ b/sprout/weed/context/parse_context/operator/address_of.hpp @@ -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 +#include +#include +#include +#include +#include +#include +#include +#include + +namespace sprout { + namespace weed { + // + // parse_context::eval + // + template + template + struct parse_context::eval< + Expr, + typename std::enable_if< + std::is_same< + typename sprout::weed::traits::tag_of::type, + sprout::weed::tag::address_of + >::value + >::type + > { + private: + typedef sprout::weed::parse_context context_type; + public: + typedef typename sprout::weed::traits::attribute_of::type attribute_type; + typedef sprout::weed::eval_result 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 diff --git a/sprout/weed/context/parse_context/operator/bitwise_or.hpp b/sprout/weed/context/parse_context/operator/bitwise_or.hpp new file mode 100644 index 00000000..3928cab1 --- /dev/null +++ b/sprout/weed/context/parse_context/operator/bitwise_or.hpp @@ -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 +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace sprout { + namespace weed { + // + // parse_context::eval + // + template + template + struct parse_context::eval< + Expr, + typename std::enable_if< + std::is_same< + typename sprout::weed::traits::tag_of::type, + sprout::weed::tag::bitwise_or + >::value + >::type + > { + private: + typedef sprout::weed::parse_context 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::type attr1_type; + typedef typename sprout::weed::traits::attribute_of::type attr2_type; + public: + typedef typename sprout::weed::traits::attribute_of::type attribute_type; + typedef sprout::weed::eval_result result_type; + private: + template + 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(res.attr()), + context_type(ctx, res.current()) + ) + : result_type(false, ctx.begin(), attribute_type(), ctx) + ; + } + template + 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(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 diff --git a/sprout/weed/context/parse_context/operator/dereference.hpp b/sprout/weed/context/parse_context/operator/dereference.hpp new file mode 100644 index 00000000..0d874951 --- /dev/null +++ b/sprout/weed/context/parse_context/operator/dereference.hpp @@ -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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace sprout { + namespace weed { + // + // parse_context::eval + // + template + template + struct parse_context::eval< + Expr, + typename std::enable_if< + std::is_same< + typename sprout::weed::traits::tag_of::type, + sprout::weed::tag::dereference + >::value + >::type + > { + private: + typedef sprout::weed::parse_context context_type; + typedef typename sprout::tuples::tuple_element<0, typename Expr::args_type>::type expr_type; + typedef typename sprout::weed::traits::limit_of::type limit; + typedef typename sprout::weed::traits::attribute_of::type attr_type; + public: + typedef typename sprout::weed::traits::attribute_of::type attribute_type; + typedef sprout::weed::eval_result result_type; + private: + template + 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(head, attrs...), + ctx + ) + ; + } + template + 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(head, attrs..., res.attr()), + res.ctx() + ) + : result_type( + true, + ctx.begin(), + sprout::weed::attr_cnv::times(head, attrs...), + ctx + ) + ; + } + template + 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(head, attrs...), + ctx + ) + ; + } + template + 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 + 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 + 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( + 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 diff --git a/sprout/weed/context/parse_context/operator/logical_not.hpp b/sprout/weed/context/parse_context/operator/logical_not.hpp new file mode 100644 index 00000000..644a2cea --- /dev/null +++ b/sprout/weed/context/parse_context/operator/logical_not.hpp @@ -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 +#include +#include +#include +#include +#include +#include +#include +#include + +namespace sprout { + namespace weed { + // + // parse_context::eval + // + template + template + struct parse_context::eval< + Expr, + typename std::enable_if< + std::is_same< + typename sprout::weed::traits::tag_of::type, + sprout::weed::tag::logical_not + >::value + >::type + > { + private: + typedef sprout::weed::parse_context context_type; + public: + typedef typename sprout::weed::traits::attribute_of::type attribute_type; + typedef sprout::weed::eval_result 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 diff --git a/sprout/weed/context/parse_context/operator/modulus.hpp b/sprout/weed/context/parse_context/operator/modulus.hpp new file mode 100644 index 00000000..228cf242 --- /dev/null +++ b/sprout/weed/context/parse_context/operator/modulus.hpp @@ -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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace sprout { + namespace weed { + // + // parse_context::eval + // + template + template + struct parse_context::eval< + Expr, + typename std::enable_if< + std::is_same< + typename sprout::weed::traits::tag_of::type, + sprout::weed::tag::modulus + >::value + >::type + > { + private: + typedef sprout::weed::parse_context 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::type limit; + typedef typename sprout::weed::traits::attribute_of::type attr_type; + public: + typedef typename sprout::weed::traits::attribute_of::type attribute_type; + typedef sprout::weed::eval_result result_type; + private: + template + 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(attrs...), + ctx + ) + ; + } + template + 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(head, attrs...), + ctx + ) + ; + } + template + 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(head, attrs..., res.attr()), + res.ctx() + ) + : result_type( + true, + ctx.begin(), + sprout::weed::attr_cnv::modulus(head, attrs...), + ctx + ) + ; + } + template + 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(head, attrs...), + ctx + ) + ; + } + template + 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 + 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 + 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 + 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( + 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 diff --git a/sprout/weed/context/parse_context/operator/shift_left.hpp b/sprout/weed/context/parse_context/operator/shift_left.hpp new file mode 100644 index 00000000..a6ba5875 --- /dev/null +++ b/sprout/weed/context/parse_context/operator/shift_left.hpp @@ -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 +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace sprout { + namespace weed { + // + // parse_context::eval + // + template + template + struct parse_context::eval< + Expr, + typename std::enable_if< + std::is_same< + typename sprout::weed::traits::tag_of::type, + sprout::weed::tag::shift_left + >::value + >::type + > { + private: + typedef sprout::weed::parse_context context_type; + public: + typedef typename sprout::weed::traits::attribute_of::type attribute_type; + typedef sprout::weed::eval_result result_type; + private: + template + 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 + 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 diff --git a/sprout/weed/context/parse_context/operator/unary_plus.hpp b/sprout/weed/context/parse_context/operator/unary_plus.hpp new file mode 100644 index 00000000..272ca7f3 --- /dev/null +++ b/sprout/weed/context/parse_context/operator/unary_plus.hpp @@ -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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace sprout { + namespace weed { + // + // parse_context::eval + // + template + template + struct parse_context::eval< + Expr, + typename std::enable_if< + std::is_same< + typename sprout::weed::traits::tag_of::type, + sprout::weed::tag::unary_plus + >::value + >::type + > { + private: + typedef sprout::weed::parse_context context_type; + typedef typename sprout::tuples::tuple_element<0, typename Expr::args_type>::type expr_type; + typedef typename sprout::weed::traits::limit_of::type limit; + typedef typename sprout::weed::traits::attribute_of::type attr_type; + public: + typedef typename sprout::weed::traits::attribute_of::type attribute_type; + typedef sprout::weed::eval_result result_type; + private: + template + 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(head, attrs...), + ctx + ) + ; + } + template + 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(head, attrs..., res.attr()), + res.ctx() + ) + : result_type( + true, + ctx.begin(), + sprout::weed::attr_cnv::times(head, attrs...), + ctx + ) + ; + } + template + 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(head, attrs...), + ctx + ) + ; + } + template + 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 + 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 + 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( + 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 diff --git a/sprout/weed/context/parse_context/terminal.hpp b/sprout/weed/context/parse_context/terminal.hpp new file mode 100644 index 00000000..ad6820ce --- /dev/null +++ b/sprout/weed/context/parse_context/terminal.hpp @@ -0,0 +1,9 @@ +#ifndef SPROUT_WEED_CONTEXT_PARSE_CONTEXT_TERMINAL_HPP +#define SPROUT_WEED_CONTEXT_PARSE_CONTEXT_TERMINAL_HPP + +#include +#include +#include +#include + +#endif // #ifndef SPROUT_WEED_CONTEXT_PARSE_CONTEXT_TERMINAL_HPP diff --git a/sprout/weed/context/parse_context/terminal/char_type.hpp b/sprout/weed/context/parse_context/terminal/char_type.hpp new file mode 100644 index 00000000..4e1340a6 --- /dev/null +++ b/sprout/weed/context/parse_context/terminal/char_type.hpp @@ -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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace sprout { + namespace weed { + // + // parse_context::eval + // + template + template + struct parse_context::eval< + Expr, + typename std::enable_if< + std::is_same< + typename sprout::weed::traits::tag_of::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 context_type; + public: + typedef typename sprout::weed::traits::attribute_of::type attribute_type; + typedef sprout::weed::eval_result result_type; + public: + SPROUT_CONSTEXPR result_type operator()( + Expr const& expr, + context_type const& ctx + ) const + { + typedef typename std::iterator_traits::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 diff --git a/sprout/weed/context/parse_context/terminal/parser.hpp b/sprout/weed/context/parse_context/terminal/parser.hpp new file mode 100644 index 00000000..2b8a24c8 --- /dev/null +++ b/sprout/weed/context/parse_context/terminal/parser.hpp @@ -0,0 +1,68 @@ +#ifndef SPROUT_WEED_CONTEXT_PARSE_CONTEXT_TERMINAL_PARSER_HPP +#define SPROUT_WEED_CONTEXT_PARSE_CONTEXT_TERMINAL_PARSER_HPP + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace sprout { + namespace weed { + // + // parse_context::eval + // + template + template + struct parse_context::eval< + Expr, + typename std::enable_if< + std::is_same< + typename sprout::weed::traits::tag_of::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 context_type; + typedef typename sprout::tuples::tuple_element<0, typename Expr::args_type>::type parser_type; + public: + typedef typename sprout::weed::traits::attribute_of::type attribute_type; + typedef sprout::weed::eval_result result_type; + private: + template + 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 diff --git a/sprout/weed/context/parse_context/terminal/string.hpp b/sprout/weed/context/parse_context/terminal/string.hpp new file mode 100644 index 00000000..eed0f2e2 --- /dev/null +++ b/sprout/weed/context/parse_context/terminal/string.hpp @@ -0,0 +1,75 @@ +#ifndef SPROUT_WEED_CONTEXT_PARSE_CONTEXT_TERMINAL_STRING_HPP +#define SPROUT_WEED_CONTEXT_PARSE_CONTEXT_TERMINAL_STRING_HPP + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include HDR_ALGORITHM_SSCRISK_CEL_OR_SPROUT_DETAIL +#include HDR_ITERATOR_SSCRISK_CEL_OR_SPROUT_DETAIL + +namespace sprout { + namespace weed { + // + // parse_context::eval + // + template + template + struct parse_context::eval< + Expr, + typename std::enable_if< + std::is_same< + typename sprout::weed::traits::tag_of::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 context_type; + public: + typedef typename sprout::weed::traits::attribute_of::type attribute_type; + typedef sprout::weed::eval_result result_type; + private: + template + 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 diff --git a/sprout/weed/context/parse_context_fwd.hpp b/sprout/weed/context/parse_context_fwd.hpp new file mode 100644 index 00000000..9c75847b --- /dev/null +++ b/sprout/weed/context/parse_context_fwd.hpp @@ -0,0 +1,41 @@ +#ifndef SPROUT_WEED_CONTEXT_PARSE_CONTEXT_FWD_HPP +#define SPROUT_WEED_CONTEXT_PARSE_CONTEXT_FWD_HPP + +#include + +namespace sprout { + namespace weed { + // + // parse_context + // + template + class parse_context { + public: + template + 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 diff --git a/sprout/weed/detail/c_str_as_string.hpp b/sprout/weed/detail/c_str_as_string.hpp new file mode 100644 index 00000000..3135c6a9 --- /dev/null +++ b/sprout/weed/detail/c_str_as_string.hpp @@ -0,0 +1,22 @@ +#ifndef SPROUT_WEED_DETAIL_C_STR_AS_STRING_HPP +#define SPROUT_WEED_DETAIL_C_STR_AS_STRING_HPP + +#include +#include +#include + +namespace sprout { + namespace weed { + namespace detail { + template + struct c_str_as_string; + template + struct c_str_as_string { + public: + typedef sprout::basic_string type; + }; + } // namespace detail + } // namespace weed +} // namespace sprout + +#endif // #ifndef SPROUT_WEED_DETAIL_C_STR_AS_STRING_HPP diff --git a/sprout/weed/detail/is_both_tuple.hpp b/sprout/weed/detail/is_both_tuple.hpp new file mode 100644 index 00000000..45b8bc4e --- /dev/null +++ b/sprout/weed/detail/is_both_tuple.hpp @@ -0,0 +1,30 @@ +#ifndef SPROUT_WEED_DETAIL_IS_BOTH_TUPLE_HPP +#define SPROUT_WEED_DETAIL_IS_BOTH_TUPLE_HPP + +#include +#include +#include + +namespace sprout { + namespace weed { + namespace detail { + template + struct is_both_tuple + : public std::false_type + {}; + template + struct is_both_tuple< + T, + U, + typename std::enable_if< + sprout::weed::traits::is_tuple::value + && sprout::weed::traits::is_tuple::value + >::type + > + : public std::true_type + {}; + } // namespace detail + } // namespace weed +} // namespace sprout + +#endif // #ifndef SPROUT_WEED_DETAIL_IS_BOTH_TUPLE_HPP diff --git a/sprout/weed/detail/is_both_unused.hpp b/sprout/weed/detail/is_both_unused.hpp new file mode 100644 index 00000000..5b989e74 --- /dev/null +++ b/sprout/weed/detail/is_both_unused.hpp @@ -0,0 +1,30 @@ +#ifndef SPROUT_WEED_DETAIL_IS_BOTH_UNUSED_HPP +#define SPROUT_WEED_DETAIL_IS_BOTH_UNUSED_HPP + +#include +#include +#include + +namespace sprout { + namespace weed { + namespace detail { + template + struct is_both_unused + : public std::false_type + {}; + template + struct is_both_unused< + T, + U, + typename std::enable_if< + sprout::weed::traits::is_unused::value + && sprout::weed::traits::is_unused::value + >::type + > + : public std::true_type + {}; + } // namespace detail + } // namespace weed +} // namespace sprout + +#endif // #ifndef SPROUT_WEED_DETAIL_IS_BOTH_UNUSED_HPP diff --git a/sprout/weed/detail/is_container_and_elem.hpp b/sprout/weed/detail/is_container_and_elem.hpp new file mode 100644 index 00000000..02d88f3d --- /dev/null +++ b/sprout/weed/detail/is_container_and_elem.hpp @@ -0,0 +1,33 @@ +#ifndef SPROUT_WEED_DETAIL_IS_CONTAINER_AND_ELEM_HPP +#define SPROUT_WEED_DETAIL_IS_CONTAINER_AND_ELEM_HPP + +#include +#include +#include + +namespace sprout { + namespace weed { + namespace detail { + template + struct is_container_and_elem + : public std::false_type + {}; + template + struct is_container_and_elem< + T, + U, + typename std::enable_if< + sprout::weed::traits::is_container::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 diff --git a/sprout/weed/detail/is_different_elem.hpp b/sprout/weed/detail/is_different_elem.hpp new file mode 100644 index 00000000..419ac65a --- /dev/null +++ b/sprout/weed/detail/is_different_elem.hpp @@ -0,0 +1,43 @@ +#ifndef SPROUT_WEED_DETAIL_IS_DIFFERENT_ELEM_HPP +#define SPROUT_WEED_DETAIL_IS_DIFFERENT_ELEM_HPP + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace sprout { + namespace weed { + namespace detail { + template + struct is_different_elem + : public std::false_type + {}; + template + struct is_different_elem< + T, + U, + typename std::enable_if< + !std::is_same::value + && !is_same_container::value + && !is_container_and_elem::value + && !is_elem_and_container::value + && !is_both_tuple::value + && !is_tuple_and_elem::value + && !is_elem_and_tuple::value + && !sprout::weed::traits::is_unused::value + && !sprout::weed::traits::is_unused::value + >::type + > + : public std::true_type + {}; + } // namespace detail + } // namespace weed +} // namespace sprout + +#endif // #ifndef SPROUT_WEED_DETAIL_IS_DIFFERENT_ELEM_HPP diff --git a/sprout/weed/detail/is_elem_and_container.hpp b/sprout/weed/detail/is_elem_and_container.hpp new file mode 100644 index 00000000..e97f82f7 --- /dev/null +++ b/sprout/weed/detail/is_elem_and_container.hpp @@ -0,0 +1,33 @@ +#ifndef SPROUT_WEED_DETAIL_IS_ELEM_AND_CONTAINER_HPP +#define SPROUT_WEED_DETAIL_IS_ELEM_AND_CONTAINER_HPP + +#include +#include +#include + +namespace sprout { + namespace weed { + namespace detail { + template + struct is_elem_and_container + : public std::false_type + {}; + template + struct is_elem_and_container< + T, + U, + typename std::enable_if< + sprout::weed::traits::is_container::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 diff --git a/sprout/weed/detail/is_elem_and_tuple.hpp b/sprout/weed/detail/is_elem_and_tuple.hpp new file mode 100644 index 00000000..59009077 --- /dev/null +++ b/sprout/weed/detail/is_elem_and_tuple.hpp @@ -0,0 +1,32 @@ +#ifndef SPROUT_WEED_DETAIL_IS_ELEM_AND_TUPLE_HPP +#define SPROUT_WEED_DETAIL_IS_ELEM_AND_TUPLE_HPP + +#include +#include +#include +#include + +namespace sprout { + namespace weed { + namespace detail { + template + struct is_elem_and_tuple + : public std::false_type + {}; + template + struct is_elem_and_tuple< + T, + U, + typename std::enable_if< + !sprout::weed::traits::is_tuple::value + && !sprout::weed::traits::is_unused::value + && sprout::weed::traits::is_tuple::value + >::type + > + : public std::true_type + {}; + } // namespace detail + } // namespace weed +} // namespace sprout + +#endif // #ifndef SPROUT_WEED_DETAIL_IS_ELEM_AND_TUPLE_HPP diff --git a/sprout/weed/detail/is_elem_and_unused.hpp b/sprout/weed/detail/is_elem_and_unused.hpp new file mode 100644 index 00000000..6d28ccf4 --- /dev/null +++ b/sprout/weed/detail/is_elem_and_unused.hpp @@ -0,0 +1,30 @@ +#ifndef SPROUT_WEED_DETAIL_IS_ELEM_AND_UNUSED_HPP +#define SPROUT_WEED_DETAIL_IS_ELEM_AND_UNUSED_HPP + +#include +#include +#include + +namespace sprout { + namespace weed { + namespace detail { + template + struct is_elem_and_unused + : public std::false_type + {}; + template + struct is_elem_and_unused< + T, + U, + typename std::enable_if< + !sprout::weed::traits::is_unused::value + && sprout::weed::traits::is_unused::value + >::type + > + : public std::true_type + {}; + } // namespace detail + } // namespace weed +} // namespace sprout + +#endif // #ifndef SPROUT_WEED_DETAIL_IS_ELEM_AND_UNUSED_HPP diff --git a/sprout/weed/detail/is_same_container.hpp b/sprout/weed/detail/is_same_container.hpp new file mode 100644 index 00000000..78859f8b --- /dev/null +++ b/sprout/weed/detail/is_same_container.hpp @@ -0,0 +1,34 @@ +#ifndef SPROUT_WEED_DETAIL_IS_SAME_CONTAINER_HPP +#define SPROUT_WEED_DETAIL_IS_SAME_CONTAINER_HPP + +#include +#include +#include + +namespace sprout { + namespace weed { + namespace detail { + template + struct is_same_container + : public std::false_type + {}; + template + struct is_same_container< + T, + U, + typename std::enable_if< + sprout::weed::traits::is_container::value + && sprout::weed::traits::is_container::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 diff --git a/sprout/weed/detail/is_same_elem.hpp b/sprout/weed/detail/is_same_elem.hpp new file mode 100644 index 00000000..602c3547 --- /dev/null +++ b/sprout/weed/detail/is_same_elem.hpp @@ -0,0 +1,43 @@ +#ifndef SPROUT_WEED_DETAIL_IS_SAME_ELEM_HPP +#define SPROUT_WEED_DETAIL_IS_SAME_ELEM_HPP + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace sprout { + namespace weed { + namespace detail { + template + struct is_same_elem + : public std::false_type + {}; + template + struct is_same_elem< + T, + U, + typename std::enable_if< + std::is_same::value + && !is_same_container::value + && !is_container_and_elem::value + && !is_elem_and_container::value + && !is_both_tuple::value + && !is_tuple_and_elem::value + && !is_elem_and_tuple::value + && !sprout::weed::traits::is_unused::value + && !sprout::weed::traits::is_unused::value + >::type + > + : public std::true_type + {}; + } // namespace detail + } // namespace weed +} // namespace sprout + +#endif // #ifndef SPROUT_WEED_DETAIL_IS_SAME_ELEM_HPP diff --git a/sprout/weed/detail/is_tuple_and_elem.hpp b/sprout/weed/detail/is_tuple_and_elem.hpp new file mode 100644 index 00000000..a541115a --- /dev/null +++ b/sprout/weed/detail/is_tuple_and_elem.hpp @@ -0,0 +1,32 @@ +#ifndef SPROUT_WEED_DETAIL_IS_TUPLE_AND_ELEM_HPP +#define SPROUT_WEED_DETAIL_IS_TUPLE_AND_ELEM_HPP + +#include +#include +#include +#include + +namespace sprout { + namespace weed { + namespace detail { + template + struct is_tuple_and_elem + : public std::false_type + {}; + template + struct is_tuple_and_elem< + T, + U, + typename std::enable_if< + sprout::weed::traits::is_tuple::value + && !sprout::weed::traits::is_tuple::value + && !sprout::weed::traits::is_unused::value + >::type + > + : public std::true_type + {}; + } // namespace detail + } // namespace weed +} // namespace sprout + +#endif // #ifndef SPROUT_WEED_DETAIL_IS_TUPLE_AND_ELEM_HPP diff --git a/sprout/weed/detail/is_unused_and_elem.hpp b/sprout/weed/detail/is_unused_and_elem.hpp new file mode 100644 index 00000000..f225193c --- /dev/null +++ b/sprout/weed/detail/is_unused_and_elem.hpp @@ -0,0 +1,30 @@ +#ifndef SPROUT_WEED_DETAIL_IS_UNUSED_AND_ELEM_HPP +#define SPROUT_WEED_DETAIL_IS_UNUSED_AND_ELEM_HPP + +#include +#include +#include + +namespace sprout { + namespace weed { + namespace detail { + template + struct is_unused_and_elem + : public std::false_type + {}; + template + struct is_unused_and_elem< + T, + U, + typename std::enable_if< + sprout::weed::traits::is_unused::value + && !sprout::weed::traits::is_unused::value + >::type + > + : public std::true_type + {}; + } // namespace detail + } // namespace weed +} // namespace sprout + +#endif // #ifndef SPROUT_WEED_DETAIL_IS_UNUSED_AND_ELEM_HPP diff --git a/sprout/weed/detail/uncvref.hpp b/sprout/weed/detail/uncvref.hpp new file mode 100644 index 00000000..2bf6318b --- /dev/null +++ b/sprout/weed/detail/uncvref.hpp @@ -0,0 +1,23 @@ +#ifndef SPROUT_WEED_DETAIL_UNCVREF_HPP +#define SPROUT_WEED_DETAIL_UNCVREF_HPP + +#include +#include + +namespace sprout { + namespace weed { + namespace detail { + template + struct uncvref + : public std::conditional< + std::is_array::value + || std::is_array::type>::value, + typename std::remove_reference::type, + typename std::decay::type + > + {}; + } // namespace detail + } // namespace weed +} // namespace sprout + +#endif // #ifndef SPROUT_WEED_DETAIL_UNCVREF_HPP diff --git a/sprout/weed/detail/xdigits.hpp b/sprout/weed/detail/xdigits.hpp new file mode 100644 index 00000000..319c9b80 --- /dev/null +++ b/sprout/weed/detail/xdigits.hpp @@ -0,0 +1,86 @@ +#ifndef SPROUT_WEED_DETAIL_XDIGITS_HPP +#define SPROUT_WEED_DETAIL_XDIGITS_HPP + +#include +#include +#include +#include +#include + +namespace sprout { + namespace weed { + namespace detail { + template + struct xdigits; + + template<> + struct xdigits { + public: + SPROUT_STATIC_CONSTEXPR sprout::basic_string table = sprout::to_string("0123456789abcdefABCDEF"); + }; + SPROUT_CONSTEXPR sprout::basic_string sprout::weed::detail::xdigits::table; + + template<> + struct xdigits { + public: + SPROUT_STATIC_CONSTEXPR sprout::basic_string table = sprout::to_string(L"0123456789abcdefABCDEF"); + }; + SPROUT_CONSTEXPR sprout::basic_string sprout::weed::detail::xdigits::table; + + template<> + struct xdigits { + public: + SPROUT_STATIC_CONSTEXPR sprout::basic_string table = sprout::to_string(u"0123456789abcdefABCDEF"); + }; + SPROUT_CONSTEXPR sprout::basic_string sprout::weed::detail::xdigits::table; + + template<> + struct xdigits { + public: + SPROUT_STATIC_CONSTEXPR sprout::basic_string table = sprout::to_string(U"0123456789abcdefABCDEF"); + }; + SPROUT_CONSTEXPR sprout::basic_string sprout::weed::detail::xdigits::table; + + template + struct xvalues; + + template<> + struct xvalues { + public: + SPROUT_STATIC_CONSTEXPR sprout::array table = sprout::array{ + {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 sprout::weed::detail::xvalues::table; + + template + SPROUT_CONSTEXPR sprout::tuples::tuple xvalue_at(std::size_t i) { + return i < 22 + ? sprout::tuples::tuple( + static_cast(sprout::weed::detail::xvalues::table[i]), + true + ) + : sprout::tuples::tuple( + IntType(), + false + ) + ; + } + template + SPROUT_CONSTEXPR sprout::tuples::tuple from_xdigit(Elem c) { + return sprout::weed::detail::xvalue_at( + NS_SSCRISK_CEL_OR_SPROUT_DETAIL::distance( + sprout::weed::detail::xdigits::table.begin(), + NS_SSCRISK_CEL_OR_SPROUT_DETAIL::find( + sprout::weed::detail::xdigits::table.begin(), + sprout::weed::detail::xdigits::table.end(), + c + ) + ) + ); + } + } // namespace detail + } // namespace weed +} // namespace sprout + +#endif // #ifndef SPROUT_WEED_DETAIL_XDIGITS_HPP diff --git a/sprout/weed/eval_result.hpp b/sprout/weed/eval_result.hpp new file mode 100644 index 00000000..d3517c03 --- /dev/null +++ b/sprout/weed/eval_result.hpp @@ -0,0 +1,56 @@ +#ifndef SPROUT_WEED_EVAL_RESULT_HPP +#define SPROUT_WEED_EVAL_RESULT_HPP + +#include +#include + +namespace sprout { + namespace weed { + // + // eval_result + // + template + class eval_result { + public: + typedef sprout::weed::parser_result 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 diff --git a/sprout/weed/expr.hpp b/sprout/weed/expr.hpp new file mode 100644 index 00000000..ec45860b --- /dev/null +++ b/sprout/weed/expr.hpp @@ -0,0 +1,12 @@ +#ifndef SPROUT_WEED_EXPR_HPP +#define SPROUT_WEED_EXPR_HPP + +#include +#include +#include +#include +#include +#include +#include + +#endif // #ifndef SPROUT_WEED_EXPR_HPP diff --git a/sprout/weed/expr/eval.hpp b/sprout/weed/expr/eval.hpp new file mode 100644 index 00000000..01fa7fb4 --- /dev/null +++ b/sprout/weed/expr/eval.hpp @@ -0,0 +1,32 @@ +#ifndef SPROUT_WEED_EXPR_EVAL_HPP +#define SPROUT_WEED_EXPR_EVAL_HPP + +#include +#include +#include + +namespace sprout { + namespace weed { + // + // eval + // + template + SPROUT_CONSTEXPR inline typename Context::template eval< + typename sprout::weed::traits::terminal_or_expr_of::type + >::result_type eval( + Expr const& expr, + Context const& ctx + ) + { + typedef typename Context::template eval< + typename sprout::weed::traits::terminal_or_expr_of::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 diff --git a/sprout/weed/expr/expr.hpp b/sprout/weed/expr/expr.hpp new file mode 100644 index 00000000..8a216fd1 --- /dev/null +++ b/sprout/weed/expr/expr.hpp @@ -0,0 +1,32 @@ +#ifndef SPROUT_WEED_EXPR_EXPR_HPP +#define SPROUT_WEED_EXPR_EXPR_HPP + +#include +#include +#include + +namespace sprout { + namespace weed { + // + // expr + // + template + class expr { + public: + typedef Tag expr_tag; + typedef sprout::tuples::tuple args_type; + private: + args_type args_; + public: + template + SPROUT_CONSTEXPR explicit expr(As&&... args) + : args_(sprout::forward(args)...) + {} + SPROUT_CONSTEXPR args_type const& args() const { + return args_; + } + }; + } // namespace weed +} // namespace sprout + +#endif // #ifndef SPROUT_WEED_EXPR_EXPR_HPP diff --git a/sprout/weed/expr/make_expr.hpp b/sprout/weed/expr/make_expr.hpp new file mode 100644 index 00000000..4cb9a53f --- /dev/null +++ b/sprout/weed/expr/make_expr.hpp @@ -0,0 +1,25 @@ +#ifndef SPROUT_WEED_EXPR_MAKE_EXPR_HPP +#define SPROUT_WEED_EXPR_MAKE_EXPR_HPP + +#include +#include +#include +#include +#include + +namespace sprout { + namespace weed { + // + // make_expr + // + template + SPROUT_CONSTEXPR inline typename sprout::weed::traits::expr_of::type + make_expr(Args&&... args) { + return typename sprout::weed::traits::expr_of::type( + sprout::weed::make_terminal_or_expr(sprout::forward(args))... + ); + } + } // namespace weed +} // namespace sprout + +#endif // #ifndef SPROUT_WEED_EXPR_MAKE_EXPR_HPP diff --git a/sprout/weed/expr/make_terminal.hpp b/sprout/weed/expr/make_terminal.hpp new file mode 100644 index 00000000..53ca722c --- /dev/null +++ b/sprout/weed/expr/make_terminal.hpp @@ -0,0 +1,42 @@ +#ifndef SPROUT_WEED_EXPR_MAKE_TERMINAL_HPP +#define SPROUT_WEED_EXPR_MAKE_TERMINAL_HPP + +#include +#include +#include +#include +#include +#include +#include + +namespace sprout { + namespace weed { + // + // make_terminal + // + template + SPROUT_CONSTEXPR inline typename std::enable_if< + !sprout::weed::traits::is_c_str< + typename sprout::weed::detail::uncvref::type + >::value, + typename sprout::weed::traits::terminal_of::type + >::type make_terminal(Arg&& arg) { + return typename sprout::weed::traits::terminal_of::type( + sprout::forward(arg) + ); + } + template + SPROUT_CONSTEXPR inline typename std::enable_if< + sprout::weed::traits::is_c_str< + typename sprout::weed::detail::uncvref::type + >::value, + typename sprout::weed::traits::terminal_of::type + >::type make_terminal(Arg&& arg) { + return typename sprout::weed::traits::terminal_of::type( + sprout::to_string(sprout::forward(arg)) + ); + } + } // namespace weed +} // namespace sprout + +#endif // #ifndef SPROUT_WEED_EXPR_MAKE_TERMINAL_HPP diff --git a/sprout/weed/expr/make_terminal_or_expr.hpp b/sprout/weed/expr/make_terminal_or_expr.hpp new file mode 100644 index 00000000..cf9a52b1 --- /dev/null +++ b/sprout/weed/expr/make_terminal_or_expr.hpp @@ -0,0 +1,38 @@ +#ifndef SPROUT_WEED_EXPR_MAKE_TERMINAL_OR_EXPR_HPP +#define SPROUT_WEED_EXPR_MAKE_TERMINAL_OR_EXPR_HPP + +#include +#include +#include +#include +#include +#include +#include + +namespace sprout { + namespace weed { + // + // make_terminal_or_expr + // + template + SPROUT_CONSTEXPR inline typename std::enable_if< + sprout::weed::traits::is_expr< + typename sprout::weed::detail::uncvref::type + >::value, + typename sprout::weed::traits::terminal_or_expr_of::type + >::type make_terminal_or_expr(Arg&& arg) { + return sprout::forward(arg); + } + template + SPROUT_CONSTEXPR inline typename std::enable_if< + !sprout::weed::traits::is_expr< + typename sprout::weed::detail::uncvref::type + >::value, + typename sprout::weed::traits::terminal_or_expr_of::type + >::type make_terminal_or_expr(Arg&& arg) { + return sprout::weed::make_terminal(sprout::forward(arg)); + } + } // namespace weed +} // namespace sprout + +#endif // #ifndef SPROUT_WEED_EXPR_MAKE_TERMINAL_OR_EXPR_HPP diff --git a/sprout/weed/expr/tag.hpp b/sprout/weed/expr/tag.hpp new file mode 100644 index 00000000..fb6286b6 --- /dev/null +++ b/sprout/weed/expr/tag.hpp @@ -0,0 +1,21 @@ +#ifndef SPROUT_WEED_EXPR_TAG_HPP +#define SPROUT_WEED_EXPR_TAG_HPP + +#include + +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 diff --git a/sprout/weed/limited.hpp b/sprout/weed/limited.hpp new file mode 100644 index 00000000..3f61666a --- /dev/null +++ b/sprout/weed/limited.hpp @@ -0,0 +1,22 @@ +#ifndef SPROUT_WEED_LIMITED_HPP +#define SPROUT_WEED_LIMITED_HPP + +#include + +namespace sprout { + namespace weed { + // + // limited + // + struct limited { + public: + enum category { + discard, + circular, + stopover + }; + }; + } // namespace weed +} // namespace sprout + +#endif // #ifndef SPROUT_WEED_LIMITED_HPP diff --git a/sprout/weed/operator.hpp b/sprout/weed/operator.hpp new file mode 100644 index 00000000..0c56f223 --- /dev/null +++ b/sprout/weed/operator.hpp @@ -0,0 +1,13 @@ +#ifndef SPROUT_WEED_OPERATOR_HPP +#define SPROUT_WEED_OPERATOR_HPP + +#include +#include +#include +#include +#include +#include +#include +#include + +#endif // #ifndef SPROUT_WEED_OPERATOR_HPP diff --git a/sprout/weed/operator/address_of.hpp b/sprout/weed/operator/address_of.hpp new file mode 100644 index 00000000..5df73480 --- /dev/null +++ b/sprout/weed/operator/address_of.hpp @@ -0,0 +1,37 @@ +#ifndef SPROUT_WEED_OPERATOR_ADDRESS_OF_HPP +#define SPROUT_WEED_OPERATOR_ADDRESS_OF_HPP + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace sprout { + namespace weed { + // + // operator& + // + template< + typename Arg, + typename = typename std::enable_if< + sprout::weed::traits::is_parser< + typename sprout::weed::detail::uncvref::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::forward(arg) + ); + } + } // namespace weed +} // namespace sprout + +#endif // #ifndef SPROUT_WEED_OPERATOR_ADDRESS_OF_HPP diff --git a/sprout/weed/operator/bitwise_or.hpp b/sprout/weed/operator/bitwise_or.hpp new file mode 100644 index 00000000..86314c48 --- /dev/null +++ b/sprout/weed/operator/bitwise_or.hpp @@ -0,0 +1,43 @@ +#ifndef SPROUT_WEED_OPERATOR_BITWISE_OR_HPP +#define SPROUT_WEED_OPERATOR_BITWISE_OR_HPP + +#include +#include +#include +#include +#include +#include +#include +#include + +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::type + >::value + && sprout::weed::traits::is_parser< + typename sprout::weed::detail::uncvref::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::forward(arg1), + sprout::forward(arg2) + ); + } + } // namespace weed +} // namespace sprout + +#endif // #ifndef SPROUT_WEED_OPERATOR_BITWISE_OR_HPP diff --git a/sprout/weed/operator/dereference.hpp b/sprout/weed/operator/dereference.hpp new file mode 100644 index 00000000..7367e23b --- /dev/null +++ b/sprout/weed/operator/dereference.hpp @@ -0,0 +1,37 @@ +#ifndef SPROUT_WEED_OPERATOR_DEREFERENCE_HPP +#define SPROUT_WEED_OPERATOR_DEREFERENCE_HPP + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace sprout { + namespace weed { + // + // operator* + // + template< + typename Arg, + typename = typename std::enable_if< + sprout::weed::traits::is_parser< + typename sprout::weed::detail::uncvref::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::forward(arg) + ); + } + } // namespace weed +} // namespace sprout + +#endif // #ifndef SPROUT_WEED_OPERATOR_DEREFERENCE_HPP diff --git a/sprout/weed/operator/logical_not.hpp b/sprout/weed/operator/logical_not.hpp new file mode 100644 index 00000000..6f566a4d --- /dev/null +++ b/sprout/weed/operator/logical_not.hpp @@ -0,0 +1,37 @@ +#ifndef SPROUT_WEED_OPERATOR_LOGICAL_NOT_HPP +#define SPROUT_WEED_OPERATOR_LOGICAL_NOT_HPP + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace sprout { + namespace weed { + // + // operator! + // + template< + typename Arg, + typename = typename std::enable_if< + sprout::weed::traits::is_parser< + typename sprout::weed::detail::uncvref::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::forward(arg) + ); + } + } // namespace weed +} // namespace sprout + +#endif // #ifndef SPROUT_WEED_OPERATOR_LOGICAL_NOT_HPP diff --git a/sprout/weed/operator/modulus.hpp b/sprout/weed/operator/modulus.hpp new file mode 100644 index 00000000..68e691be --- /dev/null +++ b/sprout/weed/operator/modulus.hpp @@ -0,0 +1,43 @@ +#ifndef SPROUT_WEED_OPERATOR_MODULUS_HPP +#define SPROUT_WEED_OPERATOR_MODULUS_HPP + +#include +#include +#include +#include +#include +#include +#include +#include + +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::type + >::value + && sprout::weed::traits::is_parser< + typename sprout::weed::detail::uncvref::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::forward(arg1), + sprout::forward(arg2) + ); + } + } // namespace weed +} // namespace sprout + +#endif // #ifndef SPROUT_WEED_OPERATOR_MODULUS_HPP diff --git a/sprout/weed/operator/shift_left.hpp b/sprout/weed/operator/shift_left.hpp new file mode 100644 index 00000000..5e13ffc3 --- /dev/null +++ b/sprout/weed/operator/shift_left.hpp @@ -0,0 +1,43 @@ +#ifndef SPROUT_WEED_OPERATOR_SHIFT_LEFT_HPP +#define SPROUT_WEED_OPERATOR_SHIFT_LEFT_HPP + +#include +#include +#include +#include +#include +#include +#include +#include + +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::type + >::value + && sprout::weed::traits::is_parser< + typename sprout::weed::detail::uncvref::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::forward(arg1), + sprout::forward(arg2) + ); + } + } // namespace weed +} // namespace sprout + +#endif // #ifndef SPROUT_WEED_OPERATOR_SHIFT_LEFT_HPP diff --git a/sprout/weed/operator/unary_plus.hpp b/sprout/weed/operator/unary_plus.hpp new file mode 100644 index 00000000..95c8279e --- /dev/null +++ b/sprout/weed/operator/unary_plus.hpp @@ -0,0 +1,37 @@ +#ifndef SPROUT_WEED_OPERATOR_UNARY_PLUS_HPP +#define SPROUT_WEED_OPERATOR_UNARY_PLUS_HPP + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace sprout { + namespace weed { + // + // operator+ + // + template< + typename Arg, + typename = typename std::enable_if< + sprout::weed::traits::is_parser< + typename sprout::weed::detail::uncvref::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::forward(arg) + ); + } + } // namespace weed +} // namespace sprout + +#endif // #ifndef SPROUT_WEED_OPERATOR_UNARY_PLUS_HPP diff --git a/sprout/weed/parse.hpp b/sprout/weed/parse.hpp new file mode 100644 index 00000000..a630aa6a --- /dev/null +++ b/sprout/weed/parse.hpp @@ -0,0 +1,32 @@ +#ifndef SPROUT_WEED_PARSE_HPP +#define SPROUT_WEED_PARSE_HPP + +#include +#include +#include +#include + +namespace sprout { + namespace weed { + // + // parse + // + template + SPROUT_CONSTEXPR inline typename sprout::weed::parse_context::template eval< + typename sprout::weed::traits::terminal_or_expr_of::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(first, last) + ).presult() + ; + } + } // namespace weed +} // namespace sprout + +#endif // #ifndef SPROUT_WEED_PARSE_HPP diff --git a/sprout/weed/parser.hpp b/sprout/weed/parser.hpp new file mode 100644 index 00000000..1ae38873 --- /dev/null +++ b/sprout/weed/parser.hpp @@ -0,0 +1,14 @@ +#ifndef SPROUT_WEED_PARSER_HPP +#define SPROUT_WEED_PARSER_HPP + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#endif // #ifndef SPROUT_WEED_PARSER_HPP diff --git a/sprout/weed/parser/auxiliary.hpp b/sprout/weed/parser/auxiliary.hpp new file mode 100644 index 00000000..fe0a5933 --- /dev/null +++ b/sprout/weed/parser/auxiliary.hpp @@ -0,0 +1,9 @@ +#ifndef SPROUT_WEED_PARSER_AUXILIARY_HPP +#define SPROUT_WEED_PARSER_AUXILIARY_HPP + +#include +#include +#include +#include + +#endif // #ifndef SPROUT_WEED_PARSER_AUXILIARY_HPP diff --git a/sprout/weed/parser/auxiliary/eoi.hpp b/sprout/weed/parser/auxiliary/eoi.hpp new file mode 100644 index 00000000..73fe34d5 --- /dev/null +++ b/sprout/weed/parser/auxiliary/eoi.hpp @@ -0,0 +1,49 @@ +#ifndef SPROUT_WEED_PARSER_AUXILIARY_EOI_HPP +#define SPROUT_WEED_PARSER_AUXILIARY_EOI_HPP + +#include +#include +#include +#include +#include + +namespace sprout { + namespace weed { + // + // eoi_p + // + struct eoi_p + : public sprout::weed::parser_base + { + public: + template + struct attribute { + public: + typedef sprout::weed::unused type; + }; + template + struct result { + public: + typedef sprout::weed::parser_result::type> type; + }; + public: + template + SPROUT_CONSTEXPR typename result::type operator()( + Iterator first, + Iterator last, + Context const& + ) const + { + typedef typename result::type result_type; + typedef typename attribute::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 diff --git a/sprout/weed/parser/auxiliary/eol.hpp b/sprout/weed/parser/auxiliary/eol.hpp new file mode 100644 index 00000000..9822e72d --- /dev/null +++ b/sprout/weed/parser/auxiliary/eol.hpp @@ -0,0 +1,62 @@ +#ifndef SPROUT_WEED_PARSER_AUXILIARY_EOL_HPP +#define SPROUT_WEED_PARSER_AUXILIARY_EOL_HPP + +#include +#include +#include +#include +#include +#include + +namespace sprout { + namespace weed { + // + // eol_p + // + struct eol_p + : public sprout::weed::parser_base + { + public: + template + struct attribute { + public: + typedef sprout::weed::unused type; + }; + template + struct result { + public: + typedef sprout::weed::parser_result::type> type; + }; + public: + template + SPROUT_CONSTEXPR typename result::type operator()( + Iterator first, + Iterator last, + Context const& + ) const + { + typedef typename result::type result_type; + typedef typename attribute::type attribute_type; + typedef typename std::iterator_traits::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 diff --git a/sprout/weed/parser/auxiliary/eps.hpp b/sprout/weed/parser/auxiliary/eps.hpp new file mode 100644 index 00000000..35bc0472 --- /dev/null +++ b/sprout/weed/parser/auxiliary/eps.hpp @@ -0,0 +1,49 @@ +#ifndef SPROUT_WEED_PARSER_AUXILIARY_EPS_HPP +#define SPROUT_WEED_PARSER_AUXILIARY_EPS_HPP + +#include +#include +#include +#include +#include + +namespace sprout { + namespace weed { + // + // eps_p + // + struct eps_p + : public sprout::weed::parser_base + { + public: + template + struct attribute { + public: + typedef sprout::weed::unused type; + }; + template + struct result { + public: + typedef sprout::weed::parser_result::type> type; + }; + public: + template + SPROUT_CONSTEXPR typename result::type operator()( + Iterator first, + Iterator last, + Context const& + ) const + { + typedef typename result::type result_type; + typedef typename attribute::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 diff --git a/sprout/weed/parser/char.hpp b/sprout/weed/parser/char.hpp new file mode 100644 index 00000000..4786de70 --- /dev/null +++ b/sprout/weed/parser/char.hpp @@ -0,0 +1,8 @@ +#ifndef SPROUT_WEED_PARSER_CHAR_HPP +#define SPROUT_WEED_PARSER_CHAR_HPP + +#include +#include +#include + +#endif // #ifndef SPROUT_WEED_PARSER_CHAR_HPP diff --git a/sprout/weed/parser/char/char.hpp b/sprout/weed/parser/char/char.hpp new file mode 100644 index 00000000..91b5ac84 --- /dev/null +++ b/sprout/weed/parser/char/char.hpp @@ -0,0 +1,161 @@ +#ifndef SPROUT_WEED_PARSER_CHAR_CHAR_HPP +#define SPROUT_WEED_PARSER_CHAR_CHAR_HPP + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace sprout { + namespace weed { + // + // lit_char_p + // + template + struct lit_char_p + : public sprout::weed::parser_base + { + public: + template + struct attribute { + public: + typedef sprout::weed::unused type; + }; + template + struct result { + public: + typedef sprout::weed::parser_result::type> type; + }; + private: + T t_; + public: + lit_char_p() = default; + SPROUT_CONSTEXPR explicit lit_char_p(T const& t) + : t_(t) + {} + template + SPROUT_CONSTEXPR typename result::type operator()( + Iterator first, + Iterator last, + Context const& + ) const + { + typedef typename result::type result_type; + typedef typename attribute::type attribute_type; + typedef typename std::iterator_traits::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::type()) + ; + } + }; + // + // lit_g + // + template + struct lit_g::eval< + T, + typename std::enable_if< + sprout::weed::traits::is_char_type::value + >::type + > { + public: + typedef sprout::weed::lit_char_p result_type; + public: + SPROUT_CONSTEXPR result_type operator()(T const& t) const { + return result_type(t); + } + }; + + // + // char_p + // + template + struct char_p + : public sprout::weed::parser_base + { + public: + template + struct attribute { + public: + typedef typename std::iterator_traits::value_type type; + }; + template + struct result { + public: + typedef sprout::weed::parser_result::type> type; + }; + private: + T t_; + public: + char_p() = default; + SPROUT_CONSTEXPR explicit char_p(T const& t) + : t_(t) + {} + template + SPROUT_CONSTEXPR typename result::type operator()( + Iterator first, + Iterator last, + Context const& + ) const + { + typedef typename result::type result_type; + typedef typename attribute::type attribute_type; + typedef typename std::iterator_traits::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 + struct attribute { + public: + typedef typename std::iterator_traits::value_type type; + }; + template + struct result { + public: + typedef sprout::weed::parser_result::type> type; + }; + public: + template + SPROUT_CONSTEXPR typename result::type operator()( + Iterator first, + Iterator last, + Context const& + ) const + { + typedef typename result::type result_type; + typedef typename attribute::type attribute_type; + return first != last + ? result_type(true, sprout::next(first), *first) + : result_type(false, first, attribute_type()) + ; + } + template + SPROUT_CONSTEXPR sprout::weed::char_p operator()(T const& t) const { + return sprout::weed::char_p(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 diff --git a/sprout/weed/parser/char/char_class.hpp b/sprout/weed/parser/char/char_class.hpp new file mode 100644 index 00000000..b078cc5a --- /dev/null +++ b/sprout/weed/parser/char/char_class.hpp @@ -0,0 +1,132 @@ +#ifndef SPROUT_WEED_PARSER_CHAR_CHAR_CLASS_HPP +#define SPROUT_WEED_PARSER_CHAR_CHAR_CLASS_HPP + +#include +#include +#include +#include +#include +#include +#include + +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 \ + struct NAME \ + : public sprout::weed::parser_base \ + { \ + public: \ + template \ + struct attribute { \ + public: \ + typedef typename std::conditional< \ + Nil, \ + sprout::weed::unused, \ + typename std::iterator_traits::value_type \ + >::type type; \ + }; \ + template \ + struct result { \ + public: \ + typedef sprout::weed::parser_result::type> type; \ + }; \ + public: \ + template \ + SPROUT_CONSTEXPR typename result::type operator()( \ + Iterator first, \ + Iterator last, \ + Context const& \ + ) const \ + { \ + typedef typename result::type result_type; \ + typedef typename attribute::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 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(); + } // namespace weed +} // namespace sprout + +#endif // #ifndef SPROUT_WEED_PARSER_CHAR_CHAR_CLASS_HPP diff --git a/sprout/weed/parser/directive.hpp b/sprout/weed/parser/directive.hpp new file mode 100644 index 00000000..f547631e --- /dev/null +++ b/sprout/weed/parser/directive.hpp @@ -0,0 +1,8 @@ +#ifndef SPROUT_WEED_PARSER_DIRECTIVE_HPP +#define SPROUT_WEED_PARSER_DIRECTIVE_HPP + +#include +#include +#include + +#endif // #ifndef SPROUT_WEED_PARSER_DIRECTIVE_HPP diff --git a/sprout/weed/parser/directive/omit.hpp b/sprout/weed/parser/directive/omit.hpp new file mode 100644 index 00000000..8e45e7fa --- /dev/null +++ b/sprout/weed/parser/directive/omit.hpp @@ -0,0 +1,86 @@ +#ifndef SPROUT_WEED_PARSER_DIRECTIVE_OMIT_HPP +#define SPROUT_WEED_PARSER_DIRECTIVE_OMIT_HPP + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace sprout { + namespace weed { + // + // omit_p + // + template + struct omit_p + : public sprout::weed::parser_base + { + public: + template + struct attribute { + public: + typedef sprout::weed::unused type; + }; + template + struct result { + public: + typedef sprout::weed::parser_result::type> type; + }; + private: + typedef typename sprout::weed::traits::terminal_or_expr_of::type expr_type; + private: + expr_type expr_; + private: + template + SPROUT_CONSTEXPR typename result::type call( + Iterator first, + Result const& res + ) const + { + typedef typename result::type result_type; + typedef typename attribute::type attribute_type; + return res.success() + ? result_type(true, res.current(), attribute_type()) + : 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 + SPROUT_CONSTEXPR typename result::type operator()( + Iterator first, + Iterator last, + Context const& ctx + ) const + { + return call(first, sprout::weed::eval(expr_, ctx)); + } + }; + // + // omit_d + // + struct omit_d { + public: + template + SPROUT_CONSTEXPR sprout::weed::omit_p operator[](Parser const& p) const { + return sprout::weed::omit_p(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 diff --git a/sprout/weed/parser/directive/repeat.hpp b/sprout/weed/parser/directive/repeat.hpp new file mode 100644 index 00000000..e2875096 --- /dev/null +++ b/sprout/weed/parser/directive/repeat.hpp @@ -0,0 +1,211 @@ +#ifndef SPROUT_WEED_PARSER_DIRECTIVE_REPEAT_HPP +#define SPROUT_WEED_PARSER_DIRECTIVE_REPEAT_HPP + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace sprout { + namespace weed { + // + // repeat_p + // + template + struct repeat_p + : public sprout::weed::parser_base + { + private: + template + struct eval { + private: + typedef typename sprout::weed::traits::limit_of::type limit; + typedef typename sprout::weed::traits::attribute_of::type attr_type; + public: + typedef typename repeat_p::template attribute::type attribute_type; + typedef typename repeat_p::template result::type result_type; + private: + template + 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(attrs..., res.attr())) + : p.count_ <= sizeof...(Attrs) + ? result_type(true, first, sprout::weed::attr_cnv::times(attrs...)) + : result_type(false, first, attribute_type()) + ; + } + template + 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(attrs...)) + : result_type(false, first, attribute_type()) + ; + } + template + 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 + 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 + 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( + p, + first, + sprout::weed::eval(p.expr_, ctx) + ); + } + }; + public: + template + struct attribute { + public: + typedef typename sprout::weed::attr_cnv::result_of::times< + sprout::weed::traits::limit_of::value, + typename sprout::weed::traits::attribute_of::type + >::type type; + }; + template + struct result { + public: + typedef sprout::weed::parser_result::type> type; + }; + private: + typedef typename sprout::weed::traits::terminal_or_expr_of::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 + SPROUT_CONSTEXPR typename result::type operator()( + Iterator first, + Iterator last, + Context const& ctx + ) const + { + return eval()(*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 + SPROUT_CONSTEXPR sprout::weed::repeat_p operator[](Parser const& p) const { + return sprout::weed::repeat_p(p, count_); + } + }; + + // + // repeat_d + // + struct repeat_d { + public: + template + SPROUT_CONSTEXPR sprout::weed::repeat_p operator[](Parser const& p) const { + return sprout::weed::repeat_p(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 diff --git a/sprout/weed/parser/lim.hpp b/sprout/weed/parser/lim.hpp new file mode 100644 index 00000000..8e8b1dd0 --- /dev/null +++ b/sprout/weed/parser/lim.hpp @@ -0,0 +1,95 @@ +#ifndef SPROUT_WEED_PARSER_LIM_HPP +#define SPROUT_WEED_PARSER_LIM_HPP + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace sprout { + namespace weed { + // + // limit_p + // + template + struct limit_p + : public sprout::weed::parser_base + { + public: + SPROUT_STATIC_CONSTEXPR std::size_t limit = Limit; + public: + template + struct attribute { + public: + typedef typename sprout::weed::traits::attribute_of::type type; + }; + template + struct result { + public: + typedef sprout::weed::parser_result::type> type; + }; + private: + typedef typename sprout::weed::traits::terminal_or_expr_of::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 + SPROUT_CONSTEXPR typename result::type operator()( + Iterator first, + Iterator last, + Context const& ctx + ) const + { + return sprout::weed::eval(expr_, ctx).presult(); + } + }; + template + SPROUT_CONSTEXPR std::size_t limit_p::limit; + + // + // lim + // + template + SPROUT_CONSTEXPR sprout::weed::limit_p lim(Parser const& p) { + return sprout::weed::limit_p(p); + } + template + SPROUT_CONSTEXPR sprout::weed::limit_p lim( + Parser const& p, + sprout::weed::limited::category limited_category + ) + { + return sprout::weed::limit_p(p, limited_category); + } + + namespace traits { + // + // limit_of + // + template + struct limit_of, Iterator, Context> + : public std::integral_constant + {}; + } // namespace traits + } // namespace weed +} // namespace sprout + +#endif // #ifndef SPROUT_WEED_PARSER_LIM_HPP diff --git a/sprout/weed/parser/lit.hpp b/sprout/weed/parser/lit.hpp new file mode 100644 index 00000000..5c61c1f4 --- /dev/null +++ b/sprout/weed/parser/lit.hpp @@ -0,0 +1,33 @@ +#ifndef SPROUT_WEED_PARSER_LIT_HPP +#define SPROUT_WEED_PARSER_LIT_HPP + +#include +#include +#include + +namespace sprout { + namespace weed { + // + // lit_g + // + struct lit_g { + public: + template + struct eval; + public: + template + SPROUT_CONSTEXPR typename eval< + typename sprout::weed::detail::uncvref::type + >::result_type operator()(T&& t) const { + typedef eval::type> eval_type; + return eval_type()(sprout::forward(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 diff --git a/sprout/weed/parser/numeric.hpp b/sprout/weed/parser/numeric.hpp new file mode 100644 index 00000000..5ebc6083 --- /dev/null +++ b/sprout/weed/parser/numeric.hpp @@ -0,0 +1,7 @@ +#ifndef SPROUT_WEED_PARSER_NUMERIC_HPP +#define SPROUT_WEED_PARSER_NUMERIC_HPP + +#include +#include + +#endif // #ifndef SPROUT_WEED_PARSER_NUMERIC_HPP diff --git a/sprout/weed/parser/numeric/hex.hpp b/sprout/weed/parser/numeric/hex.hpp new file mode 100644 index 00000000..a2ddf42a --- /dev/null +++ b/sprout/weed/parser/numeric/hex.hpp @@ -0,0 +1,132 @@ +#ifndef SPROUT_WEED_PARSER_NUMERIC_HEX_HPP +#define SPROUT_WEED_PARSER_NUMERIC_HEX_HPP + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace sprout { + namespace weed { + // + // hex_p + // + template + struct hex_p + : public sprout::weed::parser_base + { + public: + template + struct attribute { + public: + typedef IntType type; + }; + template + struct result { + public: + typedef sprout::weed::parser_result::type> type; + }; + private: + template + SPROUT_CONSTEXPR typename std::enable_if< + N == Max, + typename result::type + >::type call_1(Iterator first, Iterator last, Iterator temp_first, IntType t, PResult const& res) const { + typedef typename result::type result_type; + typedef typename attribute::type attribute_type; + return sprout::tuples::get<1>(res) + ? result_type(true, sprout::next(first), static_cast(t << 4 | sprout::tuples::get<0>(res))) + : N < Min + ? result_type(false, temp_first, attribute_type()) + : result_type(true, first, t) + ; + } + template + SPROUT_CONSTEXPR typename std::enable_if< + N != Max, + typename result::type + >::type call_1(Iterator first, Iterator last, Iterator temp_first, IntType t, PResult const& res) const { + typedef typename result::type result_type; + typedef typename attribute::type attribute_type; + return sprout::tuples::get<1>(res) + ? call_0(sprout::next(first), last, temp_first, static_cast(t << 4 | sprout::tuples::get<0>(res))) + : N < Min + ? result_type(false, temp_first, attribute_type()) + : result_type(true, first, t) + ; + } + template + SPROUT_CONSTEXPR typename result::type call_0(Iterator first, Iterator last, Iterator temp_first, IntType t) const { + typedef typename result::type result_type; + typedef typename attribute::type attribute_type; + return first != last + ? call_1(first, last, temp_first, t, sprout::weed::detail::from_xdigit(*first)) + : N < Min + ? result_type(false, temp_first, attribute_type()) + : result_type(true, first, t) + ; + } + template + SPROUT_CONSTEXPR typename result::type call(Iterator first, Iterator last, Iterator temp_first, PResult const& res) const { + typedef typename result::type result_type; + typedef typename attribute::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 + SPROUT_CONSTEXPR typename result::type operator()(Iterator first, Iterator last, Context const&) const { + typedef typename result::type result_type; + typedef typename attribute::type attribute_type; + return first != last + ? call(first, last, first, sprout::weed::detail::from_xdigit(*first)) + : result_type(false, first, attribute_type()) + ; + } + }; + // + // hex8 + // hex16 + // hex32 + // hex64 + // uhex8 + // uhex16 + // uhex32 + // uhex64 + // + SPROUT_STATIC_CONSTEXPR sprout::weed::hex_p hex8 = sprout::weed::hex_p(); + SPROUT_STATIC_CONSTEXPR sprout::weed::hex_p hex16 = sprout::weed::hex_p(); + SPROUT_STATIC_CONSTEXPR sprout::weed::hex_p hex32 = sprout::weed::hex_p(); + SPROUT_STATIC_CONSTEXPR sprout::weed::hex_p hex64 = sprout::weed::hex_p(); + SPROUT_STATIC_CONSTEXPR sprout::weed::hex_p uhex8 = sprout::weed::hex_p(); + SPROUT_STATIC_CONSTEXPR sprout::weed::hex_p uhex16 = sprout::weed::hex_p(); + SPROUT_STATIC_CONSTEXPR sprout::weed::hex_p uhex32 = sprout::weed::hex_p(); + SPROUT_STATIC_CONSTEXPR sprout::weed::hex_p uhex64 = sprout::weed::hex_p(); + // + // hex8f + // hex16f + // hex32f + // hex64f + // uhex8f + // uhex16f + // uhex32f + // uhex64f + // + SPROUT_STATIC_CONSTEXPR sprout::weed::hex_p hex8f = sprout::weed::hex_p(); + SPROUT_STATIC_CONSTEXPR sprout::weed::hex_p hex16f = sprout::weed::hex_p(); + SPROUT_STATIC_CONSTEXPR sprout::weed::hex_p hex32f = sprout::weed::hex_p(); + SPROUT_STATIC_CONSTEXPR sprout::weed::hex_p hex64f = sprout::weed::hex_p(); + SPROUT_STATIC_CONSTEXPR sprout::weed::hex_p uhex8f = sprout::weed::hex_p(); + SPROUT_STATIC_CONSTEXPR sprout::weed::hex_p uhex16f = sprout::weed::hex_p(); + SPROUT_STATIC_CONSTEXPR sprout::weed::hex_p uhex32f = sprout::weed::hex_p(); + SPROUT_STATIC_CONSTEXPR sprout::weed::hex_p uhex64f = sprout::weed::hex_p(); + } // namespace weed +} // namespace sprout + +#endif // #ifndef SPROUT_WEED_PARSER_NUMERIC_HEX_HPP diff --git a/sprout/weed/parser/parser_base.hpp b/sprout/weed/parser/parser_base.hpp new file mode 100644 index 00000000..7dc47a61 --- /dev/null +++ b/sprout/weed/parser/parser_base.hpp @@ -0,0 +1,15 @@ +#ifndef SPROUT_WEED_PARSER_PARSER_BASE_HPP +#define SPROUT_WEED_PARSER_PARSER_BASE_HPP + +#include + +namespace sprout { + namespace weed { + // + // parser_base + // + class parser_base {}; + } // namespace weed +} // namespace sprout + +#endif // #ifndef SPROUT_WEED_PARSER_PARSER_BASE_HPP diff --git a/sprout/weed/parser/string.hpp b/sprout/weed/parser/string.hpp new file mode 100644 index 00000000..9ae747b2 --- /dev/null +++ b/sprout/weed/parser/string.hpp @@ -0,0 +1,7 @@ +#ifndef SPROUT_WEED_PARSER_STRING_HPP +#define SPROUT_WEED_PARSER_STRING_HPP + +#include +#include + +#endif // #ifndef SPROUT_WEED_PARSER_STRING_HPP diff --git a/sprout/weed/parser/string/string.hpp b/sprout/weed/parser/string/string.hpp new file mode 100644 index 00000000..43ba6ee6 --- /dev/null +++ b/sprout/weed/parser/string/string.hpp @@ -0,0 +1,162 @@ +#ifndef SPROUT_WEED_PARSER_STRING_STRING_HPP +#define SPROUT_WEED_PARSER_STRING_STRING_HPP + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include HDR_ALGORITHM_SSCRISK_CEL_OR_SPROUT_DETAIL +#include HDR_ITERATOR_SSCRISK_CEL_OR_SPROUT_DETAIL + +namespace sprout { + namespace weed { + // + // lit_str_p + // + template + struct lit_str_p + : public sprout::weed::parser_base + { + public: + template + struct attribute { + public: + typedef sprout::weed::unused type; + }; + template + struct result { + public: + typedef sprout::weed::parser_result::type> type; + }; + private: + T t_; + public: + lit_str_p() = default; + SPROUT_CONSTEXPR explicit lit_str_p(T const& t) + : t_(t) + {} + template + SPROUT_CONSTEXPR typename result::type operator()( + Iterator first, + Iterator last, + Context const& + ) const + { + typedef typename result::type result_type; + typedef typename attribute::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::type()) + ; + } + }; + // + // lit_g + // + template + struct lit_g::eval< + T, + typename std::enable_if< + sprout::weed::traits::is_c_str::value + >::type + > { + public: + typedef sprout::weed::lit_str_p< + typename sprout::weed::detail::c_str_as_string::type + > result_type; + public: + SPROUT_CONSTEXPR result_type operator()(T const& t) const { + return result_type(sprout::to_string(t)); + } + }; + template + struct lit_g::eval< + T, + typename std::enable_if< + sprout::weed::traits::is_string::value + >::type + > { + public: + typedef sprout::weed::lit_str_p result_type; + public: + SPROUT_CONSTEXPR result_type operator()(T const& t) const { + return result_type(t); + } + }; + + // + // str_p + // + template + struct str_p + : public sprout::weed::parser_base + { + public: + template + struct attribute { + public: + typedef T type; + }; + template + struct result { + public: + typedef sprout::weed::parser_result::type> type; + }; + private: + T t_; + public: + str_p() = default; + SPROUT_CONSTEXPR explicit str_p(T const& t) + : t_(t) + {} + template + SPROUT_CONSTEXPR typename result::type operator()( + Iterator first, + Iterator last, + Context const& + ) const + { + typedef typename result::type result_type; + typedef typename attribute::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::type()) + ; + } + }; + // + // string + // + template + SPROUT_CONSTEXPR inline typename std::enable_if< + sprout::weed::traits::is_c_str::value, + sprout::weed::str_p< + typename sprout::weed::detail::c_str_as_string::type + > + >::type string(T const& t) { + return sprout::weed::str_p< + typename sprout::weed::detail::c_str_as_string::type + >(sprout::to_string(t)); + } + template + SPROUT_CONSTEXPR inline typename std::enable_if< + sprout::weed::traits::is_string::value, + sprout::weed::str_p + >::type string(T const& t) { + return sprout::weed::str_p(t); + } + } // namespace weed +} // namespace sprout + +#endif // #ifndef SPROUT_WEED_PARSER_STRING_STRING_HPP diff --git a/sprout/weed/parser_result.hpp b/sprout/weed/parser_result.hpp new file mode 100644 index 00000000..bb9fbda6 --- /dev/null +++ b/sprout/weed/parser_result.hpp @@ -0,0 +1,41 @@ +#ifndef SPROUT_WEED_PARSER_RESULT_HPP +#define SPROUT_WEED_PARSER_RESULT_HPP + +#include + +namespace sprout { + namespace weed { + // + // parser_result + // + template + 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 diff --git a/sprout/weed/traits.hpp b/sprout/weed/traits.hpp new file mode 100644 index 00000000..8da000b6 --- /dev/null +++ b/sprout/weed/traits.hpp @@ -0,0 +1,9 @@ +#ifndef SPROUT_WEED_TRAITS_HPP +#define SPROUT_WEED_TRAITS_HPP + +#include +#include +#include +#include + +#endif // #ifndef SPROUT_WEED_TRAITS_HPP diff --git a/sprout/weed/traits/expr.hpp b/sprout/weed/traits/expr.hpp new file mode 100644 index 00000000..a5d6ddd6 --- /dev/null +++ b/sprout/weed/traits/expr.hpp @@ -0,0 +1,11 @@ +#ifndef SPROUT_WEED_TRAITS_EXPR_HPP +#define SPROUT_WEED_TRAITS_EXPR_HPP + +#include +#include +#include +#include +#include +#include + +#endif // #ifndef SPROUT_WEED_TRAITS_EXPR_HPP diff --git a/sprout/weed/traits/expr/expr_of.hpp b/sprout/weed/traits/expr/expr_of.hpp new file mode 100644 index 00000000..a35b05c5 --- /dev/null +++ b/sprout/weed/traits/expr/expr_of.hpp @@ -0,0 +1,30 @@ +#ifndef SPROUT_WEED_TRAITS_EXPR_EXPR_OF_HPP +#define SPROUT_WEED_TRAITS_EXPR_EXPR_OF_HPP + +#include +#include +#include +#include +#include + +namespace sprout { + namespace weed { + namespace traits { + // + // expr_of + // + template + struct expr_of { + public: + typedef sprout::weed::expr< + Tag, + typename sprout::weed::traits::terminal_or_expr_of< + typename sprout::weed::detail::uncvref::type + >::type... + > type; + }; + } // namespace traits + } // namespace weed +} // namespace sprout + +#endif // #ifndef SPROUT_WEED_TRAITS_EXPR_EXPR_OF_HPP diff --git a/sprout/weed/traits/expr/is_expr.hpp b/sprout/weed/traits/expr/is_expr.hpp new file mode 100644 index 00000000..13986c17 --- /dev/null +++ b/sprout/weed/traits/expr/is_expr.hpp @@ -0,0 +1,30 @@ +#ifndef SPROUT_WEED_TRAITS_EXPR_IS_EXPR_HPP +#define SPROUT_WEED_TRAITS_EXPR_IS_EXPR_HPP + +#include +#include +#include + +namespace sprout { + namespace weed { + namespace traits { + // + // is_expr + // + template + struct is_expr + : public std::false_type + {}; + template + struct is_expr + : public sprout::weed::traits::is_expr + {}; + template + struct is_expr > + : public std::true_type + {}; + } // namespace traits + } // namespace weed +} // namespace sprout + +#endif // #ifndef SPROUT_WEED_TRAITS_EXPR_IS_EXPR_HPP diff --git a/sprout/weed/traits/expr/tag_of.hpp b/sprout/weed/traits/expr/tag_of.hpp new file mode 100644 index 00000000..fd88d7c3 --- /dev/null +++ b/sprout/weed/traits/expr/tag_of.hpp @@ -0,0 +1,34 @@ +#ifndef SPROUT_WEED_TRAITS_EXPR_TAG_OF_HPP +#define SPROUT_WEED_TRAITS_EXPR_TAG_OF_HPP + +#include +#include +#include + +namespace sprout { + namespace weed { + namespace traits { + // + // tag_of + // + template + struct tag_of; + template + struct tag_of + : public sprout::weed::traits::tag_of + {}; + template + struct tag_of< + Expr, + typename std::enable_if< + sprout::weed::traits::is_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 diff --git a/sprout/weed/traits/expr/terminal_of.hpp b/sprout/weed/traits/expr/terminal_of.hpp new file mode 100644 index 00000000..9682eeef --- /dev/null +++ b/sprout/weed/traits/expr/terminal_of.hpp @@ -0,0 +1,56 @@ +#ifndef SPROUT_WEED_TRAITS_EXPR_TERMINAL_OF_HPP +#define SPROUT_WEED_TRAITS_EXPR_TERMINAL_OF_HPP + +#include +#include +#include +#include +#include +#include +#include + +namespace sprout { + namespace weed { + namespace traits { + // + // terminal_of + // + template + struct terminal_of; + template + struct terminal_of< + Arg, + typename std::enable_if< + !sprout::weed::traits::is_c_str< + typename sprout::weed::detail::uncvref::type + >::value + >::type + > { + public: + typedef sprout::weed::expr< + sprout::weed::tag::terminal, + typename sprout::weed::detail::uncvref::type + > type; + }; + template + struct terminal_of< + Arg, + typename std::enable_if< + sprout::weed::traits::is_c_str< + typename sprout::weed::detail::uncvref::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::type + >::type + > type; + }; + } // namespace traits + } // namespace weed +} // namespace sprout + +#endif // #ifndef SPROUT_WEED_TRAITS_EXPR_TERMINAL_OF_HPP diff --git a/sprout/weed/traits/expr/terminal_or_expr_of.hpp b/sprout/weed/traits/expr/terminal_or_expr_of.hpp new file mode 100644 index 00000000..ff2fcf06 --- /dev/null +++ b/sprout/weed/traits/expr/terminal_or_expr_of.hpp @@ -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 +#include +#include +#include +#include + +namespace sprout { + namespace weed { + namespace traits { + // + // terminal_or_expr_of + // + template + struct terminal_or_expr_of { + public: + typedef typename std::conditional< + sprout::weed::traits::is_expr< + typename sprout::weed::detail::uncvref::type + >::value, + typename sprout::weed::detail::uncvref::type, + typename sprout::weed::traits::terminal_of::type + >::type type; + }; + } // namespace traits + } // namespace weed +} // namespace sprout + +#endif // #ifndef SPROUT_WEED_TRAITS_EXPR_TERMINAL_OR_EXPR_OF_HPP diff --git a/sprout/weed/traits/parser.hpp b/sprout/weed/traits/parser.hpp new file mode 100644 index 00000000..23df37dd --- /dev/null +++ b/sprout/weed/traits/parser.hpp @@ -0,0 +1,9 @@ +#ifndef SPROUT_WEED_TRAITS_PARSER_HPP +#define SPROUT_WEED_TRAITS_PARSER_HPP + +#include +#include +#include +#include + +#endif // #ifndef SPROUT_WEED_TRAITS_PARSER_HPP diff --git a/sprout/weed/traits/parser/attribute_of.hpp b/sprout/weed/traits/parser/attribute_of.hpp new file mode 100644 index 00000000..db74f5e4 --- /dev/null +++ b/sprout/weed/traits/parser/attribute_of.hpp @@ -0,0 +1,115 @@ +#ifndef SPROUT_WEED_TRAITS_PARSER_ATTRIBUTE_OF_HPP +#define SPROUT_WEED_TRAITS_PARSER_ATTRIBUTE_OF_HPP + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace sprout { + namespace weed { + namespace traits { + // + // attribute_of + // + template + struct attribute_of; + template + struct attribute_of + : public sprout::weed::traits::attribute_of + {}; + template + struct attribute_of< + T, + Iterator, + Context, + typename std::enable_if< + sprout::weed::traits::is_parser::value + && !sprout::weed::traits::is_expr::value + && !sprout::weed::traits::is_char_type::value + && !sprout::weed::traits::is_c_str::value + && !sprout::weed::traits::is_string::value + >::type + > { + public: + typedef typename T::template attribute::type type; + }; + template + struct attribute_of< + T, + Iterator, + Context, + typename std::enable_if< + sprout::weed::traits::is_char_type::value + || sprout::weed::traits::is_c_str::value + || sprout::weed::traits::is_string::value + >::type + > { + public: + typedef sprout::weed::unused type; + }; + template + struct attribute_of, Iterator, Context> + : public sprout::weed::traits::attribute_of + {}; + template + struct attribute_of, Iterator, Context> + : public sprout::weed::attr_cnv::result_of::times< + sprout::weed::traits::limit_of::value, + typename sprout::weed::traits::attribute_of::type + > + {}; + template + struct attribute_of, Iterator, Context> + : public sprout::weed::attr_cnv::result_of::times< + sprout::weed::traits::limit_of::value, + typename sprout::weed::traits::attribute_of::type + > + {}; + template + struct attribute_of, Iterator, Context> { + public: + typedef sprout::weed::unused type; + }; + template + struct attribute_of, Iterator, Context> { + public: + typedef sprout::weed::unused type; + }; + template + struct attribute_of, Iterator, Context> + : public sprout::weed::attr_cnv::result_of::shift_left< + typename sprout::weed::traits::attribute_of::type, + typename sprout::weed::traits::attribute_of::type + > + {}; + template + struct attribute_of, Iterator, Context> + : public sprout::weed::attr_cnv::result_of::modulus< + sprout::weed::traits::limit_of::value, + typename sprout::weed::traits::attribute_of::type + > + {}; + template + struct attribute_of, Iterator, Context> + : public sprout::weed::attr_cnv::result_of::bitwise_or< + typename sprout::weed::traits::attribute_of::type, + typename sprout::weed::traits::attribute_of::type + > + {}; + } // namespace traits + } // namespace weed +} // namespace sprout + +#endif // #ifndef SPROUT_WEED_TRAITS_PARSER_ATTRIBUTE_OF_HPP diff --git a/sprout/weed/traits/parser/is_parser.hpp b/sprout/weed/traits/parser/is_parser.hpp new file mode 100644 index 00000000..d5d9ad8d --- /dev/null +++ b/sprout/weed/traits/parser/is_parser.hpp @@ -0,0 +1,75 @@ +#ifndef SPROUT_WEED_TRAITS_PARSER_IS_PARSER_HPP +#define SPROUT_WEED_TRAITS_PARSER_IS_PARSER_HPP + +#include +#include +#include +#include +#include +#include +#include + +namespace sprout { + namespace weed { + namespace traits { + // + // is_parser + // + template + struct is_parser; + template + struct is_parser< + T, + typename std::enable_if< + std::is_const::value + && !std::is_array::value + >::type + > + : public sprout::weed::traits::is_parser< + typename std::remove_const::type + > + {}; + template + struct is_parser< + T, + typename std::enable_if< + std::is_base_of::value + && !std::is_const::value + >::type + > + : public std::true_type + {}; + template + struct is_parser< + T, + typename std::enable_if< + sprout::weed::traits::is_expr::value + && !std::is_const::value + >::type + > + : public std::true_type + {}; + template + struct is_parser< + T, + typename std::enable_if< + sprout::weed::traits::is_char_type::value + && !std::is_const::value + >::type + > + : public std::true_type + {}; + template + struct is_parser< + T, + typename std::enable_if< + sprout::weed::traits::is_c_str::value + >::type + > + : public std::true_type + {}; + } // namespace traits + } // namespace weed +} // namespace sprout + +#endif // #ifndef SPROUT_WEED_TRAITS_PARSER_IS_PARSER_HPP diff --git a/sprout/weed/traits/parser/limit_of.hpp b/sprout/weed/traits/parser/limit_of.hpp new file mode 100644 index 00000000..3cfc069d --- /dev/null +++ b/sprout/weed/traits/parser/limit_of.hpp @@ -0,0 +1,32 @@ +#ifndef SPROUT_WEED_TRAITS_PARSER_LIMIT_OF_HPP +#define SPROUT_WEED_TRAITS_PARSER_LIMIT_OF_HPP + +#include +#include +#include +#include +#include + +namespace sprout { + namespace weed { + namespace traits { + // + // limit_of + // + template + struct limit_of + : public std::integral_constant + {}; + template + struct limit_of + : public sprout::weed::traits::limit_of + {}; + template + struct limit_of, Iterator, Context> + : public sprout::weed::traits::limit_of + {}; + } // namespace traits + } // namespace weed +} // namespace sprout + +#endif // #ifndef SPROUT_WEED_TRAITS_PARSER_LIMIT_OF_HPP diff --git a/sprout/weed/traits/type.hpp b/sprout/weed/traits/type.hpp new file mode 100644 index 00000000..246eb795 --- /dev/null +++ b/sprout/weed/traits/type.hpp @@ -0,0 +1,12 @@ +#ifndef SPROUT_WEED_TRAITS_TYPE_HPP +#define SPROUT_WEED_TRAITS_TYPE_HPP + +#include +#include +#include +#include +#include +#include +#include + +#endif // #ifndef SPROUT_WEED_TRAITS_TYPE_HPP diff --git a/sprout/weed/traits/type/is_c_str.hpp b/sprout/weed/traits/type/is_c_str.hpp new file mode 100644 index 00000000..b02b1f8a --- /dev/null +++ b/sprout/weed/traits/type/is_c_str.hpp @@ -0,0 +1,41 @@ +#ifndef SPROUT_WEED_TRAITS_TYPE_IS_C_STR_HPP +#define SPROUT_WEED_TRAITS_TYPE_IS_C_STR_HPP + +#include +#include + +namespace sprout { + namespace weed { + namespace traits { + // + // is_c_str + // + template + struct is_c_str + : public std::false_type + {}; + template + struct is_c_str + : public sprout::weed::traits::is_c_str + {}; + template + struct is_c_str + : public std::true_type + {}; + template + struct is_c_str + : public std::true_type + {}; + template + struct is_c_str + : public std::true_type + {}; + template + struct is_c_str + : public std::true_type + {}; + } // namespace traits + } // namespace weed +} // namespace sprout + +#endif // #ifndef SPROUT_WEED_TRAITS_TYPE_IS_C_STR_HPP diff --git a/sprout/weed/traits/type/is_char_type.hpp b/sprout/weed/traits/type/is_char_type.hpp new file mode 100644 index 00000000..da9ff043 --- /dev/null +++ b/sprout/weed/traits/type/is_char_type.hpp @@ -0,0 +1,41 @@ +#ifndef SPROUT_WEED_TRAITS_TYPE_IS_CHAR_TYPE_HPP +#define SPROUT_WEED_TRAITS_TYPE_IS_CHAR_TYPE_HPP + +#include +#include + +namespace sprout { + namespace weed { + namespace traits { + // + // is_char_type + // + template + struct is_char_type + : public std::false_type + {}; + template + struct is_char_type + : public sprout::weed::traits::is_char_type + {}; + template<> + struct is_char_type + : public std::true_type + {}; + template<> + struct is_char_type + : public std::true_type + {}; + template<> + struct is_char_type + : public std::true_type + {}; + template<> + struct is_char_type + : public std::true_type + {}; + } // namespace traits + } // namespace weed +} // namespace sprout + +#endif // #ifndef SPROUT_WEED_TRAITS_TYPE_IS_CHAR_TYPE_HPP diff --git a/sprout/weed/traits/type/is_container.hpp b/sprout/weed/traits/type/is_container.hpp new file mode 100644 index 00000000..77ee655c --- /dev/null +++ b/sprout/weed/traits/type/is_container.hpp @@ -0,0 +1,35 @@ +#ifndef SPROUT_WEED_TRAITS_TYPE_IS_CONTAINER_HPP +#define SPROUT_WEED_TRAITS_TYPE_IS_CONTAINER_HPP + +#include +#include +#include +#include + +namespace sprout { + namespace weed { + namespace traits { + // + // is_container + // + template + struct is_container + : public std::false_type + {}; + template + struct is_container + : public sprout::weed::traits::is_container + {}; + template + struct is_container > + : public std::true_type + {}; + template + struct is_container > + : public std::true_type + {}; + } // namespace traits + } // namespace weed +} // namespace sprout + +#endif // #ifndef SPROUT_WEED_TRAITS_TYPE_IS_CONTAINER_HPP diff --git a/sprout/weed/traits/type/is_string.hpp b/sprout/weed/traits/type/is_string.hpp new file mode 100644 index 00000000..512217d3 --- /dev/null +++ b/sprout/weed/traits/type/is_string.hpp @@ -0,0 +1,30 @@ +#ifndef SPROUT_WEED_TRAITS_TYPE_IS_STRING_HPP +#define SPROUT_WEED_TRAITS_TYPE_IS_STRING_HPP + +#include +#include +#include + +namespace sprout { + namespace weed { + namespace traits { + // + // is_string + // + template + struct is_string + : public std::false_type + {}; + template + struct is_string + : public sprout::weed::traits::is_string + {}; + template + struct is_string > + : public std::true_type + {}; + } // namespace traits + } // namespace weed +} // namespace sprout + +#endif // #ifndef SPROUT_WEED_TRAITS_TYPE_IS_STRING_HPP diff --git a/sprout/weed/traits/type/is_tuple.hpp b/sprout/weed/traits/type/is_tuple.hpp new file mode 100644 index 00000000..47c887ce --- /dev/null +++ b/sprout/weed/traits/type/is_tuple.hpp @@ -0,0 +1,30 @@ +#ifndef SPROUT_WEED_TRAITS_TYPE_IS_TUPLE_HPP +#define SPROUT_WEED_TRAITS_TYPE_IS_TUPLE_HPP + +#include +#include +#include + +namespace sprout { + namespace weed { + namespace traits { + // + // is_tuple + // + template + struct is_tuple + : public std::false_type + {}; + template + struct is_tuple + : public sprout::weed::traits::is_tuple + {}; + template + struct is_tuple > + : public std::true_type + {}; + } // namespace traits + } // namespace weed +} // namespace sprout + +#endif // #ifndef SPROUT_WEED_TRAITS_TYPE_IS_TUPLE_HPP diff --git a/sprout/weed/traits/type/is_unused.hpp b/sprout/weed/traits/type/is_unused.hpp new file mode 100644 index 00000000..34c2833b --- /dev/null +++ b/sprout/weed/traits/type/is_unused.hpp @@ -0,0 +1,26 @@ +#ifndef SPROUT_WEED_TRAITS_TYPE_IS_UNUSED_HPP +#define SPROUT_WEED_TRAITS_TYPE_IS_UNUSED_HPP + +#include +#include +#include + +namespace sprout { + namespace weed { + namespace traits { + // + // is_unused + // + template + struct is_unused + : public std::is_same + {}; + template + struct is_unused + : public sprout::weed::traits::is_unused + {}; + } // namespace traits + } // namespace weed +} // namespace sprout + +#endif // #ifndef SPROUT_WEED_TRAITS_TYPE_IS_UNUSED_HPP diff --git a/sprout/weed/unused.hpp b/sprout/weed/unused.hpp new file mode 100644 index 00000000..cbeea223 --- /dev/null +++ b/sprout/weed/unused.hpp @@ -0,0 +1,24 @@ +#ifndef SPROUT_WEED_UNUSED_HPP +#define SPROUT_WEED_UNUSED_HPP + +#include + +namespace sprout { + namespace weed { + // + // unused + // + struct unused { + public: + unused() = default; + template + SPROUT_CONSTEXPR unused(T) {} + template + SPROUT_CONSTEXPR operator T() const { + return T(); + } + }; + } // namespace weed +} // namespace sprout + +#endif // #ifndef SPROUT_WEED_UNUSED_HPP