mirror of
https://github.com/bolero-MURAKAMI/Sprout
synced 2025-08-03 12:49:50 +00:00
sprout/weed.hpp 追加
This commit is contained in:
parent
8103682fdb
commit
ecfc2b297a
96 changed files with 5127 additions and 0 deletions
9
sprout/weed/parser/auxiliary.hpp
Normal file
9
sprout/weed/parser/auxiliary.hpp
Normal file
|
@ -0,0 +1,9 @@
|
|||
#ifndef SPROUT_WEED_PARSER_AUXILIARY_HPP
|
||||
#define SPROUT_WEED_PARSER_AUXILIARY_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/weed/parser/auxiliary/eol.hpp>
|
||||
#include <sprout/weed/parser/auxiliary/eoi.hpp>
|
||||
#include <sprout/weed/parser/auxiliary/eps.hpp>
|
||||
|
||||
#endif // #ifndef SPROUT_WEED_PARSER_AUXILIARY_HPP
|
49
sprout/weed/parser/auxiliary/eoi.hpp
Normal file
49
sprout/weed/parser/auxiliary/eoi.hpp
Normal file
|
@ -0,0 +1,49 @@
|
|||
#ifndef SPROUT_WEED_PARSER_AUXILIARY_EOI_HPP
|
||||
#define SPROUT_WEED_PARSER_AUXILIARY_EOI_HPP
|
||||
|
||||
#include <cstddef>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/weed/unused.hpp>
|
||||
#include <sprout/weed/parser_result.hpp>
|
||||
#include <sprout/weed/parser/parser_base.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace weed {
|
||||
//
|
||||
// eoi_p
|
||||
//
|
||||
struct eoi_p
|
||||
: public sprout::weed::parser_base
|
||||
{
|
||||
public:
|
||||
template<typename Context, typename Iterator>
|
||||
struct attribute {
|
||||
public:
|
||||
typedef sprout::weed::unused type;
|
||||
};
|
||||
template<typename Context, typename Iterator>
|
||||
struct result {
|
||||
public:
|
||||
typedef sprout::weed::parser_result<Iterator, typename attribute<Context, Iterator>::type> type;
|
||||
};
|
||||
public:
|
||||
template<typename Context, typename Iterator>
|
||||
SPROUT_CONSTEXPR typename result<Context, Iterator>::type operator()(
|
||||
Iterator first,
|
||||
Iterator last,
|
||||
Context const&
|
||||
) const
|
||||
{
|
||||
typedef typename result<Context, Iterator>::type result_type;
|
||||
typedef typename attribute<Context, Iterator>::type attribute_type;
|
||||
return result_type(first == last, first, attribute_type());
|
||||
}
|
||||
};
|
||||
//
|
||||
// eoi
|
||||
//
|
||||
SPROUT_STATIC_CONSTEXPR sprout::weed::eoi_p eoi = sprout::weed::eoi_p();
|
||||
} // namespace weed
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_WEED_PARSER_AUXILIARY_EOI_HPP
|
62
sprout/weed/parser/auxiliary/eol.hpp
Normal file
62
sprout/weed/parser/auxiliary/eol.hpp
Normal file
|
@ -0,0 +1,62 @@
|
|||
#ifndef SPROUT_WEED_PARSER_AUXILIARY_EOL_HPP
|
||||
#define SPROUT_WEED_PARSER_AUXILIARY_EOL_HPP
|
||||
|
||||
#include <cstddef>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/iterator/next.hpp>
|
||||
#include <sprout/weed/unused.hpp>
|
||||
#include <sprout/weed/parser_result.hpp>
|
||||
#include <sprout/weed/parser/parser_base.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace weed {
|
||||
//
|
||||
// eol_p
|
||||
//
|
||||
struct eol_p
|
||||
: public sprout::weed::parser_base
|
||||
{
|
||||
public:
|
||||
template<typename Context, typename Iterator>
|
||||
struct attribute {
|
||||
public:
|
||||
typedef sprout::weed::unused type;
|
||||
};
|
||||
template<typename Context, typename Iterator>
|
||||
struct result {
|
||||
public:
|
||||
typedef sprout::weed::parser_result<Iterator, typename attribute<Context, Iterator>::type> type;
|
||||
};
|
||||
public:
|
||||
template<typename Context, typename Iterator>
|
||||
SPROUT_CONSTEXPR typename result<Context, Iterator>::type operator()(
|
||||
Iterator first,
|
||||
Iterator last,
|
||||
Context const&
|
||||
) const
|
||||
{
|
||||
typedef typename result<Context, Iterator>::type result_type;
|
||||
typedef typename attribute<Context, Iterator>::type attribute_type;
|
||||
typedef typename std::iterator_traits<Iterator>::value_type elem_type;
|
||||
return first != last
|
||||
? *first == elem_type('\r')
|
||||
? sprout::next(first) != last
|
||||
? *sprout::next(first) == elem_type('\n')
|
||||
? result_type(true, sprout::next(sprout::next(first)), attribute_type())
|
||||
: result_type(true, sprout::next(first), attribute_type())
|
||||
: result_type(true, sprout::next(first), attribute_type())
|
||||
: *first == elem_type('\n')
|
||||
? result_type(true, sprout::next(first), attribute_type())
|
||||
: result_type(false, first, attribute_type())
|
||||
: result_type(false, first, attribute_type())
|
||||
;
|
||||
}
|
||||
};
|
||||
//
|
||||
// eol
|
||||
//
|
||||
SPROUT_STATIC_CONSTEXPR sprout::weed::eol_p eol = sprout::weed::eol_p();
|
||||
} // namespace weed
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_WEED_PARSER_AUXILIARY_EOL_HPP
|
49
sprout/weed/parser/auxiliary/eps.hpp
Normal file
49
sprout/weed/parser/auxiliary/eps.hpp
Normal file
|
@ -0,0 +1,49 @@
|
|||
#ifndef SPROUT_WEED_PARSER_AUXILIARY_EPS_HPP
|
||||
#define SPROUT_WEED_PARSER_AUXILIARY_EPS_HPP
|
||||
|
||||
#include <cstddef>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/weed/unused.hpp>
|
||||
#include <sprout/weed/parser_result.hpp>
|
||||
#include <sprout/weed/parser/parser_base.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace weed {
|
||||
//
|
||||
// eps_p
|
||||
//
|
||||
struct eps_p
|
||||
: public sprout::weed::parser_base
|
||||
{
|
||||
public:
|
||||
template<typename Context, typename Iterator>
|
||||
struct attribute {
|
||||
public:
|
||||
typedef sprout::weed::unused type;
|
||||
};
|
||||
template<typename Context, typename Iterator>
|
||||
struct result {
|
||||
public:
|
||||
typedef sprout::weed::parser_result<Iterator, typename attribute<Context, Iterator>::type> type;
|
||||
};
|
||||
public:
|
||||
template<typename Context, typename Iterator>
|
||||
SPROUT_CONSTEXPR typename result<Context, Iterator>::type operator()(
|
||||
Iterator first,
|
||||
Iterator last,
|
||||
Context const&
|
||||
) const
|
||||
{
|
||||
typedef typename result<Context, Iterator>::type result_type;
|
||||
typedef typename attribute<Context, Iterator>::type attribute_type;
|
||||
return result_type(true, first, attribute_type());
|
||||
}
|
||||
};
|
||||
//
|
||||
// eps
|
||||
//
|
||||
SPROUT_STATIC_CONSTEXPR sprout::weed::eps_p eps = sprout::weed::eps_p();
|
||||
} // namespace weed
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_WEED_PARSER_AUXILIARY_EPS_HPP
|
8
sprout/weed/parser/char.hpp
Normal file
8
sprout/weed/parser/char.hpp
Normal file
|
@ -0,0 +1,8 @@
|
|||
#ifndef SPROUT_WEED_PARSER_CHAR_HPP
|
||||
#define SPROUT_WEED_PARSER_CHAR_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/weed/parser/char/char.hpp>
|
||||
#include <sprout/weed/parser/char/char_class.hpp>
|
||||
|
||||
#endif // #ifndef SPROUT_WEED_PARSER_CHAR_HPP
|
161
sprout/weed/parser/char/char.hpp
Normal file
161
sprout/weed/parser/char/char.hpp
Normal file
|
@ -0,0 +1,161 @@
|
|||
#ifndef SPROUT_WEED_PARSER_CHAR_CHAR_HPP
|
||||
#define SPROUT_WEED_PARSER_CHAR_CHAR_HPP
|
||||
|
||||
#include <iterator>
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/iterator/next.hpp>
|
||||
#include <sprout/weed/unused.hpp>
|
||||
#include <sprout/weed/parser_result.hpp>
|
||||
#include <sprout/weed/parser/parser_base.hpp>
|
||||
#include <sprout/weed/parser/lit.hpp>
|
||||
#include <sprout/weed/traits/type/is_char_type.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace weed {
|
||||
//
|
||||
// lit_char_p
|
||||
//
|
||||
template<typename T>
|
||||
struct lit_char_p
|
||||
: public sprout::weed::parser_base
|
||||
{
|
||||
public:
|
||||
template<typename Context, typename Iterator>
|
||||
struct attribute {
|
||||
public:
|
||||
typedef sprout::weed::unused type;
|
||||
};
|
||||
template<typename Context, typename Iterator>
|
||||
struct result {
|
||||
public:
|
||||
typedef sprout::weed::parser_result<Iterator, typename attribute<Context, Iterator>::type> type;
|
||||
};
|
||||
private:
|
||||
T t_;
|
||||
public:
|
||||
lit_char_p() = default;
|
||||
SPROUT_CONSTEXPR explicit lit_char_p(T const& t)
|
||||
: t_(t)
|
||||
{}
|
||||
template<typename Context, typename Iterator>
|
||||
SPROUT_CONSTEXPR typename result<Context, Iterator>::type operator()(
|
||||
Iterator first,
|
||||
Iterator last,
|
||||
Context const&
|
||||
) const
|
||||
{
|
||||
typedef typename result<Context, Iterator>::type result_type;
|
||||
typedef typename attribute<Context, Iterator>::type attribute_type;
|
||||
typedef typename std::iterator_traits<Iterator>::value_type elem_type;
|
||||
return first != last && *first == elem_type(t_)
|
||||
? result_type(true, sprout::next(first), attribute_type())
|
||||
: result_type(false, first, typename attribute<Context, Iterator>::type())
|
||||
;
|
||||
}
|
||||
};
|
||||
//
|
||||
// lit_g
|
||||
//
|
||||
template<typename T>
|
||||
struct lit_g::eval<
|
||||
T,
|
||||
typename std::enable_if<
|
||||
sprout::weed::traits::is_char_type<T>::value
|
||||
>::type
|
||||
> {
|
||||
public:
|
||||
typedef sprout::weed::lit_char_p<T> result_type;
|
||||
public:
|
||||
SPROUT_CONSTEXPR result_type operator()(T const& t) const {
|
||||
return result_type(t);
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// char_p
|
||||
//
|
||||
template<typename T>
|
||||
struct char_p
|
||||
: public sprout::weed::parser_base
|
||||
{
|
||||
public:
|
||||
template<typename Context, typename Iterator>
|
||||
struct attribute {
|
||||
public:
|
||||
typedef typename std::iterator_traits<Iterator>::value_type type;
|
||||
};
|
||||
template<typename Context, typename Iterator>
|
||||
struct result {
|
||||
public:
|
||||
typedef sprout::weed::parser_result<Iterator, typename attribute<Context, Iterator>::type> type;
|
||||
};
|
||||
private:
|
||||
T t_;
|
||||
public:
|
||||
char_p() = default;
|
||||
SPROUT_CONSTEXPR explicit char_p(T const& t)
|
||||
: t_(t)
|
||||
{}
|
||||
template<typename Context, typename Iterator>
|
||||
SPROUT_CONSTEXPR typename result<Context, Iterator>::type operator()(
|
||||
Iterator first,
|
||||
Iterator last,
|
||||
Context const&
|
||||
) const
|
||||
{
|
||||
typedef typename result<Context, Iterator>::type result_type;
|
||||
typedef typename attribute<Context, Iterator>::type attribute_type;
|
||||
typedef typename std::iterator_traits<Iterator>::value_type elem_type;
|
||||
return first != last && *first == elem_type(t_)
|
||||
? result_type(true, sprout::next(first), *first)
|
||||
: result_type(false, first, attribute_type())
|
||||
;
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// any_char_p
|
||||
//
|
||||
struct any_char_p
|
||||
: public sprout::weed::parser_base
|
||||
{
|
||||
public:
|
||||
template<typename Context, typename Iterator>
|
||||
struct attribute {
|
||||
public:
|
||||
typedef typename std::iterator_traits<Iterator>::value_type type;
|
||||
};
|
||||
template<typename Context, typename Iterator>
|
||||
struct result {
|
||||
public:
|
||||
typedef sprout::weed::parser_result<Iterator, typename attribute<Context, Iterator>::type> type;
|
||||
};
|
||||
public:
|
||||
template<typename Context, typename Iterator>
|
||||
SPROUT_CONSTEXPR typename result<Context, Iterator>::type operator()(
|
||||
Iterator first,
|
||||
Iterator last,
|
||||
Context const&
|
||||
) const
|
||||
{
|
||||
typedef typename result<Context, Iterator>::type result_type;
|
||||
typedef typename attribute<Context, Iterator>::type attribute_type;
|
||||
return first != last
|
||||
? result_type(true, sprout::next(first), *first)
|
||||
: result_type(false, first, attribute_type())
|
||||
;
|
||||
}
|
||||
template<typename T>
|
||||
SPROUT_CONSTEXPR sprout::weed::char_p<T> operator()(T const& t) const {
|
||||
return sprout::weed::char_p<T>(t);
|
||||
}
|
||||
};
|
||||
//
|
||||
// char_
|
||||
//
|
||||
SPROUT_STATIC_CONSTEXPR sprout::weed::any_char_p char_ = sprout::weed::any_char_p();
|
||||
} // namespace weed
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_WEED_PARSER_CHAR_CHAR_HPP
|
132
sprout/weed/parser/char/char_class.hpp
Normal file
132
sprout/weed/parser/char/char_class.hpp
Normal file
|
@ -0,0 +1,132 @@
|
|||
#ifndef SPROUT_WEED_PARSER_CHAR_CHAR_CLASS_HPP
|
||||
#define SPROUT_WEED_PARSER_CHAR_CHAR_CLASS_HPP
|
||||
|
||||
#include <cstddef>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/iterator/next.hpp>
|
||||
#include <sprout/weed/unused.hpp>
|
||||
#include <sprout/weed/parser_result.hpp>
|
||||
#include <sprout/weed/parser/parser_base.hpp>
|
||||
#include <sscrisk/cel/cctype.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace weed {
|
||||
//
|
||||
// alnum_p
|
||||
// alpha_p
|
||||
// blank_p
|
||||
// cntrl_p
|
||||
// digit_p
|
||||
// graph_p
|
||||
// print_p
|
||||
// punct_p
|
||||
// space_p
|
||||
// xdigit_p
|
||||
// lower_p
|
||||
// upper_p
|
||||
//
|
||||
#define SPROUT_WEED_DEFINE_CTYPE_P(NAME, ISNAME) \
|
||||
template<bool Nil = false> \
|
||||
struct NAME \
|
||||
: public sprout::weed::parser_base \
|
||||
{ \
|
||||
public: \
|
||||
template<typename Context, typename Iterator> \
|
||||
struct attribute { \
|
||||
public: \
|
||||
typedef typename std::conditional< \
|
||||
Nil, \
|
||||
sprout::weed::unused, \
|
||||
typename std::iterator_traits<Iterator>::value_type \
|
||||
>::type type; \
|
||||
}; \
|
||||
template<typename Context, typename Iterator> \
|
||||
struct result { \
|
||||
public: \
|
||||
typedef sprout::weed::parser_result<Iterator, typename attribute<Context, Iterator>::type> type; \
|
||||
}; \
|
||||
public: \
|
||||
template<typename Context, typename Iterator> \
|
||||
SPROUT_CONSTEXPR typename result<Context, Iterator>::type operator()( \
|
||||
Iterator first, \
|
||||
Iterator last, \
|
||||
Context const& \
|
||||
) const \
|
||||
{ \
|
||||
typedef typename result<Context, Iterator>::type result_type; \
|
||||
typedef typename attribute<Context, Iterator>::type attribute_type; \
|
||||
return first != last && sscrisk::cel::ISNAME(*first) \
|
||||
? result_type(true, sprout::next(first), *first) \
|
||||
: result_type(false, first, attribute_type()) \
|
||||
; \
|
||||
} \
|
||||
}
|
||||
SPROUT_WEED_DEFINE_CTYPE_P(alnum_p, isalnum);
|
||||
SPROUT_WEED_DEFINE_CTYPE_P(alpha_p, isalpha);
|
||||
SPROUT_WEED_DEFINE_CTYPE_P(blank_p, isblank);
|
||||
SPROUT_WEED_DEFINE_CTYPE_P(cntrl_p, iscntrl);
|
||||
SPROUT_WEED_DEFINE_CTYPE_P(digit_p, isdigit);
|
||||
SPROUT_WEED_DEFINE_CTYPE_P(graph_p, isgraph);
|
||||
SPROUT_WEED_DEFINE_CTYPE_P(print_p, isprint);
|
||||
SPROUT_WEED_DEFINE_CTYPE_P(punct_p, ispunct);
|
||||
SPROUT_WEED_DEFINE_CTYPE_P(space_p, isspace);
|
||||
SPROUT_WEED_DEFINE_CTYPE_P(xdigit_p, isxdigit);
|
||||
SPROUT_WEED_DEFINE_CTYPE_P(lower_p, islower);
|
||||
SPROUT_WEED_DEFINE_CTYPE_P(upper_p, isupper);
|
||||
#undef SPROUT_WEED_DEFINE_CTYPE_P
|
||||
//
|
||||
// alnum
|
||||
// alpha
|
||||
// blank
|
||||
// cntrl
|
||||
// digit
|
||||
// graph
|
||||
// print
|
||||
// punct
|
||||
// space
|
||||
// xdigit
|
||||
// lower
|
||||
// upper
|
||||
//
|
||||
SPROUT_STATIC_CONSTEXPR sprout::weed::alnum_p<> alnum = sprout::weed::alnum_p<>();
|
||||
SPROUT_STATIC_CONSTEXPR sprout::weed::alpha_p<> alpha = sprout::weed::alpha_p<>();
|
||||
SPROUT_STATIC_CONSTEXPR sprout::weed::blank_p<> blank = sprout::weed::blank_p<>();
|
||||
SPROUT_STATIC_CONSTEXPR sprout::weed::cntrl_p<> cntrl = sprout::weed::cntrl_p<>();
|
||||
SPROUT_STATIC_CONSTEXPR sprout::weed::digit_p<> digit = sprout::weed::digit_p<>();
|
||||
SPROUT_STATIC_CONSTEXPR sprout::weed::graph_p<> graph = sprout::weed::graph_p<>();
|
||||
SPROUT_STATIC_CONSTEXPR sprout::weed::print_p<> print = sprout::weed::print_p<>();
|
||||
SPROUT_STATIC_CONSTEXPR sprout::weed::punct_p<> punct = sprout::weed::punct_p<>();
|
||||
SPROUT_STATIC_CONSTEXPR sprout::weed::space_p<> space = sprout::weed::space_p<>();
|
||||
SPROUT_STATIC_CONSTEXPR sprout::weed::xdigit_p<> xdigit = sprout::weed::xdigit_p<>();
|
||||
SPROUT_STATIC_CONSTEXPR sprout::weed::lower_p<> lower = sprout::weed::lower_p<>();
|
||||
SPROUT_STATIC_CONSTEXPR sprout::weed::upper_p<> upper = sprout::weed::upper_p<>();
|
||||
//
|
||||
// alnum_
|
||||
// alpha_
|
||||
// blank_
|
||||
// cntrl_
|
||||
// digit_
|
||||
// graph_
|
||||
// print_
|
||||
// punct_
|
||||
// space_
|
||||
// xdigit_
|
||||
// lower_
|
||||
// upper_
|
||||
//
|
||||
SPROUT_STATIC_CONSTEXPR sprout::weed::alnum_p<true> alnum_ = sprout::weed::alnum_p<true>();
|
||||
SPROUT_STATIC_CONSTEXPR sprout::weed::alpha_p<true> alpha_ = sprout::weed::alpha_p<true>();
|
||||
SPROUT_STATIC_CONSTEXPR sprout::weed::blank_p<true> blank_ = sprout::weed::blank_p<true>();
|
||||
SPROUT_STATIC_CONSTEXPR sprout::weed::cntrl_p<true> cntrl_ = sprout::weed::cntrl_p<true>();
|
||||
SPROUT_STATIC_CONSTEXPR sprout::weed::digit_p<true> digit_ = sprout::weed::digit_p<true>();
|
||||
SPROUT_STATIC_CONSTEXPR sprout::weed::graph_p<true> graph_ = sprout::weed::graph_p<true>();
|
||||
SPROUT_STATIC_CONSTEXPR sprout::weed::print_p<true> print_ = sprout::weed::print_p<true>();
|
||||
SPROUT_STATIC_CONSTEXPR sprout::weed::punct_p<true> punct_ = sprout::weed::punct_p<true>();
|
||||
SPROUT_STATIC_CONSTEXPR sprout::weed::space_p<true> space_ = sprout::weed::space_p<true>();
|
||||
SPROUT_STATIC_CONSTEXPR sprout::weed::xdigit_p<true> xdigit_ = sprout::weed::xdigit_p<true>();
|
||||
SPROUT_STATIC_CONSTEXPR sprout::weed::lower_p<true> lower_ = sprout::weed::lower_p<true>();
|
||||
SPROUT_STATIC_CONSTEXPR sprout::weed::upper_p<true> upper_ = sprout::weed::upper_p<true>();
|
||||
} // namespace weed
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_WEED_PARSER_CHAR_CHAR_CLASS_HPP
|
8
sprout/weed/parser/directive.hpp
Normal file
8
sprout/weed/parser/directive.hpp
Normal file
|
@ -0,0 +1,8 @@
|
|||
#ifndef SPROUT_WEED_PARSER_DIRECTIVE_HPP
|
||||
#define SPROUT_WEED_PARSER_DIRECTIVE_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/weed/parser/directive/omit.hpp>
|
||||
#include <sprout/weed/parser/directive/repeat.hpp>
|
||||
|
||||
#endif // #ifndef SPROUT_WEED_PARSER_DIRECTIVE_HPP
|
86
sprout/weed/parser/directive/omit.hpp
Normal file
86
sprout/weed/parser/directive/omit.hpp
Normal file
|
@ -0,0 +1,86 @@
|
|||
#ifndef SPROUT_WEED_PARSER_DIRECTIVE_OMIT_HPP
|
||||
#define SPROUT_WEED_PARSER_DIRECTIVE_OMIT_HPP
|
||||
|
||||
#include <cstddef>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/weed/unused.hpp>
|
||||
#include <sprout/weed/parser_result.hpp>
|
||||
#include <sprout/weed/expr/make_terminal_or_expr.hpp>
|
||||
#include <sprout/weed/expr/eval.hpp>
|
||||
#include <sprout/weed/parser/parser_base.hpp>
|
||||
#include <sprout/weed/traits/expr/terminal_or_expr_of.hpp>
|
||||
#include <sprout/weed/traits/parser/attribute_of.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace weed {
|
||||
//
|
||||
// omit_p
|
||||
//
|
||||
template<typename Parser>
|
||||
struct omit_p
|
||||
: public sprout::weed::parser_base
|
||||
{
|
||||
public:
|
||||
template<typename Context, typename Iterator>
|
||||
struct attribute {
|
||||
public:
|
||||
typedef sprout::weed::unused type;
|
||||
};
|
||||
template<typename Context, typename Iterator>
|
||||
struct result {
|
||||
public:
|
||||
typedef sprout::weed::parser_result<Iterator, typename attribute<Context, Iterator>::type> type;
|
||||
};
|
||||
private:
|
||||
typedef typename sprout::weed::traits::terminal_or_expr_of<Parser>::type expr_type;
|
||||
private:
|
||||
expr_type expr_;
|
||||
private:
|
||||
template<typename Context, typename Iterator, typename Result>
|
||||
SPROUT_CONSTEXPR typename result<Context, Iterator>::type call(
|
||||
Iterator first,
|
||||
Result const& res
|
||||
) const
|
||||
{
|
||||
typedef typename result<Context, Iterator>::type result_type;
|
||||
typedef typename attribute<Context, Iterator>::type attribute_type;
|
||||
return res.success()
|
||||
? result_type(true, res.current(), attribute_type())
|
||||
: result_type(false, first, attribute_type())
|
||||
;
|
||||
}
|
||||
public:
|
||||
omit_p() = default;
|
||||
SPROUT_CONSTEXPR explicit omit_p(
|
||||
Parser const& p
|
||||
)
|
||||
: expr_(sprout::weed::make_terminal_or_expr(p))
|
||||
{}
|
||||
template<typename Context, typename Iterator>
|
||||
SPROUT_CONSTEXPR typename result<Context, Iterator>::type operator()(
|
||||
Iterator first,
|
||||
Iterator last,
|
||||
Context const& ctx
|
||||
) const
|
||||
{
|
||||
return call<Context>(first, sprout::weed::eval(expr_, ctx));
|
||||
}
|
||||
};
|
||||
//
|
||||
// omit_d
|
||||
//
|
||||
struct omit_d {
|
||||
public:
|
||||
template<typename Parser>
|
||||
SPROUT_CONSTEXPR sprout::weed::omit_p<Parser> operator[](Parser const& p) const {
|
||||
return sprout::weed::omit_p<Parser>(p);
|
||||
}
|
||||
};
|
||||
//
|
||||
// omit
|
||||
//
|
||||
SPROUT_CONSTEXPR sprout::weed::omit_d omit = sprout::weed::omit_d();
|
||||
} // namespace weed
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_WEED_PARSER_DIRECTIVE_OMIT_HPP
|
211
sprout/weed/parser/directive/repeat.hpp
Normal file
211
sprout/weed/parser/directive/repeat.hpp
Normal file
|
@ -0,0 +1,211 @@
|
|||
#ifndef SPROUT_WEED_PARSER_DIRECTIVE_REPEAT_HPP
|
||||
#define SPROUT_WEED_PARSER_DIRECTIVE_REPEAT_HPP
|
||||
|
||||
#include <cstddef>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/weed/parser_result.hpp>
|
||||
#include <sprout/weed/expr/make_terminal_or_expr.hpp>
|
||||
#include <sprout/weed/expr/eval.hpp>
|
||||
#include <sprout/weed/parser/parser_base.hpp>
|
||||
#include <sprout/weed/attr_cnv/result_of/times.hpp>
|
||||
#include <sprout/weed/attr_cnv/times.hpp>
|
||||
#include <sprout/weed/traits/expr/terminal_or_expr_of.hpp>
|
||||
#include <sprout/weed/traits/parser/attribute_of.hpp>
|
||||
#include <sprout/weed/traits/parser/limit_of.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace weed {
|
||||
//
|
||||
// repeat_p
|
||||
//
|
||||
template<typename Parser>
|
||||
struct repeat_p
|
||||
: public sprout::weed::parser_base
|
||||
{
|
||||
private:
|
||||
template<typename Context, typename Iterator>
|
||||
struct eval {
|
||||
private:
|
||||
typedef typename sprout::weed::traits::limit_of<Parser, Iterator, Context>::type limit;
|
||||
typedef typename sprout::weed::traits::attribute_of<Parser, Iterator, Context>::type attr_type;
|
||||
public:
|
||||
typedef typename repeat_p::template attribute<Context, Iterator>::type attribute_type;
|
||||
typedef typename repeat_p::template result<Context, Iterator>::type result_type;
|
||||
private:
|
||||
template<typename Result, typename... Attrs>
|
||||
SPROUT_CONSTEXPR typename std::enable_if<
|
||||
sizeof...(Attrs) + 1 == limit::value,
|
||||
result_type
|
||||
>::type call(
|
||||
repeat_p const& p,
|
||||
Iterator first,
|
||||
Result const& res,
|
||||
Attrs const&... attrs
|
||||
) const
|
||||
{
|
||||
return res.success()
|
||||
? result_type(true, res.current(), sprout::weed::attr_cnv::times<limit::value, attr_type>(attrs..., res.attr()))
|
||||
: p.count_ <= sizeof...(Attrs)
|
||||
? result_type(true, first, sprout::weed::attr_cnv::times<limit::value, attr_type>(attrs...))
|
||||
: result_type(false, first, attribute_type())
|
||||
;
|
||||
}
|
||||
template<typename Result, typename... Attrs>
|
||||
SPROUT_CONSTEXPR typename std::enable_if<
|
||||
sizeof...(Attrs) + 1 != limit::value,
|
||||
result_type
|
||||
>::type call(
|
||||
repeat_p const& p,
|
||||
Iterator first,
|
||||
Result const& res,
|
||||
Attrs const&... attrs
|
||||
) const
|
||||
{
|
||||
return res.success()
|
||||
? call(p, p.count_ <= sizeof...(Attrs) ? res.current() : first, sprout::weed::eval(p.expr_, res.ctx()), attrs..., res.attr())
|
||||
: p.count_ <= sizeof...(Attrs)
|
||||
? result_type(true, first, sprout::weed::attr_cnv::times<limit::value, attr_type>(attrs...))
|
||||
: result_type(false, first, attribute_type())
|
||||
;
|
||||
}
|
||||
template<typename Result>
|
||||
SPROUT_CONSTEXPR result_type call_inf(
|
||||
repeat_p const& p,
|
||||
Iterator first,
|
||||
Result const& res,
|
||||
std::size_t n
|
||||
) const
|
||||
{
|
||||
return res.success()
|
||||
? call_inf(p, p.count_ <= n ? res.current() : first, sprout::weed::eval(p.expr_, res.ctx()), n + 1)
|
||||
: result_type(p.count_ <= n || p.count_ == std::size_t(-1), first, attribute_type())
|
||||
;
|
||||
}
|
||||
template<bool Infinity, typename Result>
|
||||
SPROUT_CONSTEXPR typename std::enable_if<
|
||||
Infinity,
|
||||
result_type
|
||||
>::type call(
|
||||
repeat_p const& p,
|
||||
Iterator first,
|
||||
Result const& res
|
||||
) const
|
||||
{
|
||||
return res.success()
|
||||
? call_inf(
|
||||
p,
|
||||
p.count_ <= 0 ? res.current() : first,
|
||||
sprout::weed::eval(p.expr_, res.ctx()),
|
||||
1
|
||||
)
|
||||
: result_type(p.count_ <= 0 || p.count_ == std::size_t(-1), first, attribute_type())
|
||||
;
|
||||
}
|
||||
template<bool Infinity, typename Result>
|
||||
SPROUT_CONSTEXPR typename std::enable_if<
|
||||
!Infinity,
|
||||
result_type
|
||||
>::type call(
|
||||
repeat_p const& p,
|
||||
Iterator first,
|
||||
Result const& res
|
||||
) const
|
||||
{
|
||||
return res.success()
|
||||
? call(
|
||||
p,
|
||||
p.count_ <= 0 ? res.current() : first,
|
||||
sprout::weed::eval(p.expr_, res.ctx()),
|
||||
res.attr()
|
||||
)
|
||||
: result_type(p.count_ <= 0, first, attribute_type())
|
||||
;
|
||||
}
|
||||
public:
|
||||
SPROUT_CONSTEXPR result_type operator()(
|
||||
repeat_p const& p,
|
||||
Iterator first,
|
||||
Context const& ctx
|
||||
) const
|
||||
{
|
||||
return call<limit::value == std::size_t(-1)>(
|
||||
p,
|
||||
first,
|
||||
sprout::weed::eval(p.expr_, ctx)
|
||||
);
|
||||
}
|
||||
};
|
||||
public:
|
||||
template<typename Context, typename Iterator>
|
||||
struct attribute {
|
||||
public:
|
||||
typedef typename sprout::weed::attr_cnv::result_of::times<
|
||||
sprout::weed::traits::limit_of<Parser, Iterator, Context>::value,
|
||||
typename sprout::weed::traits::attribute_of<Parser, Iterator, Context>::type
|
||||
>::type type;
|
||||
};
|
||||
template<typename Context, typename Iterator>
|
||||
struct result {
|
||||
public:
|
||||
typedef sprout::weed::parser_result<Iterator, typename attribute<Context, Iterator>::type> type;
|
||||
};
|
||||
private:
|
||||
typedef typename sprout::weed::traits::terminal_or_expr_of<Parser>::type expr_type;
|
||||
private:
|
||||
expr_type expr_;
|
||||
std::size_t count_;
|
||||
public:
|
||||
repeat_p() = default;
|
||||
SPROUT_CONSTEXPR explicit repeat_p(Parser const& p, std::size_t count = -1)
|
||||
: expr_(sprout::weed::make_terminal_or_expr(p))
|
||||
, count_(count)
|
||||
{}
|
||||
template<typename Context, typename Iterator>
|
||||
SPROUT_CONSTEXPR typename result<Context, Iterator>::type operator()(
|
||||
Iterator first,
|
||||
Iterator last,
|
||||
Context const& ctx
|
||||
) const
|
||||
{
|
||||
return eval<Context, Iterator>()(*this, first, ctx);
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// repeat_g
|
||||
//
|
||||
struct repeat_g {
|
||||
private:
|
||||
std::size_t count_;
|
||||
public:
|
||||
SPROUT_CONSTEXPR explicit repeat_g(std::size_t count)
|
||||
: count_(count)
|
||||
{}
|
||||
template<typename Parser>
|
||||
SPROUT_CONSTEXPR sprout::weed::repeat_p<Parser> operator[](Parser const& p) const {
|
||||
return sprout::weed::repeat_p<Parser>(p, count_);
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// repeat_d
|
||||
//
|
||||
struct repeat_d {
|
||||
public:
|
||||
template<typename Parser>
|
||||
SPROUT_CONSTEXPR sprout::weed::repeat_p<Parser> operator[](Parser const& p) const {
|
||||
return sprout::weed::repeat_p<Parser>(p);
|
||||
}
|
||||
SPROUT_CONSTEXPR sprout::weed::repeat_g operator()(std::size_t count) const {
|
||||
return sprout::weed::repeat_g(count);
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// repeat
|
||||
//
|
||||
SPROUT_CONSTEXPR sprout::weed::repeat_d repeat = sprout::weed::repeat_d();
|
||||
} // namespace weed
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_WEED_PARSER_DIRECTIVE_REPEAT_HPP
|
95
sprout/weed/parser/lim.hpp
Normal file
95
sprout/weed/parser/lim.hpp
Normal file
|
@ -0,0 +1,95 @@
|
|||
#ifndef SPROUT_WEED_PARSER_LIM_HPP
|
||||
#define SPROUT_WEED_PARSER_LIM_HPP
|
||||
|
||||
#include <cstddef>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/weed/parser_result.hpp>
|
||||
#include <sprout/weed/limited.hpp>
|
||||
#include <sprout/weed/expr/make_terminal_or_expr.hpp>
|
||||
#include <sprout/weed/expr/eval.hpp>
|
||||
#include <sprout/weed/parser/parser_base.hpp>
|
||||
#include <sprout/weed/traits/expr/terminal_or_expr_of.hpp>
|
||||
#include <sprout/weed/traits/parser/attribute_of.hpp>
|
||||
#include <sprout/weed/traits/parser/limit_of.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace weed {
|
||||
//
|
||||
// limit_p
|
||||
//
|
||||
template<typename Parser, std::size_t Limit>
|
||||
struct limit_p
|
||||
: public sprout::weed::parser_base
|
||||
{
|
||||
public:
|
||||
SPROUT_STATIC_CONSTEXPR std::size_t limit = Limit;
|
||||
public:
|
||||
template<typename Context, typename Iterator>
|
||||
struct attribute {
|
||||
public:
|
||||
typedef typename sprout::weed::traits::attribute_of<Parser, Iterator, Context>::type type;
|
||||
};
|
||||
template<typename Context, typename Iterator>
|
||||
struct result {
|
||||
public:
|
||||
typedef sprout::weed::parser_result<Iterator, typename attribute<Context, Iterator>::type> type;
|
||||
};
|
||||
private:
|
||||
typedef typename sprout::weed::traits::terminal_or_expr_of<Parser>::type expr_type;
|
||||
private:
|
||||
expr_type expr_;
|
||||
sprout::weed::limited::category limited_category_;
|
||||
public:
|
||||
limit_p() = default;
|
||||
SPROUT_CONSTEXPR explicit limit_p(
|
||||
Parser const& p,
|
||||
sprout::weed::limited::category limited_category = sprout::weed::limited::discard
|
||||
)
|
||||
: expr_(sprout::weed::make_terminal_or_expr(p))
|
||||
, limited_category_(limited_category)
|
||||
{}
|
||||
SPROUT_CONSTEXPR sprout::weed::limited::category limited_category() const {
|
||||
return limited_category_;
|
||||
}
|
||||
template<typename Context, typename Iterator>
|
||||
SPROUT_CONSTEXPR typename result<Context, Iterator>::type operator()(
|
||||
Iterator first,
|
||||
Iterator last,
|
||||
Context const& ctx
|
||||
) const
|
||||
{
|
||||
return sprout::weed::eval(expr_, ctx).presult();
|
||||
}
|
||||
};
|
||||
template<typename Parser, std::size_t Limit>
|
||||
SPROUT_CONSTEXPR std::size_t limit_p<Parser, Limit>::limit;
|
||||
|
||||
//
|
||||
// lim
|
||||
//
|
||||
template<std::size_t Limit, typename Parser>
|
||||
SPROUT_CONSTEXPR sprout::weed::limit_p<Parser, Limit> lim(Parser const& p) {
|
||||
return sprout::weed::limit_p<Parser, Limit>(p);
|
||||
}
|
||||
template<std::size_t Limit, typename Parser>
|
||||
SPROUT_CONSTEXPR sprout::weed::limit_p<Parser, Limit> lim(
|
||||
Parser const& p,
|
||||
sprout::weed::limited::category limited_category
|
||||
)
|
||||
{
|
||||
return sprout::weed::limit_p<Parser, Limit>(p, limited_category);
|
||||
}
|
||||
|
||||
namespace traits {
|
||||
//
|
||||
// limit_of
|
||||
//
|
||||
template<typename Parser, std::size_t Limit, typename Iterator, typename Context>
|
||||
struct limit_of<sprout::weed::limit_p<Parser, Limit>, Iterator, Context>
|
||||
: public std::integral_constant<std::size_t, Limit>
|
||||
{};
|
||||
} // namespace traits
|
||||
} // namespace weed
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_WEED_PARSER_LIM_HPP
|
33
sprout/weed/parser/lit.hpp
Normal file
33
sprout/weed/parser/lit.hpp
Normal file
|
@ -0,0 +1,33 @@
|
|||
#ifndef SPROUT_WEED_PARSER_LIT_HPP
|
||||
#define SPROUT_WEED_PARSER_LIT_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/utility/forward.hpp>
|
||||
#include <sprout/weed/detail/uncvref.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace weed {
|
||||
//
|
||||
// lit_g
|
||||
//
|
||||
struct lit_g {
|
||||
public:
|
||||
template<typename T, typename = void>
|
||||
struct eval;
|
||||
public:
|
||||
template<typename T>
|
||||
SPROUT_CONSTEXPR typename eval<
|
||||
typename sprout::weed::detail::uncvref<T>::type
|
||||
>::result_type operator()(T&& t) const {
|
||||
typedef eval<typename sprout::weed::detail::uncvref<T>::type> eval_type;
|
||||
return eval_type()(sprout::forward<T>(t));
|
||||
}
|
||||
};
|
||||
//
|
||||
// lit
|
||||
//
|
||||
SPROUT_STATIC_CONSTEXPR sprout::weed::lit_g lit = sprout::weed::lit_g();
|
||||
} // namespace weed
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_WEED_PARSER_LIT_HPP
|
7
sprout/weed/parser/numeric.hpp
Normal file
7
sprout/weed/parser/numeric.hpp
Normal file
|
@ -0,0 +1,7 @@
|
|||
#ifndef SPROUT_WEED_PARSER_NUMERIC_HPP
|
||||
#define SPROUT_WEED_PARSER_NUMERIC_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/weed/parser/numeric/hex.hpp>
|
||||
|
||||
#endif // #ifndef SPROUT_WEED_PARSER_NUMERIC_HPP
|
132
sprout/weed/parser/numeric/hex.hpp
Normal file
132
sprout/weed/parser/numeric/hex.hpp
Normal file
|
@ -0,0 +1,132 @@
|
|||
#ifndef SPROUT_WEED_PARSER_NUMERIC_HEX_HPP
|
||||
#define SPROUT_WEED_PARSER_NUMERIC_HEX_HPP
|
||||
|
||||
#include <cstddef>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/iterator/next.hpp>
|
||||
#include <sprout/tuple/tuple.hpp>
|
||||
#include <sprout/weed/unused.hpp>
|
||||
#include <sprout/weed/parser_result.hpp>
|
||||
#include <sprout/weed/parser/parser_base.hpp>
|
||||
#include <sprout/weed/detail/xdigits.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace weed {
|
||||
//
|
||||
// hex_p
|
||||
//
|
||||
template<typename IntType, std::size_t Min = sizeof(IntType) * 2, std::size_t Max = sizeof(IntType) * 2>
|
||||
struct hex_p
|
||||
: public sprout::weed::parser_base
|
||||
{
|
||||
public:
|
||||
template<typename Context, typename Iterator>
|
||||
struct attribute {
|
||||
public:
|
||||
typedef IntType type;
|
||||
};
|
||||
template<typename Context, typename Iterator>
|
||||
struct result {
|
||||
public:
|
||||
typedef sprout::weed::parser_result<Iterator, typename attribute<Context, Iterator>::type> type;
|
||||
};
|
||||
private:
|
||||
template<std::size_t N, typename Context, typename Iterator, typename PResult>
|
||||
SPROUT_CONSTEXPR typename std::enable_if<
|
||||
N == Max,
|
||||
typename result<Context, Iterator>::type
|
||||
>::type call_1(Iterator first, Iterator last, Iterator temp_first, IntType t, PResult const& res) const {
|
||||
typedef typename result<Context, Iterator>::type result_type;
|
||||
typedef typename attribute<Context, Iterator>::type attribute_type;
|
||||
return sprout::tuples::get<1>(res)
|
||||
? result_type(true, sprout::next(first), static_cast<IntType>(t << 4 | sprout::tuples::get<0>(res)))
|
||||
: N < Min
|
||||
? result_type(false, temp_first, attribute_type())
|
||||
: result_type(true, first, t)
|
||||
;
|
||||
}
|
||||
template<std::size_t N, typename Context, typename Iterator, typename PResult>
|
||||
SPROUT_CONSTEXPR typename std::enable_if<
|
||||
N != Max,
|
||||
typename result<Context, Iterator>::type
|
||||
>::type call_1(Iterator first, Iterator last, Iterator temp_first, IntType t, PResult const& res) const {
|
||||
typedef typename result<Context, Iterator>::type result_type;
|
||||
typedef typename attribute<Context, Iterator>::type attribute_type;
|
||||
return sprout::tuples::get<1>(res)
|
||||
? call_0<N, Context>(sprout::next(first), last, temp_first, static_cast<IntType>(t << 4 | sprout::tuples::get<0>(res)))
|
||||
: N < Min
|
||||
? result_type(false, temp_first, attribute_type())
|
||||
: result_type(true, first, t)
|
||||
;
|
||||
}
|
||||
template<std::size_t N, typename Context, typename Iterator>
|
||||
SPROUT_CONSTEXPR typename result<Context, Iterator>::type call_0(Iterator first, Iterator last, Iterator temp_first, IntType t) const {
|
||||
typedef typename result<Context, Iterator>::type result_type;
|
||||
typedef typename attribute<Context, Iterator>::type attribute_type;
|
||||
return first != last
|
||||
? call_1<N + 1, Context>(first, last, temp_first, t, sprout::weed::detail::from_xdigit<IntType>(*first))
|
||||
: N < Min
|
||||
? result_type(false, temp_first, attribute_type())
|
||||
: result_type(true, first, t)
|
||||
;
|
||||
}
|
||||
template<typename Context, typename Iterator, typename PResult>
|
||||
SPROUT_CONSTEXPR typename result<Context, Iterator>::type call(Iterator first, Iterator last, Iterator temp_first, PResult const& res) const {
|
||||
typedef typename result<Context, Iterator>::type result_type;
|
||||
typedef typename attribute<Context, Iterator>::type attribute_type;
|
||||
return sprout::tuples::get<1>(res)
|
||||
? call_0<1, Context>(sprout::next(first), last, temp_first, sprout::tuples::get<0>(res))
|
||||
: result_type(false, temp_first, attribute_type())
|
||||
;
|
||||
}
|
||||
public:
|
||||
template<typename Context, typename Iterator>
|
||||
SPROUT_CONSTEXPR typename result<Context, Iterator>::type operator()(Iterator first, Iterator last, Context const&) const {
|
||||
typedef typename result<Context, Iterator>::type result_type;
|
||||
typedef typename attribute<Context, Iterator>::type attribute_type;
|
||||
return first != last
|
||||
? call<Context>(first, last, first, sprout::weed::detail::from_xdigit<IntType>(*first))
|
||||
: result_type(false, first, attribute_type())
|
||||
;
|
||||
}
|
||||
};
|
||||
//
|
||||
// hex8
|
||||
// hex16
|
||||
// hex32
|
||||
// hex64
|
||||
// uhex8
|
||||
// uhex16
|
||||
// uhex32
|
||||
// uhex64
|
||||
//
|
||||
SPROUT_STATIC_CONSTEXPR sprout::weed::hex_p<std::int8_t, 1> hex8 = sprout::weed::hex_p<std::int8_t, 1>();
|
||||
SPROUT_STATIC_CONSTEXPR sprout::weed::hex_p<std::int16_t, 1> hex16 = sprout::weed::hex_p<std::int16_t, 1>();
|
||||
SPROUT_STATIC_CONSTEXPR sprout::weed::hex_p<std::int32_t, 1> hex32 = sprout::weed::hex_p<std::int32_t, 1>();
|
||||
SPROUT_STATIC_CONSTEXPR sprout::weed::hex_p<std::int64_t, 1> hex64 = sprout::weed::hex_p<std::int64_t, 1>();
|
||||
SPROUT_STATIC_CONSTEXPR sprout::weed::hex_p<std::uint8_t, 1> uhex8 = sprout::weed::hex_p<std::uint8_t, 1>();
|
||||
SPROUT_STATIC_CONSTEXPR sprout::weed::hex_p<std::uint16_t, 1> uhex16 = sprout::weed::hex_p<std::uint16_t, 1>();
|
||||
SPROUT_STATIC_CONSTEXPR sprout::weed::hex_p<std::uint32_t, 1> uhex32 = sprout::weed::hex_p<std::uint32_t, 1>();
|
||||
SPROUT_STATIC_CONSTEXPR sprout::weed::hex_p<std::uint64_t, 1> uhex64 = sprout::weed::hex_p<std::uint64_t, 1>();
|
||||
//
|
||||
// hex8f
|
||||
// hex16f
|
||||
// hex32f
|
||||
// hex64f
|
||||
// uhex8f
|
||||
// uhex16f
|
||||
// uhex32f
|
||||
// uhex64f
|
||||
//
|
||||
SPROUT_STATIC_CONSTEXPR sprout::weed::hex_p<std::int8_t> hex8f = sprout::weed::hex_p<std::int8_t>();
|
||||
SPROUT_STATIC_CONSTEXPR sprout::weed::hex_p<std::int16_t> hex16f = sprout::weed::hex_p<std::int16_t>();
|
||||
SPROUT_STATIC_CONSTEXPR sprout::weed::hex_p<std::int32_t> hex32f = sprout::weed::hex_p<std::int32_t>();
|
||||
SPROUT_STATIC_CONSTEXPR sprout::weed::hex_p<std::int64_t> hex64f = sprout::weed::hex_p<std::int64_t>();
|
||||
SPROUT_STATIC_CONSTEXPR sprout::weed::hex_p<std::uint8_t> uhex8f = sprout::weed::hex_p<std::uint8_t>();
|
||||
SPROUT_STATIC_CONSTEXPR sprout::weed::hex_p<std::uint16_t> uhex16f = sprout::weed::hex_p<std::uint16_t>();
|
||||
SPROUT_STATIC_CONSTEXPR sprout::weed::hex_p<std::uint32_t> uhex32f = sprout::weed::hex_p<std::uint32_t>();
|
||||
SPROUT_STATIC_CONSTEXPR sprout::weed::hex_p<std::uint64_t> uhex64f = sprout::weed::hex_p<std::uint64_t>();
|
||||
} // namespace weed
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_WEED_PARSER_NUMERIC_HEX_HPP
|
15
sprout/weed/parser/parser_base.hpp
Normal file
15
sprout/weed/parser/parser_base.hpp
Normal file
|
@ -0,0 +1,15 @@
|
|||
#ifndef SPROUT_WEED_PARSER_PARSER_BASE_HPP
|
||||
#define SPROUT_WEED_PARSER_PARSER_BASE_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace weed {
|
||||
//
|
||||
// parser_base
|
||||
//
|
||||
class parser_base {};
|
||||
} // namespace weed
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_WEED_PARSER_PARSER_BASE_HPP
|
7
sprout/weed/parser/string.hpp
Normal file
7
sprout/weed/parser/string.hpp
Normal file
|
@ -0,0 +1,7 @@
|
|||
#ifndef SPROUT_WEED_PARSER_STRING_HPP
|
||||
#define SPROUT_WEED_PARSER_STRING_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/weed/parser/string/string.hpp>
|
||||
|
||||
#endif // #ifndef SPROUT_WEED_PARSER_STRING_HPP
|
162
sprout/weed/parser/string/string.hpp
Normal file
162
sprout/weed/parser/string/string.hpp
Normal file
|
@ -0,0 +1,162 @@
|
|||
#ifndef SPROUT_WEED_PARSER_STRING_STRING_HPP
|
||||
#define SPROUT_WEED_PARSER_STRING_STRING_HPP
|
||||
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/string.hpp>
|
||||
#include <sprout/fixed_container/begin.hpp>
|
||||
#include <sprout/fixed_container/end.hpp>
|
||||
#include <sprout/fixed_container/size.hpp>
|
||||
#include <sprout/iterator/next.hpp>
|
||||
#include <sprout/weed/unused.hpp>
|
||||
#include <sprout/weed/parser_result.hpp>
|
||||
#include <sprout/weed/parser/parser_base.hpp>
|
||||
#include <sprout/weed/parser/lit.hpp>
|
||||
#include <sprout/weed/traits/type/is_c_str.hpp>
|
||||
#include <sprout/weed/traits/type/is_string.hpp>
|
||||
#include HDR_ALGORITHM_SSCRISK_CEL_OR_SPROUT_DETAIL
|
||||
#include HDR_ITERATOR_SSCRISK_CEL_OR_SPROUT_DETAIL
|
||||
|
||||
namespace sprout {
|
||||
namespace weed {
|
||||
//
|
||||
// lit_str_p
|
||||
//
|
||||
template<typename T>
|
||||
struct lit_str_p
|
||||
: public sprout::weed::parser_base
|
||||
{
|
||||
public:
|
||||
template<typename Context, typename Iterator>
|
||||
struct attribute {
|
||||
public:
|
||||
typedef sprout::weed::unused type;
|
||||
};
|
||||
template<typename Context, typename Iterator>
|
||||
struct result {
|
||||
public:
|
||||
typedef sprout::weed::parser_result<Iterator, typename attribute<Context, Iterator>::type> type;
|
||||
};
|
||||
private:
|
||||
T t_;
|
||||
public:
|
||||
lit_str_p() = default;
|
||||
SPROUT_CONSTEXPR explicit lit_str_p(T const& t)
|
||||
: t_(t)
|
||||
{}
|
||||
template<typename Context, typename Iterator>
|
||||
SPROUT_CONSTEXPR typename result<Context, Iterator>::type operator()(
|
||||
Iterator first,
|
||||
Iterator last,
|
||||
Context const&
|
||||
) const
|
||||
{
|
||||
typedef typename result<Context, Iterator>::type result_type;
|
||||
typedef typename attribute<Context, Iterator>::type attribute_type;
|
||||
return NS_SSCRISK_CEL_OR_SPROUT_DETAIL::distance(first, last) >= sprout::size(t_)
|
||||
&&NS_SSCRISK_CEL_OR_SPROUT_DETAIL::equal(sprout::begin(t_), sprout::end(t_), first)
|
||||
? result_type(true, sprout::next(first, sprout::size(t_)), attribute_type())
|
||||
: result_type(false, first, typename attribute<Context, Iterator>::type())
|
||||
;
|
||||
}
|
||||
};
|
||||
//
|
||||
// lit_g
|
||||
//
|
||||
template<typename T>
|
||||
struct lit_g::eval<
|
||||
T,
|
||||
typename std::enable_if<
|
||||
sprout::weed::traits::is_c_str<T>::value
|
||||
>::type
|
||||
> {
|
||||
public:
|
||||
typedef sprout::weed::lit_str_p<
|
||||
typename sprout::weed::detail::c_str_as_string<T const>::type
|
||||
> result_type;
|
||||
public:
|
||||
SPROUT_CONSTEXPR result_type operator()(T const& t) const {
|
||||
return result_type(sprout::to_string(t));
|
||||
}
|
||||
};
|
||||
template<typename T>
|
||||
struct lit_g::eval<
|
||||
T,
|
||||
typename std::enable_if<
|
||||
sprout::weed::traits::is_string<T>::value
|
||||
>::type
|
||||
> {
|
||||
public:
|
||||
typedef sprout::weed::lit_str_p<T> result_type;
|
||||
public:
|
||||
SPROUT_CONSTEXPR result_type operator()(T const& t) const {
|
||||
return result_type(t);
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// str_p
|
||||
//
|
||||
template<typename T>
|
||||
struct str_p
|
||||
: public sprout::weed::parser_base
|
||||
{
|
||||
public:
|
||||
template<typename Context, typename Iterator>
|
||||
struct attribute {
|
||||
public:
|
||||
typedef T type;
|
||||
};
|
||||
template<typename Context, typename Iterator>
|
||||
struct result {
|
||||
public:
|
||||
typedef sprout::weed::parser_result<Iterator, typename attribute<Context, Iterator>::type> type;
|
||||
};
|
||||
private:
|
||||
T t_;
|
||||
public:
|
||||
str_p() = default;
|
||||
SPROUT_CONSTEXPR explicit str_p(T const& t)
|
||||
: t_(t)
|
||||
{}
|
||||
template<typename Context, typename Iterator>
|
||||
SPROUT_CONSTEXPR typename result<Context, Iterator>::type operator()(
|
||||
Iterator first,
|
||||
Iterator last,
|
||||
Context const&
|
||||
) const
|
||||
{
|
||||
typedef typename result<Context, Iterator>::type result_type;
|
||||
typedef typename attribute<Context, Iterator>::type attribute_type;
|
||||
return NS_SSCRISK_CEL_OR_SPROUT_DETAIL::distance(first, last) >= sprout::size(t_)
|
||||
&&NS_SSCRISK_CEL_OR_SPROUT_DETAIL::equal(sprout::begin(t_), sprout::end(t_), first)
|
||||
? result_type(true, sprout::next(first, sprout::size(t_)), attribute_type())
|
||||
: result_type(false, first, typename attribute<Context, Iterator>::type())
|
||||
;
|
||||
}
|
||||
};
|
||||
//
|
||||
// string
|
||||
//
|
||||
template<typename T>
|
||||
SPROUT_CONSTEXPR inline typename std::enable_if<
|
||||
sprout::weed::traits::is_c_str<T const>::value,
|
||||
sprout::weed::str_p<
|
||||
typename sprout::weed::detail::c_str_as_string<T const>::type
|
||||
>
|
||||
>::type string(T const& t) {
|
||||
return sprout::weed::str_p<
|
||||
typename sprout::weed::detail::c_str_as_string<T const>::type
|
||||
>(sprout::to_string(t));
|
||||
}
|
||||
template<typename T>
|
||||
SPROUT_CONSTEXPR inline typename std::enable_if<
|
||||
sprout::weed::traits::is_string<T>::value,
|
||||
sprout::weed::str_p<T>
|
||||
>::type string(T const& t) {
|
||||
return sprout::weed::str_p<T>(t);
|
||||
}
|
||||
} // namespace weed
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_WEED_PARSER_STRING_STRING_HPP
|
Loading…
Add table
Add a link
Reference in a new issue