-
Notifications
You must be signed in to change notification settings - Fork 0
/
Parser.h
392 lines (364 loc) · 14.7 KB
/
Parser.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
#ifndef PARSER_H_
#define PARSER_H_
#include <atomic>
#include <cmath>
#include <math.h>
#include <map>
#include <mutex>
#include <sstream>
#include <set>
#include <thread>
#include <algorithm>
//#include <bits/stdc++.h> //doesn't work on osx, algorithm works instead
#include "DateTimeInfo.h"
#include "Expr.h"
#include "ExprtkFns.h"
#include "Getline.h"
#include "hashtk/HashTk.h"
#include "LuaFns.h"
#include "Lua.h"
#include "Pagination.h"
#include "SystemInfo.h"
#include "TrackedInfo.h"
#include "Variables.h"
#include "Timer.h"
int find_last_of_special(const std::string& s);
void setIncrMode(const int& IncrMode);
struct Parser
{
std::mutex* os_mtx;
std::set<TrackedInfo>* trackedAll;
TrackedInfo toBuild;
DateTimeInfo dateTimeInfo;
int codeBlockDepth,
htmlCommentDepth;
std::string indentAmount;
bool addMemberFnsGlobal, addScopeGlobal, replaceVarsGlobal;
bool contentAdded;
std::string promptChar;
std::string parsedText;
int mode;
bool exprtkParams;
bool lolcatActive, lolcatInit;
std::string lolcatCmd;
std::set<Path> depFiles, includedFiles;
std::istringstream dummy_iss;
std::vector<std::string> tabCompletionStrs;
Pagination pagesInfo;
Variables vars;
Lua lua;
exprtk::symbol_table<double> symbol_table;
exprtk::rtl::io::package<double> basicio_package; //could potentially make these pointers and
exprtk::rtl::io::file::package<double> fileio_package; //only initialise if/when added
exprtk::rtl::vecops::package<double> vectorops_package;
Expr expr;
ExprSet exprset;
exprtk_cd<double> exprtk_cd_fn;
exprtk_sys<double> exprtk_sys_fn;
exprtk_to_string<double> exprtk_to_string_fn;
exprtk_nsm_tonumber<double> exprtk_nsm_tonumber_fn;
exprtk_nsm_tostring<double> exprtk_nsm_tostring_fn;
exprtk_nsm_setnumber<double> exprtk_nsm_setnumber_fn;
exprtk_nsm_setstring<double> exprtk_nsm_setstring_fn;
exprtk_nsm_write<double> exprtk_nsm_write_fn;
//project info
Directory contentDir,
outputDir;
bool backupScripts, consoleLocked;
Path consoleLockedPath;
int consoleLockedOnLine;
std::string contentExt,
outputExt,
scriptExt,
unixTextEditor,
winTextEditor;
Path defaultTemplate;
Parser(std::set<TrackedInfo>* TrackedAll,
std::mutex* OS_mtx,
const Directory& ContentDir,
const Directory& OutputDir,
const std::string& ContentExt,
const std::string& OutputExt,
const std::string& ScriptExt,
const Path& DefaultTemplate,
const bool& makeBackup,
const std::string& UnixTextEditor,
const std::string& WinTextEditor);
int lua_addnsmfns();
int lolcat_init(const std::string& lolcat_cmd);
int run_script(std::ostream& os,
const Path& scriptPath,
const bool& makeBackup,
const bool& outputWhatDoing);
int refresh_completions();
int shell(std::string& langStr, char& langCh, std::ostream& eos);
int interpreter(std::string& langStr, char& langCh, std::ostream& eos);
int interactive(std::string& langStr, char& langCh, std::ostream& eos);
int run(const Path& path, char& langCh, const std::vector<std::string>& params, std::ostream& eos);
int build(const TrackedInfo& ToBuild,
std::atomic<double>& estNoPagesFinished,
std::atomic<int>& noPagesToBuild,
std::ostream& eos);
int n_read_and_process(const bool& indent,
const std::string& inStr,
int lineNo,
const Path& readPath,
std::set<Path> antiDepsOfReadPath,
std::string& outStr,
std::ostream& eos);
int n_read_and_process_fast(const bool& indent,
const std::string& inStr,
int lineNo,
const Path& readPath,
std::set<Path>& antiDepsOfReadPath,
std::string& outStr,
std::ostream& eos);
int n_read_and_process_fast(const bool& indent,
const bool& addOutput,
const std::string& inStr,
int lineNo,
const Path& readPath,
std::set<Path>& antiDepsOfReadPath,
std::string& outStr,
std::ostream& eos);
int f_read_and_process(const bool& addOutput,
const std::string& inStr,
int lineNo,
const Path& readPath,
std::set<Path> antiDepsOfReadPath,
std::string& outStr,
std::ostream& eos);
int f_read_and_process_fast(const bool& addOutput,
const std::string& inStr,
int lineNo,
const Path& readPath,
std::set<Path>& antiDepsOfReadPath,
std::string& outStr,
std::ostream& eos);
int read_and_process_fn(const bool& indent,
const std::string& baseIndentAmount,
const char& lang,
const bool& addOutput,
const std::string& inStr,
int& lineNo,
size_t& linePos,
const Path& readPath,
std::set<Path>& antiDepsOfReadPath,
std::string& outStr,
std::ostream& eos);
inline int skip_whitespace(const bool& checkEOF,
const std::string& inStr,
int& lineNo,
size_t& linePos,
const Path& readPath,
const std::string& callType,
std::ostream& eos);
void get_line(const std::string& str, std::string& restOfLine, size_t& linePos);
int try_system_call(const std::string& funcName,
const std::vector<std::string>& options,
const std::vector<std::string>& params,
const Path& readPath,
std::set<Path>& antiDepsOfReadPath,
const int& sLineNo,
const int& lineNo,
std::ostream& eos,
std::string& outStr);
int try_system_call_console(const std::string& funcName,
const std::vector<std::string>& options,
const std::vector<std::string>& params,
const Path& readPath,
std::set<Path>& antiDepsOfReadPath,
const int& sLineNo,
const int& lineNo,
std::ostream& eos,
std::string& outStr);
int try_system_call_inject(const std::string& funcName,
const std::vector<std::string>& options,
const std::vector<std::string>& params,
const Path& readPath,
std::set<Path>& antiDepsOfReadPath,
const int& sLineNo,
const int& lineNo,
std::ostream& eos,
std::string& outStr);
int try_system_call(const int& whereTo,
const std::string& funcName,
const std::vector<std::string>& options,
const std::vector<std::string>& params,
const Path& readPath,
std::set<Path>& antiDepsOfReadPath,
const int& sLineNo,
const int& lineNo,
std::ostream& eos,
std::string& outStr);
int parse_replace(const char& lang,
std::string& str,
const std::string& strType,
const Path& readPath,
std::set<Path>& antiDepsOfReadPath,
const int& lineNo,
const std::string& callType,
const int& callLineNo,
std::ostream& eos);
int parse_replace(const bool& addOutput,
const char& lang,
std::string& str,
const std::string& strType,
const Path& readPath,
std::set<Path>& antiDepsOfReadPath,
const int& lineNo,
const std::string& callType,
const int& callLineNo,
std::ostream& eos);
int parse_replace(const char& lang,
std::vector<std::string>& strs,
const std::string& strType,
const Path& readPath,
std::set<Path>& antiDepsOfReadPath,
const int& lineNo,
const std::string& callType,
const int& callLineNo,
std::ostream& eos);
int replace_var(std::string& str,
const Path& readPath,
const int& lineNo,
const std::string& callType,
std::ostream& eos);
int replace_vars(std::vector<std::string>& strs,
const int& spos,
const Path& readPath,
const int& lineNo,
const std::string& callType,
std::ostream& eos);
int get_bool(bool& bVal, const std::string& str);
int get_bool(bool& bVal,
const std::string& str,
const Path& readPath,
const int& lineNo,
const std::string& callType,
std::ostream& eos);
int read_str_from_stream(const VPos& spos, std::string& str);
int getline_from_stream(const VPos& spos, std::string& str);
int set_var_from_str(const VPos& vpos,
const std::string& value,
const Path& readPath,
const int& lineNo,
const std::string& callType,
std::ostream& eos);
int add_fn(const std::string& fnName,
const char& fnLang,
const std::string& fnBlock,
const std::string& fnType,
const size_t& layer,
const bool& isConst,
const bool& isPrivate,
const bool& isUnscoped,
const bool& addOut,
const std::unordered_set<std::string>& inScopes,
const Path& readPath,
const int& lineNo,
const std::string& callType,
std::ostream &eos);
int read_func_name(std::string& funcName,
bool& parseFuncName,
size_t& linePos,
const std::string& inStr,
const Path& readPath,
int& lineNo,
std::ostream& eos);
int read_def(std::string& varType,
std::vector<std::pair<std::string, std::vector<std::string> > >& vars,
size_t& linePos,
const std::string& inStr,
const Path& readPath,
int& lineNo,
const std::string& callType,
std::ostream& eos);
int read_sh_params(std::vector<std::string>& params,
const char& separator,
size_t& linePos,
const std::string& inStr,
const Path& readPath,
int& lineNo,
const std::string& callType,
std::ostream& eos);
int read_params(std::vector<std::string>& params,
size_t& linePos,
const std::string& inStr,
const Path& readPath,
int& lineNo,
const std::string& callType,
std::ostream& eos);
int read_params(std::vector<std::string>& params,
const char& separator,
size_t& linePos,
const std::string& inStr,
const Path& readPath,
int& lineNo,
const std::string& callType,
std::ostream& eos);
int read_paramsStr(std::string& paramsStr,
bool& parseParams,
size_t& linePos,
const std::string& inStr,
const Path& readPath,
int& lineNo,
const std::string& callType,
std::ostream& eos);
int read_optionsStr(std::string& optionsStr,
bool& parseOptions,
size_t& linePos,
const std::string& inStr,
const Path& readPath,
int& lineNo,
const std::string& callType,
std::ostream& eos);
int read_options(std::vector<std::string>& options,
size_t& linePos,
const std::string& inStr,
const Path& readPath,
int& lineNo,
const std::string& callType,
std::ostream& eos);
int read_block(std::string& block,
size_t& linePos,
const std::string& inStr,
const Path& readPath,
int& lineNo,
int& bLineNo,
const std::string& callType,
std::ostream& eos);
int read_block_del(std::string& block,
size_t& linePos,
const std::string& inStr,
const Path& readPath,
int& lineNo,
int& bLineNo,
const std::string& callType,
std::ostream& eos);
int read_else_blocks(std::vector<std::string>& conditions,
std::vector<int>& cLineNos,
std::vector<std::string>& blocks,
std::vector<int>& bLineNos,
std::string& whitespace,
size_t& linePos,
const std::string& inStr,
const Path& readPath,
int& lineNo,
const std::string& callType,
std::ostream& eos);
int valid_type(std::string& typeStr,
const Path& readPath,
std::set<Path>& antiDepsOfReadPath,
int& lineNo, //can this be constant?
const std::string& callType,
const int& callLineNo,
std::ostream& eos);
int change_prompt_char(const std::string& charStr);
void print_exprtk_parser_errs(std::ostream& eos,
const exprtk::parser<double>& parser,
const std::string& expr_str,
const Path& readPath,
const int& lineNo);
};
#endif //PARSER_H_