1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
|
// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
#ifndef TAO_JSON_PEGTL_NORMAL_HPP
#define TAO_JSON_PEGTL_NORMAL_HPP
#include <string>
#include <type_traits>
#include <utility>
#include "apply_mode.hpp"
#include "config.hpp"
#include "demangle.hpp"
#include "match.hpp"
#include "parse_error.hpp"
#include "rewind_mode.hpp"
#include "internal/enable_control.hpp"
#include "internal/has_match.hpp"
namespace TAO_JSON_PEGTL_NAMESPACE
{
template< typename Rule >
struct normal
{
static constexpr bool enable = internal::enable_control< Rule >;
template< typename ParseInput, typename... States >
static void start( const ParseInput& /*unused*/, States&&... /*unused*/ ) noexcept
{}
template< typename ParseInput, typename... States >
static void success( const ParseInput& /*unused*/, States&&... /*unused*/ ) noexcept
{}
template< typename ParseInput, typename... States >
static void failure( const ParseInput& /*unused*/, States&&... /*unused*/ ) noexcept
{}
template< typename ParseInput, typename... States >
[[noreturn]] static void raise( const ParseInput& in, States&&... /*unused*/ )
{
throw parse_error( "parse error matching " + std::string( demangle< Rule >() ), in );
}
template< template< typename... > class Action,
typename Iterator,
typename ParseInput,
typename... States >
static auto apply( const Iterator& begin, const ParseInput& in, States&&... st ) noexcept( noexcept( Action< Rule >::apply( std::declval< const typename ParseInput::action_t& >(), st... ) ) )
-> decltype( Action< Rule >::apply( std::declval< const typename ParseInput::action_t& >(), st... ) )
{
const typename ParseInput::action_t action_input( begin, in );
return Action< Rule >::apply( action_input, st... );
}
template< template< typename... > class Action,
typename ParseInput,
typename... States >
static auto apply0( const ParseInput& /*unused*/, States&&... st ) noexcept( noexcept( Action< Rule >::apply0( st... ) ) )
-> decltype( Action< Rule >::apply0( st... ) )
{
return Action< Rule >::apply0( st... );
}
template< apply_mode A,
rewind_mode M,
template< typename... >
class Action,
template< typename... >
class Control,
typename ParseInput,
typename... States >
[[nodiscard]] static bool match( ParseInput& in, States&&... st )
{
if constexpr( internal::has_match< bool, Rule, A, M, Action, Control, ParseInput, States... > ) {
return Action< Rule >::template match< Rule, A, M, Action, Control >( in, st... );
}
else {
return TAO_JSON_PEGTL_NAMESPACE::match< Rule, A, M, Action, Control >( in, st... );
}
}
};
} // namespace TAO_JSON_PEGTL_NAMESPACE
#endif
|