-
Notifications
You must be signed in to change notification settings - Fork 0
/
fmts.hpp
270 lines (261 loc) · 6.65 KB
/
fmts.hpp
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
#include "fmt/core.h"
#include "tokenizer/tokenizer.h"
#include "analyser/analyser.h"
namespace fmt {
template<>
struct formatter<miniplc0::ErrorCode> {
template <typename ParseContext>
constexpr auto parse(ParseContext &ctx) { return ctx.begin(); }
template <typename FormatContext>
auto format(const miniplc0::ErrorCode &p, FormatContext &ctx) {
std::string name;
switch (p) {
case miniplc0::ErrNoError:
name = "No error.";
break;
case miniplc0::ErrStreamError:
name = "Stream error.";
break;
case miniplc0::ErrEOF:
name = "EOF";
break;
case miniplc0::ErrInvalidInput:
name = "The input is invalid.";
break;
case miniplc0::ErrInvalidIdentifier:
name = "Identifier is invalid";
break;
case miniplc0::ErrIntegerOverflow:
name = "The integer is too big(int64_t).";
break;
case miniplc0::ErrNoBegin:
name = "The program should start with 'begin'.";
break;
case miniplc0::ErrNoEnd:
name = "The program should end with 'end'.";
break;
case miniplc0::ErrNeedIdentifier:
name = "Need an identifier here.";
break;
case miniplc0::ErrConstantNeedValue:
name = "The constant need a value to initialize.";
break;
case miniplc0::ErrNoSemicolon:
name = "Zai? Wei shen me bu xie fen hao.";
break;
case miniplc0::ErrInvalidVariableDeclaration:
name = "The declaration is invalid.";
break;
case miniplc0::ErrIncompleteExpression:
name = "The expression is incomplete.";
break;
case miniplc0::ErrNotDeclared:
name = "The variable or constant must be declared before being used.";
break;
case miniplc0::ErrAssignToConstant:
name = "Trying to assign value to a constant.";
break;
case miniplc0::ErrDuplicateDeclaration:
name = "The variable or constant has been declared.";
break;
case miniplc0::ErrNotInitialized:
name = "The variable has not been initialized.";
break;
case miniplc0::ErrInvalidAssignment:
name = "The assignment statement is invalid.";
break;
case miniplc0::ErrInvalidPrint:
name = "The output statement is invalid.";
break;
case miniplc0::ErrNorightbracket:
name = "no right bracket";
break;
case miniplc0::ErrInvalidFunctioncall:
name = "the function call is invalid";
break;
case miniplc0::ErrInvalidfunctionreturn:
name = "the function return is invalid";
break;
case miniplc0::Errinvalidscan:
name = "the scan is invalid";
break;
case miniplc0::Errinvalidprint:
name = "the print is invalid";
break;
case miniplc0::Errinvalidbreak:
name = "the break is invalid";
break;
case miniplc0::Errinvalidcontinue:
name = "the continue is invalid";
break;
case miniplc0::Errinvaliddowhile:
name = " the do while loop is invalid";
break;
case miniplc0::Errinvalidfor:
name = "the for loop is invalid";
break;
case miniplc0::ErrNoMain:
name = "there is no main function";
break;
case miniplc0::Errinvalidcomment:
name = "the multi comment is invalid";
break;
}
return format_to(ctx.out(), name);
}
};
template<>
struct formatter<miniplc0::CompilationError> {
template <typename ParseContext>
constexpr auto parse(ParseContext &ctx) { return ctx.begin(); }
template <typename FormatContext>
auto format(const miniplc0::CompilationError &p, FormatContext &ctx) {
return format_to(ctx.out(), "Line: {} Column: {} Error: {}", p.GetPos().first, p.GetPos().second, p.GetCode());
}
};
}
namespace fmt {
template<>
struct formatter<miniplc0::Token> {
template <typename ParseContext>
constexpr auto parse(ParseContext &ctx) { return ctx.begin(); }
template <typename FormatContext>
auto format(const miniplc0::Token &p, FormatContext &ctx) {
return format_to(ctx.out(),
"Line: {} Column: {} Type: {} Value: {}",
p.GetStartPos().first, p.GetStartPos().second, p.GetType(), p.GetValueString());
}
};
template<>
struct formatter<miniplc0::TokenType> {
template <typename ParseContext>
constexpr auto parse(ParseContext &ctx) { return ctx.begin(); }
template <typename FormatContext>
auto format(const miniplc0::TokenType &p, FormatContext &ctx) {
std::string name;
switch (p) {
case miniplc0::NULL_TOKEN:
name = "NullToken";
break;
case miniplc0::DECIMAL_INTEGER:
name = "deCIMal integer";
break;
case miniplc0::IDENTIFIER:
name = "Identifier";
break;
case miniplc0::HEXADECIMAL_INTEGER:
name = "hexadeciaml";
break;
case miniplc0::VOID:
name = "VOID";
break;
case miniplc0::INT:
name = "int";
break;
case miniplc0::CHAR:
name = "char";
break;
case miniplc0::DOUBLE:
name = "double";
break;
case miniplc0::CONST:
name = "Const";
break;
case miniplc0::SCAN:
name = "scan";
break;
case miniplc0::PRINT:
name = "Print";
break;
case miniplc0::STRUCT:
name ="struct";
break;
case miniplc0::IF:
name = "if";
break;
case miniplc0::ELSE:
name ="else";
break;
case miniplc0::SWITCH:
name ="switch";
break;
case miniplc0::CASE:
name ="case";
break;
case miniplc0::DEFAULT:
name ="default";
break;
case miniplc0::WHILE:
name ="while";
break;
case miniplc0::FOR:
name ="for";
break;
case miniplc0::DO:
name = "do";
break;
case miniplc0::RETURN:
name ="return";
break;
case miniplc0::BREAK:
name ="break";
break;
case miniplc0::CONTINUE:
name="continue";
break;
case miniplc0::PLUS_SIGN:
name = "PlusSign";
break;
case miniplc0::MINUS_SIGN:
name = "MinusSign";
break;
case miniplc0::MULTIPLICATION_SIGN:
name = "MultiplicationSign";
break;
case miniplc0::DIVISION_SIGN:
name = "DivisionSign";
break;
case miniplc0::EQUAL_SIGN:
name = "EqualSign";
break;
case miniplc0::LESS_SIGN:
name ="less";
break;
case miniplc0::LESS_EQUAL_SIGN:
name ="lessequal";
break;
case miniplc0::GREATER_SIGN:
name ="greater";
break;
case miniplc0::GREATER_EQUAL_SIGN:
name ="greaterequal";
break;
case miniplc0::ISEQUAL_SIGN:
name ="isequal";
break;
case miniplc0::NOEQUAL_SIGN:
name ="noequal";
break;
case miniplc0::SEMICOLON:
name = "Semicolon";
break;
case miniplc0::LEFT_BRACKET:
name = "LeftBracket";
break;
case miniplc0::RIGHT_BRACKET:
name = "RightBracket";
break;
case miniplc0::LEFTBIG_BRACKET:
name ="leftbigbracket";
break;
case miniplc0::RIGHTBIG_BRACKET:
name ="rightbig_bracket";
break;
case miniplc0::COMMA_SIGN:
name ="comma";
break;
}
return format_to(ctx.out(), name);
}
};
}