diff --git a/include/boost/parser/detail/make_input_subrange.hpp b/include/boost/parser/detail/make_input_subrange.hpp deleted file mode 100644 index 11b7d092..00000000 --- a/include/boost/parser/detail/make_input_subrange.hpp +++ /dev/null @@ -1,118 +0,0 @@ -// Copyright (C) 2024 T. Zachary Laine -// -// Distributed under the Boost Software License, Version 1.0. (See -// accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) -#ifndef BOOST_PARSER_DETAIL_MAKE_INPUT_SUBRANGE_HPP -#define BOOST_PARSER_DETAIL_MAKE_INPUT_SUBRANGE_HPP - -#include -#include - -#include - - -namespace boost::parser::detail { - - template - struct is_utf8_view : std::false_type - {}; - template - struct is_utf8_view> : std::true_type - {}; - -#if BOOST_PARSER_USE_CONCEPTS - - template - using iterator_t = std::ranges::iterator_t; - template - using sentinel_t = std::ranges::sentinel_t; - template - using iter_value_t = std::iter_value_t; - template - using iter_reference_t = std::iter_reference_t; - template - using range_value_t = std::ranges::range_value_t; - template - using range_reference_t = std::ranges::range_reference_t; - template - using range_rvalue_reference_t = std::ranges::range_rvalue_reference_t; - - template - constexpr bool is_parsable_code_unit_v = code_unit; - -#else - - template - using iterator_t = - decltype(detail::text::detail::begin(std::declval())); - template - using sentinel_t = - decltype(detail::text::detail::end(std::declval())); - template - using iter_value_t = typename std::iterator_traits::value_type; - template - using iter_reference_t = decltype(*std::declval()); - template - using iter_rvalue_reference_t = decltype(std::move(*std::declval())); - template - using range_value_t = iter_value_t>; - template - using range_reference_t = iter_reference_t>; - template - using range_rvalue_reference_t = iter_rvalue_reference_t>; - - template - constexpr bool is_parsable_code_unit_impl = - std::is_same_v || std::is_same_v || -#if defined(__cpp_char8_t) - std::is_same_v || -#endif - std::is_same_v || std::is_same_v; - - template - constexpr bool is_parsable_code_unit_v = - is_parsable_code_unit_impl>; - -#endif - - template - constexpr auto make_input_subrange(R && r) noexcept - { - using r_t = remove_cv_ref_t; - if constexpr (std::is_pointer_v) { - using value_type = iter_value_t; - if constexpr (std::is_same_v) { - return BOOST_PARSER_SUBRANGE(r, text::null_sentinel); - } else { - return r | text::as_utf32; - } - } else { - using value_type = range_value_t; - if constexpr (text::detail::is_bounded_array_v) { - if constexpr (std::is_same_v) { - 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 && - !is_utf8_view::value) { - return BOOST_PARSER_SUBRANGE( - detail::text::detail::begin(r), - detail::text::detail::end(r)); - } else { - return r | text::as_utf32; - } - } - } - } - -} - -#endif diff --git a/include/boost/parser/lexer.hpp b/include/boost/parser/lexer.hpp index 0fd39b7f..d2052a1a 100644 --- a/include/boost/parser/lexer.hpp +++ b/include/boost/parser/lexer.hpp @@ -17,7 +17,6 @@ #include #include #include -#include // TODO: Now moot. #include #include diff --git a/include/boost/parser/parser.hpp b/include/boost/parser/parser.hpp index c291f3e7..bf3a8319 100644 --- a/include/boost/parser/parser.hpp +++ b/include/boost/parser/parser.hpp @@ -14,7 +14,6 @@ #include #include #include -#include #include #include @@ -1034,6 +1033,13 @@ namespace boost { namespace parser { struct is_one_plus_p> : std::true_type {}; + template + struct is_utf8_view : std::false_type + {}; + template + struct is_utf8_view> : std::true_type + {}; + template using optional_type = remove_cv_ref_t())>; @@ -1055,7 +1061,48 @@ namespace boost { namespace parser { using has_push_back = decltype(std::declval().push_back(*std::declval().begin())); -#if !BOOST_PARSER_USE_CONCEPTS +#if BOOST_PARSER_USE_CONCEPTS + + template + using iterator_t = std::ranges::iterator_t; + template + using sentinel_t = std::ranges::sentinel_t; + template + using iter_value_t = std::iter_value_t; + template + using iter_reference_t = std::iter_reference_t; + template + using range_value_t = std::ranges::range_value_t; + template + using range_reference_t = std::ranges::range_reference_t; + template + using range_rvalue_reference_t = + std::ranges::range_rvalue_reference_t; + + template + constexpr bool is_parsable_code_unit_v = code_unit; + +#else + + template + using iterator_t = + decltype(detail::text::detail::begin(std::declval())); + template + using sentinel_t = + decltype(detail::text::detail::end(std::declval())); + template + using iter_value_t = typename std::iterator_traits::value_type; + template + using iter_reference_t = decltype(*std::declval()); + template + using iter_rvalue_reference_t = + decltype(std::move(*std::declval())); + template + using range_value_t = iter_value_t>; + template + using range_reference_t = iter_reference_t>; + template + using range_rvalue_reference_t = iter_rvalue_reference_t>; template using has_insert = decltype(std::declval().insert( @@ -1075,6 +1122,18 @@ namespace boost { namespace parser { (std::is_same_v, U> || (std::is_same_v && std::is_same_v)); + template + constexpr bool is_parsable_code_unit_impl = + std::is_same_v || std::is_same_v || +#if defined(__cpp_char8_t) + std::is_same_v || +#endif + std::is_same_v || std::is_same_v; + + template + constexpr bool is_parsable_code_unit_v = + is_parsable_code_unit_impl>; + template constexpr bool is_parsable_iter_v = is_parsable_code_unit_v< remove_cv_ref_t>>; @@ -2552,6 +2611,43 @@ namespace boost { namespace parser { } } + template + constexpr auto make_input_subrange(R && r) noexcept + { + using r_t = remove_cv_ref_t; + if constexpr (std::is_pointer_v) { + using value_type = iter_value_t; + if constexpr (std::is_same_v) { + return BOOST_PARSER_SUBRANGE(r, text::null_sentinel); + } else { + return r | text::as_utf32; + } + } else { + using value_type = range_value_t; + if constexpr (text::detail::is_bounded_array_v) { + if constexpr (std::is_same_v) { + 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 && + !is_utf8_view::value) { + return BOOST_PARSER_SUBRANGE( + detail::text::detail::begin(r), + detail::text::detail::end(r)); + } else { + return r | text::as_utf32; + } + } + } + } + template constexpr auto make_view_begin(R & r) noexcept {