7#include "PFileParser.h"
62 if(currentIndentation == 0lu || vecIndentation.size() == 0lu){
63 vecIndentation.clear();
64 vecIndentation.push_back(currentIndentation);
67 std::vector<size_t> vecOutIndentation;
68 std::vector<size_t>::const_iterator it(vecIndentation.begin());
69 bool isCurrentLower(
true);
70 while(isCurrentLower && it != vecIndentation.end()){
71 isCurrentLower = *it < currentIndentation;
73 vecOutIndentation.push_back(*it);
77 vecOutIndentation.push_back(currentIndentation);
78 vecIndentation = vecOutIndentation;
87 char ch = parser.getCurrentCh();
96 PString value(data.
currentText.eraseFirstLastChar(
" \t\n"));
109bool parse_yml_key(PString & key,
size_t & keyIndentation, PFileParser & parser){
110 parser.pushPosition();
111 PString possibleKey(parser.getStrComposedOf(
"_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"));
112 if(possibleKey !=
"" && parser.isMatch(
":")){
114 keyIndentation = parser.getColumn() - possibleKey.size() - 1lu;
117 parser.popPosition();
126 if(parser.isMatch(
"\"")){
127 str =
"\"" + parser.getUntilKey(
"\"");
128 }
else if(parser.isMatch(
"'")){
129 str =
"'" + parser.getUntilKey(
"'");
141 if(vecVal == NULL){
return;}
151 if(parser.isMatch(
"\'")){
152 PString str(
"\'" + parser.getUntilKey(
"\'"));
154 }
else if(parser.isMatch(
"\"")){
155 PString str(
"\"" + parser.getUntilKey(
"\""));
176 if(!parser.isMatch(
"{",
"$§_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/*+-.")){
return false;}
185 parser.getStrComposedOf(
" \t\n");
188 std::cerr <<
"parse_yml_compactDicoContent : error at " << parser.getLocation() << std::endl;
189 std::cerr <<
"\tunexpected token '"<<parser.getNextToken()<<
"'" << std::endl;
206 parser.pushPosition();
208 size_t keyIndentation(0lu);
210 parser.popPosition();
218 keyIndentation = -1lu;
244 if(!parser.isMatch(
"[")){
return false;}
253 listValue.push_back(vecTmp);
255 while(
parse_yml_isParse(data) && !parser.isMatchRewind(
"]") && !parser.isMatchRewind(
",")){
260 listValue.push_back(vecTmp);
263 if(!parser.isMatch(
",") && !parser.isMatchRewind(
"]")){
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;
280 if(!parser.isMatch(
"- ")){
return false;}
281 size_t currentIndentation(parser.getColumn() - 1lu);
305 if(parser.isMatch(
"#")){parser.getUntilKeyWithoutPatern(
"\n");}
325 parser.getStrComposedOf(
" \t\n");
328 std::cerr <<
"parser_yml_fileParser : error at " << parser.getLocation() << std::endl;
329 std::cerr <<
"\tunexpected token '"<<parser.getNextToken()<<
"'" << std::endl;
345 parser.setWhiteSpace(
"");
346 parser.setSeparator(
":-'\",{}[]>|#");
347 parser.setEscapeChar(
'\\');
348 if(!parser.open(fileName)){
349 std::cerr <<
"parser_yml : cannot open file '"<<fileName<<
"'" << std::endl;
Vector of keys and values.
void setIndentation(size_t indentation)
Sets the indentation of the VecValue.
void setValue(const PString &value)
Sets the value of the VecValue.
void setKey(const PString &key)
Sets the key of the VecValue.
const std::vector< VecValue > & getVecChild() const
Gets the vecChild of the VecValue.
void setType(const VecValueType::VecValueType &type)
Sets the type of the VecValue.
bool parser_yml_fileParser(VecValue &dico, PFileParser &parser)
Parse a yml file and update the given VecValue.
bool parse_yml_compactDicoContent(VecValue &parent, PFileParser &parser, PYmlParserData &data)
Parse compact dico content.
void parse_yml_incrementCurrentChar(PFileParser &parser, PYmlParserData &data)
Increment the current character.
bool parse_yml_dicoContent(VecValue &parent, PFileParser &parser, PYmlParserData &data)
Parse dico content.
void parse_yml_dicoSetValue(VecValue *vecVal, const PString &value)
Set a value into a VecValue.
void parse_yml_updateIndentation(std::vector< size_t > &vecIndentation, size_t currentIndentation)
Update the indentation vector by respect to the given indentation.
bool parse_yml_listContent(VecValue &parent, PFileParser &parser, PYmlParserData &data)
Parse dico content.
bool parser_yml(DicoValue &dico, const PPath &fileName)
Parse a yml file and update the given DicoValue.
void parse_yml_playCurrentText(PYmlParserData &data)
Play the current parsed text.
bool parse_yml_compactListContent(VecValue &parent, PFileParser &parser, PYmlParserData &data)
Parse compact dico content.
PYmlParserData default_PYmlParserData()
Default value of PYmlParserData.
void parse_yml_stopParsing(PYmlParserData &data)
Stop the file parsing.
bool parse_yml_string(PString &str, PFileParser &parser)
Parse string value.
bool parse_yml_stringValue(PFileParser &parser, PYmlParserData &data)
Parse compact dico content.
bool parse_yml_isParse(const PYmlParserData &data)
Say if the file parsing is enable.
bool parse_yml_all(VecValue &parent, PFileParser &parser, PYmlParserData &data)
Parse all yml features.
bool parse_yml_key(PString &key, size_t &keyIndentation, PFileParser &parser)
Parse key.
Data used to parse a yml file.
bool compactMode
True if the compact mode is activated.
bool isRun
True to continue the parsing, false to stop.
size_t currentLine
Current line number.
std::vector< size_t > vecIndentation
Vector of previous line indentations.
PString currentText
Current parsed text.
VecValue * currentlyParsedKeyValue
Currently parsed key value.
VecValue * addChildToParentVecValueAddListItem(VecValue &mainVecValue, const std::vector< size_t > &vecIndentation, bool isCompactMode, const VecValue &child, size_t currentIndentation)
Add the given child to the main VecValue and return a pointer to the added child.
VecValue * addChildToParentVecValue(VecValue &mainVecValue, const std::vector< size_t > &vecIndentation, bool isCompactMode, const VecValue &child, size_t currentIndentation)
Add the given child to the main VecValue and return a pointer to the added child.
void vecValueToDicoValue(DicoValue &dicoValue, const VecValue &vecVal, bool isMainValue)
Convert a VecValue into a DicoValue.
std::vector< VecValue > VecVecValue