| 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 | 20 | PYmlParserData default_PYmlParserData(){ | |
| 32 | 20 | PYmlParserData data; | |
| 33 | 20 | data.isRun = true; | |
| 34 | 20 | data.compactMode = false; | |
| 35 | 20 | data.currentLine = 1lu; | |
| 36 |
1/1✓ Branch 0 (3→4) taken 20 times.
|
20 | data.currentText = ""; |
| 37 | 20 | data.currentlyParsedKeyValue = NULL; | |
| 38 | 20 | 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 | 2883 | bool parse_yml_isParse(const PYmlParserData & data){ | |
| 54 | 2883 | 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 | 246 | void parse_yml_updateIndentation(std::vector<size_t> & vecIndentation, size_t currentIndentation){ | |
| 62 |
5/6✓ Branch 0 (2→3) taken 162 times.
✓ Branch 1 (2→5) taken 84 times.
✗ Branch 2 (4→5) not taken.
✓ Branch 3 (4→6) taken 162 times.
✓ Branch 4 (7→8) taken 84 times.
✓ Branch 5 (7→11) taken 162 times.
|
246 | if(currentIndentation == 0lu || vecIndentation.size() == 0lu){ //If there is no indentation |
| 63 | 84 | vecIndentation.clear(); | |
| 64 |
1/1✓ Branch 0 (9→10) taken 84 times.
|
84 | vecIndentation.push_back(currentIndentation); |
| 65 | 84 | return; | |
| 66 | } | ||
| 67 | 162 | std::vector<size_t> vecOutIndentation; | |
| 68 | 162 | std::vector<size_t>::const_iterator it(vecIndentation.begin()); | |
| 69 | 162 | bool isCurrentLower(true); | |
| 70 |
6/6✓ Branch 0 (26→27) taken 406 times.
✓ Branch 1 (26→36) taken 94 times.
✓ Branch 2 (34→35) taken 338 times.
✓ Branch 3 (34→36) taken 68 times.
✓ Branch 4 (37→17) taken 338 times.
✓ Branch 5 (37→38) taken 162 times.
|
906 | while(isCurrentLower && it != vecIndentation.end()){ //Get previous indentation until the current one |
| 71 | 338 | isCurrentLower = *it < currentIndentation; | |
| 72 |
2/2✓ Branch 0 (19→20) taken 244 times.
✓ Branch 1 (19→23) taken 94 times.
|
338 | if(isCurrentLower){ |
| 73 |
1/1✓ Branch 0 (22→23) taken 244 times.
|
244 | vecOutIndentation.push_back(*it); |
| 74 | } | ||
| 75 | ++it; | ||
| 76 | } | ||
| 77 |
1/1✓ Branch 0 (38→39) taken 162 times.
|
162 | vecOutIndentation.push_back(currentIndentation); //Add the current indentation |
| 78 |
1/1✓ Branch 0 (39→40) taken 162 times.
|
162 | vecIndentation = vecOutIndentation; |
| 79 | 162 | } | |
| 80 | |||
| 81 | ///Increment the current character | ||
| 82 | /** @param[out] parser : parser to be used | ||
| 83 | * @param data : parsing data | ||
| 84 | */ | ||
| 85 | 2493 | 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 | 2493 | char ch = parser.getCurrentCh(); | |
| 88 | 2493 | data.currentText += ch; | |
| 89 | 2493 | parser.getNextChar(); | |
| 90 | 2493 | } | |
| 91 | |||
| 92 | ///Play the current parsed text | ||
| 93 | /** @param[out] data : parsing data | ||
| 94 | */ | ||
| 95 | 282 | void parse_yml_playCurrentText(PYmlParserData & data){ | |
| 96 |
2/2✓ Branch 0 (2→3) taken 282 times.
✓ Branch 2 (3→4) taken 282 times.
|
282 | PString value(data.currentText.eraseFirstLastChar(" \t\n")); |
| 97 | |||
| 98 |
6/7✓ Branch 0 (5→6) taken 282 times.
✗ Branch 1 (5→9) not taken.
✓ Branch 2 (6→7) taken 282 times.
✓ Branch 4 (7→8) taken 102 times.
✓ Branch 5 (7→9) taken 180 times.
✓ Branch 6 (10→11) taken 102 times.
✓ Branch 7 (10→12) taken 180 times.
|
282 | if(data.currentlyParsedKeyValue != NULL && value != ""){ |
| 99 |
1/1✓ Branch 0 (11→12) taken 102 times.
|
102 | data.currentlyParsedKeyValue->setValue(value); |
| 100 | } | ||
| 101 |
1/1✓ Branch 0 (12→13) taken 282 times.
|
282 | data.currentText = ""; |
| 102 | 282 | } | |
| 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 | 2533 | bool parse_yml_key(PString & key, size_t & keyIndentation, PFileParser & parser){ | |
| 110 |
1/1✓ Branch 0 (2→3) taken 2533 times.
|
2533 | parser.pushPosition(); |
| 111 |
2/2✓ Branch 0 (3→4) taken 2533 times.
✓ Branch 2 (4→5) taken 2533 times.
|
2533 | PString possibleKey(parser.getStrComposedOf("_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")); |
| 112 |
11/13✓ Branch 0 (6→7) taken 2533 times.
✓ Branch 2 (7→8) taken 838 times.
✓ Branch 3 (7→12) taken 1695 times.
✓ Branch 4 (8→9) taken 838 times.
✓ Branch 6 (9→10) taken 838 times.
✓ Branch 8 (10→11) taken 188 times.
✓ Branch 9 (10→12) taken 650 times.
✓ Branch 10 (13→14) taken 838 times.
✓ Branch 11 (13→15) taken 1695 times.
✓ Branch 12 (15→16) taken 188 times.
✓ Branch 13 (15→20) taken 2345 times.
✗ Branch 14 (28→29) not taken.
✗ Branch 15 (28→30) not taken.
|
2533 | if(possibleKey != "" && parser.isMatch(":")){ |
| 113 |
1/1✓ Branch 0 (16→17) taken 188 times.
|
188 | key = possibleKey; |
| 114 |
1/1✓ Branch 0 (17→18) taken 188 times.
|
188 | keyIndentation = parser.getColumn() - possibleKey.size() - 1lu; |
| 115 | 188 | return true; | |
| 116 | } | ||
| 117 |
1/1✓ Branch 0 (20→21) taken 2345 times.
|
2345 | parser.popPosition(); |
| 118 | 2345 | return false; | |
| 119 | 2533 | } | |
| 120 | |||
| 121 | ///Parse string value | ||
| 122 | /** @param[out] str : parsed string value | ||
| 123 | * @param[out] parser : PFileParser to be used | ||
| 124 | */ | ||
| 125 | 26 | bool parse_yml_string(PString & str, PFileParser & parser){ | |
| 126 |
4/4✓ Branch 0 (2→3) taken 26 times.
✓ Branch 2 (3→4) taken 26 times.
✓ Branch 4 (5→6) taken 2 times.
✓ Branch 5 (5→14) taken 24 times.
|
26 | if(parser.isMatch("\"")){ |
| 127 |
4/4✓ Branch 0 (6→7) taken 2 times.
✓ Branch 2 (7→8) taken 2 times.
✓ Branch 4 (8→9) taken 2 times.
✓ Branch 6 (9→10) taken 2 times.
|
2 | str = "\"" + parser.getUntilKey("\""); |
| 128 |
4/4✓ Branch 0 (14→15) taken 24 times.
✓ Branch 2 (15→16) taken 24 times.
✓ Branch 4 (17→18) taken 2 times.
✓ Branch 5 (17→26) taken 22 times.
|
24 | }else if(parser.isMatch("'")){ |
| 129 |
4/4✓ Branch 0 (18→19) taken 2 times.
✓ Branch 2 (19→20) taken 2 times.
✓ Branch 4 (20→21) taken 2 times.
✓ Branch 6 (21→22) taken 2 times.
|
2 | str = "'" + parser.getUntilKey("'"); |
| 130 | }else{ | ||
| 131 | 22 | return false; | |
| 132 | } | ||
| 133 | 4 | 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 | 64 | void parse_yml_dicoSetValue(VecValue * vecVal, const PString & value){ | |
| 141 |
1/2✗ Branch 0 (2→3) not taken.
✓ Branch 1 (2→4) taken 64 times.
|
64 | if(vecVal == NULL){return;} |
| 142 | 64 | vecVal->setValue(value); | |
| 143 |
1/1✓ Branch 0 (5→6) taken 64 times.
|
64 | 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 | 2345 | bool parse_yml_stringValue(PFileParser & parser, PYmlParserData & data){ | |
| 151 |
4/4✓ Branch 0 (2→3) taken 2345 times.
✓ Branch 2 (3→4) taken 2345 times.
✓ Branch 4 (5→6) taken 14 times.
✓ Branch 5 (5→16) taken 2331 times.
|
2345 | if(parser.isMatch("\'")){ |
| 152 |
4/4✓ Branch 0 (6→7) taken 14 times.
✓ Branch 2 (7→8) taken 14 times.
✓ Branch 4 (8→9) taken 14 times.
✓ Branch 6 (9→10) taken 14 times.
|
14 | PString str("\'" + parser.getUntilKey("\'")); |
| 153 |
1/1✓ Branch 0 (13→14) taken 14 times.
|
14 | parse_yml_dicoSetValue(data.currentlyParsedKeyValue, str); |
| 154 |
4/4✓ Branch 0 (16→17) taken 2331 times.
✓ Branch 2 (17→18) taken 2331 times.
✓ Branch 4 (19→20) taken 50 times.
✓ Branch 5 (19→30) taken 2281 times.
|
2345 | }else if(parser.isMatch("\"")){ |
| 155 |
4/4✓ Branch 0 (20→21) taken 50 times.
✓ Branch 2 (21→22) taken 50 times.
✓ Branch 4 (22→23) taken 50 times.
✓ Branch 6 (23→24) taken 50 times.
|
50 | PString str("\"" + parser.getUntilKey("\"")); |
| 156 |
1/1✓ Branch 0 (27→28) taken 50 times.
|
50 | parse_yml_dicoSetValue(data.currentlyParsedKeyValue, str); |
| 157 | 50 | }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 | 2281 | return false; | |
| 165 | // } | ||
| 166 | } | ||
| 167 | 64 | 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 | 2593 | bool parse_yml_compactDicoContent(VecValue & parent, PFileParser & parser, PYmlParserData & data){ | |
| 176 |
5/5✓ Branch 0 (2→3) taken 2593 times.
✓ Branch 2 (3→4) taken 2593 times.
✓ Branch 4 (4→5) taken 2593 times.
✓ Branch 6 (7→8) taken 2591 times.
✓ Branch 7 (7→9) taken 2 times.
|
2593 | if(!parser.isMatch("{", "$§_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/*+-.")){return false;} |
| 177 |
1/1✓ Branch 0 (9→10) taken 2 times.
|
2 | std::vector<size_t> saveVecIndentation = data.vecIndentation; |
| 178 |
1/1✓ Branch 0 (10→11) taken 2 times.
|
2 | parse_yml_playCurrentText(data); |
| 179 | 2 | bool oldMode = data.compactMode; | |
| 180 | 2 | data.compactMode = true; | |
| 181 | |||
| 182 | 2 | VecValue & dico = *data.currentlyParsedKeyValue; | |
| 183 | 2 | data.vecIndentation.clear(); | |
| 184 |
1/1✓ Branch 0 (12→13) taken 2 times.
|
2 | data.vecIndentation.push_back(0lu); |
| 185 |
2/2✓ Branch 0 (13→14) taken 2 times.
✓ Branch 2 (14→15) taken 2 times.
|
2 | parser.getStrComposedOf(" \t\n"); //Skip all blank characters |
| 186 |
9/13✓ Branch 0 (36→37) taken 28 times.
✓ Branch 2 (37→38) taken 28 times.
✗ Branch 3 (37→42) not taken.
✓ Branch 4 (38→39) taken 28 times.
✓ Branch 6 (39→40) taken 28 times.
✓ Branch 8 (40→41) taken 26 times.
✓ Branch 9 (40→42) taken 2 times.
✓ Branch 10 (43→44) taken 28 times.
✗ Branch 11 (43→45) not taken.
✓ Branch 12 (45→18) taken 26 times.
✓ Branch 13 (45→46) taken 2 times.
✗ Branch 14 (71→72) not taken.
✗ Branch 15 (71→73) not taken.
|
28 | while(parse_yml_isParse(data) && !parser.isMatch("}")){ |
| 187 |
2/3✓ Branch 0 (18→19) taken 26 times.
✗ Branch 2 (19→20) not taken.
✓ Branch 3 (19→32) taken 26 times.
|
26 | 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 26 times.
✓ Branch 2 (33→34) taken 26 times.
|
26 | parser.isMatch(","); //Skip comma if there is one |
| 193 | } | ||
| 194 |
1/1✓ Branch 0 (46→47) taken 2 times.
|
2 | parse_yml_playCurrentText(data); |
| 195 |
1/1✓ Branch 0 (47→48) taken 2 times.
|
2 | data.vecIndentation = saveVecIndentation; |
| 196 | 2 | data.compactMode = oldMode; | |
| 197 | 2 | return true; | |
| 198 | 2 | } | |
| 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 | 2533 | bool parse_yml_dicoContent(VecValue & parent, PFileParser & parser, PYmlParserData & data){ | |
| 206 |
1/1✓ Branch 0 (2→3) taken 2533 times.
|
2533 | parser.pushPosition(); |
| 207 |
1/1✓ Branch 0 (3→4) taken 2533 times.
|
2533 | PString keyName(""); |
| 208 | 2533 | size_t keyIndentation(0lu); | |
| 209 |
3/3✓ Branch 0 (4→5) taken 2533 times.
✓ Branch 2 (5→6) taken 2345 times.
✓ Branch 3 (5→8) taken 188 times.
|
2533 | if(!parse_yml_key(keyName, keyIndentation, parser)){ //Check if there is a key |
| 210 |
1/1✓ Branch 0 (6→7) taken 2345 times.
|
2345 | parser.popPosition(); //This is not a key |
| 211 | 2345 | return false; | |
| 212 | } | ||
| 213 |
1/1✓ Branch 0 (8→9) taken 188 times.
|
188 | parse_yml_playCurrentText(data); |
| 214 |
1/1✓ Branch 0 (9→10) taken 188 times.
|
188 | VecValue dico; |
| 215 |
1/1✓ Branch 0 (10→11) taken 188 times.
|
188 | dico.setKey(keyName); |
| 216 |
1/1✓ Branch 0 (11→12) taken 188 times.
|
188 | dico.setType(VecValueType::KEY); |
| 217 |
2/2✓ Branch 0 (12→13) taken 4 times.
✓ Branch 1 (12→14) taken 184 times.
|
188 | if(data.compactMode){ |
| 218 | 4 | keyIndentation = -1lu; | |
| 219 | } | ||
| 220 |
1/1✓ Branch 0 (14→15) taken 188 times.
|
188 | 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 188 times.
|
188 | 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 188 times.
|
188 | parse_yml_updateIndentation(data.vecIndentation, keyIndentation); |
| 226 | |||
| 227 | ///Let's update the current VecValue to be completd with values and lists | ||
| 228 | 188 | 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 | 188 | return true; | |
| 236 | 2533 | } | |
| 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 | 2605 | bool parse_yml_compactListContent(VecValue & parent, PFileParser & parser, PYmlParserData & data){ | |
| 244 |
4/4✓ Branch 0 (2→3) taken 2605 times.
✓ Branch 2 (3→4) taken 2605 times.
✓ Branch 4 (5→6) taken 2593 times.
✓ Branch 5 (5→7) taken 12 times.
|
2605 | if(!parser.isMatch("[")){return false;} |
| 245 | 12 | parse_yml_playCurrentText(data); | |
| 246 | 12 | VecVecValue & listValue = data.currentlyParsedKeyValue->getVecChild(); | |
| 247 | |||
| 248 |
11/16✓ Branch 0 (93→94) taken 38 times.
✓ Branch 2 (94→95) taken 38 times.
✗ Branch 3 (94→101) not taken.
✓ Branch 4 (95→96) taken 38 times.
✓ Branch 6 (96→97) taken 38 times.
✓ Branch 8 (97→98) taken 26 times.
✓ Branch 9 (97→101) taken 12 times.
✓ Branch 10 (98→99) taken 26 times.
✓ Branch 12 (99→100) taken 26 times.
✗ Branch 13 (99→101) not taken.
✓ Branch 14 (102→103) taken 38 times.
✗ Branch 15 (102→104) not taken.
✓ Branch 16 (104→10) taken 26 times.
✓ Branch 17 (104→105) taken 12 times.
✗ Branch 18 (164→165) not taken.
✗ Branch 19 (164→166) not taken.
|
38 | while(parse_yml_isParse(data) && !parser.isMatch("]") && !parser.isEndOfFile()){ |
| 249 |
1/1✓ Branch 0 (10→11) taken 26 times.
|
26 | PString tmpStr(""); |
| 250 |
3/3✓ Branch 0 (11→12) taken 26 times.
✓ Branch 2 (12→13) taken 4 times.
✓ Branch 3 (12→18) taken 22 times.
|
26 | if(parse_yml_string(tmpStr, parser)){ |
| 251 |
1/1✓ Branch 0 (13→14) taken 4 times.
|
4 | VecValue vecTmp; |
| 252 |
1/1✓ Branch 0 (14→15) taken 4 times.
|
4 | vecTmp.setValue(tmpStr); |
| 253 |
1/1✓ Branch 0 (15→16) taken 4 times.
|
4 | listValue.push_back(vecTmp); |
| 254 | 4 | }else{ | |
| 255 |
17/24✓ Branch 0 (21→22) taken 234 times.
✓ Branch 2 (22→23) taken 234 times.
✗ Branch 3 (22→32) not taken.
✓ Branch 4 (23→24) taken 234 times.
✓ Branch 6 (24→25) taken 234 times.
✓ Branch 8 (25→26) taken 222 times.
✓ Branch 9 (25→32) taken 12 times.
✓ Branch 10 (26→27) taken 222 times.
✓ Branch 12 (27→28) taken 222 times.
✓ Branch 14 (28→29) taken 212 times.
✓ Branch 15 (28→32) taken 10 times.
✓ Branch 16 (29→30) taken 212 times.
✓ Branch 18 (30→31) taken 212 times.
✗ Branch 19 (30→32) not taken.
✓ Branch 20 (33→34) taken 222 times.
✓ Branch 21 (33→35) taken 12 times.
✓ Branch 22 (35→36) taken 234 times.
✗ Branch 23 (35→37) not taken.
✓ Branch 24 (37→19) taken 212 times.
✓ Branch 25 (37→38) taken 22 times.
✗ Branch 26 (127→128) not taken.
✗ Branch 27 (127→129) not taken.
✗ Branch 28 (131→132) not taken.
✗ Branch 29 (131→133) not taken.
|
234 | while(parse_yml_isParse(data) && !parser.isMatchRewind("]") && !parser.isMatchRewind(",") && !parser.isEndOfFile()){ |
| 256 |
1/1✓ Branch 0 (19→20) taken 212 times.
|
212 | parse_yml_incrementCurrentChar(parser, data); |
| 257 | } | ||
| 258 |
1/1✓ Branch 0 (38→39) taken 22 times.
|
22 | VecValue vecTmp; |
| 259 |
3/3✓ Branch 0 (39→40) taken 22 times.
✓ Branch 2 (40→41) taken 22 times.
✓ Branch 4 (41→42) taken 22 times.
|
22 | vecTmp.setValue(data.currentText.eraseFirstChar(" \t\n")); |
| 260 |
1/1✓ Branch 0 (44→45) taken 22 times.
|
22 | listValue.push_back(vecTmp); |
| 261 |
1/1✓ Branch 0 (45→46) taken 22 times.
|
22 | data.currentText = ""; |
| 262 | 22 | } | |
| 263 | |||
| 264 | // Vérification de fin de fichier avant de continuer | ||
| 265 |
2/3✓ Branch 0 (48→49) taken 26 times.
✗ Branch 2 (49→50) not taken.
✓ Branch 3 (49→59) taken 26 times.
|
26 | if(parser.isEndOfFile()){ |
| 266 | ✗ | parse_yml_stopParsing(data); | |
| 267 | ✗ | std::cerr << "parse_yml_compactListContent : error at " << parser.getLocation() << std::endl; | |
| 268 | ✗ | std::cerr << "\tunexpected end of file, missing ']'" << std::endl; | |
| 269 | ✗ | return false; | |
| 270 | } | ||
| 271 | |||
| 272 |
11/18✓ Branch 0 (59→60) taken 26 times.
✓ Branch 2 (60→61) taken 26 times.
✓ Branch 4 (61→62) taken 12 times.
✓ Branch 5 (61→66) taken 14 times.
✓ Branch 6 (62→63) taken 12 times.
✓ Branch 8 (63→64) taken 12 times.
✗ Branch 10 (64→65) not taken.
✓ Branch 11 (64→66) taken 12 times.
✓ Branch 12 (67→68) taken 12 times.
✓ Branch 13 (67→69) taken 14 times.
✓ Branch 14 (69→70) taken 26 times.
✗ Branch 15 (69→71) not taken.
✗ Branch 16 (71→72) not taken.
✓ Branch 17 (71→87) taken 26 times.
✗ Branch 18 (147→148) not taken.
✗ Branch 19 (147→149) not taken.
✗ Branch 20 (151→152) not taken.
✗ Branch 21 (151→153) not taken.
|
26 | if(!parser.isMatch(",") && !parser.isMatchRewind("]")){ |
| 273 | ✗ | parse_yml_stopParsing(data); | |
| 274 | ✗ | std::cerr << "parser_yml_fileParser : error at " << parser.getLocation() << std::endl; | |
| 275 | ✗ | std::cerr << "\tunexpected token '"<<parser.getNextToken()<<"'" << std::endl; | |
| 276 | ✗ | std::cerr << "\texpected token ',' or ']'" << std::endl; | |
| 277 | ✗ | return false; | |
| 278 | } | ||
| 279 | 26 | } | |
| 280 | |||
| 281 | // Si on sort de la boucle sans avoir trouvé ']' et qu'on est à la fin du fichier | ||
| 282 |
4/13✓ Branch 0 (105→106) taken 12 times.
✗ Branch 2 (106→107) not taken.
✓ Branch 3 (106→111) taken 12 times.
✗ Branch 4 (107→108) not taken.
✗ Branch 6 (108→109) not taken.
✗ Branch 8 (109→110) not taken.
✗ Branch 9 (109→111) not taken.
✗ Branch 10 (112→113) not taken.
✓ Branch 11 (112→114) taken 12 times.
✗ Branch 12 (114→115) not taken.
✓ Branch 13 (114→119) taken 12 times.
✗ Branch 14 (168→169) not taken.
✗ Branch 15 (168→170) not taken.
|
12 | if(parser.isEndOfFile() && !parser.isMatchRewind("]")){ |
| 283 | ✗ | parse_yml_stopParsing(data); | |
| 284 | ✗ | std::cerr << "parse_yml_compactListContent : error - missing closing ']'" << std::endl; | |
| 285 | ✗ | return false; | |
| 286 | } | ||
| 287 | |||
| 288 | 12 | return true; | |
| 289 | } | ||
| 290 | |||
| 291 | ///Parse dico content | ||
| 292 | /** @param[out] parent : parent VecValue | ||
| 293 | * @param[out] parser : PFileParser to be used | ||
| 294 | * @param[out] data : extra parser data to be used | ||
| 295 | */ | ||
| 296 | 2591 | bool parse_yml_listContent(VecValue & parent, PFileParser & parser, PYmlParserData & data){ | |
| 297 |
4/4✓ Branch 0 (2→3) taken 2591 times.
✓ Branch 2 (3→4) taken 2591 times.
✓ Branch 4 (5→6) taken 2533 times.
✓ Branch 5 (5→7) taken 58 times.
|
2591 | if(!parser.isMatch("- ")){return false;} //There is no extra space, this is exactly the syntax |
| 298 |
1/1✓ Branch 0 (7→8) taken 58 times.
|
58 | size_t currentIndentation(parser.getColumn() - 1lu); |
| 299 |
1/1✓ Branch 0 (8→9) taken 58 times.
|
58 | parse_yml_playCurrentText(data); |
| 300 |
1/1✓ Branch 0 (9→10) taken 58 times.
|
58 | VecValue dashList; |
| 301 |
2/2✓ Branch 0 (10→11) taken 58 times.
✓ Branch 2 (11→12) taken 58 times.
|
58 | dashList.setKey(""); |
| 302 |
1/1✓ Branch 0 (13→14) taken 58 times.
|
58 | dashList.setType(VecValueType::LIST_ITEM); |
| 303 |
1/1✓ Branch 0 (14→15) taken 58 times.
|
58 | dashList.setIndentation(currentIndentation); |
| 304 | // std::cerr << "parse_yml_listContent : Add LIST_ITEM at " << parser.getLocation() << std::endl; | ||
| 305 | //Add the dico into its parent and get back the pointer of the current dico we want to fill | ||
| 306 |
1/1✓ Branch 0 (15→16) taken 58 times.
|
58 | VecValue * ptrDashList = addChildToParentVecValueAddListItem(parent, data.vecIndentation, data.compactMode, dashList, currentIndentation); |
| 307 | |||
| 308 | //Update indentation to be used to fill the VecValue in the current dico | ||
| 309 |
1/1✓ Branch 0 (16→17) taken 58 times.
|
58 | parse_yml_updateIndentation(data.vecIndentation, currentIndentation); |
| 310 | |||
| 311 | ///Let's update the current VecValue to be completd with values and lists | ||
| 312 | 58 | data.currentlyParsedKeyValue = ptrDashList; | |
| 313 | 58 | return true; | |
| 314 | 58 | } | |
| 315 | |||
| 316 | ///Parse all yml features | ||
| 317 | /** @param[out] parent : parent VecValue | ||
| 318 | * @param[out] parser : PFileParser to be used | ||
| 319 | * @param[out] data : extra parser data to be used | ||
| 320 | */ | ||
| 321 | 2609 | bool parse_yml_all(VecValue & parent, PFileParser & parser, PYmlParserData & data){ | |
| 322 |
6/6✓ Branch 0 (2→3) taken 2609 times.
✓ Branch 2 (3→4) taken 2609 times.
✓ Branch 4 (5→6) taken 4 times.
✓ Branch 5 (5→11) taken 2605 times.
✓ Branch 6 (6→7) taken 4 times.
✓ Branch 8 (7→8) taken 4 times.
|
2609 | if(parser.isMatch("#")){parser.getUntilKeyWithoutPatern("\n");} //Skip the comment |
| 323 |
2/2✓ Branch 0 (12→13) taken 2593 times.
✓ Branch 1 (12→22) taken 12 times.
|
2605 | else if(parse_yml_compactListContent(parent, parser, data)){} |
| 324 |
2/2✓ Branch 0 (14→15) taken 2591 times.
✓ Branch 1 (14→22) taken 2 times.
|
2593 | else if(parse_yml_compactDicoContent(parent, parser, data)){} |
| 325 |
2/2✓ Branch 0 (16→17) taken 2533 times.
✓ Branch 1 (16→22) taken 58 times.
|
2591 | else if(parse_yml_listContent(parent, parser, data)){} |
| 326 |
2/2✓ Branch 0 (18→19) taken 2345 times.
✓ Branch 1 (18→22) taken 188 times.
|
2533 | else if(parse_yml_dicoContent(parent, parser, data)){} |
| 327 |
2/2✓ Branch 0 (20→21) taken 2281 times.
✓ Branch 1 (20→22) taken 64 times.
|
2345 | else if(parse_yml_stringValue(parser, data)){} |
| 328 | else{ | ||
| 329 | 2281 | parse_yml_incrementCurrentChar(parser, data); | |
| 330 | } | ||
| 331 | 2609 | return true; | |
| 332 | } | ||
| 333 | |||
| 334 | ///Parse a yml file and update the given VecValue | ||
| 335 | /** @param[out] dico : dictionnary of values | ||
| 336 | * @param parser : PFileParser to be used | ||
| 337 | * @return true on success, false otherwise | ||
| 338 | */ | ||
| 339 | 20 | bool parser_yml_fileParser(VecValue & dico, PFileParser & parser){ | |
| 340 |
1/1✓ Branch 0 (2→3) taken 20 times.
|
20 | PYmlParserData data(default_PYmlParserData()); |
| 341 | 20 | data.currentlyParsedKeyValue = &dico; | |
| 342 |
2/2✓ Branch 0 (3→4) taken 20 times.
✓ Branch 2 (4→5) taken 20 times.
|
20 | parser.getStrComposedOf(" \t\n"); //Skip all blank characters |
| 343 |
7/8✓ Branch 0 (25→26) taken 2603 times.
✓ Branch 2 (26→27) taken 2583 times.
✓ Branch 3 (26→30) taken 20 times.
✓ Branch 4 (27→28) taken 2583 times.
✓ Branch 6 (28→29) taken 2583 times.
✗ Branch 7 (28→30) not taken.
✓ Branch 8 (31→8) taken 2583 times.
✓ Branch 9 (31→32) taken 20 times.
|
2623 | while(!parser.isEndOfFile() && parse_yml_isParse(data)){ |
| 344 |
2/3✓ Branch 0 (8→9) taken 2583 times.
✓ Branch 2 (9→10) taken 2583 times.
✗ Branch 3 (9→11) not taken.
|
2583 | if(!parse_yml_all(dico, parser, data)){ |
| 345 | ✗ | std::cerr << "parser_yml_fileParser : error at " << parser.getLocation() << std::endl; | |
| 346 | ✗ | std::cerr << "\tunexpected token '"<<parser.getNextToken()<<"'" << std::endl; | |
| 347 | ✗ | parse_yml_stopParsing(data); | |
| 348 | } | ||
| 349 | } | ||
| 350 |
1/1✓ Branch 0 (32→33) taken 20 times.
|
20 | parse_yml_playCurrentText(data); |
| 351 | 20 | return data.isRun; | |
| 352 | 20 | } | |
| 353 | |||
| 354 | ///Parse a VecValue from a file | ||
| 355 | /** @param[out] dico : dictionnary of values | ||
| 356 | * @param fileName : name of the file to be parsed | ||
| 357 | * @return true on success, false otherwise | ||
| 358 | */ | ||
| 359 | 18 | bool parser_yml_parseVecValue(VecValue & dico, const PPath & fileName){ | |
| 360 |
1/1✓ Branch 0 (2→3) taken 18 times.
|
18 | PFileParser parser; |
| 361 |
2/2✓ Branch 0 (3→4) taken 18 times.
✓ Branch 2 (4→5) taken 18 times.
|
18 | parser.setWhiteSpace(""); |
| 362 |
2/2✓ Branch 0 (6→7) taken 18 times.
✓ Branch 2 (7→8) taken 18 times.
|
18 | parser.setSeparator(":-'\",{}[]>|#"); |
| 363 |
1/1✓ Branch 0 (9→10) taken 18 times.
|
18 | parser.setEscapeChar('\\'); |
| 364 |
2/3✓ Branch 0 (10→11) taken 18 times.
✗ Branch 2 (11→12) not taken.
✓ Branch 3 (11→17) taken 18 times.
|
18 | if(!parser.open(fileName)){ |
| 365 | ✗ | std::cerr << "parser_yml_parseVecValue : cannot open file '"<<fileName<<"'" << std::endl; | |
| 366 | ✗ | return false; | |
| 367 | } | ||
| 368 |
1/1✓ Branch 0 (17→18) taken 18 times.
|
18 | dico.setType(VecValueType::MAIN); |
| 369 |
3/3✓ Branch 0 (18→19) taken 18 times.
✓ Branch 2 (19→20) taken 18 times.
✓ Branch 4 (20→21) taken 18 times.
|
18 | dico.setIndentation(parser.getLocation().getColumn()); |
| 370 |
1/1✓ Branch 0 (22→23) taken 18 times.
|
18 | return parser_yml_fileParser(dico, parser); |
| 371 | 18 | } | |
| 372 | |||
| 373 | ///Parse a yml file and update the given DicoValue | ||
| 374 | /** @param[out] dico : dictionnary of values | ||
| 375 | * @param fileName : name of the file to be parsed | ||
| 376 | * @return true on success, false otherwise | ||
| 377 | */ | ||
| 378 | 9 | bool parser_yml(DicoValue & dico, const PPath & fileName){ | |
| 379 |
1/1✓ Branch 0 (2→3) taken 9 times.
|
9 | VecValue vecValue; |
| 380 |
1/1✓ Branch 0 (3→4) taken 9 times.
|
9 | bool b(parser_yml_parseVecValue(vecValue, fileName)); |
| 381 |
1/1✓ Branch 0 (4→5) taken 9 times.
|
9 | vecValueToDicoValue(dico, vecValue); |
| 382 | 9 | return b; | |
| 383 | 9 | } | |
| 384 | |||
| 385 | ///Parse a yml file and update the given ConfigNode | ||
| 386 | /** @param[out] dico : ConfigNode of values | ||
| 387 | * @param fileName : name of the file to be parsed | ||
| 388 | * @return true on success, false otherwise | ||
| 389 | */ | ||
| 390 | 9 | bool parser_yml(ConfigNode & dico, const PPath & fileName){ | |
| 391 |
1/1✓ Branch 0 (2→3) taken 9 times.
|
9 | VecValue vecValue; |
| 392 |
1/1✓ Branch 0 (3→4) taken 9 times.
|
9 | bool b(parser_yml_parseVecValue(vecValue, fileName)); |
| 393 |
1/1✓ Branch 0 (4→5) taken 9 times.
|
9 | vecValueToConfigNode(dico, vecValue); |
| 394 | 9 | return b; | |
| 395 | 9 | } | |
| 396 | |||
| 397 | ///Parse a toml string | ||
| 398 | /** @param[out] node : ConfigNode to be updated | ||
| 399 | * @param fileName : name of the file to be parsed | ||
| 400 | * @return true on success, false otherwise | ||
| 401 | */ | ||
| 402 | 2 | bool parser_ymlString(ConfigNode & node, const PString & fileContent){ | |
| 403 |
1/1✓ Branch 0 (2→3) taken 2 times.
|
2 | PFileParser parser; |
| 404 |
2/2✓ Branch 0 (3→4) taken 2 times.
✓ Branch 2 (4→5) taken 2 times.
|
2 | parser.setWhiteSpace(""); |
| 405 |
2/2✓ Branch 0 (6→7) taken 2 times.
✓ Branch 2 (7→8) taken 2 times.
|
2 | parser.setSeparator(":-'\",{}[]>|#"); |
| 406 |
1/1✓ Branch 0 (9→10) taken 2 times.
|
2 | parser.setEscapeChar('\\'); |
| 407 |
1/1✓ Branch 0 (10→11) taken 2 times.
|
2 | parser.setFileContent(fileContent); |
| 408 |
1/1✓ Branch 0 (11→12) taken 2 times.
|
2 | VecValue vecValue; |
| 409 |
1/1✓ Branch 0 (12→13) taken 2 times.
|
2 | vecValue.setType(VecValueType::MAIN); |
| 410 |
3/3✓ Branch 0 (13→14) taken 2 times.
✓ Branch 2 (14→15) taken 2 times.
✓ Branch 4 (15→16) taken 2 times.
|
2 | vecValue.setIndentation(parser.getLocation().getColumn()); |
| 411 |
1/1✓ Branch 0 (17→18) taken 2 times.
|
2 | bool b = parser_yml_fileParser(vecValue, parser); |
| 412 |
1/1✓ Branch 0 (18→19) taken 2 times.
|
2 | vecValueToConfigNode(node, vecValue); |
| 413 | |||
| 414 | 2 | return b; | |
| 415 | 2 | } | |
| 416 |