diff --git a/include/tao/pegtl/internal/function.hpp b/include/tao/pegtl/internal/function.hpp index ca49d8016..390cf8905 100644 --- a/include/tao/pegtl/internal/function.hpp +++ b/include/tao/pegtl/internal/function.hpp @@ -17,6 +17,8 @@ namespace TAO_PEGTL_NAMESPACE::internal template< typename Peek, typename Func, Func Tion > struct function; +#if defined( __GNUC__ ) || defined( __clang__ ) + template< bool E, typename Input, bool ( *Tion )( Input& ) noexcept( E ) > struct function< void, bool ( * )( Input& ) noexcept( E ), Tion > { @@ -99,6 +101,174 @@ namespace TAO_PEGTL_NAMESPACE::internal } }; +#else + + template< typename Input, bool ( *Tion )( Input& ) noexcept( true ) > + struct function< void, bool ( * )( Input& ) noexcept( true ), Tion > + { + using rule_t = function; + using subs_t = empty_list; + + template< typename ParseInput > + [[nodiscard]] static bool match( ParseInput& in ) noexcept( true ) + { + return Tion( in ); + } + }; + + template< typename Input, bool ( *Tion )( Input& ) noexcept( false ) > + struct function< void, bool ( * )( Input& ) noexcept( false ), Tion > + { + using rule_t = function; + using subs_t = empty_list; + + template< typename ParseInput > + [[nodiscard]] static bool match( ParseInput& in ) noexcept( false ) + { + return Tion( in ); + } + }; + + template< typename Input, typename... States, bool ( *Tion )( Input&, States... ) noexcept( true ) > + struct function< void, bool ( * )( Input&, States... ) noexcept( true ), Tion > + { + using rule_t = function; + using subs_t = empty_list; + + template< apply_mode A, + rewind_mode M, + template< typename... > + class Action, + template< typename... > + class Control, + typename ParseInput > + [[nodiscard]] static bool match( ParseInput& in, States... st ) noexcept( true ) + { + return Tion( in, st... ); + } + }; + + template< typename Input, typename... States, bool ( *Tion )( Input&, States... ) noexcept( false ) > + struct function< void, bool ( * )( Input&, States... ) noexcept( false ), Tion > + { + using rule_t = function; + using subs_t = empty_list; + + template< apply_mode A, + rewind_mode M, + template< typename... > + class Action, + template< typename... > + class Control, + typename ParseInput > + [[nodiscard]] static bool match( ParseInput& in, States... st ) noexcept( false ) + { + return Tion( in, st... ); + } + }; + + template< typename Peek, typename Data, bool ( *Tion )( Data ) noexcept( true ) > + struct function< Peek, bool ( * )( Data ) noexcept( true ), Tion > + { + using peek_t = Peek; + // using data_t = typename Peek::data_t; + + using rule_t = function; + using subs_t = empty_list; + + template< typename ParseInput > + [[nodiscard]] static bool match( ParseInput& in ) + { + if( const auto t = Peek::peek( in ) ) { + if( Tion( t.data() ) ) { + in.template consume< function >( t.size() ); + return true; + } + } + return false; + } + }; + + template< typename Peek, typename Data, bool ( *Tion )( Data ) noexcept( false ) > + struct function< Peek, bool ( * )( Data ) noexcept( false ), Tion > + { + using peek_t = Peek; + // using data_t = typename Peek::data_t; + + using rule_t = function; + using subs_t = empty_list; + + template< typename ParseInput > + [[nodiscard]] static bool match( ParseInput& in ) + { + if( const auto t = Peek::peek( in ) ) { + if( Tion( t.data() ) ) { + in.template consume< function >( t.size() ); + return true; + } + } + return false; + } + }; + + template< typename Peek, typename Data, typename... States, bool ( *Tion )( Data, States... ) noexcept( true ) > + struct function< Peek, bool ( * )( Data, States... ) noexcept( true ), Tion > + { + using peek_t = Peek; + // using data_t = typename Peek::data_t; + + using rule_t = function; + using subs_t = empty_list; + + template< apply_mode A, + rewind_mode M, + template< typename... > + class Action, + template< typename... > + class Control, + typename ParseInput > + [[nodiscard]] static bool match( ParseInput& in, States... st ) + { + if( const auto t = Peek::peek( in ) ) { + if( Tion( t.data(), st... ) ) { + in.template consume< function >( t.size() ); + return true; + } + } + return false; + } + }; + + template< typename Peek, typename Data, typename... States, bool ( *Tion )( Data, States... ) noexcept( false ) > + struct function< Peek, bool ( * )( Data, States... ) noexcept( false ), Tion > + { + using peek_t = Peek; + // using data_t = typename Peek::data_t; + + using rule_t = function; + using subs_t = empty_list; + + template< apply_mode A, + rewind_mode M, + template< typename... > + class Action, + template< typename... > + class Control, + typename ParseInput > + [[nodiscard]] static bool match( ParseInput& in, States... st ) + { + if( const auto t = Peek::peek( in ) ) { + if( Tion( t.data(), st... ) ) { + in.template consume< function >( t.size() ); + return true; + } + } + return false; + } + }; + +#endif + template< typename Peek, typename Func, Func Tion > inline constexpr bool enable_control< function< Peek, Func, Tion > > = false; diff --git a/include/tao/pegtl/parse_error.hpp b/include/tao/pegtl/parse_error.hpp index 9f4f6b092..fc541c169 100644 --- a/include/tao/pegtl/parse_error.hpp +++ b/include/tao/pegtl/parse_error.hpp @@ -9,6 +9,10 @@ #include #include +#if !defined( __cpp_exceptions ) +#error "Exception support required for tao/pegtl/parse_error.hpp" +#endif + #include "config.hpp" #include "parse_error_base.hpp" diff --git a/include/tao/pegtl/parse_error_base.hpp b/include/tao/pegtl/parse_error_base.hpp index 366d71749..70757b66b 100644 --- a/include/tao/pegtl/parse_error_base.hpp +++ b/include/tao/pegtl/parse_error_base.hpp @@ -10,6 +10,10 @@ #include #include +#if !defined( __cpp_exceptions ) +#error "Exception support required for tao/pegtl/parse_error_base.hpp" +#endif + #include "config.hpp" namespace TAO_PEGTL_NAMESPACE diff --git a/src/example/pegtl/abnf2pegtl.cpp b/src/example/pegtl/abnf2pegtl.cpp index a58bf884c..10004f7a8 100644 --- a/src/example/pegtl/abnf2pegtl.cpp +++ b/src/example/pegtl/abnf2pegtl.cpp @@ -30,7 +30,9 @@ #include #include +#if defined( __cpp_exceptions ) #include +#endif namespace TAO_PEGTL_NAMESPACE { diff --git a/src/test/pegtl/buffer_cstream_input.cpp b/src/test/pegtl/buffer_cstream_input.cpp index 58d7fa544..ccea4001f 100644 --- a/src/test/pegtl/buffer_cstream_input.cpp +++ b/src/test/pegtl/buffer_cstream_input.cpp @@ -22,7 +22,7 @@ namespace TAO_PEGTL_NAMESPACE void unit_test() { - const char* const filename = "src/test/pegtl/file_data.txt"; + const char* const filename = "src/test/pegtl/data/test_data.txt"; { std::FILE* stream = internal::read_file_open( filename ); TAO_PEGTL_TEST_ASSERT( stream != nullptr ); diff --git a/src/test/pegtl/buffer_istream_input.cpp b/src/test/pegtl/buffer_istream_input.cpp index e0660d799..6205b963c 100644 --- a/src/test/pegtl/buffer_istream_input.cpp +++ b/src/test/pegtl/buffer_istream_input.cpp @@ -36,7 +36,7 @@ namespace TAO_PEGTL_NAMESPACE } } #endif - const char* filename = "src/test/pegtl/file_data.txt"; + const char* filename = "src/test/pegtl/data/test_data.txt"; { std::ifstream stream( filename ); static_istream_input< void > in( stream ); diff --git a/src/test/pegtl/file_data.txt b/src/test/pegtl/data/test_data.txt similarity index 100% rename from src/test/pegtl/file_data.txt rename to src/test/pegtl/data/test_data.txt diff --git a/src/test/pegtl/internal_file_mapper.cpp b/src/test/pegtl/internal_file_mapper.cpp index e107ffea1..5fa649239 100644 --- a/src/test/pegtl/internal_file_mapper.cpp +++ b/src/test/pegtl/internal_file_mapper.cpp @@ -37,7 +37,7 @@ namespace TAO_PEGTL_NAMESPACE const std::string s = "dummy content\n"; const std::string dummy_content = s + s + s + s + s + s + s + s + s + s + s; - internal::file_mapper mapper( "src/test/pegtl/file_data.txt" ); + internal::file_mapper mapper( "src/test/pegtl/data/test_data.txt" ); TAO_PEGTL_TEST_ASSERT( !mapper.empty() ); TAO_PEGTL_TEST_ASSERT( mapper.size() == 154 ); TAO_PEGTL_TEST_ASSERT( std::string_view( mapper.data(), mapper.size() ) == dummy_content ); diff --git a/src/test/pegtl/verify_file.hpp b/src/test/pegtl/verify_file.hpp index ce21dee14..12627b2b7 100644 --- a/src/test/pegtl/verify_file.hpp +++ b/src/test/pegtl/verify_file.hpp @@ -66,10 +66,10 @@ namespace TAO_PEGTL_NAMESPACE } #endif { - T in( "src/test/pegtl/file_data.txt" ); - TAO_PEGTL_TEST_ASSERT( in.direct_source() == "src/test/pegtl/file_data.txt" ); + T in( "src/test/pegtl/data/test_data.txt" ); + TAO_PEGTL_TEST_ASSERT( in.direct_source() == "src/test/pegtl/data/test_data.txt" ); TAO_PEGTL_TEST_ASSERT( parse< file_grammar >( in ) ); - TAO_PEGTL_TEST_ASSERT( in.direct_source() == "src/test/pegtl/file_data.txt" ); + TAO_PEGTL_TEST_ASSERT( in.direct_source() == "src/test/pegtl/data/test_data.txt" ); } { T in( TAO_PEGTL_TEST_FILENAME );