Directory: | ./ |
---|---|
File: | tmp_project/PhoenixYml/src/parser_yml.cpp |
Date: | 2025-03-27 14:50:11 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 172 | 185 | 93.0% |
Branches: | 228 | 322 | 70.8% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | /*************************************** | ||
2 | Auteur : Pierre Aubert | ||
3 | Mail : pierre.aubert@lapp.in2p3.fr | ||
4 | Licence : CeCILL-C | ||
5 | ****************************************/ | ||
6 | |||
7 | #include "PFileParser.h" | ||
8 | #include "vec_value_utils.h" | ||
9 | |||
10 | #include "parser_yml.h" | ||
11 | |||
12 | ///@brief Data used to parse a yml file | ||
13 | struct PYmlParserData{ | ||
14 | ///True to continue the parsing, false to stop | ||
15 | bool isRun; | ||
16 | ///True if the compact mode is activated | ||
17 | bool compactMode; | ||
18 | ///Current line number | ||
19 | size_t currentLine; | ||
20 | ///Vector of previous line indentations | ||
21 | std::vector<size_t> vecIndentation; | ||
22 | ///Current parsed text | ||
23 | PString currentText; | ||
24 | ///Currently parsed key value | ||
25 | VecValue * currentlyParsedKeyValue; | ||
26 | }; | ||
27 | |||
28 | ///Default value of PYmlParserData | ||
29 | /** @return default PYmlParserData | ||
30 | */ | ||
31 | 12 | PYmlParserData default_PYmlParserData(){ | |
32 | 12 | PYmlParserData data; | |
33 | 12 | data.isRun = true; | |
34 | 12 | data.compactMode = false; | |
35 | 12 | data.currentLine = 1lu; | |
36 |
1/1✓ Branch 1 taken 12 times.
|
12 | data.currentText = ""; |
37 | 12 | data.currentlyParsedKeyValue = NULL; | |
38 | 12 | return data; | |
39 | } | ||
40 | |||
41 | bool parse_yml_all(VecValue & parent, PFileParser & parser, PYmlParserData & data); | ||
42 | |||
43 | ///Stop the file parsing | ||
44 | /** @param[out] data : parsing data | ||
45 | */ | ||
46 | ✗ | void parse_yml_stopParsing(PYmlParserData & data){ | |
47 | ✗ | data.isRun = false; | |
48 | } | ||
49 | |||
50 | ///Say if the file parsing is enable | ||
51 | /** @param data : parsing data | ||
52 | */ | ||
53 | 1719 | bool parse_yml_isParse(const PYmlParserData & data){ | |
54 | 1719 | return data.isRun; | |
55 | } | ||
56 | |||
57 | ///Update the indentation vector by respect to the given indentation | ||
58 | /** @param[out] vecIndentation : vector of indentation to be updated | ||
59 | * @param currentIndentation : current indentation | ||
60 | */ | ||
61 | 160 | void parse_yml_updateIndentation(std::vector<size_t> & vecIndentation, size_t currentIndentation){ | |
62 |
5/6✓ Branch 0 taken 118 times.
✓ Branch 1 taken 42 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 118 times.
✓ Branch 5 taken 42 times.
✓ Branch 6 taken 118 times.
|
160 | if(currentIndentation == 0lu || vecIndentation.size() == 0lu){ //If there is no indentation |
63 | 42 | vecIndentation.clear(); | |
64 |
1/1✓ Branch 1 taken 42 times.
|
42 | vecIndentation.push_back(currentIndentation); |
65 | 42 | return; | |
66 | } | ||
67 | 118 | std::vector<size_t> vecOutIndentation; | |
68 | 118 | std::vector<size_t>::const_iterator it(vecIndentation.begin()); | |
69 | 118 | bool isCurrentLower(true); | |
70 |
6/6✓ Branch 0 taken 315 times.
✓ Branch 1 taken 77 times.
✓ Branch 4 taken 274 times.
✓ Branch 5 taken 41 times.
✓ Branch 6 taken 274 times.
✓ Branch 7 taken 118 times.
|
392 | while(isCurrentLower && it != vecIndentation.end()){ //Get previous indentation until the current one |
71 | 274 | isCurrentLower = *it < currentIndentation; | |
72 |
2/2✓ Branch 0 taken 197 times.
✓ Branch 1 taken 77 times.
|
274 | if(isCurrentLower){ |
73 |
1/1✓ Branch 2 taken 197 times.
|
197 | vecOutIndentation.push_back(*it); |
74 | } | ||
75 | 274 | ++it; | |
76 | } | ||
77 |
1/1✓ Branch 1 taken 118 times.
|
118 | vecOutIndentation.push_back(currentIndentation); //Add the current indentation |
78 |
1/1✓ Branch 1 taken 118 times.
|
118 | vecIndentation = vecOutIndentation; |
79 | 118 | } | |
80 | |||
81 | ///Increment the current character | ||
82 | /** @param[out] parser : parser to be used | ||
83 | * @param data : parsing data | ||
84 | */ | ||
85 | 1465 | void parse_yml_incrementCurrentChar(PFileParser & parser, PYmlParserData & data){ | |
86 | //If nothing is known I need to save the current char in the MACRO TEXT | ||
87 | 1465 | char ch = parser.getCurrentCh(); | |
88 | 1465 | data.currentText += ch; | |
89 | 1465 | parser.getNextChar(); | |
90 | 1465 | } | |
91 | |||
92 | ///Play the current parsed text | ||
93 | /** @param[out] data : parsing data | ||
94 | */ | ||
95 | 180 | void parse_yml_playCurrentText(PYmlParserData & data){ | |
96 |
2/2✓ Branch 1 taken 180 times.
✓ Branch 4 taken 180 times.
|
180 | PString value(data.currentText.eraseFirstLastChar(" \t\n")); |
97 | |||
98 |
6/7✓ Branch 0 taken 180 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 180 times.
✓ Branch 5 taken 59 times.
✓ Branch 6 taken 121 times.
✓ Branch 7 taken 59 times.
✓ Branch 8 taken 121 times.
|
180 | if(data.currentlyParsedKeyValue != NULL && value != ""){ |
99 |
1/1✓ Branch 1 taken 59 times.
|
59 | data.currentlyParsedKeyValue->setValue(value); |
100 | } | ||
101 |
1/1✓ Branch 1 taken 180 times.
|
180 | data.currentText = ""; |
102 | 180 | } | |
103 | |||
104 | ///Parse key | ||
105 | /** @param[out] key : parsed key | ||
106 | * @param[out] keyIndentation : indentation of the key | ||
107 | * @param[out] parser : PFileParser to be used | ||
108 | */ | ||
109 | 1545 | bool parse_yml_key(PString & key, size_t & keyIndentation, PFileParser & parser){ | |
110 |
1/1✓ Branch 1 taken 1545 times.
|
1545 | parser.pushPosition(); |
111 |
2/2✓ Branch 1 taken 1545 times.
✓ Branch 4 taken 1545 times.
|
1545 | PString possibleKey(parser.getStrComposedOf("_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")); |
112 |
11/13✓ Branch 1 taken 1545 times.
✓ Branch 3 taken 474 times.
✓ Branch 4 taken 1071 times.
✓ Branch 6 taken 474 times.
✓ Branch 9 taken 474 times.
✓ Branch 11 taken 132 times.
✓ Branch 12 taken 342 times.
✓ Branch 13 taken 474 times.
✓ Branch 14 taken 1071 times.
✓ Branch 16 taken 132 times.
✓ Branch 17 taken 1413 times.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
|
1545 | if(possibleKey != "" && parser.isMatch(":")){ |
113 |
1/1✓ Branch 1 taken 132 times.
|
132 | key = possibleKey; |
114 |
1/1✓ Branch 1 taken 132 times.
|
132 | keyIndentation = parser.getColumn() - possibleKey.size() - 1lu; |
115 | 132 | return true; | |
116 | } | ||
117 |
1/1✓ Branch 1 taken 1413 times.
|
1413 | parser.popPosition(); |
118 | 1413 | return false; | |
119 | 1545 | } | |
120 | |||
121 | ///Parse string value | ||
122 | /** @param[out] str : parsed string value | ||
123 | * @param[out] parser : PFileParser to be used | ||
124 | */ | ||
125 | 13 | bool parse_yml_string(PString & str, PFileParser & parser){ | |
126 |
3/3✓ Branch 2 taken 13 times.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 12 times.
|
13 | if(parser.isMatch("\"")){ |
127 |
3/3✓ Branch 2 taken 1 times.
✓ Branch 5 taken 1 times.
✓ Branch 8 taken 1 times.
|
1 | str = "\"" + parser.getUntilKey("\""); |
128 |
3/3✓ Branch 2 taken 12 times.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 11 times.
|
12 | }else if(parser.isMatch("'")){ |
129 |
3/3✓ Branch 2 taken 1 times.
✓ Branch 5 taken 1 times.
✓ Branch 8 taken 1 times.
|
1 | str = "'" + parser.getUntilKey("'"); |
130 | }else{ | ||
131 | 11 | return false; | |
132 | } | ||
133 | 2 | return true; | |
134 | } | ||
135 | |||
136 | ///Set a value into a VecValue | ||
137 | /** @param[out] vecVal : vector of value | ||
138 | * @param value : value to be used | ||
139 | */ | ||
140 | 54 | void parse_yml_dicoSetValue(VecValue * vecVal, const PString & value){ | |
141 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 54 times.
|
54 | if(vecVal == NULL){return;} |
142 | 54 | vecVal->setValue(value); | |
143 |
1/1✓ Branch 1 taken 54 times.
|
54 | vecVal->setType(VecValueType::VALUE); |
144 | } | ||
145 | |||
146 | ///Parse compact dico content | ||
147 | /** @param[out] parser : PFileParser to be used | ||
148 | * @param[out] data : extra parser data to be used | ||
149 | */ | ||
150 | 1413 | bool parse_yml_stringValue(PFileParser & parser, PYmlParserData & data){ | |
151 |
3/3✓ Branch 2 taken 1413 times.
✓ Branch 5 taken 5 times.
✓ Branch 6 taken 1408 times.
|
1413 | if(parser.isMatch("\'")){ |
152 |
4/4✓ Branch 1 taken 5 times.
✓ Branch 4 taken 5 times.
✓ Branch 7 taken 5 times.
✓ Branch 10 taken 5 times.
|
10 | PString str("\'" + parser.getUntilKey("\'")); |
153 |
1/1✓ Branch 1 taken 5 times.
|
5 | parse_yml_dicoSetValue(data.currentlyParsedKeyValue, str); |
154 |
3/3✓ Branch 3 taken 1408 times.
✓ Branch 6 taken 49 times.
✓ Branch 7 taken 1359 times.
|
1413 | }else if(parser.isMatch("\"")){ |
155 |
4/4✓ Branch 1 taken 49 times.
✓ Branch 4 taken 49 times.
✓ Branch 7 taken 49 times.
✓ Branch 10 taken 49 times.
|
98 | PString str("\"" + parser.getUntilKey("\"")); |
156 |
1/1✓ Branch 1 taken 49 times.
|
49 | parse_yml_dicoSetValue(data.currentlyParsedKeyValue, str); |
157 | 49 | }else{ | |
158 | // PString strValue(parser.getStrComposedOf("_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789%$£?.*/+=-&~#(){}[]|!<>@°")); | ||
159 | // parser.skipWhiteSpace(); | ||
160 | // PString strValue(parser.getStrComposedOf("_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789{}§")); | ||
161 | // if(strValue != ""){ | ||
162 | // parse_yml_dicoSetValue(data.currentlyParsedKeyValue, strValue); | ||
163 | // }else{ | ||
164 | 1359 | return false; | |
165 | // } | ||
166 | } | ||
167 | 54 | return true; | |
168 | } | ||
169 | |||
170 | ///Parse compact dico content | ||
171 | /** @param[out] parent : parent VecValue | ||
172 | * @param[out] parser : PFileParser to be used | ||
173 | * @param[out] data : extra parser data to be used | ||
174 | */ | ||
175 | 1574 | bool parse_yml_compactDicoContent(VecValue & parent, PFileParser & parser, PYmlParserData & data){ | |
176 |
5/5✓ Branch 1 taken 1574 times.
✓ Branch 4 taken 1574 times.
✓ Branch 7 taken 1574 times.
✓ Branch 11 taken 1573 times.
✓ Branch 12 taken 1 times.
|
1574 | if(!parser.isMatch("{", "$§_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/*+-.")){return false;} |
177 |
1/1✓ Branch 1 taken 1 times.
|
1 | std::vector<size_t> saveVecIndentation = data.vecIndentation; |
178 |
1/1✓ Branch 1 taken 1 times.
|
1 | parse_yml_playCurrentText(data); |
179 | 1 | bool oldMode = data.compactMode; | |
180 | 1 | data.compactMode = true; | |
181 | |||
182 | 1 | VecValue & dico = *data.currentlyParsedKeyValue; | |
183 | 1 | data.vecIndentation.clear(); | |
184 |
1/1✓ Branch 1 taken 1 times.
|
1 | data.vecIndentation.push_back(0lu); |
185 |
2/2✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
|
1 | parser.getStrComposedOf(" \t\n"); //Skip all blank characters |
186 |
9/13✓ Branch 1 taken 14 times.
✓ Branch 3 taken 14 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 14 times.
✓ Branch 9 taken 14 times.
✓ Branch 11 taken 13 times.
✓ Branch 12 taken 1 times.
✓ Branch 13 taken 14 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 13 times.
✓ Branch 17 taken 1 times.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
|
14 | while(parse_yml_isParse(data) && !parser.isMatch("}")){ |
187 |
2/3✓ Branch 1 taken 13 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 13 times.
|
13 | if(!parse_yml_all(dico, parser, data)){ |
188 | ✗ | std::cerr << "parse_yml_compactDicoContent : error at " << parser.getLocation() << std::endl; | |
189 | ✗ | std::cerr << "\tunexpected token '"<<parser.getNextToken()<<"'" << std::endl; | |
190 | ✗ | parse_yml_stopParsing(data); | |
191 | } | ||
192 |
2/2✓ Branch 1 taken 13 times.
✓ Branch 4 taken 13 times.
|
13 | parser.isMatch(","); //Skip comma if there is one |
193 | } | ||
194 |
1/1✓ Branch 1 taken 1 times.
|
1 | parse_yml_playCurrentText(data); |
195 |
1/1✓ Branch 1 taken 1 times.
|
1 | data.vecIndentation = saveVecIndentation; |
196 | 1 | data.compactMode = oldMode; | |
197 | 1 | return true; | |
198 | 1 | } | |
199 | |||
200 | ///Parse dico content | ||
201 | /** @param[out] parent : parent VecValue | ||
202 | * @param[out] parser : PFileParser to be used | ||
203 | * @param[out] data : extra parser data to be used | ||
204 | */ | ||
205 | 1545 | bool parse_yml_dicoContent(VecValue & parent, PFileParser & parser, PYmlParserData & data){ | |
206 |
1/1✓ Branch 1 taken 1545 times.
|
1545 | parser.pushPosition(); |
207 |
1/1✓ Branch 1 taken 1545 times.
|
1545 | PString keyName(""); |
208 | 1545 | size_t keyIndentation(0lu); | |
209 |
3/3✓ Branch 1 taken 1545 times.
✓ Branch 3 taken 1413 times.
✓ Branch 4 taken 132 times.
|
1545 | if(!parse_yml_key(keyName, keyIndentation, parser)){ //Check if there is a key |
210 |
1/1✓ Branch 1 taken 1413 times.
|
1413 | parser.popPosition(); //This is not a key |
211 | 1413 | return false; | |
212 | } | ||
213 |
1/1✓ Branch 1 taken 132 times.
|
132 | parse_yml_playCurrentText(data); |
214 |
1/1✓ Branch 1 taken 132 times.
|
132 | VecValue dico; |
215 |
1/1✓ Branch 1 taken 132 times.
|
132 | dico.setKey(keyName); |
216 |
1/1✓ Branch 1 taken 132 times.
|
132 | dico.setType(VecValueType::KEY); |
217 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 130 times.
|
132 | if(data.compactMode){ |
218 | 2 | keyIndentation = -1lu; | |
219 | } | ||
220 |
1/1✓ Branch 1 taken 132 times.
|
132 | dico.setIndentation(keyIndentation); |
221 | //Add the dico into its parent and get back the pointer of the current dico we want to fill | ||
222 |
1/1✓ Branch 1 taken 132 times.
|
132 | VecValue * ptrDico = addChildToParentVecValue(parent, data.vecIndentation, data.compactMode, dico, keyIndentation); |
223 | |||
224 | //Update indentation to be used to fill the VecValue in the current dico | ||
225 |
1/1✓ Branch 1 taken 132 times.
|
132 | parse_yml_updateIndentation(data.vecIndentation, keyIndentation); |
226 | |||
227 | ///Let's update the current VecValue to be completd with values and lists | ||
228 | 132 | data.currentlyParsedKeyValue = ptrDico; | |
229 | |||
230 | //We do not need to parse the dico content, because its content will depend on what comes next (key, value, list) | ||
231 | |||
232 | //OK, on pourrait dire que les dicos se regroupent par leur indentation donc ça fonctionne | ||
233 | //Et que les valeurs associée (string, listes) sont ajoutées en utilisant data.currentlyParsedKeyValue | ||
234 | |||
235 | 132 | return true; | |
236 | 1545 | } | |
237 | |||
238 | ///Parse compact dico content | ||
239 | /** @param[out] parent : parent VecValue | ||
240 | * @param[out] parser : PFileParser to be used | ||
241 | * @param[out] data : extra parser data to be used | ||
242 | */ | ||
243 | 1580 | bool parse_yml_compactListContent(VecValue & parent, PFileParser & parser, PYmlParserData & data){ | |
244 |
3/3✓ Branch 2 taken 1580 times.
✓ Branch 5 taken 1574 times.
✓ Branch 6 taken 6 times.
|
1580 | if(!parser.isMatch("[")){return false;} |
245 | 6 | parse_yml_playCurrentText(data); | |
246 | 6 | VecVecValue & listValue = data.currentlyParsedKeyValue->getVecChild(); | |
247 | |||
248 |
9/13✓ Branch 1 taken 19 times.
✓ Branch 3 taken 19 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 19 times.
✓ Branch 9 taken 19 times.
✓ Branch 11 taken 13 times.
✓ Branch 12 taken 6 times.
✓ Branch 13 taken 19 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 13 times.
✓ Branch 17 taken 6 times.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
|
19 | while(parse_yml_isParse(data) && !parser.isMatch("]")){ |
249 |
1/1✓ Branch 1 taken 13 times.
|
13 | PString tmpStr(""); |
250 |
3/3✓ Branch 1 taken 13 times.
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 11 times.
|
13 | if(parse_yml_string(tmpStr, parser)){ |
251 |
1/1✓ Branch 1 taken 2 times.
|
2 | VecValue vecTmp; |
252 |
1/1✓ Branch 1 taken 2 times.
|
2 | vecTmp.setValue(tmpStr); |
253 |
1/1✓ Branch 1 taken 2 times.
|
2 | listValue.push_back(vecTmp); |
254 | 2 | }else{ | |
255 |
15/21✓ Branch 1 taken 117 times.
✓ Branch 3 taken 117 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 117 times.
✓ Branch 9 taken 117 times.
✓ Branch 11 taken 111 times.
✓ Branch 12 taken 6 times.
✓ Branch 14 taken 111 times.
✓ Branch 17 taken 111 times.
✓ Branch 19 taken 106 times.
✓ Branch 20 taken 5 times.
✓ Branch 21 taken 111 times.
✓ Branch 22 taken 6 times.
✓ Branch 24 taken 117 times.
✗ Branch 25 not taken.
✓ Branch 27 taken 106 times.
✓ Branch 28 taken 11 times.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
✗ Branch 32 not taken.
✗ Branch 33 not taken.
|
117 | while(parse_yml_isParse(data) && !parser.isMatchRewind("]") && !parser.isMatchRewind(",")){ |
256 |
1/1✓ Branch 1 taken 106 times.
|
106 | parse_yml_incrementCurrentChar(parser, data); |
257 | } | ||
258 |
1/1✓ Branch 1 taken 11 times.
|
11 | VecValue vecTmp; |
259 |
3/3✓ Branch 1 taken 11 times.
✓ Branch 4 taken 11 times.
✓ Branch 7 taken 11 times.
|
11 | vecTmp.setValue(data.currentText.eraseFirstChar(" \t\n")); |
260 |
1/1✓ Branch 1 taken 11 times.
|
11 | listValue.push_back(vecTmp); |
261 |
1/1✓ Branch 1 taken 11 times.
|
11 | data.currentText = ""; |
262 | 11 | } | |
263 |
11/18✓ Branch 1 taken 13 times.
✓ Branch 4 taken 13 times.
✓ Branch 6 taken 6 times.
✓ Branch 7 taken 7 times.
✓ Branch 9 taken 6 times.
✓ Branch 12 taken 6 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 6 times.
✓ Branch 16 taken 6 times.
✓ Branch 17 taken 7 times.
✓ Branch 19 taken 13 times.
✗ Branch 20 not taken.
✗ Branch 22 not taken.
✓ Branch 23 taken 13 times.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
|
13 | if(!parser.isMatch(",") && !parser.isMatchRewind("]")){ |
264 | ✗ | parse_yml_stopParsing(data); | |
265 | ✗ | std::cerr << "parser_yml_fileParser : error at " << parser.getLocation() << std::endl; | |
266 | ✗ | std::cerr << "\tunexpected token '"<<parser.getNextToken()<<"'" << std::endl; | |
267 | ✗ | std::cerr << "\texpect token ',' or ']'" << std::endl; | |
268 | ✗ | return true; | |
269 | } | ||
270 |
1/2✓ Branch 1 taken 13 times.
✗ Branch 2 not taken.
|
13 | } |
271 | 6 | return true; | |
272 | } | ||
273 | |||
274 | ///Parse dico content | ||
275 | /** @param[out] parent : parent VecValue | ||
276 | * @param[out] parser : PFileParser to be used | ||
277 | * @param[out] data : extra parser data to be used | ||
278 | */ | ||
279 | 1573 | bool parse_yml_listContent(VecValue & parent, PFileParser & parser, PYmlParserData & data){ | |
280 |
4/4✓ Branch 1 taken 1573 times.
✓ Branch 4 taken 1573 times.
✓ Branch 7 taken 1545 times.
✓ Branch 8 taken 28 times.
|
1573 | if(!parser.isMatch("- ")){return false;} //There is no extra space, this is exactly the syntax |
281 |
1/1✓ Branch 1 taken 28 times.
|
28 | size_t currentIndentation(parser.getColumn() - 1lu); |
282 |
1/1✓ Branch 1 taken 28 times.
|
28 | parse_yml_playCurrentText(data); |
283 |
1/1✓ Branch 1 taken 28 times.
|
28 | VecValue dashList; |
284 |
2/2✓ Branch 1 taken 28 times.
✓ Branch 4 taken 28 times.
|
28 | dashList.setKey(""); |
285 |
1/1✓ Branch 1 taken 28 times.
|
28 | dashList.setType(VecValueType::LIST_ITEM); |
286 |
1/1✓ Branch 1 taken 28 times.
|
28 | dashList.setIndentation(currentIndentation); |
287 | // std::cerr << "parse_yml_listContent : Add LIST_ITEM at " << parser.getLocation() << std::endl; | ||
288 | //Add the dico into its parent and get back the pointer of the current dico we want to fill | ||
289 |
1/1✓ Branch 1 taken 28 times.
|
28 | VecValue * ptrDashList = addChildToParentVecValueAddListItem(parent, data.vecIndentation, data.compactMode, dashList, currentIndentation); |
290 | |||
291 | //Update indentation to be used to fill the VecValue in the current dico | ||
292 |
1/1✓ Branch 1 taken 28 times.
|
28 | parse_yml_updateIndentation(data.vecIndentation, currentIndentation); |
293 | |||
294 | ///Let's update the current VecValue to be completd with values and lists | ||
295 | 28 | data.currentlyParsedKeyValue = ptrDashList; | |
296 | 28 | return true; | |
297 | 28 | } | |
298 | |||
299 | ///Parse all yml features | ||
300 | /** @param[out] parent : parent VecValue | ||
301 | * @param[out] parser : PFileParser to be used | ||
302 | * @param[out] data : extra parser data to be used | ||
303 | */ | ||
304 | 1582 | bool parse_yml_all(VecValue & parent, PFileParser & parser, PYmlParserData & data){ | |
305 |
4/4✓ Branch 2 taken 1582 times.
✓ Branch 5 taken 2 times.
✓ Branch 6 taken 1580 times.
✓ Branch 9 taken 2 times.
|
1582 | if(parser.isMatch("#")){parser.getUntilKeyWithoutPatern("\n");} //Skip the comment |
306 |
2/2✓ Branch 1 taken 1574 times.
✓ Branch 2 taken 6 times.
|
1580 | else if(parse_yml_compactListContent(parent, parser, data)){} |
307 |
2/2✓ Branch 1 taken 1573 times.
✓ Branch 2 taken 1 times.
|
1574 | else if(parse_yml_compactDicoContent(parent, parser, data)){} |
308 |
2/2✓ Branch 1 taken 1545 times.
✓ Branch 2 taken 28 times.
|
1573 | else if(parse_yml_listContent(parent, parser, data)){} |
309 |
2/2✓ Branch 1 taken 1413 times.
✓ Branch 2 taken 132 times.
|
1545 | else if(parse_yml_dicoContent(parent, parser, data)){} |
310 |
2/2✓ Branch 1 taken 1359 times.
✓ Branch 2 taken 54 times.
|
1413 | else if(parse_yml_stringValue(parser, data)){} |
311 | else{ | ||
312 | 1359 | parse_yml_incrementCurrentChar(parser, data); | |
313 | } | ||
314 | 1582 | return true; | |
315 | } | ||
316 | |||
317 | ///Parse a yml file and update the given VecValue | ||
318 | /** @param[out] dico : dictionnary of values | ||
319 | * @param parser : PFileParser to be used | ||
320 | * @return true on success, false otherwise | ||
321 | */ | ||
322 | 12 | bool parser_yml_fileParser(VecValue & dico, PFileParser & parser){ | |
323 |
1/1✓ Branch 1 taken 12 times.
|
12 | PYmlParserData data(default_PYmlParserData()); |
324 | 12 | data.currentlyParsedKeyValue = &dico; | |
325 |
2/2✓ Branch 1 taken 12 times.
✓ Branch 4 taken 12 times.
|
12 | parser.getStrComposedOf(" \t\n"); //Skip all blank characters |
326 |
7/8✓ Branch 1 taken 1581 times.
✓ Branch 3 taken 1569 times.
✓ Branch 4 taken 12 times.
✓ Branch 6 taken 1569 times.
✓ Branch 8 taken 1569 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 1569 times.
✓ Branch 11 taken 12 times.
|
1581 | while(!parser.isEndOfFile() && parse_yml_isParse(data)){ |
327 |
2/3✓ Branch 1 taken 1569 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1569 times.
|
1569 | if(!parse_yml_all(dico, parser, data)){ |
328 | ✗ | std::cerr << "parser_yml_fileParser : error at " << parser.getLocation() << std::endl; | |
329 | ✗ | std::cerr << "\tunexpected token '"<<parser.getNextToken()<<"'" << std::endl; | |
330 | ✗ | parse_yml_stopParsing(data); | |
331 | } | ||
332 | } | ||
333 |
1/1✓ Branch 1 taken 12 times.
|
12 | parse_yml_playCurrentText(data); |
334 | 12 | return data.isRun; | |
335 | 12 | } | |
336 | |||
337 | |||
338 | ///Parse a yml file and update the given DicoValue | ||
339 | /** @param[out] dico : dictionnary of values | ||
340 | * @param fileName : name of the file to be parsed | ||
341 | * @return true on success, false otherwise | ||
342 | */ | ||
343 | 13 | bool parser_yml(DicoValue & dico, const PPath & fileName){ | |
344 |
1/1✓ Branch 1 taken 13 times.
|
13 | PFileParser parser; |
345 |
2/2✓ Branch 1 taken 13 times.
✓ Branch 4 taken 13 times.
|
13 | parser.setWhiteSpace(""); |
346 |
2/2✓ Branch 1 taken 13 times.
✓ Branch 4 taken 13 times.
|
13 | parser.setSeparator(":-'\",{}[]>|#"); |
347 |
1/1✓ Branch 1 taken 13 times.
|
13 | parser.setEscapeChar('\\'); |
348 |
3/3✓ Branch 1 taken 13 times.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 12 times.
|
13 | if(!parser.open(fileName)){ |
349 |
4/4✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 7 taken 1 times.
✓ Branch 10 taken 1 times.
|
1 | std::cerr << "parser_yml : cannot open file '"<<fileName<<"'" << std::endl; |
350 | 1 | return false; | |
351 | } | ||
352 |
1/1✓ Branch 1 taken 12 times.
|
12 | VecValue vecValue; |
353 |
1/1✓ Branch 1 taken 12 times.
|
12 | vecValue.setType(VecValueType::MAIN); |
354 |
3/3✓ Branch 1 taken 12 times.
✓ Branch 4 taken 12 times.
✓ Branch 7 taken 12 times.
|
12 | vecValue.setIndentation(parser.getLocation().getColumn()); |
355 |
1/1✓ Branch 1 taken 12 times.
|
12 | bool b(parser_yml_fileParser(vecValue, parser)); |
356 |
1/1✓ Branch 1 taken 12 times.
|
12 | vecValueToDicoValue(dico, vecValue); |
357 | 12 | return b; | |
358 | 13 | } | |
359 | |||
360 | |||
361 |