diff --git a/include/tao/pegtl/rules.hpp b/include/tao/pegtl/rules.hpp index f83b58a7b..ccfbf8cca 100644 --- a/include/tao/pegtl/rules.hpp +++ b/include/tao/pegtl/rules.hpp @@ -9,10 +9,11 @@ #if defined( __cpp_exceptions ) #include + +#include "parse_error_base.hpp" #endif #include "config.hpp" -#include "parse_error.hpp" #include "internal/combine_traits.hpp" #include "internal/invert_traits.hpp" diff --git a/src/example/pegtl/abnf2_record.cpp b/src/example/pegtl/abnf2_record.cpp index 02ee1eb26..68ad82054 100644 --- a/src/example/pegtl/abnf2_record.cpp +++ b/src/example/pegtl/abnf2_record.cpp @@ -2,6 +2,14 @@ // 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( __cpp_exceptions ) +#include +int main() +{ + std::cout << "Exception support disabled, example is dummy..." << std::endl; +} +#else + #include #include @@ -44,3 +52,5 @@ int main( int argc, char** argv ) // NOLINT(bugprone-exception-escape) } return 0; } + +#endif diff --git a/src/example/pegtl/dispatch.cpp b/src/example/pegtl/dispatch.cpp index 8c88bb2ec..8c6cffb5a 100644 --- a/src/example/pegtl/dispatch.cpp +++ b/src/example/pegtl/dispatch.cpp @@ -35,7 +35,8 @@ namespace example pegtl::file_input<> in( path ); using clause1 = pegtl::clause1< action1, pegtl::json::string_content, pegtl::json::key_content >; using clause2 = pegtl::clause2< action2, pegtl::json::begin_array, pegtl::json::end_array, pegtl::json::begin_object, pegtl::json::end_object >; - pegtl::dispatch< clause1, clause2 >::parse< pegtl::must< pegtl::json::text, pegtl::eof > >( in ); + const auto b = pegtl::dispatch< clause1, clause2 >::parse< pegtl::seq< pegtl::json::text, pegtl::eof > >( in ); + std::cerr << "SUCCESS " << b << std::endl; } } // namespace example diff --git a/src/example/pegtl/json_coverage.cpp b/src/example/pegtl/json_coverage.cpp index e4f252e46..4e5f620ca 100644 --- a/src/example/pegtl/json_coverage.cpp +++ b/src/example/pegtl/json_coverage.cpp @@ -43,7 +43,7 @@ int main( int argc, char** argv ) // NOLINT(bugprone-exception-escape) } #else if( !pegtl::coverage< example::grammar, pegtl::nothing, example::control >( in, result ) ) { - std::cerr << "error occurred" << std::endl; + std::cerr << "Error occurred -- exceptions disabled" << std::endl; return 1; } #endif diff --git a/src/example/pegtl/json_errors.hpp b/src/example/pegtl/json_errors.hpp index b708b4fe3..72edccbd4 100644 --- a/src/example/pegtl/json_errors.hpp +++ b/src/example/pegtl/json_errors.hpp @@ -7,7 +7,10 @@ #include #include + +#if defined( __cpp_exceptions ) #include +#endif namespace pegtl = TAO_PEGTL_NAMESPACE; diff --git a/src/example/pegtl/json_record.cpp b/src/example/pegtl/json_record.cpp index 73377d1a2..c90adcf03 100644 --- a/src/example/pegtl/json_record.cpp +++ b/src/example/pegtl/json_record.cpp @@ -27,6 +27,7 @@ int main( int argc, char** argv ) // NOLINT(bugprone-exception-escape) } using input_t = pegtl::text_file_input<>; input_t in( argv[ 1 ] ); +#if defined( __cpp_exceptions ) try { const auto v = pegtl::record< pegtl::json::number, pegtl::json::key_content, @@ -43,5 +44,14 @@ int main( int argc, char** argv ) // NOLINT(bugprone-exception-escape) << std::setw( int( p.count ) ) << '^' << std::endl; return 1; } +#else + const auto v = pegtl::record< pegtl::json::number, + pegtl::json::key_content, + pegtl::json::string_content, + pegtl::json::true_, + pegtl::json::false_, + pegtl::json::null >::parse< example::grammar >( in ); + std::cout << v; +#endif return 0; } diff --git a/src/test/pegtl/buffer_buffer_common.cpp b/src/test/pegtl/buffer_buffer_common.cpp index 4644f707a..6da7c4abe 100644 --- a/src/test/pegtl/buffer_buffer_common.cpp +++ b/src/test/pegtl/buffer_buffer_common.cpp @@ -66,8 +66,10 @@ namespace TAO_PEGTL_NAMESPACE bc.require( 10 ); +#if defined( __cpp_exceptions ) TAO_PEGTL_TEST_THROWS( bc.require( 101 ) ); TAO_PEGTL_TEST_THROWS( (void)bc.end( 100, 101 ) ); +#endif TAO_PEGTL_TEST_ASSERT( !bc.empty() ); TAO_PEGTL_TEST_ASSERT( bc.size( 1 ) == 20 ); @@ -84,8 +86,10 @@ namespace TAO_PEGTL_NAMESPACE bc.require( 90 ); +#if defined( __cpp_exceptions ) TAO_PEGTL_TEST_THROWS( bc.require( 101 ) ); TAO_PEGTL_TEST_THROWS( (void)bc.end( 100, 101 ) ); +#endif TAO_PEGTL_TEST_ASSERT( !bc.empty() ); TAO_PEGTL_TEST_ASSERT( bc.size( 1 ) == 90 ); @@ -102,8 +106,10 @@ namespace TAO_PEGTL_NAMESPACE bc.require( 100 ); +#if defined( __cpp_exceptions ) TAO_PEGTL_TEST_THROWS( bc.require( 101 ) ); TAO_PEGTL_TEST_THROWS( (void)bc.end( 100, 101 ) ); +#endif TAO_PEGTL_TEST_ASSERT( !bc.empty() ); TAO_PEGTL_TEST_ASSERT( bc.size( 1 ) == 100 ); @@ -122,8 +128,10 @@ namespace TAO_PEGTL_NAMESPACE bc.discard(); +#if defined( __cpp_exceptions ) TAO_PEGTL_TEST_THROWS( bc.require( 101 ) ); TAO_PEGTL_TEST_THROWS( (void)bc.end( 100, 101 ) ); +#endif TAO_PEGTL_TEST_ASSERT( !bc.empty() ); TAO_PEGTL_TEST_ASSERT( bc.size( 1 ) == 100 ); @@ -140,8 +148,10 @@ namespace TAO_PEGTL_NAMESPACE bc.consume( 60 ); +#if defined( __cpp_exceptions ) TAO_PEGTL_TEST_THROWS( bc.require( 101 ) ); TAO_PEGTL_TEST_THROWS( (void)bc.end( 100, 101 ) ); +#endif TAO_PEGTL_TEST_ASSERT( !bc.empty() ); TAO_PEGTL_TEST_ASSERT( bc.size( 1 ) == 40 ); @@ -160,8 +170,10 @@ namespace TAO_PEGTL_NAMESPACE bc.discard(); +#if defined( __cpp_exceptions ) TAO_PEGTL_TEST_THROWS( bc.require( 101 ) ); TAO_PEGTL_TEST_THROWS( (void)bc.end( 100, 101 ) ); +#endif TAO_PEGTL_TEST_ASSERT( !bc.empty() ); TAO_PEGTL_TEST_ASSERT( bc.size( 1 ) == 40 ); @@ -178,8 +190,10 @@ namespace TAO_PEGTL_NAMESPACE bc.consume( 30 ); +#if defined( __cpp_exceptions ) TAO_PEGTL_TEST_THROWS( bc.require( 101 ) ); TAO_PEGTL_TEST_THROWS( (void)bc.end( 100, 101 ) ); +#endif TAO_PEGTL_TEST_ASSERT( !bc.empty() ); TAO_PEGTL_TEST_ASSERT( bc.size( 1 ) == 10 ); @@ -197,8 +211,10 @@ namespace TAO_PEGTL_NAMESPACE bc.require( 50 ); +#if defined( __cpp_exceptions ) TAO_PEGTL_TEST_THROWS( bc.require( 101 ) ); TAO_PEGTL_TEST_THROWS( (void)bc.end( 100, 101 ) ); +#endif TAO_PEGTL_TEST_ASSERT( !bc.empty() ); TAO_PEGTL_TEST_ASSERT( bc.size( 1 ) == 50 ); @@ -213,7 +229,10 @@ namespace TAO_PEGTL_NAMESPACE TAO_PEGTL_TEST_ASSERT( bc.current() == bc.buffer_start() + 30 ); bc.buffer_check_size( 50 ); + +#if defined( __cpp_exceptions ) TAO_PEGTL_TEST_THROWS( bc.buffer_check_size( 51 ) ); +#endif } void unit_test() diff --git a/src/test/pegtl/include.cpp b/src/test/pegtl/include.cpp index 513fdef42..efba51380 100644 --- a/src/test/pegtl/include.cpp +++ b/src/test/pegtl/include.cpp @@ -19,8 +19,10 @@ #include #include #include +#if defined( __cpp_exceptions ) #include #include +#endif #include #include #include @@ -77,7 +79,9 @@ #include #include +#if defined( __cpp_exceptions ) #include +#endif #include #include #include diff --git a/src/test/pegtl/internal_unwind_guard.cpp b/src/test/pegtl/internal_unwind_guard.cpp index 4e0870072..bd4e7a0c0 100644 --- a/src/test/pegtl/internal_unwind_guard.cpp +++ b/src/test/pegtl/internal_unwind_guard.cpp @@ -2,6 +2,14 @@ // 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( __cpp_exceptions ) +#include +int main() +{ + std::cout << "Exception support disabled, skipping test..." << std::endl; +} +#else + #include "test.hpp" #include @@ -44,3 +52,5 @@ namespace TAO_PEGTL_NAMESPACE } // namespace TAO_PEGTL_NAMESPACE #include "main.hpp" + +#endif