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 | 9 | PYmlParserData default_PYmlParserData(){ | |
32 | 9 | PYmlParserData data; | |
33 | 9 | data.isRun = true; | |
34 | 9 | data.compactMode = false; | |
35 | 9 | data.currentLine = 1lu; | |
36 |
1/1✓ Branch 0 (3→4) taken 9 times.
|
9 | data.currentText = ""; |
37 | 9 | data.currentlyParsedKeyValue = NULL; | |
38 | 9 | 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 | 1381 | bool parse_yml_isParse(const PYmlParserData & data){ | |
54 | 1381 | 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 | 113 | void parse_yml_updateIndentation(std::vector<size_t> & vecIndentation, size_t currentIndentation){ | |
62 |
5/6✓ Branch 0 (2→3) taken 74 times.
✓ Branch 1 (2→5) taken 39 times.
✗ Branch 2 (4→5) not taken.
✓ Branch 3 (4→6) taken 74 times.
✓ Branch 4 (7→8) taken 39 times.
✓ Branch 5 (7→11) taken 74 times.
|
113 | if(currentIndentation == 0lu || vecIndentation.size() == 0lu){ //If there is no indentation |
63 | 39 | vecIndentation.clear(); | |
64 |
1/1✓ Branch 0 (9→10) taken 39 times.
|
39 | vecIndentation.push_back(currentIndentation); |
65 | 39 | return; | |
66 | } | ||
67 | 74 | std::vector<size_t> vecOutIndentation; | |
68 | 74 | std::vector<size_t>::const_iterator it(vecIndentation.begin()); | |
69 | 74 | bool isCurrentLower(true); | |
70 |
6/6✓ Branch 0 (26→27) taken 189 times.
✓ Branch 1 (26→36) taken 42 times.
✓ Branch 2 (34→35) taken 157 times.
✓ Branch 3 (34→36) taken 32 times.
✓ Branch 4 (37→17) taken 157 times.
✓ Branch 5 (37→38) taken 74 times.
|
420 | while(isCurrentLower && it != vecIndentation.end()){ //Get previous indentation until the current one |
71 | 157 | isCurrentLower = *it < currentIndentation; | |
72 |
2/2✓ Branch 0 (19→20) taken 115 times.
✓ Branch 1 (19→23) taken 42 times.
|
157 | if(isCurrentLower){ |
73 |
1/1✓ Branch 0 (22→23) taken 115 times.
|
115 | vecOutIndentation.push_back(*it); |
74 | } | ||
75 | ++it; | ||
76 | } | ||
77 |
1/1✓ Branch 0 (38→39) taken 74 times.
|
74 | vecOutIndentation.push_back(currentIndentation); //Add the current indentation |
78 |
1/1✓ Branch 0 (39→40) taken 74 times.
|
74 | vecIndentation = vecOutIndentation; |
79 | 74 | } | |
80 | |||
81 | ///Increment the current character | ||
82 | /** @param[out] parser : parser to be used | ||
83 | * @param data : parsing data | ||
84 | */ | ||
85 | 1200 | 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 | 1200 | char ch = parser.getCurrentCh(); | |
88 | 1200 | data.currentText += ch; | |
89 | 1200 | parser.getNextChar(); | |
90 | 1200 | } | |
91 | |||
92 | ///Play the current parsed text | ||
93 | /** @param[out] data : parsing data | ||
94 | */ | ||
95 | 130 | void parse_yml_playCurrentText(PYmlParserData & data){ | |
96 |
2/2✓ Branch 0 (2→3) taken 130 times.
✓ Branch 2 (3→4) taken 130 times.
|
130 | PString value(data.currentText.eraseFirstLastChar(" \t\n")); |
97 | |||
98 |
6/7✓ Branch 0 (5→6) taken 130 times.
✗ Branch 1 (5→9) not taken.
✓ Branch 2 (6→7) taken 130 times.
✓ Branch 4 (7→8) taken 47 times.
✓ Branch 5 (7→9) taken 83 times.
✓ Branch 6 (10→11) taken 47 times.
✓ Branch 7 (10→12) taken 83 times.
|
130 | if(data.currentlyParsedKeyValue != NULL && value != ""){ |
99 |
1/1✓ Branch 0 (11→12) taken 47 times.
|
47 | data.currentlyParsedKeyValue->setValue(value); |
100 | } | ||
101 |
1/1✓ Branch 0 (12→13) taken 130 times.
|
130 | data.currentText = ""; |
102 | 130 | } | |
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 | 1213 | bool parse_yml_key(PString & key, size_t & keyIndentation, PFileParser & parser){ | |
110 |
1/1✓ Branch 0 (2→3) taken 1213 times.
|
1213 | parser.pushPosition(); |
111 |
2/2✓ Branch 0 (3→4) taken 1213 times.
✓ Branch 2 (4→5) taken 1213 times.
|
1213 | PString possibleKey(parser.getStrComposedOf("_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")); |
112 |
11/13✓ Branch 0 (6→7) taken 1213 times.
✓ Branch 2 (7→8) taken 387 times.
✓ Branch 3 (7→12) taken 826 times.
✓ Branch 4 (8→9) taken 387 times.
✓ Branch 6 (9→10) taken 387 times.
✓ Branch 8 (10→11) taken 91 times.
✓ Branch 9 (10→12) taken 296 times.
✓ Branch 10 (13→14) taken 387 times.
✓ Branch 11 (13→15) taken 826 times.
✓ Branch 12 (15→16) taken 91 times.
✓ Branch 13 (15→20) taken 1122 times.
✗ Branch 14 (28→29) not taken.
✗ Branch 15 (28→30) not taken.
|
1213 | if(possibleKey != "" && parser.isMatch(":")){ |
113 |
1/1✓ Branch 0 (16→17) taken 91 times.
|
91 | key = possibleKey; |
114 |
1/1✓ Branch 0 (17→18) taken 91 times.
|
91 | keyIndentation = parser.getColumn() - possibleKey.size() - 1lu; |
115 | 91 | return true; | |
116 | } | ||
117 |
1/1✓ Branch 0 (20→21) taken 1122 times.
|
1122 | parser.popPosition(); |
118 | 1122 | return false; | |
119 | 1213 | } | |
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 |
4/4✓ Branch 0 (2→3) taken 13 times.
✓ Branch 2 (3→4) taken 13 times.
✓ Branch 4 (5→6) taken 1 times.
✓ Branch 5 (5→14) taken 12 times.
|
13 | if(parser.isMatch("\"")){ |
127 |
4/4✓ Branch 0 (6→7) taken 1 times.
✓ Branch 2 (7→8) taken 1 times.
✓ Branch 4 (8→9) taken 1 times.
✓ Branch 6 (9→10) taken 1 times.
|
1 | str = "\"" + parser.getUntilKey("\""); |
128 |
4/4✓ Branch 0 (14→15) taken 12 times.
✓ Branch 2 (15→16) taken 12 times.
✓ Branch 4 (17→18) taken 1 times.
✓ Branch 5 (17→26) taken 11 times.
|
12 | }else if(parser.isMatch("'")){ |
129 |
4/4✓ Branch 0 (18→19) taken 1 times.
✓ Branch 2 (19→20) taken 1 times.
✓ Branch 4 (20→21) taken 1 times.
✓ Branch 6 (21→22) 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 | 28 | void parse_yml_dicoSetValue(VecValue * vecVal, const PString & value){ | |
141 |
1/2✗ Branch 0 (2→3) not taken.
✓ Branch 1 (2→4) taken 28 times.
|
28 | if(vecVal == NULL){return;} |
142 | 28 | vecVal->setValue(value); | |
143 |
1/1✓ Branch 0 (5→6) taken 28 times.
|
28 | 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 | 1122 | bool parse_yml_stringValue(PFileParser & parser, PYmlParserData & data){ | |
151 |
4/4✓ Branch 0 (2→3) taken 1122 times.
✓ Branch 2 (3→4) taken 1122 times.
✓ Branch 4 (5→6) taken 5 times.
✓ Branch 5 (5→16) taken 1117 times.
|
1122 | if(parser.isMatch("\'")){ |
152 |
4/4✓ Branch 0 (6→7) taken 5 times.
✓ Branch 2 (7→8) taken 5 times.
✓ Branch 4 (8→9) taken 5 times.
✓ Branch 6 (9→10) taken 5 times.
|
5 | PString str("\'" + parser.getUntilKey("\'")); |
153 |
1/1✓ Branch 0 (13→14) taken 5 times.
|
5 | parse_yml_dicoSetValue(data.currentlyParsedKeyValue, str); |
154 |
4/4✓ Branch 0 (16→17) taken 1117 times.
✓ Branch 2 (17→18) taken 1117 times.
✓ Branch 4 (19→20) taken 23 times.
✓ Branch 5 (19→30) taken 1094 times.
|
1122 | }else if(parser.isMatch("\"")){ |
155 |
4/4✓ Branch 0 (20→21) taken 23 times.
✓ Branch 2 (21→22) taken 23 times.
✓ Branch 4 (22→23) taken 23 times.
✓ Branch 6 (23→24) taken 23 times.
|
23 | PString str("\"" + parser.getUntilKey("\"")); |
156 |
1/1✓ Branch 0 (27→28) taken 23 times.
|
23 | parse_yml_dicoSetValue(data.currentlyParsedKeyValue, str); |
157 | 23 | }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 | 1094 | return false; | |
165 | // } | ||
166 | } | ||
167 | 28 | 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 | 1236 | bool parse_yml_compactDicoContent(VecValue & parent, PFileParser & parser, PYmlParserData & data){ | |
176 |
5/5✓ Branch 0 (2→3) taken 1236 times.
✓ Branch 2 (3→4) taken 1236 times.
✓ Branch 4 (4→5) taken 1236 times.
✓ Branch 6 (7→8) taken 1235 times.
✓ Branch 7 (7→9) taken 1 times.
|
1236 | if(!parser.isMatch("{", "$§_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/*+-.")){return false;} |
177 |
1/1✓ Branch 0 (9→10) taken 1 times.
|
1 | std::vector<size_t> saveVecIndentation = data.vecIndentation; |
178 |
1/1✓ Branch 0 (10→11) 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 0 (12→13) taken 1 times.
|
1 | data.vecIndentation.push_back(0lu); |
185 |
2/2✓ Branch 0 (13→14) taken 1 times.
✓ Branch 2 (14→15) taken 1 times.
|
1 | parser.getStrComposedOf(" \t\n"); //Skip all blank characters |
186 |
9/13✓ Branch 0 (36→37) taken 14 times.
✓ Branch 2 (37→38) taken 14 times.
✗ Branch 3 (37→42) not taken.
✓ Branch 4 (38→39) taken 14 times.
✓ Branch 6 (39→40) taken 14 times.
✓ Branch 8 (40→41) taken 13 times.
✓ Branch 9 (40→42) taken 1 times.
✓ Branch 10 (43→44) taken 14 times.
✗ Branch 11 (43→45) not taken.
✓ Branch 12 (45→18) taken 13 times.
✓ Branch 13 (45→46) taken 1 times.
✗ Branch 14 (71→72) not taken.
✗ Branch 15 (71→73) not taken.
|
14 | while(parse_yml_isParse(data) && !parser.isMatch("}")){ |
187 |
2/3✓ Branch 0 (18→19) taken 13 times.
✗ Branch 2 (19→20) not taken.
✓ Branch 3 (19→32) 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 0 (32→33) taken 13 times.
✓ Branch 2 (33→34) taken 13 times.
|
13 | parser.isMatch(","); //Skip comma if there is one |
193 | } | ||
194 |
1/1✓ Branch 0 (46→47) taken 1 times.
|
1 | parse_yml_playCurrentText(data); |
195 |
1/1✓ Branch 0 (47→48) 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 | 1213 | bool parse_yml_dicoContent(VecValue & parent, PFileParser & parser, PYmlParserData & data){ | |
206 |
1/1✓ Branch 0 (2→3) taken 1213 times.
|
1213 | parser.pushPosition(); |
207 |
1/1✓ Branch 0 (3→4) taken 1213 times.
|
1213 | PString keyName(""); |
208 | 1213 | size_t keyIndentation(0lu); | |
209 |
3/3✓ Branch 0 (4→5) taken 1213 times.
✓ Branch 2 (5→6) taken 1122 times.
✓ Branch 3 (5→8) taken 91 times.
|
1213 | if(!parse_yml_key(keyName, keyIndentation, parser)){ //Check if there is a key |
210 |
1/1✓ Branch 0 (6→7) taken 1122 times.
|
1122 | parser.popPosition(); //This is not a key |
211 | 1122 | return false; | |
212 | } | ||
213 |
1/1✓ Branch 0 (8→9) taken 91 times.
|
91 | parse_yml_playCurrentText(data); |
214 |
1/1✓ Branch 0 (9→10) taken 91 times.
|
91 | VecValue dico; |
215 |
1/1✓ Branch 0 (10→11) taken 91 times.
|
91 | dico.setKey(keyName); |
216 |
1/1✓ Branch 0 (11→12) taken 91 times.
|
91 | dico.setType(VecValueType::KEY); |
217 |
2/2✓ Branch 0 (12→13) taken 2 times.
✓ Branch 1 (12→14) taken 89 times.
|
91 | if(data.compactMode){ |
218 | 2 | keyIndentation = -1lu; | |
219 | } | ||
220 |
1/1✓ Branch 0 (14→15) taken 91 times.
|
91 | 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 0 (15→16) taken 91 times.
|
91 | 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 0 (16→17) taken 91 times.
|
91 | parse_yml_updateIndentation(data.vecIndentation, keyIndentation); |
226 | |||
227 | ///Let's update the current VecValue to be completd with values and lists | ||
228 | 91 | 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 | 91 | return true; | |
236 | 1213 | } | |
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 | 1242 | bool parse_yml_compactListContent(VecValue & parent, PFileParser & parser, PYmlParserData & data){ | |
244 |
4/4✓ Branch 0 (2→3) taken 1242 times.
✓ Branch 2 (3→4) taken 1242 times.
✓ Branch 4 (5→6) taken 1236 times.
✓ Branch 5 (5→7) taken 6 times.
|
1242 | if(!parser.isMatch("[")){return false;} |
245 | 6 | parse_yml_playCurrentText(data); | |
246 | 6 | VecVecValue & listValue = data.currentlyParsedKeyValue->getVecChild(); | |
247 | |||
248 |
9/13✓ Branch 0 (80→81) taken 19 times.
✓ Branch 2 (81→82) taken 19 times.
✗ Branch 3 (81→86) not taken.
✓ Branch 4 (82→83) taken 19 times.
✓ Branch 6 (83→84) taken 19 times.
✓ Branch 8 (84→85) taken 13 times.
✓ Branch 9 (84→86) taken 6 times.
✓ Branch 10 (87→88) taken 19 times.
✗ Branch 11 (87→89) not taken.
✓ Branch 12 (89→10) taken 13 times.
✓ Branch 13 (89→90) taken 6 times.
✗ Branch 14 (132→133) not taken.
✗ Branch 15 (132→134) not taken.
|
19 | while(parse_yml_isParse(data) && !parser.isMatch("]")){ |
249 |
1/1✓ Branch 0 (10→11) taken 13 times.
|
13 | PString tmpStr(""); |
250 |
3/3✓ Branch 0 (11→12) taken 13 times.
✓ Branch 2 (12→13) taken 2 times.
✓ Branch 3 (12→18) taken 11 times.
|
13 | if(parse_yml_string(tmpStr, parser)){ |
251 |
1/1✓ Branch 0 (13→14) taken 2 times.
|
2 | VecValue vecTmp; |
252 |
1/1✓ Branch 0 (14→15) taken 2 times.
|
2 | vecTmp.setValue(tmpStr); |
253 |
1/1✓ Branch 0 (15→16) taken 2 times.
|
2 | listValue.push_back(vecTmp); |
254 | 2 | }else{ | |
255 |
15/21✓ Branch 0 (21→22) taken 117 times.
✓ Branch 2 (22→23) taken 117 times.
✗ Branch 3 (22→30) not taken.
✓ Branch 4 (23→24) taken 117 times.
✓ Branch 6 (24→25) taken 117 times.
✓ Branch 8 (25→26) taken 111 times.
✓ Branch 9 (25→30) taken 6 times.
✓ Branch 10 (26→27) taken 111 times.
✓ Branch 12 (27→28) taken 111 times.
✓ Branch 14 (28→29) taken 106 times.
✓ Branch 15 (28→30) taken 5 times.
✓ Branch 16 (31→32) taken 111 times.
✓ Branch 17 (31→33) taken 6 times.
✓ Branch 18 (33→34) taken 117 times.
✗ Branch 19 (33→35) not taken.
✓ Branch 20 (35→19) taken 106 times.
✓ Branch 21 (35→36) taken 11 times.
✗ Branch 22 (98→99) not taken.
✗ Branch 23 (98→100) not taken.
✗ Branch 24 (102→103) not taken.
✗ Branch 25 (102→104) not taken.
|
117 | while(parse_yml_isParse(data) && !parser.isMatchRewind("]") && !parser.isMatchRewind(",")){ |
256 |
1/1✓ Branch 0 (19→20) taken 106 times.
|
106 | parse_yml_incrementCurrentChar(parser, data); |
257 | } | ||
258 |
1/1✓ Branch 0 (36→37) taken 11 times.
|
11 | VecValue vecTmp; |
259 |
3/3✓ Branch 0 (37→38) taken 11 times.
✓ Branch 2 (38→39) taken 11 times.
✓ Branch 4 (39→40) taken 11 times.
|
11 | vecTmp.setValue(data.currentText.eraseFirstChar(" \t\n")); |
260 |
1/1✓ Branch 0 (42→43) taken 11 times.
|
11 | listValue.push_back(vecTmp); |
261 |
1/1✓ Branch 0 (43→44) taken 11 times.
|
11 | data.currentText = ""; |
262 | 11 | } | |
263 |
11/18✓ Branch 0 (46→47) taken 13 times.
✓ Branch 2 (47→48) taken 13 times.
✓ Branch 4 (48→49) taken 6 times.
✓ Branch 5 (48→53) taken 7 times.
✓ Branch 6 (49→50) taken 6 times.
✓ Branch 8 (50→51) taken 6 times.
✗ Branch 10 (51→52) not taken.
✓ Branch 11 (51→53) taken 6 times.
✓ Branch 12 (54→55) taken 6 times.
✓ Branch 13 (54→56) taken 7 times.
✓ Branch 14 (56→57) taken 13 times.
✗ Branch 15 (56→58) not taken.
✗ Branch 16 (58→59) not taken.
✓ Branch 17 (58→74) taken 13 times.
✗ Branch 18 (115→116) not taken.
✗ Branch 19 (115→117) not taken.
✗ Branch 20 (119→120) not taken.
✗ Branch 21 (119→121) 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 | 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 | 1235 | bool parse_yml_listContent(VecValue & parent, PFileParser & parser, PYmlParserData & data){ | |
280 |
4/4✓ Branch 0 (2→3) taken 1235 times.
✓ Branch 2 (3→4) taken 1235 times.
✓ Branch 4 (5→6) taken 1213 times.
✓ Branch 5 (5→7) taken 22 times.
|
1235 | if(!parser.isMatch("- ")){return false;} //There is no extra space, this is exactly the syntax |
281 |
1/1✓ Branch 0 (7→8) taken 22 times.
|
22 | size_t currentIndentation(parser.getColumn() - 1lu); |
282 |
1/1✓ Branch 0 (8→9) taken 22 times.
|
22 | parse_yml_playCurrentText(data); |
283 |
1/1✓ Branch 0 (9→10) taken 22 times.
|
22 | VecValue dashList; |
284 |
2/2✓ Branch 0 (10→11) taken 22 times.
✓ Branch 2 (11→12) taken 22 times.
|
22 | dashList.setKey(""); |
285 |
1/1✓ Branch 0 (13→14) taken 22 times.
|
22 | dashList.setType(VecValueType::LIST_ITEM); |
286 |
1/1✓ Branch 0 (14→15) taken 22 times.
|
22 | 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 0 (15→16) taken 22 times.
|
22 | 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 0 (16→17) taken 22 times.
|
22 | parse_yml_updateIndentation(data.vecIndentation, currentIndentation); |
293 | |||
294 | ///Let's update the current VecValue to be completd with values and lists | ||
295 | 22 | data.currentlyParsedKeyValue = ptrDashList; | |
296 | 22 | return true; | |
297 | 22 | } | |
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 | 1244 | bool parse_yml_all(VecValue & parent, PFileParser & parser, PYmlParserData & data){ | |
305 |
6/6✓ Branch 0 (2→3) taken 1244 times.
✓ Branch 2 (3→4) taken 1244 times.
✓ Branch 4 (5→6) taken 2 times.
✓ Branch 5 (5→11) taken 1242 times.
✓ Branch 6 (6→7) taken 2 times.
✓ Branch 8 (7→8) taken 2 times.
|
1244 | if(parser.isMatch("#")){parser.getUntilKeyWithoutPatern("\n");} //Skip the comment |
306 |
2/2✓ Branch 0 (12→13) taken 1236 times.
✓ Branch 1 (12→22) taken 6 times.
|
1242 | else if(parse_yml_compactListContent(parent, parser, data)){} |
307 |
2/2✓ Branch 0 (14→15) taken 1235 times.
✓ Branch 1 (14→22) taken 1 times.
|
1236 | else if(parse_yml_compactDicoContent(parent, parser, data)){} |
308 |
2/2✓ Branch 0 (16→17) taken 1213 times.
✓ Branch 1 (16→22) taken 22 times.
|
1235 | else if(parse_yml_listContent(parent, parser, data)){} |
309 |
2/2✓ Branch 0 (18→19) taken 1122 times.
✓ Branch 1 (18→22) taken 91 times.
|
1213 | else if(parse_yml_dicoContent(parent, parser, data)){} |
310 |
2/2✓ Branch 0 (20→21) taken 1094 times.
✓ Branch 1 (20→22) taken 28 times.
|
1122 | else if(parse_yml_stringValue(parser, data)){} |
311 | else{ | ||
312 | 1094 | parse_yml_incrementCurrentChar(parser, data); | |
313 | } | ||
314 | 1244 | 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 | 9 | bool parser_yml_fileParser(VecValue & dico, PFileParser & parser){ | |
323 |
1/1✓ Branch 0 (2→3) taken 9 times.
|
9 | PYmlParserData data(default_PYmlParserData()); |
324 | 9 | data.currentlyParsedKeyValue = &dico; | |
325 |
2/2✓ Branch 0 (3→4) taken 9 times.
✓ Branch 2 (4→5) taken 9 times.
|
9 | parser.getStrComposedOf(" \t\n"); //Skip all blank characters |
326 |
7/8✓ Branch 0 (25→26) taken 1240 times.
✓ Branch 2 (26→27) taken 1231 times.
✓ Branch 3 (26→30) taken 9 times.
✓ Branch 4 (27→28) taken 1231 times.
✓ Branch 6 (28→29) taken 1231 times.
✗ Branch 7 (28→30) not taken.
✓ Branch 8 (31→8) taken 1231 times.
✓ Branch 9 (31→32) taken 9 times.
|
1249 | while(!parser.isEndOfFile() && parse_yml_isParse(data)){ |
327 |
2/3✓ Branch 0 (8→9) taken 1231 times.
✓ Branch 2 (9→10) taken 1231 times.
✗ Branch 3 (9→11) not taken.
|
1231 | 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 0 (32→33) taken 9 times.
|
9 | parse_yml_playCurrentText(data); |
334 | 9 | return data.isRun; | |
335 | 9 | } | |
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 | 9 | bool parser_yml(DicoValue & dico, const PPath & fileName){ | |
344 |
1/1✓ Branch 0 (2→3) taken 9 times.
|
9 | PFileParser parser; |
345 |
2/2✓ Branch 0 (3→4) taken 9 times.
✓ Branch 2 (4→5) taken 9 times.
|
9 | parser.setWhiteSpace(""); |
346 |
2/2✓ Branch 0 (6→7) taken 9 times.
✓ Branch 2 (7→8) taken 9 times.
|
9 | parser.setSeparator(":-'\",{}[]>|#"); |
347 |
1/1✓ Branch 0 (9→10) taken 9 times.
|
9 | parser.setEscapeChar('\\'); |
348 |
2/3✓ Branch 0 (10→11) taken 9 times.
✗ Branch 2 (11→12) not taken.
✓ Branch 3 (11→17) taken 9 times.
|
9 | if(!parser.open(fileName)){ |
349 | ✗ | std::cerr << "parser_yml : cannot open file '"<<fileName<<"'" << std::endl; | |
350 | ✗ | return false; | |
351 | } | ||
352 |
1/1✓ Branch 0 (17→18) taken 9 times.
|
9 | VecValue vecValue; |
353 |
1/1✓ Branch 0 (18→19) taken 9 times.
|
9 | vecValue.setType(VecValueType::MAIN); |
354 |
3/3✓ Branch 0 (19→20) taken 9 times.
✓ Branch 2 (20→21) taken 9 times.
✓ Branch 4 (21→22) taken 9 times.
|
9 | vecValue.setIndentation(parser.getLocation().getColumn()); |
355 |
1/1✓ Branch 0 (23→24) taken 9 times.
|
9 | bool b(parser_yml_fileParser(vecValue, parser)); |
356 |
1/1✓ Branch 0 (24→25) taken 9 times.
|
9 | vecValueToDicoValue(dico, vecValue); |
357 | 9 | return b; | |
358 | 9 | } | |
359 | |||
360 | |||
361 |