Skip to content

Commit

Permalink
Manually merge PR from wravery, closes #309
Browse files Browse the repository at this point in the history
  • Loading branch information
d-frey committed Jun 29, 2022
1 parent 1693c62 commit ffc08ad
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 7 deletions.
2 changes: 1 addition & 1 deletion doc/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## 3.2.6

Released 2022-??-??
Released 2022-06-29

* Made `unwind()` optional for parse tree nodes.
* Fixed `demangle()` for MSVC, again.
Expand Down
39 changes: 39 additions & 0 deletions include/tao/pegtl/internal/unwind_guard.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright (c) 2014-2022 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/

#ifndef TAO_PEGTL_INTERNAL_UNWIND_GUARD_HPP
#define TAO_PEGTL_INTERNAL_UNWIND_GUARD_HPP

#include "../config.hpp"

#include <optional>
#include <utility>

namespace TAO_PEGTL_NAMESPACE::internal
{
template< typename Unwind >
struct unwind_guard
{
explicit unwind_guard( Unwind&& unwind_impl )
: unwind( std::move( unwind_impl ) )
{}

~unwind_guard()
{
if( unwind ) {
( *unwind )();
}
}

unwind_guard( const unwind_guard& ) = delete;
unwind_guard( unwind_guard&& ) noexcept = delete;

unwind_guard& operator=( const unwind_guard& ) = delete;
unwind_guard& operator=( unwind_guard&& ) noexcept = delete;

std::optional< Unwind > unwind;
};

} // namespace TAO_PEGTL_NAMESPACE::internal

#endif
12 changes: 6 additions & 6 deletions include/tao/pegtl/match.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "internal/marker.hpp"
#include "internal/missing_apply.hpp"
#include "internal/missing_apply0.hpp"
#include "internal/unwind_guard.hpp"

#if defined( _MSC_VER )
#pragma warning( push )
Expand Down Expand Up @@ -72,13 +73,12 @@ namespace TAO_PEGTL_NAMESPACE
{
#if defined( __cpp_exceptions )
if constexpr( has_unwind< Control< Rule >, void, const ParseInput&, States... > ) {
try {
return match_no_control< Rule, A, M, Action, Control >( in, st... );
}
catch( ... ) {
unwind_guard ug( [ & ] {
Control< Rule >::unwind( static_cast< const ParseInput& >( in ), st... );
throw;
}
} );
const auto result = match_no_control< Rule, A, M, Action, Control >( in, st... );
ug.unwind.reset();
return result;
}
else {
return match_no_control< Rule, A, M, Action, Control >( in, st... );
Expand Down

0 comments on commit ffc08ad

Please sign in to comment.