#ifndef EOLIAN_CXX_INTEGRAL_HH #define EOLIAN_CXX_INTEGRAL_HH #include #include #include "grammar/generator.hpp" #include "grammar/attributes.hpp" #include "grammar/case.hpp" namespace efl { namespace eolian { namespace grammar { namespace detail { template void generate_integral(OutputIterator sink, T integer) { std::stringstream stm; stm << integer; std::string string = stm.str(); std::copy(string.begin(), string.end(), sink); } } // literal template struct literal_integral_generator { T integral; template bool generate(OutputIterator sink, Attribute const&, Context const&) const { detail::generate_integral(sink, integral); return true; } }; template ::value>::type> literal_integral_generator as_generator(T&& literal) { return {std::forward(literal)}; } literal_integral_generator as_generator(std::size_t literal) { return {literal}; } struct integral_terminal { template literal_integral_generator operator()(T literal) const { return {literal}; } } const int_ = {}; struct integral_generator { template bool generate(OutputIterator sink, Attribute const& attribute, Context const&) const { detail::generate_integral(sink, attribute); return true; } }; integral_generator as_generator(integral_terminal) { return {}; } template struct is_eager_generator> : std::true_type {}; template <> struct is_eager_generator : std::true_type {}; template struct is_generator> : std::true_type {}; template <> struct is_generator : std::true_type {}; template struct is_generator::value>::type> : std::true_type {}; template <> struct is_generator : std::true_type {}; namespace type_traits { template struct attributes_needed> : std::integral_constant {}; template <> struct attributes_needed : std::integral_constant {}; template <> struct attributes_needed : std::integral_constant {}; } } } } #endif