diff options
Diffstat (limited to 'MoonParser/pegtl/contrib/changes.hpp')
-rw-r--r-- | MoonParser/pegtl/contrib/changes.hpp | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/MoonParser/pegtl/contrib/changes.hpp b/MoonParser/pegtl/contrib/changes.hpp new file mode 100644 index 0000000..7b9f8dc --- /dev/null +++ b/MoonParser/pegtl/contrib/changes.hpp | |||
@@ -0,0 +1,86 @@ | |||
1 | // Copyright (c) 2015-2017 Dr. Colin Hirsch and Daniel Frey | ||
2 | // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ | ||
3 | |||
4 | #ifndef TAOCPP_PEGTL_INCLUDE_CONTRIB_CHANGES_HPP | ||
5 | #define TAOCPP_PEGTL_INCLUDE_CONTRIB_CHANGES_HPP | ||
6 | |||
7 | #include <type_traits> | ||
8 | |||
9 | #include "../config.hpp" | ||
10 | #include "../normal.hpp" | ||
11 | |||
12 | namespace tao | ||
13 | { | ||
14 | namespace TAOCPP_PEGTL_NAMESPACE | ||
15 | { | ||
16 | namespace internal | ||
17 | { | ||
18 | struct dummy_disabled_state | ||
19 | { | ||
20 | template< typename... Ts > | ||
21 | void success( Ts&&... ) const noexcept | ||
22 | { | ||
23 | } | ||
24 | }; | ||
25 | |||
26 | template< apply_mode A, typename State > | ||
27 | using state_disable_helper = typename std::conditional< A == apply_mode::ACTION, State, dummy_disabled_state >::type; | ||
28 | |||
29 | } // namespace internal | ||
30 | |||
31 | template< typename Rule, typename State, template< typename... > class Base = normal > | ||
32 | struct change_state | ||
33 | : public Base< Rule > | ||
34 | { | ||
35 | template< apply_mode A, | ||
36 | rewind_mode M, | ||
37 | template< typename... > class Action, | ||
38 | template< typename... > class Control, | ||
39 | typename Input, | ||
40 | typename... States > | ||
41 | static bool match( Input& in, States&&... st ) | ||
42 | { | ||
43 | internal::state_disable_helper< A, State > s; | ||
44 | |||
45 | if( Base< Rule >::template match< A, M, Action, Control >( in, s ) ) { | ||
46 | s.success( st... ); | ||
47 | return true; | ||
48 | } | ||
49 | return false; | ||
50 | } | ||
51 | }; | ||
52 | |||
53 | template< typename Rule, template< typename... > class Action, template< typename... > class Base = normal > | ||
54 | struct change_action | ||
55 | : public Base< Rule > | ||
56 | { | ||
57 | template< apply_mode A, | ||
58 | rewind_mode M, | ||
59 | template< typename... > class, | ||
60 | template< typename... > class Control, | ||
61 | typename Input, | ||
62 | typename... States > | ||
63 | static bool match( Input& in, States&&... st ) | ||
64 | { | ||
65 | return Base< Rule >::template match< A, M, Action, Control >( in, st... ); | ||
66 | } | ||
67 | }; | ||
68 | |||
69 | template< template< typename... > class Action, template< typename... > class Base > | ||
70 | struct change_both_helper | ||
71 | { | ||
72 | template< typename T > | ||
73 | using change_action = change_action< T, Action, Base >; | ||
74 | }; | ||
75 | |||
76 | template< typename Rule, typename State, template< typename... > class Action, template< typename... > class Base = normal > | ||
77 | struct change_state_and_action | ||
78 | : public change_state< Rule, State, change_both_helper< Action, Base >::template change_action > | ||
79 | { | ||
80 | }; | ||
81 | |||
82 | } // namespace TAOCPP_PEGTL_NAMESPACE | ||
83 | |||
84 | } // namespace tao | ||
85 | |||
86 | #endif | ||