diff --git a/doc/Changelog.md b/doc/Changelog.md index 682770bfd..bee93d2d5 100644 --- a/doc/Changelog.md +++ b/doc/Changelog.md @@ -29,6 +29,7 @@ * Added rule [`try_catch_raise_nested`](Rule-Reference.md#try_catch_raise_nested-r-). * Added rule [`try_catch_std_raise_nested`](Rule-Reference.md#try_catch_std_raise_nested-r-). * Added rule [`try_catch_type_raise_nested`](Rule-Reference.md#try_catch_type_raise_nested-e-r-). +* Added rules for matching signed integers mirroring the existing ones for unsigned integers. * Moved depth counter to adapter class `input_with_depth` in [contrib](Contrib-and-Examples#contrib). * Changed default top-level `rewind_mode` to ~~`dontcare`~~ `optional`. * Replaced `rewind_mode` values `dontcare` and `active` with new value `optional`. diff --git a/doc/Rule-Reference.md b/doc/Rule-Reference.md index ddb4b08b3..70bafe041 100644 --- a/doc/Rule-Reference.md +++ b/doc/Rule-Reference.md @@ -1466,20 +1466,30 @@ Convenience wrappers for enumerated properties that return a value instead of an These rules are available in multiple versions, -* in namespace `tao::pegtl::uint8` for 8-bit integer values, +* in namespace `tao::pegtl::int8` for signed 8-bit integer values, +* in namespace `tao::pegtl::uint8` for unsigned 8-bit integer values, +* in namespace `tao::pegtl::int16_be` for big-endian 16-bit integer values, +* in namespace `tao::pegtl::int16_le` for little-endian 16-bit integer values, +* in namespace `tao::pegtl::int32_be` for big-endian 32-bit integer values, +* in namespace `tao::pegtl::int32_le` for little-endian 32-bit integer values, +* in namespace `tao::pegtl::int64_be` for big-endian 64-bit integer values, and +* in namespace `tao::pegtl::int64_le` for little-endian 64-bit integer values. * in namespace `tao::pegtl::uint16_be` for big-endian 16-bit integer values, * in namespace `tao::pegtl::uint16_le` for little-endian 16-bit integer values, * in namespace `tao::pegtl::uint32_be` for big-endian 32-bit integer values, * in namespace `tao::pegtl::uint32_le` for little-endian 32-bit integer values, * in namespace `tao::pegtl::uint64_be` for big-endian 64-bit integer values, and -* in namespace `tao::pegtl::uint64_le` for little-endian 64-bit integer values. +* in namespace `tao::pegtl::uint64_le` for little-endian 64-bit integer values, -The binary rules need to be manually included from their corresponding headers in the `contrib` section. +however please not that the masked rules are available only for unsigned integers. -These rules read one or more bytes from the input to form (and match) an 8, 16, 32 or 64-bit value, respectively, and corresponding template parameters are given as either `std::uint8_t`, `std::uint16_t`, `std::uint32_t` or `std::uin64_t`. +The binary rules need to be manually included from their corresponding headers. + +These rules read one or more bytes from the input to form (and match) an 8, 16, 32 or 64-bit value, respectively, and corresponding template parameters are given as either `std::int8_t`, `std::uint8_t`, `std::int16_t`, `std::uint16_t`, `std::int32_t`, `std::uint32_t`, `std::int64_t` or `std::uin64_t`. In the following descriptions, the parameter N is the size of a single value in bytes, i.e. either 1, 2, 4 or 8. -The term *input value* indicates a correspondingly sized integer value read from successive bytes of the input. +The term *input value* indicates a correspondingly sized integer value read from the input. +For inputs of values of size 1 like `char` or `std::byte` all integer rules can be used, for inputs of values of size greater than 1 like `int` or `long` only integer rules of matching size are possible. Binary rules do not rely on other rules. diff --git a/include/tao/pegtl/ascii.hpp b/include/tao/pegtl/ascii.hpp index 3fdf00940..94b85e6be 100644 --- a/include/tao/pegtl/ascii.hpp +++ b/include/tao/pegtl/ascii.hpp @@ -7,7 +7,7 @@ #include "config.hpp" -#include "internal/peeks.hpp" +#include "internal/peek_integer.hpp" #include "internal/result_on_found.hpp" #include "internal/rules.hpp" diff --git a/include/tao/pegtl/contrib/http.hpp b/include/tao/pegtl/contrib/http.hpp index 22f439e1d..f8b89467e 100644 --- a/include/tao/pegtl/contrib/http.hpp +++ b/include/tao/pegtl/contrib/http.hpp @@ -12,12 +12,11 @@ #include "../ascii.hpp" #include "../config.hpp" #include "../nothing.hpp" +#include "../remove_first_state.hpp" #include "../rules.hpp" #include "../utf8.hpp" #include "abnf.hpp" -#include "forward.hpp" -#include "remove_first_state.hpp" #include "uri.hpp" namespace TAO_PEGTL_NAMESPACE::http @@ -167,7 +166,7 @@ namespace TAO_PEGTL_NAMESPACE::http } break; } - in.bump_in_this_line( i ); + in.template consume< internal::eol_exclude_tag >( i ); return i > 0; } }; @@ -193,7 +192,7 @@ namespace TAO_PEGTL_NAMESPACE::http [[nodiscard]] static bool match( ParseInput& in, const std::size_t size, States&&... /*unused*/ ) { if( in.size( size ) >= size ) { - in.bump( size ); + in.template consume< internal::eol_unknown_tag >( size ); return true; } return false; diff --git a/include/tao/pegtl/contrib/unescape.hpp b/include/tao/pegtl/contrib/unescape.hpp index 7ced90f6d..9b4ea48d4 100644 --- a/include/tao/pegtl/contrib/unescape.hpp +++ b/include/tao/pegtl/contrib/unescape.hpp @@ -17,7 +17,7 @@ namespace TAO_PEGTL_NAMESPACE::unescape { // Utility functions for the unescape actions. - [[nodiscard]] inline bool utf8_append_utf32( std::string& string, const unsigned utf32 ) + [[nodiscard]] inline bool utf8_append_utf32( std::string& string, const char32_t utf32 ) { if( utf32 <= 0x7f ) { string += static_cast< char >( utf32 & 0xff ); @@ -150,7 +150,7 @@ namespace TAO_PEGTL_NAMESPACE::unescape static void apply( const ActionInput& in, std::string& s ) { assert( !in.empty() ); // First character MUST be present, usually 'u' or 'U'. - if( !utf8_append_utf32( s, unhex_string< unsigned >( in.begin() + 1, in.end() ) ) ) { + if( !utf8_append_utf32( s, unhex_string< char32_t >( in.begin() + 1, in.end() ) ) ) { throw parse_error( "invalid escaped unicode code point", in ); } } @@ -159,7 +159,7 @@ namespace TAO_PEGTL_NAMESPACE::unescape static bool apply( const ActionInput& in, std::string& s ) { assert( !in.empty() ); // First character MUST be present, usually 'u' or 'U'. - return utf8_append_utf32( s, unhex_string< unsigned >( in.begin() + 1, in.end() ) ); + return utf8_append_utf32( s, unhex_string< char32_t >( in.begin() + 1, in.end() ) ); } #endif }; @@ -189,9 +189,9 @@ namespace TAO_PEGTL_NAMESPACE::unescape { assert( ( ( in.size() + 1 ) % 6 ) == 0 ); // Expects multiple "\\u1234", starting with the first "u". for( const char* b = in.begin() + 1; b < in.end(); b += 6 ) { - const auto c = unhex_string< unsigned >( b, b + 4 ); + const auto c = unhex_string< char32_t >( b, b + 4 ); if( ( 0xd800 <= c ) && ( c <= 0xdbff ) && ( b + 6 < in.end() ) ) { - const auto d = unhex_string< unsigned >( b + 6, b + 10 ); + const auto d = unhex_string< char32_t >( b + 6, b + 10 ); if( ( 0xdc00 <= d ) && ( d <= 0xdfff ) ) { b += 6; (void)utf8_append_utf32( s, ( ( ( c & 0x03ff ) << 10 ) | ( d & 0x03ff ) ) + 0x10000 ); diff --git a/include/tao/pegtl/enums.hpp b/include/tao/pegtl/enums.hpp new file mode 100644 index 000000000..a42f5c39a --- /dev/null +++ b/include/tao/pegtl/enums.hpp @@ -0,0 +1,45 @@ +// Copyright (c) 2022-2023 Dr. Colin Hirsch and Daniel Frey +// 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_ENUMS_HPP +#define TAO_PEGTL_ENUMS_HPP + +#include "config.hpp" + +#include "internal/endian.hpp" +#include "internal/peek_endian.hpp" +#include "internal/result_on_found.hpp" +#include "internal/rules.hpp" + +namespace TAO_PEGTL_NAMESPACE +{ + namespace enums_be + { + // clang-format off + template< auto E, decltype( E )... Es > struct not_one : internal::one< internal::result_on_found::failure, internal::peek_endian< decltype( E ), internal::big_endian >, E, Es... > {}; + template< auto Lo, decltype( Lo ) Hi > struct not_range : internal::range< internal::result_on_found::failure, internal::peek_endian< decltype( Lo ), internal::big_endian >, Lo, Hi > {}; + template< auto E, decltype( E )... Es > struct one : internal::one< internal::result_on_found::success, internal::peek_endian< decltype( E ), internal::big_endian >, E, Es... > {}; + template< auto Lo, decltype( Lo ) Hi > struct range : internal::range< internal::result_on_found::success, internal::peek_endian< decltype( Lo ), internal::big_endian >, Lo, Hi > {}; + template< auto E, decltype( E )... Es > struct ranges : internal::ranges< internal::peek_endian< decltype( E ), internal::big_endian >, E, Es... > {}; + template< auto E, decltype( E )... Es > struct string : internal::seq< internal::one< internal::result_on_found::success, internal::peek_endian< decltype( E ), internal::big_endian >, E >, internal::one< internal::result_on_found::success, internal::peek_endian< decltype( E ), internal::big_endian >, Es >... > {}; + // clang-format on + + } // namespace enums_be + + namespace enums_le + { + // clang-format off + template< auto E, decltype( E )... Es > struct not_one : internal::one< internal::result_on_found::failure, internal::peek_endian< decltype( E ), internal::little_endian >, E, Es... > {}; + template< auto Lo, decltype( Lo ) Hi > struct not_range : internal::range< internal::result_on_found::failure, internal::peek_endian< decltype( Lo ), internal::little_endian >, Lo, Hi > {}; + template< auto E, decltype( E )... Es > struct one : internal::one< internal::result_on_found::success, internal::peek_endian< decltype( E ), internal::little_endian >, E, Es... > {}; + template< auto Lo, decltype( Lo ) Hi > struct range : internal::range< internal::result_on_found::success, internal::peek_endian< decltype( Lo ), internal::little_endian >, Lo, Hi > {}; + template< auto E, decltype( E )... Es > struct ranges : internal::ranges< internal::peek_endian< decltype( E ), internal::little_endian >, E, Es... > {}; + template< auto E, decltype( E )... Es > struct string : internal::seq< internal::one< internal::result_on_found::success, internal::peek_endian< decltype( E ), internal::little_endian >, E >, internal::one< internal::result_on_found::success, internal::peek_endian< decltype( E ), internal::little_endian >, Es >... > {}; + // clang-format on + + } // namespace enums_le + +} // namespace TAO_PEGTL_NAMESPACE + +#endif diff --git a/include/tao/pegtl/inputs.hpp b/include/tao/pegtl/inputs.hpp index ce3bb9631..2498c2539 100644 --- a/include/tao/pegtl/inputs.hpp +++ b/include/tao/pegtl/inputs.hpp @@ -24,7 +24,8 @@ namespace TAO_PEGTL_NAMESPACE using argv_input_with_source = internal::input_with_fakes< internal::input_with_peeks< internal::argv_input_with_source > >; // TODO: Add input_with_start? template< typename Container > using copy_input_with_source = internal::input_with_fakes< internal::input_with_peeks< internal::input_with_source< std::string, internal::copy_input< Container > > > >; - using file_input_with_source = internal::input_with_fakes< internal::input_with_peeks< internal::file_input_with_source > >; + using file_input_with_source = internal::input_with_fakes< internal::input_with_peeks< internal::file_input_with_source< file_input > > >; + using read_input_with_source = internal::input_with_fakes< internal::input_with_peeks< internal::file_input_with_source< read_input > > >; template< typename Data > using view_input_with_source = internal::input_with_fakes< internal::input_with_peeks< internal::input_with_source< std::string, internal::view_input< Data > > > >; // TODO: Add input_with_start? @@ -37,6 +38,10 @@ namespace TAO_PEGTL_NAMESPACE template< typename Eol > using text_file_input = internal::input_with_fakes< internal::input_with_peeks< internal::text_input< Eol, internal::file_input > > >; template< typename Eol > + using lazy_read_input = internal::input_with_fakes< internal::input_with_peeks< internal::lazy_input< Eol, internal::read_input > > >; + template< typename Eol > + using text_read_input = internal::input_with_fakes< internal::input_with_peeks< internal::text_input< Eol, internal::read_input > > >; + template< typename Eol > using lazy_view_input = internal::input_with_fakes< internal::input_with_peeks< internal::lazy_input< Eol, internal::view_input< char > > > >; // TODO: Add input_with_start? template< typename Eol > using text_view_input = internal::input_with_fakes< internal::input_with_peeks< internal::text_input< Eol, internal::view_input< char > > > >; // TODO: Add input_with_start? @@ -46,14 +51,31 @@ namespace TAO_PEGTL_NAMESPACE template< typename Eol > using text_copy_input_with_source = internal::input_with_fakes< internal::input_with_peeks< internal::text_input_with_source< Eol, std::string, internal::copy_input< std::string > > > >; template< typename Eol > - using lazy_file_input_with_source = internal::input_with_fakes< internal::input_with_peeks< internal::lazy_file_input_with_source< Eol > > >; + using lazy_file_input_with_source = internal::input_with_fakes< internal::input_with_peeks< internal::input_double_path< internal::lazy_input_with_source< Eol, std::filesystem::path, internal::file_input > > > >; + template< typename Eol > + using text_file_input_with_source = internal::input_with_fakes< internal::input_with_peeks< internal::input_double_path< internal::text_input_with_source< Eol, std::filesystem::path, internal::file_input > > > >; template< typename Eol > - using text_file_input_with_source = internal::input_with_fakes< internal::input_with_peeks< internal::text_file_input_with_source< Eol > > >; + using lazy_read_input_with_source = internal::input_with_fakes< internal::input_with_peeks< internal::input_double_path< internal::lazy_input_with_source< Eol, std::filesystem::path, internal::read_input > > > >; + template< typename Eol > + using text_read_input_with_source = internal::input_with_fakes< internal::input_with_peeks< internal::input_double_path< internal::text_input_with_source< Eol, std::filesystem::path, internal::read_input > > > >; template< typename Eol > using lazy_view_input_with_source = internal::input_with_fakes< internal::input_with_peeks< internal::lazy_input_with_source< Eol, std::string, internal::view_input< char > > > >; // TODO: Add input_with_start? template< typename Eol > using text_view_input_with_source = internal::input_with_fakes< internal::input_with_peeks< internal::text_input_with_source< Eol, std::string, internal::view_input< char > > > >; // TODO: Add input_with_start? +#if defined( TAO_PEGTL_MMAP_AVAILABLE ) + using mmap_input = internal::input_with_fakes< internal::input_with_peeks< internal::mmap_input< char > > >; + using mmap_input_with_source = internal::input_with_fakes< internal::input_with_peeks< internal::file_input_with_source< internal::mmap_input< char > > > >; + template< typename Eol > + using lazy_mmap_input = internal::input_with_fakes< internal::input_with_peeks< internal::lazy_input< Eol, internal::mmap_input< char > > > >; + template< typename Eol > + using text_mmap_input = internal::input_with_fakes< internal::input_with_peeks< internal::text_input< Eol, internal::mmap_input< char > > > >; + template< typename Eol > + using lazy_mmap_input_with_source = internal::input_with_fakes< internal::input_with_peeks< internal::input_double_path< internal::lazy_input_with_source< Eol, std::filesystem::path, internal::mmap_input< char > > > > >; + template< typename Eol > + using text_mmap_input_with_source = internal::input_with_fakes< internal::input_with_peeks< internal::input_double_path< internal::text_input_with_source< Eol, std::filesystem::path, internal::mmap_input< char > > > > >; +#endif + } // namespace TAO_PEGTL_NAMESPACE #endif diff --git a/include/tao/pegtl/int16.hpp b/include/tao/pegtl/int16.hpp new file mode 100644 index 000000000..95496b23d --- /dev/null +++ b/include/tao/pegtl/int16.hpp @@ -0,0 +1,50 @@ +// Copyright (c) 2018-2023 Dr. Colin Hirsch and Daniel Frey +// 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_INT16_HPP +#define TAO_PEGTL_INT16_HPP + +#include "config.hpp" + +#include "internal/peek_integer.hpp" +#include "internal/result_on_found.hpp" +#include "internal/rules.hpp" + +namespace TAO_PEGTL_NAMESPACE +{ + namespace int16_be + { + // clang-format off + struct any : internal::any< internal::peek_int16_be > {}; + template< unsigned Count > struct many : internal::many< Count, internal::peek_int16_be > {}; + + template< std::int16_t... Cs > struct not_one : internal::one< internal::result_on_found::failure, internal::peek_int16_be, Cs... > {}; + template< std::int16_t Lo, std::int16_t Hi > struct not_range : internal::range< internal::result_on_found::failure, internal::peek_int16_be, Lo, Hi > {}; + template< std::int16_t... Cs > struct one : internal::one< internal::result_on_found::success, internal::peek_int16_be, Cs... > {}; + template< std::int16_t Lo, std::int16_t Hi > struct range : internal::range< internal::result_on_found::success, internal::peek_int16_be, Lo, Hi > {}; + template< std::int16_t... Cs > struct ranges : internal::ranges< internal::peek_int16_be, Cs... > {}; + template< std::int16_t... Cs > struct string : internal::seq< internal::one< internal::result_on_found::success, internal::peek_int16_be, Cs >... > {}; + // clang-format on + + } // namespace int16_be + + namespace int16_le + { + // clang-format off + struct any : internal::any< internal::peek_int16_le > {}; + template< unsigned Count > struct many : internal::many< Count, internal::peek_int16_le > {}; + + template< std::int16_t... Cs > struct not_one : internal::one< internal::result_on_found::failure, internal::peek_int16_le, Cs... > {}; + template< std::int16_t Lo, std::int16_t Hi > struct not_range : internal::range< internal::result_on_found::failure, internal::peek_int16_le, Lo, Hi > {}; + template< std::int16_t... Cs > struct one : internal::one< internal::result_on_found::success, internal::peek_int16_le, Cs... > {}; + template< std::int16_t Lo, std::int16_t Hi > struct range : internal::range< internal::result_on_found::success, internal::peek_int16_le, Lo, Hi > {}; + template< std::int16_t... Cs > struct ranges : internal::ranges< internal::peek_int16_le, Cs... > {}; + template< std::int16_t... Cs > struct string : internal::seq< internal::one< internal::result_on_found::success, internal::peek_int16_le, Cs >... > {}; + // clang-format on + + } // namespace int16_le + +} // namespace TAO_PEGTL_NAMESPACE + +#endif diff --git a/include/tao/pegtl/int32.hpp b/include/tao/pegtl/int32.hpp new file mode 100644 index 000000000..ae6a97e30 --- /dev/null +++ b/include/tao/pegtl/int32.hpp @@ -0,0 +1,50 @@ +// Copyright (c) 2018-2023 Dr. Colin Hirsch and Daniel Frey +// 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_INT32_HPP +#define TAO_PEGTL_INT32_HPP + +#include "config.hpp" + +#include "internal/peek_integer.hpp" +#include "internal/result_on_found.hpp" +#include "internal/rules.hpp" + +namespace TAO_PEGTL_NAMESPACE +{ + namespace int32_be + { + // clang-format off + struct any : internal::any< internal::peek_int32_be > {}; + template< unsigned Count > struct many : internal::many< Count, internal::peek_int32_be > {}; + + template< std::int32_t... Cs > struct not_one : internal::one< internal::result_on_found::failure, internal::peek_int32_be, Cs... > {}; + template< std::int32_t Lo, std::int32_t Hi > struct not_range : internal::range< internal::result_on_found::failure, internal::peek_int32_be, Lo, Hi > {}; + template< std::int32_t... Cs > struct one : internal::one< internal::result_on_found::success, internal::peek_int32_be, Cs... > {}; + template< std::int32_t Lo, std::int32_t Hi > struct range : internal::range< internal::result_on_found::success, internal::peek_int32_be, Lo, Hi > {}; + template< std::int32_t... Cs > struct ranges : internal::ranges< internal::peek_int32_be, Cs... > {}; + template< std::int32_t... Cs > struct string : internal::seq< internal::one< internal::result_on_found::success, internal::peek_int32_be, Cs >... > {}; + // clang-format on + + } // namespace int32_be + + namespace int32_le + { + // clang-format off + struct any : internal::any< internal::peek_int32_le > {}; + template< unsigned Count > struct many : internal::many< Count, internal::peek_int32_le > {}; + + template< std::int32_t... Cs > struct not_one : internal::one< internal::result_on_found::failure, internal::peek_int32_le, Cs... > {}; + template< std::int32_t Lo, std::int32_t Hi > struct not_range : internal::range< internal::result_on_found::failure, internal::peek_int32_le, Lo, Hi > {}; + template< std::int32_t... Cs > struct one : internal::one< internal::result_on_found::success, internal::peek_int32_le, Cs... > {}; + template< std::int32_t Lo, std::int32_t Hi > struct range : internal::range< internal::result_on_found::success, internal::peek_int32_le, Lo, Hi > {}; + template< std::int32_t... Cs > struct ranges : internal::ranges< internal::peek_int32_le, Cs... > {}; + template< std::int32_t... Cs > struct string : internal::seq< internal::one< internal::result_on_found::success, internal::peek_int32_le, Cs >... > {}; + // clang-format on + + } // namespace uint32_le + +} // namespace TAO_PEGTL_NAMESPACE + +#endif diff --git a/include/tao/pegtl/int64.hpp b/include/tao/pegtl/int64.hpp new file mode 100644 index 000000000..02c6f80fb --- /dev/null +++ b/include/tao/pegtl/int64.hpp @@ -0,0 +1,50 @@ +// Copyright (c) 2018-2023 Dr. Colin Hirsch and Daniel Frey +// 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_INT64_HPP +#define TAO_PEGTL_INT64_HPP + +#include "config.hpp" + +#include "internal/peek_integer.hpp" +#include "internal/result_on_found.hpp" +#include "internal/rules.hpp" + +namespace TAO_PEGTL_NAMESPACE +{ + namespace int64_be + { + // clang-format off + struct any : internal::any< internal::peek_int64_be > {}; + template< unsigned Count > struct many : internal::many< Count, internal::peek_int64_be > {}; + + template< std::int64_t... Cs > struct not_one : internal::one< internal::result_on_found::failure, internal::peek_int64_be, Cs... > {}; + template< std::int64_t Lo, std::int64_t Hi > struct not_range : internal::range< internal::result_on_found::failure, internal::peek_int64_be, Lo, Hi > {}; + template< std::int64_t... Cs > struct one : internal::one< internal::result_on_found::success, internal::peek_int64_be, Cs... > {}; + template< std::int64_t Lo, std::int64_t Hi > struct range : internal::range< internal::result_on_found::success, internal::peek_int64_be, Lo, Hi > {}; + template< std::int64_t... Cs > struct ranges : internal::ranges< internal::peek_int64_be, Cs... > {}; + template< std::int64_t... Cs > struct string : internal::seq< internal::one< internal::result_on_found::success, internal::peek_int64_be, Cs >... > {}; + // clang-format on + + } // namespace int64_be + + namespace int64_le + { + // clang-format off + struct any : internal::any< internal::peek_int64_le > {}; + template< unsigned Count > struct many : internal::many< Count, internal::peek_int64_le > {}; + + template< std::int64_t... Cs > struct not_one : internal::one< internal::result_on_found::failure, internal::peek_int64_le, Cs... > {}; + template< std::int64_t Lo, std::int64_t Hi > struct not_range : internal::range< internal::result_on_found::failure, internal::peek_int64_le, Lo, Hi > {}; + template< std::int64_t... Cs > struct one : internal::one< internal::result_on_found::success, internal::peek_int64_le, Cs... > {}; + template< std::int64_t Lo, std::int64_t Hi > struct range : internal::range< internal::result_on_found::success, internal::peek_int64_le, Lo, Hi > {}; + template< std::int64_t... Cs > struct ranges : internal::ranges< internal::peek_int64_le, Cs... > {}; + template< std::int64_t... Cs > struct string : internal::seq< internal::one< internal::result_on_found::success, internal::peek_int64_le, Cs >... > {}; + // clang-format on + + } // namespace int64_le + +} // namespace TAO_PEGTL_NAMESPACE + +#endif diff --git a/include/tao/pegtl/int8.hpp b/include/tao/pegtl/int8.hpp new file mode 100644 index 000000000..70e77f737 --- /dev/null +++ b/include/tao/pegtl/int8.hpp @@ -0,0 +1,30 @@ +// Copyright (c) 2018-2023 Dr. Colin Hirsch and Daniel Frey +// 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_INT8_HPP +#define TAO_PEGTL_INT8_HPP + +#include "config.hpp" + +#include "internal/peek_integer.hpp" +#include "internal/result_on_found.hpp" +#include "internal/rules.hpp" + +namespace TAO_PEGTL_NAMESPACE::int8 +{ + // clang-format off + struct any : internal::any< internal::peek_int8 > {}; + template< unsigned Count > struct many : internal::many< Count, internal::peek_int8 > {}; + + template< std::int8_t... Cs > struct not_one : internal::one< internal::result_on_found::failure, internal::peek_int8, Cs... > {}; + template< std::int8_t Lo, std::int8_t Hi > struct not_range : internal::range< internal::result_on_found::failure, internal::peek_int8, Lo, Hi > {}; + template< std::int8_t... Cs > struct one : internal::one< internal::result_on_found::success, internal::peek_int8, Cs... > {}; + template< std::int8_t Lo, std::int8_t Hi > struct range : internal::range< internal::result_on_found::success, internal::peek_int8, Lo, Hi > {}; + template< std::int8_t... Cs > struct ranges : internal::ranges< internal::peek_int8, Cs... > {}; + template< std::int8_t... Cs > struct string : internal::seq< internal::one< internal::result_on_found::success, internal::peek_int8, Cs >... > {}; + // clang-format on + +} // namespace TAO_PEGTL_NAMESPACE::uint8 + +#endif diff --git a/include/tao/pegtl/internal/any.hpp b/include/tao/pegtl/internal/any.hpp index 7247d2b4e..4eb45aff9 100644 --- a/include/tao/pegtl/internal/any.hpp +++ b/include/tao/pegtl/internal/any.hpp @@ -5,38 +5,35 @@ #ifndef TAO_PEGTL_INTERNAL_ANY_HPP #define TAO_PEGTL_INTERNAL_ANY_HPP +#include + #include "../config.hpp" #include "../type_list.hpp" #include "enable_control.hpp" -#include "peeks.hpp" +#include "peek_integer.hpp" namespace TAO_PEGTL_NAMESPACE::internal { - template< typename Peek > - struct any; - - template<> - struct any< peek_char > + template< typename Peek, typename = void > + struct any { - using peek_t = peek_char; - using data_t = char; + using peek_t = Peek; + using data_t = typename Peek::data_t; using rule_t = any; using subs_t = empty_list; - [[nodiscard]] static bool test( const char /*unused*/ ) noexcept + [[nodiscard]] static bool test( const data_t /*unused*/ ) noexcept { return true; } template< typename ParseInput > - [[nodiscard]] static bool match( ParseInput& in ) noexcept( noexcept( in.empty() ) ) + [[nodiscard]] static bool match( ParseInput& in ) noexcept( noexcept( Peek::peek( in ) ) ) { - static_assert( sizeof( *in.current() ) == 1 ); - - if( !in.empty() ) { - in.template consume< any >( 1 ); + if( const auto t = Peek::peek( in ) ) { + in.template consume< any >( t.size() ); return true; } return false; @@ -44,7 +41,7 @@ namespace TAO_PEGTL_NAMESPACE::internal }; template< typename Peek > - struct any + struct any< Peek, std::enable_if_t< Peek::allow_bulk > > { using peek_t = Peek; using data_t = typename Peek::data_t; @@ -52,24 +49,24 @@ namespace TAO_PEGTL_NAMESPACE::internal using rule_t = any; using subs_t = empty_list; - [[nodiscard]] static bool test( const data_t /*unused*/ ) noexcept + [[nodiscard]] static bool test( const char /*unused*/ ) noexcept { return true; } template< typename ParseInput > - [[nodiscard]] static bool match( ParseInput& in ) noexcept( noexcept( Peek::peek( in ) ) ) + [[nodiscard]] static bool match( ParseInput& in ) noexcept( noexcept( in.size( 1 ) ) ) { - if( const auto t = Peek::peek( in ) ) { - in.template consume< any >( t.size() ); + if( in.size( Peek::fixed_size ) >= Peek::fixed_size ) { + in.template consume< any >( Peek::fixed_size ); return true; } return false; } }; - template< typename Peek > - inline constexpr bool enable_control< any< Peek > > = false; + template< typename Peek, typename Z > + inline constexpr bool enable_control< any< Peek, Z > > = false; } // namespace TAO_PEGTL_NAMESPACE::internal diff --git a/include/tao/pegtl/internal/file_input_with_source.hpp b/include/tao/pegtl/internal/file_input_with_source.hpp index fbcc4e138..94c5c643d 100644 --- a/include/tao/pegtl/internal/file_input_with_source.hpp +++ b/include/tao/pegtl/internal/file_input_with_source.hpp @@ -11,39 +11,38 @@ #include "../config.hpp" #include "../position_with_source.hpp" -#include "file_input.hpp" - namespace TAO_PEGTL_NAMESPACE::internal { + template< typename Input > class file_input_with_source - : public file_input + : public Input { public: - using base_t = file_input; - using data_t = file_input::data_t; - using error_position_t = position_with_source< std::filesystem::path, file_input::error_position_t >; - using rewind_position_t = file_input::rewind_position_t; + using base_t = Input; + using data_t = typename Input::data_t; + using error_position_t = position_with_source< std::filesystem::path, typename Input::error_position_t >; + using rewind_position_t = typename Input::rewind_position_t; template< typename... Ts > explicit file_input_with_source( std::filesystem::path&& s, Ts&&... ts ) - : file_input( static_cast< const std::filesystem::path& >( s ), std::forward< Ts >( ts )... ), + : Input( static_cast< const std::filesystem::path& >( s ), std::forward< Ts >( ts )... ), m_source( std::move( s ) ) {} template< typename... Ts > explicit file_input_with_source( const std::filesystem::path& s, Ts&&... ts ) - : file_input( s, std::forward< Ts >( ts )... ), + : Input( s, std::forward< Ts >( ts )... ), m_source( s ) {} [[nodiscard]] auto current_position() const { - return error_position_t( m_source, file_input::current_position() ); + return error_position_t( m_source, Input::current_position() ); } [[nodiscard]] auto previous_position( const rewind_position_t& saved ) const { - return error_position_t( m_source, file_input::previous_position( saved ) ); + return error_position_t( m_source, Input::previous_position( saved ) ); } [[nodiscard]] const std::filesystem::path& direct_source() const noexcept diff --git a/include/tao/pegtl/internal/input_double_path.hpp b/include/tao/pegtl/internal/input_double_path.hpp new file mode 100644 index 000000000..c4c44c480 --- /dev/null +++ b/include/tao/pegtl/internal/input_double_path.hpp @@ -0,0 +1,33 @@ +// Copyright (c) 2021-2023 Dr. Colin Hirsch and Daniel Frey +// 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_INPUT_DOUBLE_PATH_HPP +#define TAO_PEGTL_INTERNAL_INPUT_DOUBLE_PATH_HPP + +#include +#include + +#include "../config.hpp" + +namespace TAO_PEGTL_NAMESPACE::internal +{ + template< typename Input > + class input_double_path + : public Input + { + public: + template< typename... Ts > + explicit input_double_path( std::filesystem::path&& s, Ts&&... ts ) + : Input( std::move( s ), static_cast< const std::filesystem::path& >( s ), std::forward< Ts >( ts )... ) + {} + + template< typename... Ts > + explicit input_double_path( const std::filesystem::path& s, Ts&&... ts ) + : Input( s, s, std::forward< Ts >( ts )... ) + {} + }; + +} // namespace TAO_PEGTL_NAMESPACE::internal + +#endif diff --git a/include/tao/pegtl/internal/inputs.hpp b/include/tao/pegtl/internal/inputs.hpp index 8c12e7265..587cc8db0 100644 --- a/include/tao/pegtl/internal/inputs.hpp +++ b/include/tao/pegtl/internal/inputs.hpp @@ -19,12 +19,11 @@ #include "input_with_source.hpp" #include "input_with_start.hpp" +#include "input_double_path.hpp" + #include "argv_input_with_source.hpp" #include "file_input_with_source.hpp" #include "lazy_input_with_source.hpp" #include "text_input_with_source.hpp" -#include "lazy_file_input_with_source.hpp" -#include "text_file_input_with_source.hpp" - #endif diff --git a/include/tao/pegtl/internal/type_traits.hpp b/include/tao/pegtl/internal/integer_traits.hpp similarity index 91% rename from include/tao/pegtl/internal/type_traits.hpp rename to include/tao/pegtl/internal/integer_traits.hpp index fd386513d..9ef1d3991 100644 --- a/include/tao/pegtl/internal/type_traits.hpp +++ b/include/tao/pegtl/internal/integer_traits.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_TYPE_TRAITS_HPP -#define TAO_PEGTL_INTERNAL_TYPE_TRAITS_HPP +#ifndef TAO_PEGTL_INTERNAL_INTEGER_TRAITS_HPP +#define TAO_PEGTL_INTERNAL_INTEGER_TRAITS_HPP #include #include diff --git a/include/tao/pegtl/internal/lazy_file_input_with_source.hpp b/include/tao/pegtl/internal/lazy_file_input_with_source.hpp deleted file mode 100644 index 1fedb7ec1..000000000 --- a/include/tao/pegtl/internal/lazy_file_input_with_source.hpp +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright (c) 2021-2023 Dr. Colin Hirsch and Daniel Frey -// 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_LAZY_FILE_INPUT_WITH_SOURCE_HPP -#define TAO_PEGTL_INTERNAL_LAZY_FILE_INPUT_WITH_SOURCE_HPP - -#include -#include - -#include "../config.hpp" -#include "../position_with_source.hpp" - -#include "file_input.hpp" -#include "input_with_lines.hpp" -#include "lazy_input_with_source.hpp" - -namespace TAO_PEGTL_NAMESPACE::internal -{ - template< typename Eol, typename Input = lazy_input_with_source< Eol, std::filesystem::path, file_input > > - class lazy_file_input_with_source - : public Input - { - public: - using base_t = Input; - using data_t = typename Input::data_t; - using error_position_t = typename Input::error_position_t; - using rewind_position_t = typename Input::rewind_position_t; - - using eol_rule = Eol; - - template< typename... Ts > - explicit lazy_file_input_with_source( std::filesystem::path&& s, Ts&&... ts ) - : Input( std::move( s ), static_cast< const std::filesystem::path& >( s ), std::forward< Ts >( ts )... ) - {} - - template< typename... Ts > - explicit lazy_file_input_with_source( const std::filesystem::path& s, Ts&&... ts ) - : Input( s, s, std::forward< Ts >( ts )... ) - {} - }; - -} // namespace TAO_PEGTL_NAMESPACE::internal - -#endif diff --git a/include/tao/pegtl/internal/peek_ascii.hpp b/include/tao/pegtl/internal/peek_ascii.hpp index 013e49896..5a175395c 100644 --- a/include/tao/pegtl/internal/peek_ascii.hpp +++ b/include/tao/pegtl/internal/peek_ascii.hpp @@ -12,7 +12,7 @@ #include "data_and_size.hpp" #include "endian.hpp" -#include "type_traits.hpp" +#include "integer_traits.hpp" #include "utility.hpp" namespace TAO_PEGTL_NAMESPACE::internal @@ -26,7 +26,7 @@ namespace TAO_PEGTL_NAMESPACE::internal static constexpr bool allow_bulk = false; template< typename ParseInput > - [[nodiscard]] static pair_t peek( ParseInput& in, const std::size_t offset = 0 ) noexcept( noexcept( in.size( sizeof( data_t ) ) ) ) + [[nodiscard]] static pair_t peek( ParseInput& in, const std::size_t offset = 0 ) noexcept( noexcept( in.size( 1 ) ) ) { using temp_t = typename integer_traits< sizeof( *in.current() ) >::unsigned_t; diff --git a/include/tao/pegtl/internal/peeks.hpp b/include/tao/pegtl/internal/peek_integer.hpp similarity index 100% rename from include/tao/pegtl/internal/peeks.hpp rename to include/tao/pegtl/internal/peek_integer.hpp diff --git a/include/tao/pegtl/internal/peek_member.hpp b/include/tao/pegtl/internal/peek_member.hpp index c72df8348..d96cf154c 100644 --- a/include/tao/pegtl/internal/peek_member.hpp +++ b/include/tao/pegtl/internal/peek_member.hpp @@ -25,9 +25,6 @@ namespace TAO_PEGTL_NAMESPACE::internal using data_t = std::decay_t< T >; using pair_t = data_and_size< data_t, void >; - static constexpr bool allow_bulk = true; - static constexpr std::size_t fixed_size = 1; - template< typename ParseInput > [[nodiscard]] static pair_t peek( ParseInput& in, const std::size_t offset = 0 ) noexcept( noexcept( in.size( 1 ) ) ) { @@ -35,7 +32,7 @@ namespace TAO_PEGTL_NAMESPACE::internal } }; - // For data members of type 'T*' or 'const T*'. + // For data members of type 'T*' or 'const T*' -- will this case ever be used? template< typename C, typename T, T* C::*P > struct peek_member_impl< T* C::*, P, std::enable_if_t< std::is_member_object_pointer_v< T* C::* > > > @@ -43,9 +40,6 @@ namespace TAO_PEGTL_NAMESPACE::internal using data_t = std::decay_t< T >; using pair_t = data_and_size< data_t, void >; - static constexpr bool allow_bulk = true; - static constexpr std::size_t fixed_size = 1; - template< typename ParseInput > [[nodiscard]] static pair_t peek( ParseInput& in, const std::size_t offset = 0 ) noexcept( noexcept( in.size( 1 ) ) ) { @@ -53,7 +47,7 @@ namespace TAO_PEGTL_NAMESPACE::internal } }; - // For data members of type 'T* const' or 'const T* const'. + // For data members of type 'T* const' or 'const T* const' -- will this case ever be used? template< typename C, typename T, T* const C::* const P > struct peek_member_impl< T* const C::*, P, std::enable_if_t< std::is_member_object_pointer_v< T* const C::* > > > @@ -61,9 +55,6 @@ namespace TAO_PEGTL_NAMESPACE::internal using data_t = std::decay_t< T >; using pair_t = data_and_size< data_t, void >; - static constexpr bool allow_bulk = true; - static constexpr std::size_t fixed_size = 1; - template< typename ParseInput > [[nodiscard]] static pair_t peek( ParseInput& in, const std::size_t offset = 0 ) noexcept( noexcept( in.size( 1 ) ) ) { @@ -110,7 +101,10 @@ namespace TAO_PEGTL_NAMESPACE::internal template< auto M > struct peek_member : peek_member_impl< decltype( M ), M > - {}; + { + static constexpr bool allow_bulk = true; + static constexpr std::size_t fixed_size = 1; + }; } // namespace TAO_PEGTL_NAMESPACE::internal diff --git a/include/tao/pegtl/internal/text_file_input_with_source.hpp b/include/tao/pegtl/internal/text_file_input_with_source.hpp deleted file mode 100644 index e1857d4b2..000000000 --- a/include/tao/pegtl/internal/text_file_input_with_source.hpp +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright (c) 2021-2023 Dr. Colin Hirsch and Daniel Frey -// 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_FILE_INPUT_WITH_SOURCE_HPP -#define TAO_PEGTL_INTERNAL_TEXT_FILE_INPUT_WITH_SOURCE_HPP - -#include -#include - -#include "../config.hpp" -#include "../position_with_source.hpp" - -#include "file_input.hpp" -#include "input_with_lines.hpp" -#include "text_input_with_source.hpp" - -namespace TAO_PEGTL_NAMESPACE::internal -{ - template< typename Eol, typename Input = text_input_with_source< Eol, std::filesystem::path, file_input > > - class text_file_input_with_source - : public Input - { - public: - using base_t = Input; - using data_t = typename Input::data_t; - using error_position_t = typename Input::error_position_t; - using rewind_position_t = typename Input::rewind_position_t; - - using eol_rule = Eol; - - template< typename... Ts > - explicit text_file_input_with_source( std::filesystem::path&& s, Ts&&... ts ) - : Input( std::move( s ), static_cast< const std::filesystem::path& >( s ), std::forward< Ts >( ts )... ) - {} - - template< typename... Ts > - explicit text_file_input_with_source( const std::filesystem::path& s, Ts&&... ts ) - : Input( s, s, std::forward< Ts >( ts )... ) - {} - }; - -} // namespace TAO_PEGTL_NAMESPACE::internal - -#endif diff --git a/include/tao/pegtl/member.hpp b/include/tao/pegtl/member.hpp new file mode 100644 index 000000000..dacb7a40d --- /dev/null +++ b/include/tao/pegtl/member.hpp @@ -0,0 +1,33 @@ +// Copyright (c) 2023 Dr. Colin Hirsch and Daniel Frey +// 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_MEMBER_HPP +#define TAO_PEGTL_MEMBER_HPP + +#include + +#include "config.hpp" + +#include "internal/peek_member.hpp" +#include "internal/result_on_found.hpp" +#include "internal/rules.hpp" + +namespace TAO_PEGTL_NAMESPACE +{ + namespace member + { + // clang-format off + template< auto M, typename internal::peek_member< M >::data_t E, decltype( E )... Es > struct not_one : internal::one< internal::result_on_found::failure, internal::peek_member< M >, E, Es... > {}; + template< auto M, typename internal::peek_member< M >::data_t Lo, decltype( Lo ) Hi > struct not_range : internal::range< internal::result_on_found::failure, internal::peek_member< M >, Lo, Hi > {}; + template< auto M, typename internal::peek_member< M >::data_t E, decltype( E )... Es > struct one : internal::one< internal::result_on_found::success, internal::peek_member< M >, E, Es... > {}; + template< auto M, typename internal::peek_member< M >::data_t Lo, decltype( Lo ) Hi > struct range : internal::range< internal::result_on_found::success, internal::peek_member< M >, Lo, Hi > {}; + template< auto M, typename internal::peek_member< M >::data_t E, decltype( E )... Es > struct ranges : internal::ranges< internal::peek_member< M >, E, Es... > {}; + template< auto M, typename internal::peek_member< M >::data_t E, decltype( E )... Es > struct string : internal::seq< internal::one< internal::result_on_found::success, internal::peek_member< M >, E >, internal::one< internal::result_on_found::success, internal::peek_member< M >, Es >... > {}; + // clang-format on + + } // namespace member + +} // namespace TAO_PEGTL_NAMESPACE + +#endif diff --git a/include/tao/pegtl/uint16.hpp b/include/tao/pegtl/uint16.hpp index c39ee65b5..7da4203c2 100644 --- a/include/tao/pegtl/uint16.hpp +++ b/include/tao/pegtl/uint16.hpp @@ -7,7 +7,7 @@ #include "config.hpp" -#include "internal/peeks.hpp" +#include "internal/peek_integer.hpp" #include "internal/result_on_found.hpp" #include "internal/rules.hpp" @@ -18,6 +18,7 @@ namespace TAO_PEGTL_NAMESPACE // clang-format off struct any : internal::any< internal::peek_uint16_be > {}; template< unsigned Count > struct many : internal::many< Count, internal::peek_uint16_be > {}; + template< std::uint16_t... Cs > struct not_one : internal::one< internal::result_on_found::failure, internal::peek_uint16_be, Cs... > {}; template< std::uint16_t Lo, std::uint16_t Hi > struct not_range : internal::range< internal::result_on_found::failure, internal::peek_uint16_be, Lo, Hi > {}; template< std::uint16_t... Cs > struct one : internal::one< internal::result_on_found::success, internal::peek_uint16_be, Cs... > {}; @@ -40,6 +41,7 @@ namespace TAO_PEGTL_NAMESPACE // clang-format off struct any : internal::any< internal::peek_uint16_le > {}; template< unsigned Count > struct many : internal::many< Count, internal::peek_uint16_le > {}; + template< std::uint16_t... Cs > struct not_one : internal::one< internal::result_on_found::failure, internal::peek_uint16_le, Cs... > {}; template< std::uint16_t Lo, std::uint16_t Hi > struct not_range : internal::range< internal::result_on_found::failure, internal::peek_uint16_le, Lo, Hi > {}; template< std::uint16_t... Cs > struct one : internal::one< internal::result_on_found::success, internal::peek_uint16_le, Cs... > {}; diff --git a/include/tao/pegtl/uint32.hpp b/include/tao/pegtl/uint32.hpp index ca07fb5d9..51a1468b3 100644 --- a/include/tao/pegtl/uint32.hpp +++ b/include/tao/pegtl/uint32.hpp @@ -7,7 +7,7 @@ #include "config.hpp" -#include "internal/peeks.hpp" +#include "internal/peek_integer.hpp" #include "internal/result_on_found.hpp" #include "internal/rules.hpp" @@ -18,6 +18,7 @@ namespace TAO_PEGTL_NAMESPACE // clang-format off struct any : internal::any< internal::peek_uint32_be > {}; template< unsigned Count > struct many : internal::many< Count, internal::peek_uint32_be > {}; + template< std::uint32_t... Cs > struct not_one : internal::one< internal::result_on_found::failure, internal::peek_uint32_be, Cs... > {}; template< std::uint32_t Lo, std::uint32_t Hi > struct not_range : internal::range< internal::result_on_found::failure, internal::peek_uint32_be, Lo, Hi > {}; template< std::uint32_t... Cs > struct one : internal::one< internal::result_on_found::success, internal::peek_uint32_be, Cs... > {}; @@ -40,6 +41,7 @@ namespace TAO_PEGTL_NAMESPACE // clang-format off struct any : internal::any< internal::peek_uint32_le > {}; template< unsigned Count > struct many : internal::many< Count, internal::peek_uint32_le > {}; + template< std::uint32_t... Cs > struct not_one : internal::one< internal::result_on_found::failure, internal::peek_uint32_le, Cs... > {}; template< std::uint32_t Lo, std::uint32_t Hi > struct not_range : internal::range< internal::result_on_found::failure, internal::peek_uint32_le, Lo, Hi > {}; template< std::uint32_t... Cs > struct one : internal::one< internal::result_on_found::success, internal::peek_uint32_le, Cs... > {}; diff --git a/include/tao/pegtl/uint64.hpp b/include/tao/pegtl/uint64.hpp index 08c4f5664..2f60b032a 100644 --- a/include/tao/pegtl/uint64.hpp +++ b/include/tao/pegtl/uint64.hpp @@ -7,7 +7,7 @@ #include "config.hpp" -#include "internal/peeks.hpp" +#include "internal/peek_integer.hpp" #include "internal/result_on_found.hpp" #include "internal/rules.hpp" @@ -18,6 +18,7 @@ namespace TAO_PEGTL_NAMESPACE // clang-format off struct any : internal::any< internal::peek_uint64_be > {}; template< unsigned Count > struct many : internal::many< Count, internal::peek_uint64_be > {}; + template< std::uint64_t... Cs > struct not_one : internal::one< internal::result_on_found::failure, internal::peek_uint64_be, Cs... > {}; template< std::uint64_t Lo, std::uint64_t Hi > struct not_range : internal::range< internal::result_on_found::failure, internal::peek_uint64_be, Lo, Hi > {}; template< std::uint64_t... Cs > struct one : internal::one< internal::result_on_found::success, internal::peek_uint64_be, Cs... > {}; @@ -40,6 +41,7 @@ namespace TAO_PEGTL_NAMESPACE // clang-format off struct any : internal::any< internal::peek_uint64_le > {}; template< unsigned Count > struct many : internal::many< Count, internal::peek_uint64_le > {}; + template< std::uint64_t... Cs > struct not_one : internal::one< internal::result_on_found::failure, internal::peek_uint64_le, Cs... > {}; template< std::uint64_t Lo, std::uint64_t Hi > struct not_range : internal::range< internal::result_on_found::failure, internal::peek_uint64_le, Lo, Hi > {}; template< std::uint64_t... Cs > struct one : internal::one< internal::result_on_found::success, internal::peek_uint64_le, Cs... > {}; diff --git a/include/tao/pegtl/uint8.hpp b/include/tao/pegtl/uint8.hpp index 7df305e90..ab2e649ce 100644 --- a/include/tao/pegtl/uint8.hpp +++ b/include/tao/pegtl/uint8.hpp @@ -7,7 +7,7 @@ #include "config.hpp" -#include "internal/peeks.hpp" +#include "internal/peek_integer.hpp" #include "internal/result_on_found.hpp" #include "internal/rules.hpp" @@ -16,6 +16,7 @@ namespace TAO_PEGTL_NAMESPACE::uint8 // clang-format off struct any : internal::any< internal::peek_uint8 > {}; template< unsigned Count > struct many : internal::many< Count, internal::peek_uint8 > {}; + template< std::uint8_t... Cs > struct not_one : internal::one< internal::result_on_found::failure, internal::peek_uint8, Cs... > {}; template< std::uint8_t Lo, std::uint8_t Hi > struct not_range : internal::range< internal::result_on_found::failure, internal::peek_uint8, Lo, Hi > {}; template< std::uint8_t... Cs > struct one : internal::one< internal::result_on_found::success, internal::peek_uint8, Cs... > {}; diff --git a/src/example/pegtl/token_input.cc b/src/example/pegtl/token_input.cc deleted file mode 100644 index 953c7593c..000000000 --- a/src/example/pegtl/token_input.cc +++ /dev/null @@ -1,275 +0,0 @@ -// Copyright (c) 2020-2023 Dr. Colin Hirsch and Daniel Frey -// 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) - -#include -#include -#include - -#include - -#include - -// This file contains some experiments towards generalising inputs to -// represent sequences of arbitrary objects; it's not very complete, but -// it does get a minimal example up-and-running. One main limitation is -// that nothing that throws a parse_error can be used because positions -// aren't supported by the token_parse_input. - -namespace TAO_PEGTL_NAMESPACE -{ - template< typename ParseInput > - class token_action_input - { - public: - using input_t = ParseInput; - using value_t = typename ParseInput::value_t; - using rewind_position_t = typename ParseInput::rewind_position_t; - - token_action_input( const rewind_position_t& in_begin, const ParseInput& in_input ) noexcept - : m_begin( in_begin ), - m_input( in_input ) - {} - - token_action_input( const token_action_input& ) = delete; - token_action_input( token_action_input&& ) = delete; - - ~token_action_input() = default; - - token_action_input& operator=( const token_action_input& ) = delete; - token_action_input& operator=( token_action_input&& ) = delete; - - [[nodiscard]] const rewind_position_t& rewind_position() const noexcept - { - return m_begin; - } - - [[nodiscard]] const ParseInput& input() const noexcept - { - return m_input; - } - - [[nodiscard]] const auto& begin() const noexcept - { - return m_begin; - } - - [[nodiscard]] decltype( auto ) end() const noexcept - { - return m_input.rewind_position(); - } - - [[nodiscard]] bool empty() const noexcept - { - return begin() == end(); - } - - [[nodiscard]] std::size_t size() const noexcept - { - return std::size_t( end() - begin() ); - } - - protected: - const rewind_position_t m_begin; - const ParseInput& m_input; - }; - - template< typename T, typename Source = std::string > - class token_parse_input - { - public: - using value_t = T; - using source_t = Source; - using rewind_position_t = internal::basic_small_position< T >; - - using action_t = token_action_input< token_parse_input >; - - template< typename S > - token_parse_input( const T* in_begin, const T* in_end, S&& in_source ) - : m_begin( in_begin ), - m_current( in_begin ), - m_end( in_end ), - m_source( std::forward< S >( in_source ) ) - {} - - template< typename S > - token_parse_input( const std::vector< T >& in_vector, S&& in_source ) - : token_parse_input( in_vector.data(), in_vector.data() + in_vector.size(), std::forward< S >( in_source ) ) - {} - - token_parse_input( const token_parse_input& ) = delete; - token_parse_input( token_parse_input&& ) = delete; - - ~token_parse_input() = default; - - token_parse_input& operator=( const token_parse_input& ) = delete; - token_parse_input& operator=( token_parse_input&& ) = delete; - - void discard() const noexcept {} - - void require( const std::size_t /*unused*/ ) const noexcept {} - - [[nodiscard]] const T* current() const noexcept - { - return m_current; - } - - [[nodiscard]] const T* begin() const noexcept - { - return m_begin; - } - - [[nodiscard]] const T* end( const std::size_t /*unused*/ = 0 ) const noexcept - { - return m_end; - } - - [[nodiscard]] std::size_t byte() const noexcept - { - return std::size_t( m_current - m_begin ); // We don't return the byte offset even if this function is still called 'byte'. - } - - template< rewind_mode M > - [[nodiscard]] internal::rewind_guard< M, token_parse_input > make_rewind_guard() noexcept - { - return internal::rewind_guard< M, token_parse_input >( this ); - } - - [[nodiscard]] rewind_position_t rewind_position() const noexcept - { - return rewind_position_t( m_current ); - } - - void rewind_to_position( const rewind_position_t& data ) noexcept - { - m_current = data.data; - } - - void bump( const std::size_t in_count = 1 ) noexcept - { - m_current += in_count; - } - - void restart() - { - m_current = m_begin; - } - - [[nodiscard]] const Source& source() const noexcept - { - return this->m_source; - } - - [[nodiscard]] bool empty() const noexcept - { - return m_current == m_end; - } - - [[nodiscard]] std::size_t size( const std::size_t /*unused*/ = 0 ) const noexcept - { - return std::size_t( m_end - m_current ); - } - - [[nodiscard]] T peek_token( const std::size_t offset = 0 ) const noexcept - { - return m_current[ offset ]; - } - - private: - const T* const m_begin; - const T* m_current; - const T* const m_end; - const Source m_source; - }; - - namespace internal - { - template< typename Type, Type Value > - struct token_type - { - using rule_t = token_type; - using subs_t = empty_list; - - template< typename ParseInput > - static bool match( ParseInput& in ) - { - if( ( !in.empty() ) && ( in.peek_token().type == Value ) ) { - in.bump( 1 ); - return true; - } - return false; - } - }; - - } // namespace internal - - template< auto Value > - using token_type = internal::token_type< decltype( Value ), Value >; - - template< typename Name, typename Type, Type Value > - struct analyze_traits< Name, internal::token_type< Type, Value > > - : analyze_any_traits<> - {}; - -} // namespace TAO_PEGTL_NAMESPACE - -using namespace TAO_PEGTL_NAMESPACE; - -enum my_type -{ - a, - b, - c, - d, - e, - f -}; - -struct my_token -{ - my_type type; - std::string data; -}; - -template< typename Rule > -struct my_action - : nothing< Rule > -{}; - -template<> -struct my_action< eof > -{ - static void apply0() - { - std::cout << "We have eof!" << std::endl; - } -}; - -template<> -struct my_action< token_type< my_type::b > > -{ - template< typename ActionInput > - static void apply( const ActionInput& /*unused*/ ) - { - std::cout << "We have a token of type 'b'!" << std::endl; - } -}; - -struct my_grammar - : seq< plus< token_type< my_type::b > >, eof > -{}; - -int main() -{ - const std::vector< my_token > v{ - { my_type::b, "" }, - { my_type::b, "" } - }; - - token_parse_input< my_token > in( v, __FUNCTION__ ); - if( !parse< my_grammar, my_action >( in ) ) { - return 1; - } - - return 0; -} diff --git a/src/example/pegtl/token_input.cpp b/src/example/pegtl/token_input.cpp new file mode 100644 index 000000000..a9f674cff --- /dev/null +++ b/src/example/pegtl/token_input.cpp @@ -0,0 +1,113 @@ +// Copyright (c) 2020-2023 Dr. Colin Hirsch and Daniel Frey +// 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) + +#include +#include +#include + +#include + +#include + +// This file contains some experiments towards generalising inputs to +// represent sequences of arbitrary objects; it's not very complete, but +// it does get a minimal example up-and-running. One main limitation is +// that nothing that throws a parse_error can be used because positions +// aren't supported by the token_parse_input. + +namespace TAO_PEGTL_NAMESPACE +{ + namespace internal + { + template< typename Type, Type Value > + struct token_type + { + using rule_t = token_type; + using subs_t = empty_list; + + template< typename ParseInput > + static bool match( ParseInput& in ) + { + if( ( !in.empty() ) && ( in.current()->type == Value ) ) { + in.template consume< internal::eol_exclude_tag >( 1 ); + return true; + } + return false; + } + }; + + } // namespace internal + + template< auto Value > + using token_type = internal::token_type< decltype( Value ), Value >; + + template< typename Name, typename Type, Type Value > + struct analyze_traits< Name, internal::token_type< Type, Value > > + : analyze_any_traits<> + {}; + + template< typename Token > + using token_input = internal::input_with_fakes< internal::copy_input< std::vector< Token > > >; + +} // namespace TAO_PEGTL_NAMESPACE + +using namespace TAO_PEGTL_NAMESPACE; + +enum my_type +{ + a, + b, + c, + d, + e, + f +}; + +struct my_token +{ + my_type type; + std::string data; +}; + +template< typename Rule > +struct my_action + : nothing< Rule > +{}; + +template<> +struct my_action< eof > +{ + static void apply0() + { + std::cout << "We have eof!" << std::endl; + } +}; + +template<> +struct my_action< token_type< my_type::b > > +{ + template< typename ActionInput > + static void apply( const ActionInput& /*unused*/ ) + { + std::cout << "We have a token of type 'b'!" << std::endl; + } +}; + +struct my_grammar + : seq< plus< token_type< my_type::b > >, eof > +{}; + +int main() +{ + const std::vector< my_token > v{ + { my_type::b, "" }, + { my_type::b, "" } + }; + token_input< my_token > in( v ); + + if( !parse< my_grammar, my_action >( in ) ) { + return 1; + } + return 0; +} diff --git a/src/test/pegtl/action_apply_1.cpp b/src/test/pegtl/action_apply_1.cpp index bbb63e61e..de06702b0 100644 --- a/src/test/pegtl/action_apply_1.cpp +++ b/src/test/pegtl/action_apply_1.cpp @@ -9,11 +9,6 @@ #include "test.hpp" #include "test_inputs.hpp" -#include -#include -#include -#include - namespace TAO_PEGTL_NAMESPACE { std::vector< std::pair< std::string, std::string > > applied; diff --git a/src/test/pegtl/action_apply_2.cpp b/src/test/pegtl/action_apply_2.cpp index 318181975..c6bf231c0 100644 --- a/src/test/pegtl/action_apply_2.cpp +++ b/src/test/pegtl/action_apply_2.cpp @@ -5,11 +5,6 @@ #include "test.hpp" #include "test_inputs.hpp" -#include -#include -#include -#include - namespace TAO_PEGTL_NAMESPACE { namespace test1 diff --git a/src/test/pegtl/action_apply_3.cpp b/src/test/pegtl/action_apply_3.cpp index b8b88140e..ed07d3e3b 100644 --- a/src/test/pegtl/action_apply_3.cpp +++ b/src/test/pegtl/action_apply_3.cpp @@ -5,11 +5,6 @@ #include "test.hpp" #include "test_inputs.hpp" -#include -#include -#include -#include - namespace TAO_PEGTL_NAMESPACE { template< unsigned Size, apply_mode B, rewind_mode N, typename... Rules > diff --git a/src/test/pegtl/action_enable.cpp b/src/test/pegtl/action_enable.cpp index eb74a4841..0a39cf11d 100644 --- a/src/test/pegtl/action_enable.cpp +++ b/src/test/pegtl/action_enable.cpp @@ -5,13 +5,6 @@ #include "test.hpp" #include "test_inputs.hpp" -#include -#include -#include -#include -#include -#include - namespace TAO_PEGTL_NAMESPACE { // clang-format off diff --git a/src/test/pegtl/action_match_lazy.cpp b/src/test/pegtl/action_match_lazy.cpp index 81326adb0..1af36805e 100644 --- a/src/test/pegtl/action_match_lazy.cpp +++ b/src/test/pegtl/action_match_lazy.cpp @@ -5,12 +5,6 @@ #include "test.hpp" #include "test_inputs.hpp" -#include -#include -#include -#include -#include - namespace TAO_PEGTL_NAMESPACE { struct remove_state diff --git a/src/test/pegtl/action_match_text.cpp b/src/test/pegtl/action_match_text.cpp index a86c70254..cca6822b1 100644 --- a/src/test/pegtl/action_match_text.cpp +++ b/src/test/pegtl/action_match_text.cpp @@ -5,12 +5,6 @@ #include "test.hpp" #include "test_inputs.hpp" -#include -#include -#include -#include -#include - namespace TAO_PEGTL_NAMESPACE { struct remove_state diff --git a/src/test/pegtl/add_guard.cpp b/src/test/pegtl/add_guard.cpp index a2c99aff4..69f5bdc66 100644 --- a/src/test/pegtl/add_guard.cpp +++ b/src/test/pegtl/add_guard.cpp @@ -5,12 +5,6 @@ #include "test.hpp" #include "test_inputs.hpp" -#include -#include -#include -#include -#include - namespace TAO_PEGTL_NAMESPACE { bool ctor = false; diff --git a/src/test/pegtl/apply_mode.cpp b/src/test/pegtl/apply_mode.cpp new file mode 100644 index 000000000..9e05ecd5f --- /dev/null +++ b/src/test/pegtl/apply_mode.cpp @@ -0,0 +1,25 @@ +// Copyright (c) 2023 Dr. Colin Hirsch and Daniel Frey +// 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) + +#include + +#include "test.hpp" +#include +#include + +namespace TAO_PEGTL_NAMESPACE +{ + void unit_test() + { + static_assert( std::is_same_v< std::underlying_type_t< apply_mode >, bool > ); + + static_assert( apply_mode::action != apply_mode::nothing ); + + static_assert( internal::enum_invert_bool( apply_mode::action ) == apply_mode::nothing ); + static_assert( internal::enum_invert_bool( apply_mode::nothing ) == apply_mode::action ); + } + +} // namespace TAO_PEGTL_NAMESPACE + +#include "main.hpp" diff --git a/src/test/pegtl/ascii_classes.cpp b/src/test/pegtl/ascii_classes.cpp index e93382b21..12382633e 100644 --- a/src/test/pegtl/ascii_classes.cpp +++ b/src/test/pegtl/ascii_classes.cpp @@ -69,7 +69,7 @@ namespace TAO_PEGTL_NAMESPACE verify_rule< ranges< 'a', 'z', '4' > >( __LINE__, __FILE__, "", result_type::local_failure, 0 ); for( int i = 0; i < 128; ++i ) { - const auto c = char( i ); + const int c = char( i ); const bool is_blank = ( c == ' ' ) || ( c == '\t' ); const bool is_digit = ( '0' <= c ) && ( c <= '9' ); diff --git a/src/test/pegtl/change_action_and_state.cpp b/src/test/pegtl/change_action_and_state.cpp index e2dc73d7f..3fa2ab456 100644 --- a/src/test/pegtl/change_action_and_state.cpp +++ b/src/test/pegtl/change_action_and_state.cpp @@ -5,11 +5,6 @@ #include "test.hpp" #include "test_inputs.hpp" -#include -#include -#include -#include - namespace TAO_PEGTL_NAMESPACE { // clang-format off diff --git a/src/test/pegtl/change_action_and_states.cpp b/src/test/pegtl/change_action_and_states.cpp index 9d9317268..69b1867c3 100644 --- a/src/test/pegtl/change_action_and_states.cpp +++ b/src/test/pegtl/change_action_and_states.cpp @@ -5,11 +5,6 @@ #include "test.hpp" #include "test_inputs.hpp" -#include -#include -#include -#include - namespace TAO_PEGTL_NAMESPACE { // clang-format off diff --git a/src/test/pegtl/change_state.cpp b/src/test/pegtl/change_state.cpp index f9f892069..bf55cfc9a 100644 --- a/src/test/pegtl/change_state.cpp +++ b/src/test/pegtl/change_state.cpp @@ -5,11 +5,6 @@ #include "test.hpp" #include "test_inputs.hpp" -#include -#include -#include -#include - namespace TAO_PEGTL_NAMESPACE { // clang-format off diff --git a/src/test/pegtl/change_states.cpp b/src/test/pegtl/change_states.cpp index 03589d863..de63d3124 100644 --- a/src/test/pegtl/change_states.cpp +++ b/src/test/pegtl/change_states.cpp @@ -5,11 +5,6 @@ #include "test.hpp" #include "test_inputs.hpp" -#include -#include -#include -#include - namespace TAO_PEGTL_NAMESPACE { // clang-format off diff --git a/src/test/pegtl/contains.cpp b/src/test/pegtl/contains.cpp index 7d3a286ec..03a5d2aa4 100644 --- a/src/test/pegtl/contains.cpp +++ b/src/test/pegtl/contains.cpp @@ -4,10 +4,6 @@ #include "test.hpp" -#include -#include -#include - namespace TAO_PEGTL_NAMESPACE { // clang-format off diff --git a/src/test/pegtl/contrib_alphabet.cpp b/src/test/pegtl/contrib_alphabet.cpp index 8b01e1e3d..1cf1f1600 100644 --- a/src/test/pegtl/contrib_alphabet.cpp +++ b/src/test/pegtl/contrib_alphabet.cpp @@ -3,7 +3,6 @@ // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) #include "test.hpp" - #include namespace TAO_PEGTL_NAMESPACE diff --git a/src/test/pegtl/contrib_http.cc b/src/test/pegtl/contrib_http.cpp similarity index 77% rename from src/test/pegtl/contrib_http.cc rename to src/test/pegtl/contrib_http.cpp index 486a8774a..47884191b 100644 --- a/src/test/pegtl/contrib_http.cc +++ b/src/test/pegtl/contrib_http.cpp @@ -11,6 +11,7 @@ int main() #else #include "test.hpp" +#include "test_inputs.hpp" #include "verify_meta.hpp" #include @@ -51,42 +52,42 @@ namespace TAO_PEGTL_NAMESPACE verify_analyze< GRAMMAR >( __LINE__, __FILE__, true, false ); { - string_input in( "0\r\n\r\n", __FUNCTION__ ); + test::text_input< ascii::crlf > in( "0\r\n\r\n" ); TAO_PEGTL_TEST_ASSERT( parse< GRAMMAR >( in ) ); } { std::string dummy; - string_input in( "0\r\n\r\n", __FUNCTION__ ); + test::text_input< ascii::crlf > in( "0\r\n\r\n" ); TAO_PEGTL_TEST_ASSERT( parse< GRAMMAR >( in, dummy ) ); } { std::string state; - string_input in( "0\r\n\r\n", __FUNCTION__ ); + test::text_input< ascii::crlf > in( "0\r\n\r\n" ); TAO_PEGTL_TEST_ASSERT( parse< GRAMMAR, chunked_action >( in, state ) ); TAO_PEGTL_TEST_ASSERT( state == "a" ); } { std::string state; - string_input in( "\r\n\r\n", __FUNCTION__ ); + test::text_input< ascii::crlf > in( "\r\n\r\n" ); TAO_PEGTL_TEST_THROWS( parse< GRAMMAR, chunked_action >( in, state ) ); } { std::string state; - string_input in( "1\r\n", __FUNCTION__ ); + test::text_input< ascii::crlf > in( "1\r\n" ); TAO_PEGTL_TEST_THROWS( parse< GRAMMAR, chunked_action >( in, state ) ); } { - string_input in( "01\r\nX\r\n1a\r\nabcdefghijklmnopqrstuvwxyz\r\n0\r\n\r\n", __FUNCTION__ ); + test::text_input< ascii::crlf > in( "01\r\nX\r\n1a\r\nabcdefghijklmnopqrstuvwxyz\r\n0\r\n\r\n" ); TAO_PEGTL_TEST_ASSERT( parse< GRAMMAR >( in ) ); } { std::string dummy; - string_input in( "01\r\nX\r\n1a\r\nabcdefghijklmnopqrstuvwxyz\r\n0\r\n\r\n", __FUNCTION__ ); + test::text_input< ascii::crlf > in( "01\r\nX\r\n1a\r\nabcdefghijklmnopqrstuvwxyz\r\n0\r\n\r\n" ); TAO_PEGTL_TEST_ASSERT( parse< GRAMMAR >( in, dummy ) ); } { std::string state; - string_input in( "01\r\nX\r\n1A\r\nabcdefghijklmnopqrstuvwxyz\r\n0\r\n\r\n", __FUNCTION__ ); + test::text_input< ascii::crlf > in( "01\r\nX\r\n1A\r\nabcdefghijklmnopqrstuvwxyz\r\n0\r\n\r\n" ); TAO_PEGTL_TEST_ASSERT( parse< GRAMMAR, chunked_action >( in, state ) ); TAO_PEGTL_TEST_ASSERT( state == "ababa" ); } diff --git a/src/test/pegtl/contrib_integer.cpp b/src/test/pegtl/contrib_integer.cpp index af966cd0f..b60cd8d3e 100644 --- a/src/test/pegtl/contrib_integer.cpp +++ b/src/test/pegtl/contrib_integer.cpp @@ -20,8 +20,6 @@ int main() #include "verify_rule.hpp" #include -#include -#include namespace TAO_PEGTL_NAMESPACE { diff --git a/src/test/pegtl/contrib_iri.cpp b/src/test/pegtl/contrib_iri.cpp index e6d066532..b0248719c 100644 --- a/src/test/pegtl/contrib_iri.cpp +++ b/src/test/pegtl/contrib_iri.cpp @@ -16,10 +16,6 @@ int main() #include "verify_meta.hpp" #include "verify_rule.hpp" -#include -#include -#include - #include namespace TAO_PEGTL_NAMESPACE diff --git a/src/test/pegtl/contrib_json.cpp b/src/test/pegtl/contrib_json.cpp index accfc1cff..702d0c26f 100644 --- a/src/test/pegtl/contrib_json.cpp +++ b/src/test/pegtl/contrib_json.cpp @@ -8,7 +8,6 @@ #include "verify_rule.hpp" #include -#include namespace TAO_PEGTL_NAMESPACE { diff --git a/src/test/pegtl/contrib_raw_string.cpp b/src/test/pegtl/contrib_raw_string.cpp index 9dce2b4a4..aff4e2929 100644 --- a/src/test/pegtl/contrib_raw_string.cpp +++ b/src/test/pegtl/contrib_raw_string.cpp @@ -6,11 +6,7 @@ #include "test_inputs.hpp" #include "verify_meta.hpp" -#include -#include #include -#include -#include namespace TAO_PEGTL_NAMESPACE { diff --git a/src/test/pegtl/contrib_rep_string.cpp b/src/test/pegtl/contrib_rep_string.cpp index bbecece8f..c9ce85f42 100644 --- a/src/test/pegtl/contrib_rep_string.cpp +++ b/src/test/pegtl/contrib_rep_string.cpp @@ -3,7 +3,6 @@ // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) #include "test.hpp" - #include "verify_meta.hpp" #include "verify_rule.hpp" diff --git a/src/test/pegtl/contrib_unescape.cpp b/src/test/pegtl/contrib_unescape.cpp index d2f7560c3..a60e42248 100644 --- a/src/test/pegtl/contrib_unescape.cpp +++ b/src/test/pegtl/contrib_unescape.cpp @@ -4,10 +4,7 @@ #include "test.hpp" #include "test_inputs.hpp" - #include -#include -#include namespace TAO_PEGTL_NAMESPACE { diff --git a/src/test/pegtl/contrib_uri.cpp b/src/test/pegtl/contrib_uri.cpp index f41368b0c..f15940420 100644 --- a/src/test/pegtl/contrib_uri.cpp +++ b/src/test/pegtl/contrib_uri.cpp @@ -15,10 +15,6 @@ int main() #include "verify_meta.hpp" #include "verify_rule.hpp" -#include -#include -#include - #include namespace TAO_PEGTL_NAMESPACE diff --git a/src/test/pegtl/control_action.cpp b/src/test/pegtl/control_action.cpp index 6f855b6d8..b50d1d549 100644 --- a/src/test/pegtl/control_action.cpp +++ b/src/test/pegtl/control_action.cpp @@ -7,12 +7,6 @@ #include "test.hpp" #include "test_inputs.hpp" -#include -#include -#include -#include -#include - namespace TAO_PEGTL_NAMESPACE { template< typename Rule > diff --git a/src/test/pegtl/demangle.cpp b/src/test/pegtl/demangle.cpp index 563c05438..9b178aa91 100644 --- a/src/test/pegtl/demangle.cpp +++ b/src/test/pegtl/demangle.cpp @@ -3,13 +3,8 @@ // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) #include "test.hpp" - #include -#include -#include -#include - #define TAO_PEGTL_STRINGIFY( a ) TAO_PEGTL_STRINGIFY_IMPL( a ) #define TAO_PEGTL_STRINGIFY_IMPL( a ) #a diff --git a/src/test/pegtl/enable_control.cpp b/src/test/pegtl/enable_control.cpp index 1bee98ead..ad1e241a5 100644 --- a/src/test/pegtl/enable_control.cpp +++ b/src/test/pegtl/enable_control.cpp @@ -5,11 +5,6 @@ #include "test.hpp" #include "test_inputs.hpp" -#include -#include -#include -#include - namespace TAO_PEGTL_NAMESPACE { struct r diff --git a/src/test/pegtl/error_message_1.cpp b/src/test/pegtl/error_message_1.cpp index 8d3152d18..649d7f33f 100644 --- a/src/test/pegtl/error_message_1.cpp +++ b/src/test/pegtl/error_message_1.cpp @@ -13,12 +13,6 @@ int main() #include "test.hpp" #include "test_inputs.hpp" -#include -#include -#include -#include -#include - namespace test1 { using namespace TAO_PEGTL_NAMESPACE; diff --git a/src/test/pegtl/error_message_2.cpp b/src/test/pegtl/error_message_2.cpp index 2a94780cd..280899eb1 100644 --- a/src/test/pegtl/error_message_2.cpp +++ b/src/test/pegtl/error_message_2.cpp @@ -13,12 +13,6 @@ int main() #include "test.hpp" #include "test_inputs.hpp" -#include -#include -#include -#include -#include - namespace test2 { using namespace TAO_PEGTL_NAMESPACE; diff --git a/src/test/pegtl/error_message_3.cpp b/src/test/pegtl/error_message_3.cpp index ff9252656..9e734855a 100644 --- a/src/test/pegtl/error_message_3.cpp +++ b/src/test/pegtl/error_message_3.cpp @@ -13,12 +13,6 @@ int main() #include "test.hpp" #include "test_inputs.hpp" -#include -#include -#include -#include -#include - namespace test3 { using namespace TAO_PEGTL_NAMESPACE; diff --git a/src/test/pegtl/file_input.cpp b/src/test/pegtl/file_input.cpp new file mode 100644 index 000000000..1c9599cbd --- /dev/null +++ b/src/test/pegtl/file_input.cpp @@ -0,0 +1,21 @@ +// Copyright (c) 2015-2023 Dr. Colin Hirsch and Daniel Frey +// 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) + +#include "test.hpp" +#include "verify_file.hpp" + +namespace TAO_PEGTL_NAMESPACE +{ + void unit_test() + { + using lazy_input = lazy_file_input_with_source< ascii::lf_crlf >; + using text_input = text_file_input_with_source< ascii::lf_crlf >; + + verify_file< lazy_input >(); + verify_file< text_input >(); + } + +} // namespace TAO_PEGTL_NAMESPACE + +#include "main.hpp" diff --git a/src/test/pegtl/internal_base_inputs.cpp b/src/test/pegtl/internal_base_inputs.cpp index 448dfcacb..3653203d2 100644 --- a/src/test/pegtl/internal_base_inputs.cpp +++ b/src/test/pegtl/internal_base_inputs.cpp @@ -9,11 +9,8 @@ #include #include "test.hpp" - #include -#include #include -#include namespace TAO_PEGTL_NAMESPACE { diff --git a/src/test/pegtl/internal_endian.cpp b/src/test/pegtl/internal_endian.cpp index f15fae99e..9c68b5d91 100644 --- a/src/test/pegtl/internal_endian.cpp +++ b/src/test/pegtl/internal_endian.cpp @@ -3,7 +3,6 @@ // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) #include "test.hpp" - #include namespace TAO_PEGTL_NAMESPACE diff --git a/src/test/pegtl/internal_file_input.cpp b/src/test/pegtl/internal_file_input.cpp new file mode 100644 index 000000000..a89e73b20 --- /dev/null +++ b/src/test/pegtl/internal_file_input.cpp @@ -0,0 +1,19 @@ +// Copyright (c) 2014-2023 Dr. Colin Hirsch and Daniel Frey +// 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) + +#include "test.hpp" +#include "verify_file.hpp" + +namespace TAO_PEGTL_NAMESPACE +{ + void unit_test() + { + const internal::file_input in( "src/test/pegtl/data/duseltronik.txt" ); + const std::string data( in.start(), in.end() ); + TAO_PEGTL_TEST_ASSERT( data == "duseltronik" ); + } + +} // namespace TAO_PEGTL_NAMESPACE + +#include "main.hpp" diff --git a/src/test/pegtl/internal_inputs_lines.cpp b/src/test/pegtl/internal_inputs_lines.cpp index 49c9c924b..3aeda29f5 100644 --- a/src/test/pegtl/internal_inputs_lines.cpp +++ b/src/test/pegtl/internal_inputs_lines.cpp @@ -9,12 +9,8 @@ #include #include "test.hpp" - -#include #include -#include #include -#include namespace TAO_PEGTL_NAMESPACE { diff --git a/src/test/pegtl/internal_lazy_inputs.cpp b/src/test/pegtl/internal_lazy_inputs.cpp index a68a1f4b0..407098aed 100644 --- a/src/test/pegtl/internal_lazy_inputs.cpp +++ b/src/test/pegtl/internal_lazy_inputs.cpp @@ -3,11 +3,6 @@ // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) #include "test.hpp" - -#include -#include -#include - #include "test_inputs.hpp" namespace TAO_PEGTL_NAMESPACE diff --git a/src/test/pegtl/file_mmap.cc b/src/test/pegtl/internal_mmap_input.cpp similarity index 72% rename from src/test/pegtl/file_mmap.cc rename to src/test/pegtl/internal_mmap_input.cpp index 62ba67690..345664ed4 100644 --- a/src/test/pegtl/file_mmap.cc +++ b/src/test/pegtl/internal_mmap_input.cpp @@ -2,9 +2,6 @@ // 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) -// this include gives us _POSIX_MAPPED_FILES to test and mmap_input<> if it is set -// #include TODO! - #if defined( _POSIX_MAPPED_FILES ) || defined( _WIN32 ) #include "test.hpp" @@ -14,7 +11,9 @@ namespace TAO_PEGTL_NAMESPACE { void unit_test() { - verify_file< mmap_input<> >(); + const internal::mmap_input in( "src/test/pegtl/data/duseltronik.txt" ); + const std::string data( in.start(), in.end() ); + TAO_PEGTL_TEST_ASSERT( data == "duseltronik" ); } } // namespace TAO_PEGTL_NAMESPACE diff --git a/src/test/pegtl/internal_peek_member.cpp b/src/test/pegtl/internal_peek_member.cpp index 14d812b9c..1da1009ff 100644 --- a/src/test/pegtl/internal_peek_member.cpp +++ b/src/test/pegtl/internal_peek_member.cpp @@ -6,11 +6,7 @@ #include #include "test.hpp" - -#include #include -#include -#include namespace TAO_PEGTL_NAMESPACE { diff --git a/src/test/pegtl/file_read.cc b/src/test/pegtl/internal_read_file_stdio.cpp similarity index 50% rename from src/test/pegtl/file_read.cc rename to src/test/pegtl/internal_read_file_stdio.cpp index af5ef1c6c..46c3a5c6e 100644 --- a/src/test/pegtl/file_read.cc +++ b/src/test/pegtl/internal_read_file_stdio.cpp @@ -5,21 +5,14 @@ #include "test.hpp" #include "verify_file.hpp" +#include + namespace TAO_PEGTL_NAMESPACE { - template< tracking_mode P = tracking_mode::eager, typename Eol = ascii::lf_crlf > - struct open_input - : public read_input< P, Eol > - { - explicit open_input( const std::filesystem::path& path ) - : read_input< P, Eol >( internal::read_file_open( path ), path ) - {} - }; - void unit_test() { - verify_file< read_input<> >(); - verify_file< open_input<> >(); + const auto data = internal::read_file_stdio( "src/test/pegtl/data/duseltronik.txt" ).read_string(); + TAO_PEGTL_TEST_ASSERT( data == "duseltronik" ); } } // namespace TAO_PEGTL_NAMESPACE diff --git a/src/test/pegtl/internal_read_input.cpp b/src/test/pegtl/internal_read_input.cpp new file mode 100644 index 000000000..7361d4fb6 --- /dev/null +++ b/src/test/pegtl/internal_read_input.cpp @@ -0,0 +1,19 @@ +// Copyright (c) 2014-2023 Dr. Colin Hirsch and Daniel Frey +// 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) + +#include "test.hpp" +#include "verify_file.hpp" + +namespace TAO_PEGTL_NAMESPACE +{ + void unit_test() + { + const internal::read_input in( "src/test/pegtl/data/duseltronik.txt" ); + const std::string data( in.start(), in.end() ); + TAO_PEGTL_TEST_ASSERT( data == "duseltronik" ); + } + +} // namespace TAO_PEGTL_NAMESPACE + +#include "main.hpp" diff --git a/src/test/pegtl/internal_result_on_found.cpp b/src/test/pegtl/internal_result_on_found.cpp new file mode 100644 index 000000000..52c4d1696 --- /dev/null +++ b/src/test/pegtl/internal_result_on_found.cpp @@ -0,0 +1,25 @@ +// Copyright (c) 2023 Dr. Colin Hirsch and Daniel Frey +// 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) + +#include + +#include "test.hpp" +#include +#include + +namespace TAO_PEGTL_NAMESPACE +{ + void unit_test() + { + static_assert( std::is_same_v< std::underlying_type_t< internal::result_on_found >, bool > ); + + static_assert( internal::result_on_found::success != internal::result_on_found::failure ); + + static_assert( internal::enum_invert_bool( internal::result_on_found::success ) == internal::result_on_found::failure ); + static_assert( internal::enum_invert_bool( internal::result_on_found::failure ) == internal::result_on_found::success ); + } + +} // namespace TAO_PEGTL_NAMESPACE + +#include "main.hpp" diff --git a/src/test/pegtl/internal_text_inputs.cpp b/src/test/pegtl/internal_text_inputs.cpp index 6597a450c..bc25cb995 100644 --- a/src/test/pegtl/internal_text_inputs.cpp +++ b/src/test/pegtl/internal_text_inputs.cpp @@ -3,11 +3,6 @@ // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) #include "test.hpp" - -#include -#include -#include - #include "test_inputs.hpp" namespace TAO_PEGTL_NAMESPACE diff --git a/src/test/pegtl/mmap_input.cpp b/src/test/pegtl/mmap_input.cpp new file mode 100644 index 000000000..96bcb1977 --- /dev/null +++ b/src/test/pegtl/mmap_input.cpp @@ -0,0 +1,37 @@ +// Copyright (c) 2014-2023 Dr. Colin Hirsch and Daniel Frey +// 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) + +#if defined( _POSIX_MAPPED_FILES ) || defined( _WIN32 ) + +#include + +#include "test.hpp" +#include "verify_file.hpp" + +namespace TAO_PEGTL_NAMESPACE +{ + void unit_test() + { + using lazy_input = lazy_mmap_input_with_source< ascii::lf_crlf >; + using text_input = text_mmap_input_with_source< ascii::lf_crlf >; + + static_assert( std::is_base_of_v< internal::mmap_input< char >, lazy_input > ); + static_assert( std::is_base_of_v< internal::mmap_input< char >, text_input > ); + + verify_file< lazy_input >(); + verify_file< text_input >(); + } + +} // namespace TAO_PEGTL_NAMESPACE + +#include "main.hpp" + +#else + +int main() +{ + return 0; +} + +#endif diff --git a/src/test/pegtl/pegtl.cpp b/src/test/pegtl/pegtl.cpp index 3ca6c3714..503169c7e 100644 --- a/src/test/pegtl/pegtl.cpp +++ b/src/test/pegtl/pegtl.cpp @@ -3,9 +3,65 @@ // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) #include "test.hpp" - #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + namespace TAO_PEGTL_NAMESPACE { void unit_test() diff --git a/src/test/pegtl/print.cpp b/src/test/pegtl/print.cpp index 7489d3f48..2ecda897a 100644 --- a/src/test/pegtl/print.cpp +++ b/src/test/pegtl/print.cpp @@ -6,10 +6,6 @@ #include "test.hpp" -#include -#include -#include - namespace TAO_PEGTL_NAMESPACE { using grammar = seq< alpha, digit >; diff --git a/src/test/pegtl/read_input.cpp b/src/test/pegtl/read_input.cpp new file mode 100644 index 000000000..2a459afb7 --- /dev/null +++ b/src/test/pegtl/read_input.cpp @@ -0,0 +1,21 @@ +// Copyright (c) 2014-2023 Dr. Colin Hirsch and Daniel Frey +// 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) + +#include "test.hpp" +#include "verify_file.hpp" + +namespace TAO_PEGTL_NAMESPACE +{ + void unit_test() + { + using lazy_input = lazy_read_input_with_source< ascii::lf_crlf >; + using text_input = text_read_input_with_source< ascii::lf_crlf >; + + verify_file< lazy_input >(); + verify_file< text_input >(); + } + +} // namespace TAO_PEGTL_NAMESPACE + +#include "main.hpp" diff --git a/src/test/pegtl/remove_first_state.cpp b/src/test/pegtl/remove_first_state.cpp index bb9310b87..9207ad52d 100644 --- a/src/test/pegtl/remove_first_state.cpp +++ b/src/test/pegtl/remove_first_state.cpp @@ -5,12 +5,6 @@ #include "test.hpp" #include "test_inputs.hpp" -#include -#include -#include -#include -#include - namespace TAO_PEGTL_NAMESPACE { template< typename Rule > diff --git a/src/test/pegtl/remove_last_states.cpp b/src/test/pegtl/remove_last_states.cpp index deef18be5..de9ba2b64 100644 --- a/src/test/pegtl/remove_last_states.cpp +++ b/src/test/pegtl/remove_last_states.cpp @@ -5,12 +5,6 @@ #include "test.hpp" #include "test_inputs.hpp" -#include -#include -#include -#include -#include - namespace TAO_PEGTL_NAMESPACE { template< typename Rule > diff --git a/src/test/pegtl/rewind_mode.cpp b/src/test/pegtl/rewind_mode.cpp new file mode 100644 index 000000000..235ad2c4b --- /dev/null +++ b/src/test/pegtl/rewind_mode.cpp @@ -0,0 +1,25 @@ +// Copyright (c) 2023 Dr. Colin Hirsch and Daniel Frey +// 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) + +#include + +#include "test.hpp" +#include +#include + +namespace TAO_PEGTL_NAMESPACE +{ + void unit_test() + { + static_assert( std::is_same_v< std::underlying_type_t< rewind_mode >, bool > ); + + static_assert( rewind_mode::optional != rewind_mode::required ); + + static_assert( internal::enum_invert_bool( rewind_mode::optional ) == rewind_mode::required ); + static_assert( internal::enum_invert_bool( rewind_mode::required ) == rewind_mode::optional ); + } + +} // namespace TAO_PEGTL_NAMESPACE + +#include "main.hpp" diff --git a/src/test/pegtl/rule_action.cpp b/src/test/pegtl/rule_action.cpp index 95a26ba81..72fad5e75 100644 --- a/src/test/pegtl/rule_action.cpp +++ b/src/test/pegtl/rule_action.cpp @@ -3,7 +3,6 @@ // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) #include "test.hpp" - #include "verify_meta.hpp" #include "verify_seqs.hpp" diff --git a/src/test/pegtl/rule_at.cpp b/src/test/pegtl/rule_at.cpp index 87e335b69..891c35e5e 100644 --- a/src/test/pegtl/rule_at.cpp +++ b/src/test/pegtl/rule_at.cpp @@ -7,8 +7,6 @@ #include "verify_meta.hpp" #include "verify_rule.hpp" -#include - namespace TAO_PEGTL_NAMESPACE { int at_counter = 0; diff --git a/src/test/pegtl/rule_control.cpp b/src/test/pegtl/rule_control.cpp index a76a58974..675267261 100644 --- a/src/test/pegtl/rule_control.cpp +++ b/src/test/pegtl/rule_control.cpp @@ -3,7 +3,6 @@ // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) #include "test.hpp" - #include "verify_meta.hpp" #include "verify_seqs.hpp" diff --git a/src/test/pegtl/rule_disable.cpp b/src/test/pegtl/rule_disable.cpp index ec3035ada..f1342ba3a 100644 --- a/src/test/pegtl/rule_disable.cpp +++ b/src/test/pegtl/rule_disable.cpp @@ -3,7 +3,6 @@ // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) #include "test.hpp" - #include "verify_meta.hpp" #include "verify_seqs.hpp" diff --git a/src/test/pegtl/rule_enable.cpp b/src/test/pegtl/rule_enable.cpp index 7dde7516d..7dc060ae6 100644 --- a/src/test/pegtl/rule_enable.cpp +++ b/src/test/pegtl/rule_enable.cpp @@ -3,7 +3,6 @@ // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) #include "test.hpp" - #include "verify_meta.hpp" #include "verify_seqs.hpp" diff --git a/src/test/pegtl/rule_function.cpp b/src/test/pegtl/rule_function.cpp index 6e2d31a1f..72bddb992 100644 --- a/src/test/pegtl/rule_function.cpp +++ b/src/test/pegtl/rule_function.cpp @@ -4,11 +4,8 @@ #include "test.hpp" #include "test_inputs.hpp" - #include #include -#include -#include namespace TAO_PEGTL_NAMESPACE { diff --git a/src/test/pegtl/rule_not_at.cpp b/src/test/pegtl/rule_not_at.cpp index fc4084906..f6d976775 100644 --- a/src/test/pegtl/rule_not_at.cpp +++ b/src/test/pegtl/rule_not_at.cpp @@ -7,8 +7,6 @@ #include "verify_meta.hpp" #include "verify_rule.hpp" -#include - namespace TAO_PEGTL_NAMESPACE { int at_counter = 0; diff --git a/src/test/pegtl/rule_opt.cpp b/src/test/pegtl/rule_opt.cpp index e2c6d2016..8654f01cc 100644 --- a/src/test/pegtl/rule_opt.cpp +++ b/src/test/pegtl/rule_opt.cpp @@ -3,12 +3,9 @@ // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) #include "test.hpp" - #include "verify_meta.hpp" #include "verify_rule.hpp" -#include - namespace TAO_PEGTL_NAMESPACE { template< typename Rule > diff --git a/src/test/pegtl/rule_partial.cpp b/src/test/pegtl/rule_partial.cpp index 443deb335..18c5767fd 100644 --- a/src/test/pegtl/rule_partial.cpp +++ b/src/test/pegtl/rule_partial.cpp @@ -7,8 +7,6 @@ #include "verify_meta.hpp" #include "verify_rule.hpp" -#include - namespace TAO_PEGTL_NAMESPACE { template< typename Rule > diff --git a/src/test/pegtl/rule_plus.cpp b/src/test/pegtl/rule_plus.cpp index 4159bc662..7c7336c7a 100644 --- a/src/test/pegtl/rule_plus.cpp +++ b/src/test/pegtl/rule_plus.cpp @@ -3,7 +3,6 @@ // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) #include "test.hpp" - #include "verify_meta.hpp" #include "verify_rule.hpp" diff --git a/src/test/pegtl/rule_raise.cpp b/src/test/pegtl/rule_raise.cpp index 2de52136b..4a550ca6c 100644 --- a/src/test/pegtl/rule_raise.cpp +++ b/src/test/pegtl/rule_raise.cpp @@ -12,11 +12,8 @@ int main() #include "test.hpp" #include "test_inputs.hpp" - #include "verify_meta.hpp" -#include - #if defined( _MSC_VER ) #pragma warning( push ) #pragma warning( disable : 4702 ) diff --git a/src/test/pegtl/rule_seq.cpp b/src/test/pegtl/rule_seq.cpp index e5c72db17..6c6a7e018 100644 --- a/src/test/pegtl/rule_seq.cpp +++ b/src/test/pegtl/rule_seq.cpp @@ -3,7 +3,6 @@ // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) #include "test.hpp" - #include "verify_meta.hpp" #include "verify_seqs.hpp" diff --git a/src/test/pegtl/rule_sor.cpp b/src/test/pegtl/rule_sor.cpp index decd73168..293485886 100644 --- a/src/test/pegtl/rule_sor.cpp +++ b/src/test/pegtl/rule_sor.cpp @@ -3,7 +3,6 @@ // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) #include "test.hpp" - #include "verify_meta.hpp" #include "verify_rule.hpp" diff --git a/src/test/pegtl/rule_star.cpp b/src/test/pegtl/rule_star.cpp index eb856b698..983e8b9a7 100644 --- a/src/test/pegtl/rule_star.cpp +++ b/src/test/pegtl/rule_star.cpp @@ -3,7 +3,6 @@ // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) #include "test.hpp" - #include "verify_meta.hpp" #include "verify_rule.hpp" diff --git a/src/test/pegtl/rule_star_partial.cpp b/src/test/pegtl/rule_star_partial.cpp index 99826a3c2..25ed832c1 100644 --- a/src/test/pegtl/rule_star_partial.cpp +++ b/src/test/pegtl/rule_star_partial.cpp @@ -3,7 +3,6 @@ // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) #include "test.hpp" - #include "verify_meta.hpp" #include "verify_rule.hpp" diff --git a/src/test/pegtl/rule_state.cpp b/src/test/pegtl/rule_state.cpp index 30178bb7d..04fa24905 100644 --- a/src/test/pegtl/rule_state.cpp +++ b/src/test/pegtl/rule_state.cpp @@ -3,7 +3,6 @@ // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) #include "test.hpp" - #include "verify_meta.hpp" #include "verify_seqs.hpp" diff --git a/src/test/pegtl/rule_success.cpp b/src/test/pegtl/rule_success.cpp index 248b1a9b5..3cd62ae62 100644 --- a/src/test/pegtl/rule_success.cpp +++ b/src/test/pegtl/rule_success.cpp @@ -3,7 +3,6 @@ // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) #include "test.hpp" - #include "verify_meta.hpp" #include "verify_rule.hpp" diff --git a/src/test/pegtl/rule_try_catch_raise_nested.cpp b/src/test/pegtl/rule_try_catch_raise_nested.cpp index 81e307369..1b9ce76e0 100644 --- a/src/test/pegtl/rule_try_catch_raise_nested.cpp +++ b/src/test/pegtl/rule_try_catch_raise_nested.cpp @@ -16,8 +16,6 @@ int main() #include "test_inputs.hpp" #include "verify_seqs.hpp" -#include - #include namespace TAO_PEGTL_NAMESPACE diff --git a/src/test/pegtl/rule_until.cpp b/src/test/pegtl/rule_until.cpp index 0d640c4fd..e306f663e 100644 --- a/src/test/pegtl/rule_until.cpp +++ b/src/test/pegtl/rule_until.cpp @@ -7,8 +7,6 @@ #include "verify_meta.hpp" #include "verify_rule.hpp" -#include - namespace TAO_PEGTL_NAMESPACE { struct my_rule diff --git a/src/test/pegtl/test.hpp b/src/test/pegtl/test.hpp index ac41bae60..759dcd2c5 100644 --- a/src/test/pegtl/test.hpp +++ b/src/test/pegtl/test.hpp @@ -9,9 +9,7 @@ #include #include -#include - -// #include +#include namespace TAO_PEGTL_NAMESPACE { diff --git a/src/test/pegtl/test_inputs.hpp b/src/test/pegtl/test_inputs.hpp index 7d9873fb9..24cb91505 100644 --- a/src/test/pegtl/test_inputs.hpp +++ b/src/test/pegtl/test_inputs.hpp @@ -8,7 +8,7 @@ #include #include -#include +#include namespace TAO_PEGTL_NAMESPACE::test { @@ -19,7 +19,7 @@ namespace TAO_PEGTL_NAMESPACE::test using text_input = internal::input_with_peeks< internal::text_input< Eol, internal::input_with_fakes< internal::view_input< char > > > >; template< typename Eol > - using file_input = internal::input_with_peeks< internal::input_with_fakes< internal::text_file_input_with_source< Eol > > >; + using file_input = text_file_input_with_source< Eol >; template< typename T > [[nodiscard]] bool equal( const T& position, const std::size_t count, const std::size_t line, const std::size_t column ) noexcept diff --git a/src/test/pegtl/test_result.cpp b/src/test/pegtl/test_result.cpp index e95e9eb0a..63234f18a 100644 --- a/src/test/pegtl/test_result.cpp +++ b/src/test/pegtl/test_result.cpp @@ -5,7 +5,6 @@ #include #include "test.hpp" - #include "result_type.hpp" namespace TAO_PEGTL_NAMESPACE diff --git a/src/test/pegtl/utf8_general.cpp b/src/test/pegtl/utf8_general.cpp index 3668bcea4..3f06ef683 100644 --- a/src/test/pegtl/utf8_general.cpp +++ b/src/test/pegtl/utf8_general.cpp @@ -6,8 +6,6 @@ #include "verify_char.hpp" #include "verify_rule.hpp" -#include - namespace TAO_PEGTL_NAMESPACE { void unit_test() diff --git a/src/test/pegtl/verify_file.hpp b/src/test/pegtl/verify_file.hpp index c69cf2ae9..6ef12beb4 100644 --- a/src/test/pegtl/verify_file.hpp +++ b/src/test/pegtl/verify_file.hpp @@ -5,9 +5,7 @@ #ifndef TAO_PEGTL_SRC_TEST_PEGTL_VERIFY_FILE_HPP #define TAO_PEGTL_SRC_TEST_PEGTL_VERIFY_FILE_HPP -#include - -#include "test.hpp" +#include "test_inputs.hpp" #if defined( _MSC_VER ) #define TAO_PEGTL_TEST_FILENAME u"src/test/pegtl/file_äöü𝄞_data.txt" @@ -67,12 +65,11 @@ namespace TAO_PEGTL_NAMESPACE } } #endif - { T in( "src/test/pegtl/file_data.txt" ); - TAO_PEGTL_TEST_ASSERT( in.source() == "src/test/pegtl/file_data.txt" ); + TAO_PEGTL_TEST_ASSERT( in.direct_source() == "src/test/pegtl/file_data.txt" ); TAO_PEGTL_TEST_ASSERT( parse< file_grammar >( in ) ); - TAO_PEGTL_TEST_ASSERT( in.source() == "src/test/pegtl/file_data.txt" ); + TAO_PEGTL_TEST_ASSERT( in.direct_source() == "src/test/pegtl/file_data.txt" ); } { T in( TAO_PEGTL_TEST_FILENAME ); @@ -101,7 +98,7 @@ namespace TAO_PEGTL_NAMESPACE TAO_PEGTL_TEST_ASSERT( flag == true ); } const char* foo = "foo"; - const memory_input m( foo, foo + 3, foo ); + const text_copy_input_with_source< ascii::lf_crlf > m( foo, foo, foo + 3 ); { T in( TAO_PEGTL_TEST_FILENAME ); TAO_PEGTL_TEST_ASSERT( parse_nested< file_grammar >( m, in ) ); diff --git a/src/test/pegtl/verify_ifmt.hpp b/src/test/pegtl/verify_ifmt.hpp index 94312aede..7936d89cb 100644 --- a/src/test/pegtl/verify_ifmt.hpp +++ b/src/test/pegtl/verify_ifmt.hpp @@ -5,8 +5,6 @@ #ifndef TAO_PEGTL_SRC_TEST_PEGTL_VERIFY_IFMT_HPP #define TAO_PEGTL_SRC_TEST_PEGTL_VERIFY_IFMT_HPP -#include - #include "verify_meta.hpp" #include "verify_rule.hpp" diff --git a/src/test/pegtl/verify_impl.hpp b/src/test/pegtl/verify_impl.hpp index a159e607f..7c992cedc 100644 --- a/src/test/pegtl/verify_impl.hpp +++ b/src/test/pegtl/verify_impl.hpp @@ -10,12 +10,7 @@ #include #include -#include -#include -#include - #include "result_type.hpp" -#include "test.hpp" namespace TAO_PEGTL_NAMESPACE { diff --git a/src/test/pegtl/verify_meta.hpp b/src/test/pegtl/verify_meta.hpp index 544d0c1cc..3c3dbd967 100644 --- a/src/test/pegtl/verify_meta.hpp +++ b/src/test/pegtl/verify_meta.hpp @@ -7,8 +7,6 @@ #include -#include "test.hpp" - #include #include diff --git a/src/test/pegtl/verify_rule.hpp b/src/test/pegtl/verify_rule.hpp index 8ae750fe0..9a7722172 100644 --- a/src/test/pegtl/verify_rule.hpp +++ b/src/test/pegtl/verify_rule.hpp @@ -8,8 +8,6 @@ #include #include -#include - #include "result_type.hpp" #include "test_inputs.hpp" #include "verify_impl.hpp" diff --git a/src/test/pegtl/verify_seqs.hpp b/src/test/pegtl/verify_seqs.hpp index 981a44b70..1319a448f 100644 --- a/src/test/pegtl/verify_seqs.hpp +++ b/src/test/pegtl/verify_seqs.hpp @@ -5,8 +5,6 @@ #ifndef TAO_PEGTL_SRC_TEST_PEGTL_VERIFY_SEQS_HPP #define TAO_PEGTL_SRC_TEST_PEGTL_VERIFY_SEQS_HPP -#include - #include "verify_meta.hpp" #include "verify_rule.hpp" diff --git a/src/test/pegtl/visit.cpp b/src/test/pegtl/visit.cpp index 261d34912..837250edf 100644 --- a/src/test/pegtl/visit.cpp +++ b/src/test/pegtl/visit.cpp @@ -7,11 +7,6 @@ #include "test.hpp" -#include -#include -#include -#include - namespace TAO_PEGTL_NAMESPACE { using grammar = seq< plus< alpha >, star< sor< space, digit > > >;