HOPS
HOPS class reference
MHO_ControlFileParser.hh
Go to the documentation of this file.
1 #ifndef MHO_ControlFileParser_HH__
2 #define MHO_ControlFileParser_HH__
3 
4 #include <list>
5 #include <set>
6 #include <sstream>
7 #include <string>
8 #include <vector>
9 
10 #include "MHO_JSONHeaderWrapper.hh"
11 #include "MHO_Message.hh"
12 #include "MHO_Tokenizer.hh"
13 
16 
17 namespace hops
18 {
19 
32 {
33  public:
35  virtual ~MHO_ControlFileParser();
36 
42  void PassSetString(std::string set_string) { fSetString = set_string; };
43 
49  void SetControlFile(std::string filename);
50 
57 
63  std::string GetProcessedControlFileText() const { return fProcessedControlFileText; }
64 
71  std::string GetLegacyProcessedControlFileText() const { return fLegacyProcessedControlFileText; }
72 
73  private:
79  bool ReadFile();
83  void RemoveComments();
87  void FixSymbols();
91  void TokenizeLines();
95  void MergeTokens();
99  void ExportTokens();
103  void FindKeywords();
107  void FormStatements();
113  mho_json ConstructControlObjects();
114 
122  void SplitSetString(const std::string& set_string, std::string& prepend, std::string& append);
123 
132  void FindAndReplace(const std::string& find_str, const std::string& regex_str, const std::string& replace_str,
133  std::string& text);
134 
135  std::string fSetString;
136  std::string fControlFileName;
137 
138  //token/delimiter definitions
139  std::string fWhitespace;
140  std::string fCommentFlag;
141 
142  //workspace
143  std::string fLine; //the line from the input file
144  std::list< MHO_ControlLine > fLines;
145  using line_itr = std::list< MHO_ControlLine >::iterator;
146 
147  //format definition
148  std::string fFormatDirectory;
149  std::string fControlVersion;
150  std::vector< std::string > fKeywordNames;
151  mho_json fKeywordNamesJSON;
152 
153  //token processing
154  MHO_Tokenizer fTokenizer;
155  std::vector< MHO_Token > fFileTokens; //all tokens from file and set string
156  std::vector< std::size_t > fKeywordLocations; //index of each keyword token
157  std::vector< MHO_ControlStatement > fStatements; //collection of tokens for each logical statement
158 
159  MHO_ControlElementParser fElementParser;
160 
161  //output (the parsed text of the control file + set_string with comments removed )
162  std::string fProcessedControlFileText;
163  std::string fLegacyProcessedControlFileText;
164  std::vector< MHO_Token > fLegacyFileTokens; //only tokens from file
165 };
166 
167 } // namespace hops
168 
169 #endif
nlohmann::json mho_json
Definition: MHO_JSONHeaderWrapper.hh:5
Class MHO_ControlElementParser.
Definition: MHO_ControlElementParser.hh:33
Class MHO_ControlFileParser.
Definition: MHO_ControlFileParser.hh:32
virtual ~MHO_ControlFileParser()
Definition: MHO_ControlFileParser.cc:40
void PassSetString(std::string set_string)
Sets the global set_string (control statement) variable.
Definition: MHO_ControlFileParser.hh:42
mho_json ParseControl()
Parses control file and constructs JSON object representing control objects.
Definition: MHO_ControlFileParser.cc:47
std::string GetLegacyProcessedControlFileText() const
Getter for legacy processed control file text (just the control file tokens without set-string additi...
Definition: MHO_ControlFileParser.hh:71
void SetControlFile(std::string filename)
Setter for control file.
Definition: MHO_ControlFileParser.cc:42
MHO_ControlFileParser()
Definition: MHO_ControlFileParser.cc:29
std::string GetProcessedControlFileText() const
Getter for processed control file text (i.e. all of the tokens that make it into the control flow)
Definition: MHO_ControlFileParser.hh:63
Class MHO_Tokenizer.
Definition: MHO_Tokenizer.hh:24
Definition: MHO_ChannelLabeler.hh:17
#define append(cc)
Definition: read_control_file.c:35