diff --git a/include/tao/pegtl/analyze.hpp b/include/tao/pegtl/analyze.hpp index 2c5ff70c1..c8450c7d8 100644 --- a/include/tao/pegtl/analyze.hpp +++ b/include/tao/pegtl/analyze.hpp @@ -152,7 +152,7 @@ namespace TAO_PEGTL_NAMESPACE { using Traits = analyze_traits< Name, typename Name::rule_t >; - const auto [ i, b ] = entry.try_emplace( demangle< Name >(), Traits::type_v ); + const auto [ i, b ] = entry.try_emplace( demangle< Name >(), Traits::enum_v ); if( b ) { analyze_insert_impl( typename Traits::subs_t(), i->second.subs, entry ); } diff --git a/include/tao/pegtl/analyze_traits.hpp b/include/tao/pegtl/analyze_traits.hpp index 880ae2357..8f18e92f1 100644 --- a/include/tao/pegtl/analyze_traits.hpp +++ b/include/tao/pegtl/analyze_traits.hpp @@ -17,7 +17,7 @@ namespace TAO_PEGTL_NAMESPACE struct analyze_any_traits { // Consumption-on-success is always true; assumes bounded repetition of conjunction of sub-rules. - static constexpr internal::analyze_enum type_v = internal::analyze_enum::any; + static constexpr internal::analyze_enum enum_v = internal::analyze_enum::any; using subs_t = type_list< Rules... >; }; @@ -25,7 +25,7 @@ namespace TAO_PEGTL_NAMESPACE struct analyze_opt_traits { // Consumption-on-success not necessarily true; assumes bounded repetition of conjunction of sub-rules. - static constexpr internal::analyze_enum type_v = internal::analyze_enum::opt; + static constexpr internal::analyze_enum enum_v = internal::analyze_enum::opt; using subs_t = type_list< Rules... >; }; @@ -33,7 +33,7 @@ namespace TAO_PEGTL_NAMESPACE struct analyze_seq_traits { // Consumption-on-success depends on consumption of (non-zero bounded repetition of) conjunction of sub-rules. - static constexpr internal::analyze_enum type_v = internal::analyze_enum::seq; + static constexpr internal::analyze_enum enum_v = internal::analyze_enum::seq; using subs_t = type_list< Rules... >; }; @@ -41,7 +41,7 @@ namespace TAO_PEGTL_NAMESPACE struct analyze_sor_traits { // Consumption-on-success depends on consumption of (non-zero bounded repetition of) disjunction of sub-rules. - static constexpr internal::analyze_enum type_v = internal::analyze_enum::sor; + static constexpr internal::analyze_enum enum_v = internal::analyze_enum::sor; using subs_t = type_list< Rules... >; }; diff --git a/include/tao/pegtl/ascii.hpp b/include/tao/pegtl/ascii.hpp index 527472507..4b4222ab3 100644 --- a/include/tao/pegtl/ascii.hpp +++ b/include/tao/pegtl/ascii.hpp @@ -94,7 +94,7 @@ namespace TAO_PEGTL_NAMESPACE struct lf_crlf : ascii::lf_crlf { using eol_lazy_peek = internal::peek_char; }; struct cr_lf_crlf : ascii::cr_lf_crlf { using eol_lazy_peek = internal::peek_char; }; // clang-format on - } // namespace rule + } // namespace lazy } // namespace ascii diff --git a/include/tao/pegtl/buffer/discard.hpp b/include/tao/pegtl/buffer/discard.hpp index f02493a6b..d62791ffb 100644 --- a/include/tao/pegtl/buffer/discard.hpp +++ b/include/tao/pegtl/buffer/discard.hpp @@ -23,6 +23,6 @@ namespace TAO_PEGTL_NAMESPACE } }; -} // namespace TAO_PEGTL_NAMESPACE::internal +} // namespace TAO_PEGTL_NAMESPACE #endif diff --git a/include/tao/pegtl/buffer/require.hpp b/include/tao/pegtl/buffer/require.hpp index de0f1f858..f1babd2a9 100644 --- a/include/tao/pegtl/buffer/require.hpp +++ b/include/tao/pegtl/buffer/require.hpp @@ -32,6 +32,6 @@ namespace TAO_PEGTL_NAMESPACE : internal::success {}; -} // namespace TAO_PEGTL_NAMESPACE::internal +} // namespace TAO_PEGTL_NAMESPACE #endif diff --git a/include/tao/pegtl/contrib/dispatch.hpp b/include/tao/pegtl/contrib/dispatch.hpp index d59171a13..538c3c01a 100644 --- a/include/tao/pegtl/contrib/dispatch.hpp +++ b/include/tao/pegtl/contrib/dispatch.hpp @@ -11,9 +11,9 @@ #include "../apply_mode.hpp" #include "../config.hpp" +#include "../match.hpp" #include "../normal.hpp" #include "../nothing.hpp" -#include "../match.hpp" #include "../rewind_mode.hpp" #include "../internal/dependent_false.hpp" diff --git a/include/tao/pegtl/contrib/trace.hpp b/include/tao/pegtl/contrib/trace.hpp index addabc802..27bcc920b 100644 --- a/include/tao/pegtl/contrib/trace.hpp +++ b/include/tao/pegtl/contrib/trace.hpp @@ -9,9 +9,9 @@ #include #include "../config.hpp" -#include "../parse.hpp" #include "../normal.hpp" #include "../nothing.hpp" +#include "../parse.hpp" #include "../control/state_control.hpp" diff --git a/include/tao/pegtl/internal/analyze_traits.hpp b/include/tao/pegtl/internal/analyze_traits.hpp index b580c37e0..6d674855a 100644 --- a/include/tao/pegtl/internal/analyze_traits.hpp +++ b/include/tao/pegtl/internal/analyze_traits.hpp @@ -27,7 +27,7 @@ namespace TAO_PEGTL_NAMESPACE template< typename Name, typename... Actions > struct analyze_traits< Name, internal::apply< Actions... > > - : analyze_opt_traits<> + : analyze_opt_traits<> {}; template< typename Name, typename... Actions > diff --git a/include/tao/pegtl/internal/choose_lazy_traits.hpp b/include/tao/pegtl/internal/choose_lazy_traits.hpp index 1b915ac73..00dfcb8d8 100644 --- a/include/tao/pegtl/internal/choose_lazy_traits.hpp +++ b/include/tao/pegtl/internal/choose_lazy_traits.hpp @@ -23,7 +23,7 @@ namespace TAO_PEGTL_NAMESPACE::internal { static_assert( !std::is_same_v< Eol, void > ); - if constexpr( get_eol_rule_char_v< Eol > ) { + if constexpr( int( get_eol_rule_char_v< Eol > ) != 0 ) { char_scan_traits< Eol >::scan( pos, in ); } else if constexpr( has_eol_char_rule< Eol > ) { diff --git a/include/tao/pegtl/internal/input_with_funcs.hpp b/include/tao/pegtl/internal/input_with_funcs.hpp index 363d2efb5..b50ee03a8 100644 --- a/include/tao/pegtl/internal/input_with_funcs.hpp +++ b/include/tao/pegtl/internal/input_with_funcs.hpp @@ -6,6 +6,7 @@ #define TAO_PEGTL_INTERNAL_INPUT_WITH_FUNCS_HPP #include +#include #include #include #include diff --git a/include/tao/pegtl/internal/inputs.hpp b/include/tao/pegtl/internal/inputs.hpp index 40a0c03af..43cfe28bb 100644 --- a/include/tao/pegtl/internal/inputs.hpp +++ b/include/tao/pegtl/internal/inputs.hpp @@ -41,12 +41,12 @@ namespace TAO_PEGTL_NAMESPACE::internal template< typename Eol, typename Input > using base_short = input_with_fakes< input_with_funcs< input_with_lines< Eol, Input > > >; - template< typename Eol, typename Input > - using text_short = input_double_path< text_input_with_source< Eol, std::filesystem::path, std::filesystem::path, Input > >; - template< typename Input > using path_short = input_double_path< input_with_source< std::filesystem::path, std::filesystem::path, Input > >; + template< typename Eol, typename Input > + using text_short = input_double_path< text_input_with_source< Eol, std::filesystem::path, std::filesystem::path, Input > >; + template< typename Eol, typename Data > using base_alias = base_short< Eol, view_input< Data > >; diff --git a/include/tao/pegtl/internal/integer_size.hpp b/include/tao/pegtl/internal/integer_size.hpp index bf867e334..825b8da08 100644 --- a/include/tao/pegtl/internal/integer_size.hpp +++ b/include/tao/pegtl/internal/integer_size.hpp @@ -32,7 +32,7 @@ namespace TAO_PEGTL_NAMESPACE::internal } } - template< typename Type, typename Input> + template< typename Type, typename Input > [[nodiscard]] constexpr std::size_t integer_input_size() noexcept { using Data = typename Input::data_t; diff --git a/include/tao/pegtl/internal/utf32_to_utf8.hpp b/include/tao/pegtl/internal/utf32_to_utf8.hpp index 4da5a9d0f..edbb15618 100644 --- a/include/tao/pegtl/internal/utf32_to_utf8.hpp +++ b/include/tao/pegtl/internal/utf32_to_utf8.hpp @@ -65,7 +65,7 @@ namespace TAO_PEGTL_NAMESPACE::internal using type = String<>; }; - template< char32_t... Cs > + template< char32_t... Cs > using utf32_to_utf8_t = typename utf32_to_utf8_list< ascii_string, Cs... >::type; } // namespace TAO_PEGTL_NAMESPACE::internal diff --git a/include/tao/pegtl/internal/utf_rules.ipp b/include/tao/pegtl/internal/utf_rules.ipp index 30c03c8bb..19df0ca0d 100644 --- a/include/tao/pegtl/internal/utf_rules.ipp +++ b/include/tao/pegtl/internal/utf_rules.ipp @@ -72,7 +72,7 @@ namespace TAO_PEGTL_NAMESPACE::TAO_PEGTL_UTF_NAME struct ps : TAO_PEGTL_UTF_NAME::ps { using eol_lazy_peek = TAO_PEGTL_UTF_PEEK; }; struct eolu : TAO_PEGTL_UTF_NAME::eolu { using eol_lazy_peek = TAO_PEGTL_UTF_PEEK; }; // clang-format on - } // namespace rule + } // namespace lazy } // namespace TAO_PEGTL_NAMESPACE::TAO_PEGTL_UTF_NAME diff --git a/include/tao/pegtl/internal/utf_string.hpp b/include/tao/pegtl/internal/utf_string.hpp index 3cf946d39..527880092 100644 --- a/include/tao/pegtl/internal/utf_string.hpp +++ b/include/tao/pegtl/internal/utf_string.hpp @@ -35,7 +35,7 @@ namespace TAO_PEGTL_NAMESPACE::internal }; template< typename Peek, char32_t... Cs > - using utf_string_t = typename utf_string< Peek, Cs...>::type; + using utf_string_t = typename utf_string< Peek, Cs... >::type; } // namespace TAO_PEGTL_NAMESPACE::internal diff --git a/include/tao/pegtl/parse_error.hpp b/include/tao/pegtl/parse_error.hpp index 6c6aac29c..9f4f6b092 100644 --- a/include/tao/pegtl/parse_error.hpp +++ b/include/tao/pegtl/parse_error.hpp @@ -43,18 +43,19 @@ namespace TAO_PEGTL_NAMESPACE const position_t m_position; }; + template< typename Position > + parse_error( const std::string&, Position ) -> parse_error< std::decay_t< Position > >; + template< typename Object > [[noreturn]] void throw_parse_error( const std::string& msg, const Object& obj ) { - auto pos = internal::extract_position( obj ); - throw parse_error< std::decay_t< decltype( pos ) > >( msg, std::move( pos ) ); + throw parse_error( msg, internal::extract_position( obj ) ); } template< typename Object > [[noreturn]] void throw_with_nested_parse_error( const std::string& msg, const Object& obj ) { - auto pos = internal::extract_position( obj ); - std::throw_with_nested( parse_error< std::decay_t< decltype( pos ) > >( msg, std::move( pos ) ) ); + std::throw_with_nested( parse_error( msg, internal::extract_position( obj ) ) ); } } // namespace TAO_PEGTL_NAMESPACE diff --git a/include/tao/pegtl/position_with_source.hpp b/include/tao/pegtl/position_with_source.hpp index fdf19e576..f166f1c30 100644 --- a/include/tao/pegtl/position_with_source.hpp +++ b/include/tao/pegtl/position_with_source.hpp @@ -18,6 +18,12 @@ namespace TAO_PEGTL_NAMESPACE { Source source; + position_with_source( position_with_source&& ) = default; + position_with_source( const position_with_source& ) = default; + + position_with_source& operator=( position_with_source&& ) = default; + position_with_source& operator=( const position_with_source& ) = default; + template< typename S, typename... Ps > explicit position_with_source( S&& s, Ps&&... ps ) : Position( std::forward< Ps >( ps )... ), diff --git a/include/tao/pegtl/text_position_with_source.hpp b/include/tao/pegtl/text_position_with_source.hpp index c1afe6613..8421440d8 100644 --- a/include/tao/pegtl/text_position_with_source.hpp +++ b/include/tao/pegtl/text_position_with_source.hpp @@ -2,8 +2,8 @@ // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) -#ifndef TAO_PEGTL_INTERNAL_TEXT_POSITION_WITH_SOURCE_HPP -#define TAO_PEGTL_INTERNAL_TEXT_POSITION_WITH_SOURCE_HPP +#ifndef TAO_PEGTL_TEXT_POSITION_WITH_SOURCE_HPP +#define TAO_PEGTL_TEXT_POSITION_WITH_SOURCE_HPP #include #include diff --git a/src/test/pegtl/action_match_lazy.cpp b/src/test/pegtl/action_match_lazy.cpp index eb6582231..bdf785d81 100644 --- a/src/test/pegtl/action_match_lazy.cpp +++ b/src/test/pegtl/action_match_lazy.cpp @@ -123,7 +123,7 @@ namespace TAO_PEGTL_NAMESPACE void unit_test() { state_one state; - text_view_input< lazy::lf >in( "aaa" ); + text_view_input< lazy::lf > in( "aaa" ); global_start = in.current(); const bool parse_result = parse< grammar_one_a, action_one_a >( in, state ); TAO_PEGTL_TEST_ASSERT( parse_result ); diff --git a/src/test/pegtl/action_match_text.cpp b/src/test/pegtl/action_match_text.cpp index f268ca984..ee25ece30 100644 --- a/src/test/pegtl/action_match_text.cpp +++ b/src/test/pegtl/action_match_text.cpp @@ -129,7 +129,7 @@ namespace TAO_PEGTL_NAMESPACE void unit_test() { state_one state; - text_view_input< scan::lf >in( "aaa" ); + text_view_input< scan::lf > in( "aaa" ); global_start = in.current(); const bool parse_result = parse< grammar_one_a, action_one_a >( in, state ); TAO_PEGTL_TEST_ASSERT( parse_result ); diff --git a/src/test/pegtl/internal_get_eol_rule_char.cpp b/src/test/pegtl/internal_get_eol_rule_char.cpp index 7c31b20bb..7c5379b5a 100644 --- a/src/test/pegtl/internal_get_eol_rule_char.cpp +++ b/src/test/pegtl/internal_get_eol_rule_char.cpp @@ -5,8 +5,8 @@ #include #include -#include #include +#include #include diff --git a/src/test/pegtl/internal_lazy_scan_traits.cpp b/src/test/pegtl/internal_lazy_scan_traits.cpp index d216258f3..9d50db5a6 100644 --- a/src/test/pegtl/internal_lazy_scan_traits.cpp +++ b/src/test/pegtl/internal_lazy_scan_traits.cpp @@ -9,6 +9,7 @@ #include "test_utility.hpp" #include + #include #include #include diff --git a/src/test/pegtl/internal_text_scan_traits.cpp b/src/test/pegtl/internal_text_scan_traits.cpp index 0acaa785f..c86bb4b44 100644 --- a/src/test/pegtl/internal_text_scan_traits.cpp +++ b/src/test/pegtl/internal_text_scan_traits.cpp @@ -9,6 +9,7 @@ #include "test_utility.hpp" #include + #include namespace TAO_PEGTL_NAMESPACE diff --git a/src/test/pegtl/test_endian.hpp b/src/test/pegtl/test_endian.hpp index 82d642547..3a51d44ad 100644 --- a/src/test/pegtl/test_endian.hpp +++ b/src/test/pegtl/test_endian.hpp @@ -16,6 +16,17 @@ namespace TAO_PEGTL_NAMESPACE::test // the one in tao/pegtl/include/endian.hpp etc. for the tests to be useful... // TODO: When can we finally switch to the C++20 and C++23 endian facilities? + [[nodiscard]] inline bool is_be() noexcept + { + union { + std::uint8_t a[ 2 ]; + std::uint16_t i; + } u; + static_assert( sizeof( u ) == 2 ); + u.i = 0x1af3; + return u.a[ 0 ] == 0x1a; + } + [[nodiscard]] inline std::uint16_t b_swap( const std::uint16_t value ) noexcept { return ( ( value & 0x00ff ) << 8 ) | ( ( value & 0xff00 ) >> 8 ); @@ -28,7 +39,7 @@ namespace TAO_PEGTL_NAMESPACE::test [[nodiscard]] inline std::uint16_t h_to_be( const std::uint16_t value ) noexcept { - if( htons( value ) == value ) { + if( is_be() ) { return value; } return b_swap( value ); @@ -36,7 +47,7 @@ namespace TAO_PEGTL_NAMESPACE::test [[nodiscard]] inline std::uint16_t h_to_le( const std::uint16_t value ) noexcept { - if( htons( value ) == value ) { + if( is_be() ) { return b_swap( value ); } return value; @@ -44,7 +55,7 @@ namespace TAO_PEGTL_NAMESPACE::test [[nodiscard]] inline std::uint32_t h_to_be( const std::uint32_t value ) noexcept { - if( htonl( value ) == value ) { + if( is_be() ) { return value; } return b_swap( value ); @@ -52,7 +63,7 @@ namespace TAO_PEGTL_NAMESPACE::test [[nodiscard]] inline std::uint32_t h_to_le( const std::uint32_t value ) noexcept { - if( htonl( value ) == value ) { + if( is_be() ) { return b_swap( value ); } return value; diff --git a/src/test/pegtl/test_result.cpp b/src/test/pegtl/test_result.cpp index ac9dc5ee9..7a58b91b1 100644 --- a/src/test/pegtl/test_result.cpp +++ b/src/test/pegtl/test_result.cpp @@ -5,6 +5,7 @@ #include #include "test.hpp" + #include "result_type.hpp" namespace TAO_PEGTL_NAMESPACE @@ -15,18 +16,15 @@ namespace TAO_PEGTL_NAMESPACE std::ostringstream oss; oss << result_type::success; TAO_PEGTL_TEST_ASSERT( oss.str() == "success" ); - } - { + } { std::ostringstream oss; oss << result_type::local_failure; TAO_PEGTL_TEST_ASSERT( oss.str() == "local_failure" ); - } - { + } { std::ostringstream oss; oss << result_type::global_failure; TAO_PEGTL_TEST_ASSERT( oss.str() == "global_failure" ); - } - { + } { std::ostringstream oss; oss << static_cast< result_type >( 1764 ); TAO_PEGTL_TEST_ASSERT( oss.str() == "1764" );