Line data Source code
1 : /**
2 : * @file
3 : *
4 : * @brief A listener reacting to matches for the grammar rules defined in `YAML.g4`
5 : *
6 : * @copyright BSD License (see LICENSE.md or https://www.libelektra.org)
7 : */
8 :
9 : // -- Imports ------------------------------------------------------------------
10 :
11 : #include <stack>
12 :
13 : #include <kdb.hpp>
14 :
15 : #include "YAMLBaseListener.h"
16 :
17 : // -- Class --------------------------------------------------------------------
18 :
19 : namespace yanlr
20 : {
21 :
22 : /**
23 : * @brief This class creates a key set by listening to matches of grammar rules
24 : * specified via YAML.g4.
25 : */
26 155 : class KeyListener : public YAMLBaseListener
27 : {
28 : /** This variable stores a key set representing the textual input. */
29 : kdb::KeySet keys;
30 :
31 : /**
32 : * This stack stores a key for each level of the current key name below
33 : * parent.
34 : */
35 : std::stack<kdb::Key> parents;
36 :
37 : /**
38 : * This stack stores indices for the next array elements.
39 : */
40 : std::stack<uintmax_t> indices;
41 :
42 : public:
43 : /**
44 : * @brief This constructor creates a new empty key storage using the given
45 : * parent key.
46 : *
47 : * @param parent This key specifies the parent of all keys stored in the
48 : * object.
49 : */
50 : KeyListener (kdb::Key parent);
51 :
52 : /**
53 : * @brief This function returns the data read by the parser.
54 : *
55 : * @return The key set representing the data from the textual input
56 : */
57 : kdb::KeySet keySet ();
58 :
59 : /**
60 : * @brief This function will be called when the listener enters an empty file (that might contain comments).
61 : *
62 : * @param context The context specifies data matched by the rule.
63 : */
64 : void enterEmpty (YAML::EmptyContext * context) override;
65 :
66 : /**
67 : * @brief This function will be called after the parser exits a value.
68 : *
69 : * @param context The context specifies data matched by the rule.
70 : */
71 : void exitValue (YAML::ValueContext * context) override;
72 :
73 : /**
74 : * @brief This function will be called after the parser enters a key-value
75 : * pair.
76 : *
77 : * @param context The context specifies data matched by the rule.
78 : */
79 : virtual void enterPair (YAML::PairContext * context) override;
80 :
81 : /**
82 : * @brief This function will be called after the parser exits a key-value
83 : * pair.
84 : *
85 : * @param context The context specifies data matched by the rule.
86 : */
87 : virtual void exitPair (YAML::PairContext * context) override;
88 :
89 : /**
90 : * @brief This function will be called after the parser enters a sequence.
91 : *
92 : * @param context The context specifies data matched by the rule.
93 : */
94 : virtual void enterSequence (YAML::SequenceContext * context) override;
95 :
96 : /**
97 : * @brief This function will be called after the parser exits a sequence.
98 : *
99 : * @param context The context specifies data matched by the rule.
100 : */
101 : virtual void exitSequence (YAML::SequenceContext * context) override;
102 :
103 : /**
104 : * @brief This function will be called after the parser recognizes an element
105 : * of a sequence.
106 : *
107 : * @param context The context specifies data matched by the rule.
108 : */
109 : virtual void enterElement (YAML::ElementContext * context) override;
110 :
111 : /**
112 : * @brief This function will be called after the parser read an element of a
113 : * sequence.
114 : *
115 : * @param context The context specifies data matched by the rule.
116 : */
117 : virtual void exitElement (YAML::ElementContext * context) override;
118 : };
119 : }
|