-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlex_def.hpp
More file actions
80 lines (70 loc) · 1.75 KB
/
lex_def.hpp
File metadata and controls
80 lines (70 loc) · 1.75 KB
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
//
// Created by jaydog on 12/23/25.
//
// If you're wondering why this header is called "def", it's because I wanted a name to represent definitions for stuff
#ifndef INTEXTUAL_FILE_LANGUAGE_DEF_HPP
#define INTEXTUAL_FILE_LANGUAGE_DEF_HPP
#include <filesystem>
#include <vector>
#include <string>
#include <variant>
#include <unordered_map>
using itx_types = std::variant<std::string, int, float, bool>;
bool contains(std::string test, std::vector<std::string> finds);
std::vector<std::string> split_by_ws(std::string test);
enum LexSubType {
BUILT_IN,
STRING,
INT,
FLOAT,
BOOL,
ARRAY,
L_PARA,
R_PARA,
VAR,
MATH,
COMPARE,
COMPILE_CONST
};
enum LexMainType {
OPERATOR,
SYMBOL,
MACRO,
FUNC,
LOGIC,
KEYWORD,
L_KEYWORD, // Logic keywords such as if, while, for
TYPE,
VARIABLE,
BODY
};
struct Lex {
LexSubType sub_type;
std::string meta;
itx_types value;
LexMainType type;
std::vector<Lex> scope;
int line;
};
inline std::string resolve(const itx_types& t) {
switch (t.index()) {
case 0: return "string";
case 1: return "int";
case 2: return "float";
default: return "bool";
}
}
inline std::unordered_map<LexSubType, std::string> type_look {
{STRING, "string"},
{INT, "int"},
{FLOAT, "float"},
{BOOL, "bool"}
};
inline void callErr(std::string_view err_desc, const int line, const int status_code = 1) {
std::cerr << "line: " << line << std::endl
<< err_desc << std::endl;
exit(status_code);
}
inline std::unordered_map<std::string, std::string> alias{{"print", "output"}, {"const", "compile_const"}};
std::vector<Lex> lexer(std::vector<std::string> lines, char stop_at = '~');
#endif //INTEXTUAL_FILE_LANGUAGE_DEF_HPP