aboutsummaryrefslogtreecommitdiff
path: root/MoonParser/pegtl/contrib/counter.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'MoonParser/pegtl/contrib/counter.hpp')
-rw-r--r--MoonParser/pegtl/contrib/counter.hpp58
1 files changed, 58 insertions, 0 deletions
diff --git a/MoonParser/pegtl/contrib/counter.hpp b/MoonParser/pegtl/contrib/counter.hpp
new file mode 100644
index 0000000..52beb3b
--- /dev/null
+++ b/MoonParser/pegtl/contrib/counter.hpp
@@ -0,0 +1,58 @@
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_CONTRIB_COUNTER_HPP
5#define TAOCPP_PEGTL_INCLUDE_CONTRIB_COUNTER_HPP
6
7#include <cassert>
8#include <utility>
9
10#include "../config.hpp"
11#include "../normal.hpp"
12
13#include "../internal/demangle.hpp"
14
15namespace tao
16{
17 namespace TAOCPP_PEGTL_NAMESPACE
18 {
19 struct counter_data
20 {
21 unsigned start = 0;
22 unsigned success = 0;
23 unsigned failure = 0;
24 };
25
26 struct counter_state
27 {
28 std::map< std::string, counter_data > counts;
29 };
30
31 template< typename Rule >
32 struct counter
33 : normal< Rule >
34 {
35 template< typename Input >
36 static void start( const Input&, counter_state& ts )
37 {
38 ++ts.counts[ internal::demangle< Rule >() ].start;
39 }
40
41 template< typename Input >
42 static void success( const Input&, counter_state& ts )
43 {
44 ++ts.counts[ internal::demangle< Rule >() ].success;
45 }
46
47 template< typename Input >
48 static void failure( const Input&, counter_state& ts )
49 {
50 ++ts.counts[ internal::demangle< Rule >() ].failure;
51 }
52 };
53
54 } // namespace TAOCPP_PEGTL_NAMESPACE
55
56} // namespace tao
57
58#endif