forked from ElektraInitiative/libelektra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
listener.hpp
119 lines (100 loc) · 3.17 KB
/
listener.hpp
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/**
* @file
*
* @brief A listener reacting to matches for the grammar rules defined in `YAML.g4`
*
* @copyright BSD License (see LICENSE.md or https://www.libelektra.org)
*/
// -- Imports ------------------------------------------------------------------
#include <stack>
#include <kdb.hpp>
#include "YAMLBaseListener.h"
// -- Class --------------------------------------------------------------------
namespace yanlr
{
/**
* @brief This class creates a key set by listening to matches of grammar rules
* specified via YAML.g4.
*/
class KeyListener : public YAMLBaseListener
{
/** This variable stores a key set representing the textual input. */
kdb::KeySet keys;
/**
* This stack stores a key for each level of the current key name below
* parent.
*/
std::stack<kdb::Key> parents;
/**
* This stack stores indices for the next array elements.
*/
std::stack<uintmax_t> indices;
public:
/**
* @brief This constructor creates a new empty key storage using the given
* parent key.
*
* @param parent This key specifies the parent of all keys stored in the
* object.
*/
KeyListener (kdb::Key parent);
/**
* @brief This function returns the data read by the parser.
*
* @return The key set representing the data from the textual input
*/
kdb::KeySet keySet ();
/**
* @brief This function will be called when the listener enters an empty file (that might contain comments).
*
* @param context The context specifies data matched by the rule.
*/
void enterEmpty (YAML::EmptyContext * context) override;
/**
* @brief This function will be called after the parser exits a value.
*
* @param context The context specifies data matched by the rule.
*/
void exitValue (YAML::ValueContext * context) override;
/**
* @brief This function will be called after the parser enters a key-value
* pair.
*
* @param context The context specifies data matched by the rule.
*/
virtual void enterPair (YAML::PairContext * context) override;
/**
* @brief This function will be called after the parser exits a key-value
* pair.
*
* @param context The context specifies data matched by the rule.
*/
virtual void exitPair (YAML::PairContext * context) override;
/**
* @brief This function will be called after the parser enters a sequence.
*
* @param context The context specifies data matched by the rule.
*/
virtual void enterSequence (YAML::SequenceContext * context) override;
/**
* @brief This function will be called after the parser exits a sequence.
*
* @param context The context specifies data matched by the rule.
*/
virtual void exitSequence (YAML::SequenceContext * context) override;
/**
* @brief This function will be called after the parser recognizes an element
* of a sequence.
*
* @param context The context specifies data matched by the rule.
*/
virtual void enterElement (YAML::ElementContext * context) override;
/**
* @brief This function will be called after the parser read an element of a
* sequence.
*
* @param context The context specifies data matched by the rule.
*/
virtual void exitElement (YAML::ElementContext * context) override;
};
}