MCPcopy Create free account
hub / github.com/covscript/covscript / compiler_type::preprocessor

Class compiler_type::preprocessor

sources/compiler/lexer.cpp:344–479  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

342 }
343
344 class compiler_type::preprocessor final {
345 std::size_t last_line_num = 1, line_num = 1;
346 bool is_annotation = false;
347 bool is_command = false;
348 bool multi_line = false;
349 bool empty_buff = true;
350 bool empty_line = true;
351 std::deque<char> buff;
352 std::string command;
353 std::string line;
354
355 void new_empty_line(const context_t &context)
356 {
357 context->file_buff.emplace_back();
358 empty_line = true;
359 ++line_num;
360 }
361
362 void process_endline(const context_t &context, compiler_type &compiler, std::deque<token_base *> &tokens,
363 charset &encoding)
364 {
365 if (is_annotation) {
366 is_annotation = false;
367 new_empty_line(context);
368 return;
369 }
370 if (is_command) {
371 is_command = false;
372 if (command == "begin" && !multi_line)
373 multi_line = true;
374 else if (command == "end" && multi_line) {
375 tokens.push_back(new token_endline(last_line_num));
376 multi_line = false;
377 }
378 else {
379 auto pos = command.find(':');
380 std::string arg;
381 if (pos != std::string::npos) {
382 arg = command.substr(pos + 1);
383 command = command.substr(0, pos);
384 }
385 if (command == "charset") {
386 if (arg == "ascii")
387 encoding = charset::ascii;
388 else if (arg == "utf8")
389 encoding = charset::utf8;
390 else if (arg == "gbk")
391 encoding = charset::gbk;
392 else
393 throw exception(line_num, context->file_path, "@" + command + ": " + arg,
394 "Unavailable encoding.");
395 }
396 else if (command == "require") {
397 std::string version_str = CS_GET_VERSION_STR(COVSCRIPT_STD_VERSION);
398 if (arg > version_str)
399 throw exception(line_num, context->file_path, "@" + command + ": " + arg,
400 "Newer Language Standard required: " + arg + ", now on " + version_str);
401 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected