Skip to content

Commit

Permalink
Put detail::make_input_subrange back into parer.hpp.
Browse files Browse the repository at this point in the history
See #202.
  • Loading branch information
tzlaine committed Nov 10, 2024
1 parent 43b6a2f commit 364d8ae
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 121 deletions.
118 changes: 0 additions & 118 deletions include/boost/parser/detail/make_input_subrange.hpp

This file was deleted.

1 change: 0 additions & 1 deletion include/boost/parser/lexer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include <boost/parser/concepts.hpp>
#include <boost/parser/detail/debug_assert.hpp>
#include <boost/parser/detail/hl.hpp>
#include <boost/parser/detail/make_input_subrange.hpp> // TODO: Now moot.
#include <boost/parser/detail/numeric.hpp>

#include <ctre-unicode.hpp>
Expand Down
100 changes: 98 additions & 2 deletions include/boost/parser/parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include <boost/parser/detail/numeric.hpp>
#include <boost/parser/detail/case_fold.hpp>
#include <boost/parser/detail/unicode_char_sets.hpp>
#include <boost/parser/detail/make_input_subrange.hpp>
#include <boost/parser/detail/pp_for_each.hpp>
#include <boost/parser/detail/printing.hpp>

Expand Down Expand Up @@ -1034,6 +1033,13 @@ namespace boost { namespace parser {
struct is_one_plus_p<one_plus_parser<T>> : std::true_type
{};

template<typename T>
struct is_utf8_view : std::false_type
{};
template<typename V>
struct is_utf8_view<text::utf8_view<V>> : std::true_type
{};

template<typename T>
using optional_type = remove_cv_ref_t<decltype(*std::declval<T &>())>;

Expand All @@ -1055,7 +1061,48 @@ namespace boost { namespace parser {
using has_push_back =
decltype(std::declval<T &>().push_back(*std::declval<T>().begin()));

#if !BOOST_PARSER_USE_CONCEPTS
#if BOOST_PARSER_USE_CONCEPTS

template<typename T>
using iterator_t = std::ranges::iterator_t<T>;
template<typename T>
using sentinel_t = std::ranges::sentinel_t<T>;
template<typename T>
using iter_value_t = std::iter_value_t<T>;
template<typename T>
using iter_reference_t = std::iter_reference_t<T>;
template<typename T>
using range_value_t = std::ranges::range_value_t<T>;
template<typename T>
using range_reference_t = std::ranges::range_reference_t<T>;
template<typename T>
using range_rvalue_reference_t =
std::ranges::range_rvalue_reference_t<T>;

template<typename T>
constexpr bool is_parsable_code_unit_v = code_unit<T>;

#else

template<typename T>
using iterator_t =
decltype(detail::text::detail::begin(std::declval<T &>()));
template<typename Range>
using sentinel_t =
decltype(detail::text::detail::end(std::declval<Range &>()));
template<typename T>
using iter_value_t = typename std::iterator_traits<T>::value_type;
template<typename T>
using iter_reference_t = decltype(*std::declval<T &>());
template<typename T>
using iter_rvalue_reference_t =
decltype(std::move(*std::declval<T &>()));
template<typename T>
using range_value_t = iter_value_t<iterator_t<T>>;
template<typename T>
using range_reference_t = iter_reference_t<iterator_t<T>>;
template<typename T>
using range_rvalue_reference_t = iter_rvalue_reference_t<iterator_t<T>>;

template<typename T>
using has_insert = decltype(std::declval<T &>().insert(
Expand All @@ -1075,6 +1122,18 @@ namespace boost { namespace parser {
(std::is_same_v<detected_t<range_value_t, T>, U> ||
(std::is_same_v<T, std::string> && std::is_same_v<U, char32_t>));

template<typename T>
constexpr bool is_parsable_code_unit_impl =
std::is_same_v<T, char> || std::is_same_v<T, wchar_t> ||
#if defined(__cpp_char8_t)
std::is_same_v<T, char8_t> ||
#endif
std::is_same_v<T, char16_t> || std::is_same_v<T, char32_t>;

template<typename T>
constexpr bool is_parsable_code_unit_v =
is_parsable_code_unit_impl<std::remove_cv_t<T>>;

template<typename T>
constexpr bool is_parsable_iter_v = is_parsable_code_unit_v<
remove_cv_ref_t<detected_t<iter_value_t, T>>>;
Expand Down Expand Up @@ -2552,6 +2611,43 @@ namespace boost { namespace parser {
}
}

template<typename R>
constexpr auto make_input_subrange(R && r) noexcept
{
using r_t = remove_cv_ref_t<R>;
if constexpr (std::is_pointer_v<r_t>) {
using value_type = iter_value_t<r_t>;
if constexpr (std::is_same_v<value_type, char>) {
return BOOST_PARSER_SUBRANGE(r, text::null_sentinel);
} else {
return r | text::as_utf32;
}
} else {
using value_type = range_value_t<r_t>;
if constexpr (text::detail::is_bounded_array_v<r_t>) {
if constexpr (std::is_same_v<value_type, char>) {
auto first = detail::text::detail::begin(r);
auto last = detail::text::detail::end(r);
if (first != last && !*std::prev(last))
--last;
return BOOST_PARSER_SUBRANGE(first, last);
} else {
return r | text::as_utf32;
}
} else {
if constexpr (
std::is_same_v<value_type, char> &&
!is_utf8_view<r_t>::value) {
return BOOST_PARSER_SUBRANGE(
detail::text::detail::begin(r),
detail::text::detail::end(r));
} else {
return r | text::as_utf32;
}
}
}
}

template<typename R>
constexpr auto make_view_begin(R & r) noexcept
{
Expand Down

0 comments on commit 364d8ae

Please sign in to comment.