aboutsummaryrefslogtreecommitdiff
path: root/MoonParser/pegtl/internal/must.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'MoonParser/pegtl/internal/must.hpp')
-rw-r--r--MoonParser/pegtl/internal/must.hpp79
1 files changed, 79 insertions, 0 deletions
diff --git a/MoonParser/pegtl/internal/must.hpp b/MoonParser/pegtl/internal/must.hpp
new file mode 100644
index 0000000..4ac9920
--- /dev/null
+++ b/MoonParser/pegtl/internal/must.hpp
@@ -0,0 +1,79 @@
1// Copyright (c) 2014-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_INTERNAL_MUST_HPP
5#define TAOCPP_PEGTL_INCLUDE_INTERNAL_MUST_HPP
6
7#include "../config.hpp"
8
9#include "raise.hpp"
10#include "rule_conjunction.hpp"
11#include "skip_control.hpp"
12
13#include "../apply_mode.hpp"
14#include "../rewind_mode.hpp"
15
16#include "../analysis/generic.hpp"
17
18namespace tao
19{
20 namespace TAOCPP_PEGTL_NAMESPACE
21 {
22 namespace internal
23 {
24 // The general case applies must<> to each of the
25 // rules in the 'Rules' parameter pack individually.
26
27 template< typename... Rules >
28 struct must
29 {
30 using analyze_t = analysis::generic< analysis::rule_type::SEQ, Rules... >;
31
32 template< apply_mode A,
33 rewind_mode M,
34 template< typename... > class Action,
35 template< typename... > class Control,
36 typename Input,
37 typename... States >
38 static bool match( Input& in, States&&... st )
39 {
40 return rule_conjunction< must< Rules >... >::template match< A, M, Action, Control >( in, st... );
41 }
42 };
43
44 // While in theory the implementation for a single rule could
45 // be simplified to must< Rule > = sor< Rule, raise< Rule > >, this
46 // would result in some unnecessary run-time overhead.
47
48 template< typename Rule >
49 struct must< Rule >
50 {
51 using analyze_t = typename Rule::analyze_t;
52
53 template< apply_mode A,
54 rewind_mode,
55 template< typename... > class Action,
56 template< typename... > class Control,
57 typename Input,
58 typename... States >
59 static bool match( Input& in, States&&... st )
60 {
61 if( !Control< Rule >::template match< A, rewind_mode::DONTCARE, Action, Control >( in, st... ) ) {
62 raise< Rule >::template match< A, rewind_mode::DONTCARE, Action, Control >( in, st... );
63 }
64 return true;
65 }
66 };
67
68 template< typename... Rules >
69 struct skip_control< must< Rules... > > : std::true_type
70 {
71 };
72
73 } // namespace internal
74
75 } // namespace TAOCPP_PEGTL_NAMESPACE
76
77} // namespace tao
78
79#endif