1 // Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey
2 // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
3 
4 #ifndef TAO_PEGTL_NORMAL_HPP
5 #define TAO_PEGTL_NORMAL_HPP
6 
7 #include <type_traits>
8 #include <utility>
9 
10 #include "apply_mode.hpp"
11 #include "config.hpp"
12 #include "match.hpp"
13 #include "parse_error.hpp"
14 #include "rewind_mode.hpp"
15 
16 #include "internal/demangle.hpp"
17 #include "internal/has_match.hpp"
18 
19 namespace tao
20 {
21    namespace TAO_PEGTL_NAMESPACE
22    {
23       template< typename Rule >
24       struct normal
25       {
26          template< typename Input, typename... States >
starttao::TAO_PEGTL_NAMESPACE::normal27          static void start( const Input& /*unused*/, States&&... /*unused*/ ) noexcept
28          {
29          }
30 
31          template< typename Input, typename... States >
successtao::TAO_PEGTL_NAMESPACE::normal32          static void success( const Input& /*unused*/, States&&... /*unused*/ ) noexcept
33          {
34          }
35 
36          template< typename Input, typename... States >
failuretao::TAO_PEGTL_NAMESPACE::normal37          static void failure( const Input& /*unused*/, States&&... /*unused*/ ) noexcept
38          {
39          }
40 
41          template< typename Input, typename... States >
raisetao::TAO_PEGTL_NAMESPACE::normal42          static void raise( const Input& in, States&&... /*unused*/ )
43          {
44             throw parse_error( "parse error matching " + internal::demangle< Rule >(), in );
45          }
46 
47          template< template< typename... > class Action, typename Input, typename... States >
apply0tao::TAO_PEGTL_NAMESPACE::normal48          static auto apply0( const Input& /*unused*/, States&&... st )
49             -> decltype( Action< Rule >::apply0( st... ) )
50          {
51             return Action< Rule >::apply0( st... );
52          }
53 
54          template< template< typename... > class Action, typename Iterator, typename Input, typename... States >
applytao::TAO_PEGTL_NAMESPACE::normal55          static auto apply( const Iterator& begin, const Input& in, States&&... st )
56             -> decltype( Action< Rule >::apply( std::declval< typename Input::action_t >(), st... ) )
57          {
58             const typename Input::action_t action_input( begin, in );
59             return Action< Rule >::apply( action_input, st... );
60          }
61 
62          template< apply_mode A,
63                    rewind_mode M,
64                    template< typename... >
65                    class Action,
66                    template< typename... >
67                    class Control,
68                    typename Input,
69                    typename... States >
matchtao::TAO_PEGTL_NAMESPACE::normal70          static auto match( Input& in, States&&... st )
71             -> typename std::enable_if< internal::has_match< void, Rule, A, M, Action, Control, Input, States... >::value, bool >::type
72          {
73             return Action< Rule >::template match< Rule, A, M, Action, Control >( in, st... );
74          }
75 
76          template< apply_mode A,
77                    rewind_mode M,
78                    template< typename... >
79                    class Action,
80                    template< typename... >
81                    class Control,
82                    typename Input,
83                    typename... States,
84                    int = 1 >
matchtao::TAO_PEGTL_NAMESPACE::normal85          static auto match( Input& in, States&&... st )
86             -> typename std::enable_if< !internal::has_match< void, Rule, A, M, Action, Control, Input, States... >::value, bool >::type
87          {
88             return TAO_PEGTL_NAMESPACE::match< Rule, A, M, Action, Control >( in, st... );
89          }
90       };
91 
92    }  // namespace TAO_PEGTL_NAMESPACE
93 
94 }  // namespace tao
95 
96 #endif
97