Skip to content

Commit

Permalink
Fix no-exceptions build.
Browse files Browse the repository at this point in the history
  • Loading branch information
ColinH committed Apr 19, 2024
1 parent 5176fb6 commit 8ad555c
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 3 deletions.
3 changes: 2 additions & 1 deletion include/tao/pegtl/rules.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@

#if defined( __cpp_exceptions )
#include <exception>

#include "parse_error_base.hpp"
#endif

#include "config.hpp"
#include "parse_error.hpp"

#include "internal/combine_traits.hpp"
#include "internal/invert_traits.hpp"
Expand Down
10 changes: 10 additions & 0 deletions src/example/pegtl/abnf2_record.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <iostream>
int main()
{
std::cout << "Exception support disabled, example is dummy..." << std::endl;
}
#else

#include <iomanip>
#include <iostream>

Expand Down Expand Up @@ -44,3 +52,5 @@ int main( int argc, char** argv ) // NOLINT(bugprone-exception-escape)
}
return 0;
}

#endif
3 changes: 2 additions & 1 deletion src/example/pegtl/dispatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/example/pegtl/json_coverage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/example/pegtl/json_errors.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@

#include <tao/pegtl.hpp>
#include <tao/pegtl/contrib/json.hpp>

#if defined( __cpp_exceptions )
#include <tao/pegtl/control/must_if.hpp>
#endif

namespace pegtl = TAO_PEGTL_NAMESPACE;

Expand Down
10 changes: 10 additions & 0 deletions src/example/pegtl/json_record.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
}
19 changes: 19 additions & 0 deletions src/test/pegtl/buffer_buffer_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand All @@ -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 );
Expand All @@ -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 );
Expand All @@ -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 );
Expand All @@ -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 );
Expand All @@ -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 );
Expand All @@ -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 );
Expand All @@ -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 );
Expand All @@ -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()
Expand Down
4 changes: 4 additions & 0 deletions src/test/pegtl/include.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
#include <tao/pegtl/normal.hpp>
#include <tao/pegtl/nothing.hpp>
#include <tao/pegtl/parse.hpp>
#if defined( __cpp_exceptions )
#include <tao/pegtl/parse_error.hpp>
#include <tao/pegtl/parse_error_base.hpp>
#endif
#include <tao/pegtl/pegtl_string.hpp>
#include <tao/pegtl/pointer_position.hpp>
#include <tao/pegtl/position_with_source.hpp>
Expand Down Expand Up @@ -77,7 +79,9 @@
#include <tao/pegtl/buffer/text_buffer_input_with_source.hpp>

#include <tao/pegtl/control/input_control.hpp>
#if defined( __cpp_exceptions )
#include <tao/pegtl/control/must_if.hpp>
#endif
#include <tao/pegtl/control/remove_first_state.hpp>
#include <tao/pegtl/control/remove_last_states.hpp>
#include <tao/pegtl/control/rewind_control.hpp>
Expand Down
10 changes: 10 additions & 0 deletions src/test/pegtl/internal_unwind_guard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <iostream>
int main()
{
std::cout << "Exception support disabled, skipping test..." << std::endl;
}
#else

#include "test.hpp"

#include <tao/pegtl/internal/unwind_guard.hpp>
Expand Down Expand Up @@ -44,3 +52,5 @@ namespace TAO_PEGTL_NAMESPACE
} // namespace TAO_PEGTL_NAMESPACE

#include "main.hpp"

#endif

0 comments on commit 8ad555c

Please sign in to comment.