PhoenixLecture  2.0.0
Set of tools to make lectures
parser_toml.cpp File Reference
#include "parse_generic_string.h"
#include "parser_toml.h"
+ Include dependency graph for parser_toml.cpp:

Go to the source code of this file.

Classes

struct  PTomlParserData
 Data used to parse a toml file. More...
 

Functions

PTomlParserData default_PTomlParserData ()
 Default value of PTomlParserData. More...
 
DicoValueparse_get_parent_dico (DicoValue &parent, const PVecString &vecDicoName)
 Get the parent dictionary by respect to the vecDicoName. More...
 
bool parse_toml_all (DicoValue &parent, PFileParser &parser, PTomlParserData &data)
 
bool parse_toml_dico_def (DicoValue &parent, PFileParser &parser, PTomlParserData &data)
 Parse a dico definition. More...
 
bool parse_toml_isParse (const PTomlParserData &data)
 Say if the file parsing is enable. More...
 
void parse_toml_stopParsing (PTomlParserData &data)
 Stop the file parsing. More...
 
bool parse_toml_table_def (DicoValue &parent, PFileParser &parser, PTomlParserData &data)
 Parse a dico definition. More...
 
bool parse_toml_var (DicoValue &dico, PFileParser &parser, PTomlParserData &data)
 Parse a toml var name. More...
 
bool parse_toml_varBase (DicoValue &var, PFileParser &parser, PTomlParserData &data)
 Parse a toml var name. More...
 
bool parse_toml_varName (PString &varName, PFileParser &parser)
 Parse a toml var name. More...
 
bool parse_toml_varTable (DicoValue &dico, PFileParser &parser, PTomlParserData &data)
 Parse a toml var name. More...
 
bool parse_toml_varValue (DicoValue &var, PFileParser &parser, PTomlParserData &data)
 Parse a toml var name. More...
 
bool parse_tomlCompactDico (DicoValue &parent, PFileParser &parser, PTomlParserData &data)
 Parse a compact dico definition. More...
 

Function Documentation

◆ default_PTomlParserData()

PTomlParserData default_PTomlParserData ( )

Default value of PTomlParserData.

Returns
default PTomlParserData

Definition at line 19 of file parser_toml.cpp.

19  {
20  PTomlParserData data;
21  data.isRun = true;
22  return data;
23 }
Data used to parse a toml file.
Definition: parser_toml.cpp:11
bool isRun
True to continue the parsing, false to stop.
Definition: parser_toml.cpp:13

References PTomlParserData::isRun.

◆ parse_get_parent_dico()

DicoValue* parse_get_parent_dico ( DicoValue parent,
const PVecString vecDicoName 
)

Get the parent dictionary by respect to the vecDicoName.

Parameters
parent: main DicoValue
vecDicoName: name of the parent DicoValue of the following attributes
Returns
pointer to the parent DicoValue of the following attributes

Definition at line 180 of file parser_toml.cpp.

180  {
181  DicoValue * output = &parent;
182  for(PVecString::const_iterator it(vecDicoName.begin()); it != vecDicoName.end(); ++it){
183  output = &(output->getMapChild()[*it]);
184  output->setKey(*it);
185  }
186  return output;
187 }
Dictionnary of values.
Definition: DicoValue.h:17
void setKey(const PString &key)
Sets the key of the DicoValue.
Definition: DicoValue.cpp:148
const std::map< PString, DicoValue > & getMapChild() const
Gets the mapChild of the DicoValue.
Definition: DicoValue.cpp:218

References DicoValue::getMapChild(), and DicoValue::setKey().

Referenced by parse_toml_dico_def(), and parse_toml_table_def().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parse_toml_all()

bool parse_toml_all ( DicoValue parent,
PFileParser parser,
PTomlParserData data 
)

◆ parse_toml_dico_def()

bool parse_toml_dico_def ( DicoValue parent,
PFileParser parser,
PTomlParserData data 
)

Parse a dico definition.

Parameters
[out]parent: parent VecValue
[out]parser: PFileParser to be used
[out]data: extra parser data to be used
Returns
true on success, false otherwise

Definition at line 195 of file parser_toml.cpp.

195  {
196  if(!parser.isMatch("[")){return false;}
197  PString dicoName(parser.getUntilKeyWithoutPatern("]"));
198  PVecString vecDicoName = dicoName.split('.');
199  DicoValue * dicoDef = parse_get_parent_dico(parent, vecDicoName);
200 
201 // dicoDef.setKey(dicoName);
202  while(!parser.isEndOfFile() && parse_toml_isParse(data) && !parser.isMatchRewind("[")){ //Let's parse the vatiables of the Dico
203  if(parser.isMatch("#")){parser.getUntilKeyWithoutPatern("\n");}
204  else if(parse_toml_var(*dicoDef, parser, data)){
205 // parent.getMapChild()[dicoName] = *dicoDef;
206  }
207 // else{
208 // std::cerr << "parse_toml_dico_def : error at " << parser.getLocation() << std::endl;
209 // std::cerr << "\tcannot parse [definition]" << std::endl;
210 // parse_toml_stopParsing(data);
211 // return true;
212 // }
213  }
214  return true;
215 }
std::vector< PString > PVecString
Definition: PString.h:96
PString getUntilKeyWithoutPatern(const PString &patern)
Renvoie la chaine de caractère du caractère courant jusqu'à patern exclu.
bool isMatchRewind(const PString &patern)
Do a isMatch and then go back at the previous position.
bool isMatch(const PString &patern)
Says if the patern match with the current caracters of the PFileParser.
bool isEndOfFile() const
Dit si on est à la fin du fichier.
Definition: PFileParser.cpp:88
Extends the std::string.
Definition: PString.h:16
bool parse_toml_isParse(const PTomlParserData &data)
Say if the file parsing is enable.
Definition: parser_toml.cpp:38
DicoValue * parse_get_parent_dico(DicoValue &parent, const PVecString &vecDicoName)
Get the parent dictionary by respect to the vecDicoName.
bool parse_toml_var(DicoValue &dico, PFileParser &parser, PTomlParserData &data)
Parse a toml var name.

References PFileParser::getUntilKeyWithoutPatern(), PFileParser::isEndOfFile(), PFileParser::isMatch(), PFileParser::isMatchRewind(), parse_get_parent_dico(), parse_toml_isParse(), parse_toml_var(), and PString::split().

+ Here is the call graph for this function:

◆ parse_toml_isParse()

bool parse_toml_isParse ( const PTomlParserData data)

Say if the file parsing is enable.

Parameters
data: parsing data

Definition at line 38 of file parser_toml.cpp.

38  {
39  return data.isRun;
40 }

References PTomlParserData::isRun.

Referenced by parse_toml_dico_def(), parse_toml_table_def(), parse_toml_varValue(), and parse_tomlCompactDico().

+ Here is the caller graph for this function:

◆ parse_toml_stopParsing()

void parse_toml_stopParsing ( PTomlParserData data)

Stop the file parsing.

Parameters
[out]data: parsing data

Definition at line 31 of file parser_toml.cpp.

31  {
32  data.isRun = false;
33 }

References PTomlParserData::isRun.

Referenced by parse_toml_varBase(), parse_toml_varValue(), and parse_tomlCompactDico().

+ Here is the caller graph for this function:

◆ parse_toml_table_def()

bool parse_toml_table_def ( DicoValue parent,
PFileParser parser,
PTomlParserData data 
)

Parse a dico definition.

Parameters
[out]parent: parent VecValue
[out]parser: PFileParser to be used
[out]data: extra parser data to be used
Returns
true on success, false otherwise

Definition at line 223 of file parser_toml.cpp.

References PFileParser::getUntilKeyWithoutPatern(), DicoValue::getVecChild(), PFileParser::isEndOfFile(), PFileParser::isMatch(), PFileParser::isMatchRewind(), parse_get_parent_dico(), parse_toml_isParse(), parse_toml_var(), and PString::split().

+ Here is the call graph for this function:

◆ parse_toml_var()

bool parse_toml_var ( DicoValue dico,
PFileParser parser,
PTomlParserData data 
)

Parse a toml var name.

Parameters
[out]dico: DicoValue to be used
[out]parser: parser to be used
[out]data: extra parser data to be used
Returns
true on success, false otherwise

Definition at line 155 of file parser_toml.cpp.

155  {
156  DicoValue var;
157  if(!parse_toml_varBase(var, parser, data)){return false;}
158  dico.getMapChild()[var.getKey()] = var;
159  return true;
160 }
const PString & getKey() const
Gets the key of the DicoValue.
Definition: DicoValue.cpp:190
bool parse_toml_varBase(DicoValue &var, PFileParser &parser, PTomlParserData &data)
Parse a toml var name.

References DicoValue::getKey(), DicoValue::getMapChild(), and parse_toml_varBase().

Referenced by parse_toml_dico_def(), parse_toml_table_def(), and parse_tomlCompactDico().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parse_toml_varBase()

bool parse_toml_varBase ( DicoValue var,
PFileParser parser,
PTomlParserData data 
)

Parse a toml var name.

Parameters
[out]var: variable DicoValue to be used
[out]parser: parser to be used
[out]data: extra parser data to be used
Returns
true on success, false otherwise

Definition at line 133 of file parser_toml.cpp.

133  {
134  PString varName("");
135  if(!parse_toml_varName(varName, parser)){return false;}
136  if(!parser.isMatch("=")){
137  std::cerr << "parse_toml_varBase : missing '=' token to define value of variable '"<<varName<<"' at " << parser.getLocation() << std::endl;
139  return false;
140  }
141  var.setKey(varName);
142  bool b(true);
143  if(parse_tomlCompactDico(var, parser, data)){}
144  else if(parse_toml_varValue(var, parser, data)){}
145  else{b = false;}
146  return b;
147 }
PLocation getLocation() const
Fonction qui renvoie la PLocation du PFileParser.
void parse_toml_stopParsing(PTomlParserData &data)
Stop the file parsing.
Definition: parser_toml.cpp:31
bool parse_toml_varName(PString &varName, PFileParser &parser)
Parse a toml var name.
Definition: parser_toml.cpp:47
bool parse_toml_varValue(DicoValue &var, PFileParser &parser, PTomlParserData &data)
Parse a toml var name.
Definition: parser_toml.cpp:58
bool parse_tomlCompactDico(DicoValue &parent, PFileParser &parser, PTomlParserData &data)
Parse a compact dico definition.

References PFileParser::getLocation(), PFileParser::isMatch(), parse_toml_stopParsing(), parse_toml_varName(), parse_toml_varValue(), parse_tomlCompactDico(), and DicoValue::setKey().

Referenced by parse_toml_var(), and parse_toml_varTable().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parse_toml_varName()

bool parse_toml_varName ( PString varName,
PFileParser parser 
)

Parse a toml var name.

Parameters
[out]varName: variable name
parser: parser to be used
Returns
true on success, false otherwise

Definition at line 47 of file parser_toml.cpp.

47  {
48  varName = parser.getStrComposedOf("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_");
49  return varName != "";
50 }
PString getStrComposedOf(const PString &charset)
Get string composed of the characters in the string charset.

References PFileParser::getStrComposedOf().

Referenced by parse_toml_varBase().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parse_toml_varTable()

bool parse_toml_varTable ( DicoValue dico,
PFileParser parser,
PTomlParserData data 
)

Parse a toml var name.

Parameters
[out]dico: DicoValue to be used
[out]parser: parser to be used
[out]data: extra parser data to be used
Returns
true on success, false otherwise

Definition at line 168 of file parser_toml.cpp.

168  {
169  DicoValue var;
170  if(!parse_toml_varBase(var, parser, data)){return false;}
171  dico.getVecChild().push_back(var);
172  return true;
173 }
const std::vector< DicoValue > & getVecChild() const
Gets the vecChild of the DicoValue.
Definition: DicoValue.cpp:204

References DicoValue::getVecChild(), and parse_toml_varBase().

+ Here is the call graph for this function:

◆ parse_toml_varValue()

bool parse_toml_varValue ( DicoValue var,
PFileParser parser,
PTomlParserData data 
)

Parse a toml var name.

Parameters
[out]var: Value to be updated
[out]parser: parser to be used
[out]data: extra parser data to be used
Returns
true on success, false otherwise

Definition at line 58 of file parser_toml.cpp.

58  {
59  if(parser.isMatch("[")){ //The value is a list
60  while(!parser.isEndOfFile() && !parser.isMatch("]") && parse_toml_isParse(data)){ //Let's parse the values of the Variable
61  DicoValue subValue;
62  if(parse_toml_varValue(subValue, parser, data)){
63  var.getVecChild().push_back(subValue);
64 
65  if(!parser.isMatch(",") && !parser.isMatchRewind("]")){ //We expect one element or a comma to add more
66  std::cerr << "parse_toml_varValue : expect ',' or ']' forunclosed list of values at " << parser.getLocation() << std::endl;
68  return false;
69  }
70  }else{
71  if(!parser.isMatch("]")){
72  std::cerr << "parse_toml_varBase : missing ']' token to close empty list of value at " << parser.getLocation() << std::endl;
74  return false;
75  }
76  }
77  }
78  }else{
79  PString strValue("");
80  if(parse_generic_string(strValue, parser)){
81  var.setValue(strValue);
82  }else if(parser.isMatch("true")){
83  var.setValue("true");
84  }else if(parser.isMatch("false")){
85  var.setValue("false");
86  }else{
87  PString valueNumber(parser.getStrComposedOf("0123456789.-+e"));
88  if(valueNumber != ""){
89  var.setValue(valueNumber);
90  }else{
91  std::cerr << "parse_toml_varValue : missing value of variable '"<<var.getKey()<<"' at " << parser.getLocation() << std::endl;
93  return false;
94  }
95  }
96  }
97  return true;
98 }
void setValue(const PString &value)
Sets the value of the DicoValue.
Definition: DicoValue.cpp:141
bool parse_generic_string(PString &str, PFileParser &parser)
Parse string value.

References DicoValue::getKey(), PFileParser::getLocation(), PFileParser::getStrComposedOf(), DicoValue::getVecChild(), PFileParser::isEndOfFile(), PFileParser::isMatch(), PFileParser::isMatchRewind(), parse_generic_string(), parse_toml_isParse(), parse_toml_stopParsing(), and DicoValue::setValue().

Referenced by parse_toml_varBase().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parse_tomlCompactDico()

bool parse_tomlCompactDico ( DicoValue parent,
PFileParser parser,
PTomlParserData data 
)

Parse a compact dico definition.

Parameters
[out]parent: parent of parsed dico
[out]parser: parser to be used
[out]data: extra parser data to be used
Returns
true on success, false otherwise

Definition at line 106 of file parser_toml.cpp.

106  {
107  if(!parser.isMatch("{")){return false;}
108  while(!parser.isEndOfFile() && parse_toml_isParse(data) && !parser.isMatch("}")){ //Let's parse the vatiables of the Dico
109  if(parser.isMatch("#")){parser.getUntilKeyWithoutPatern("\n");}
110  else if(parse_toml_var(parent, parser, data)){
111  if(!parser.isMatch(",") && !parser.isMatchRewind("}")){ //We expect one element or a comma to add more
112  std::cerr << "parse_tomlCompactDico : expect ',' or '}' for unclosed dictionary of values at " << parser.getLocation() << std::endl;
114  return false;
115  }
116  }else{
117  if(!parser.isMatch("}")){
118  std::cerr << "parse_tomlCompactDico : missing '}' token to close empty dictionary of value at " << parser.getLocation() << std::endl;
120  return false;
121  }
122  }
123  }
124  return true;
125 }

References PFileParser::getLocation(), PFileParser::getUntilKeyWithoutPatern(), PFileParser::isEndOfFile(), PFileParser::isMatch(), PFileParser::isMatchRewind(), parse_toml_isParse(), parse_toml_stopParsing(), and parse_toml_var().

Referenced by parse_toml_varBase().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: