diff --git a/src/arc/lexer.cpp b/src/arc/lexer.cpp index c63e2466..d571699d 100644 --- a/src/arc/lexer.cpp +++ b/src/arc/lexer.cpp @@ -84,6 +84,8 @@ auto lexer::lex() -> token } else { + auto first = true; + while (true) { if (reader_.ended()) @@ -94,18 +96,21 @@ auto lexer::lex() -> token loc_.lines(); loc_.step(); } - else if (last == '#' && curr == '/') + else if (last == '#' && curr == '/' && !first) { advance(); break; } advance(); + first = false; } } } else if (last == '@') { + auto first = true; + while (true) { if (reader_.ended()) @@ -116,17 +121,20 @@ auto lexer::lex() -> token loc_.lines(); loc_.step(); } - else if (last == '@' && curr == '/') + else if (last == '@' && curr == '/' && !first) { advance(); break; } advance(); + first = false; } } else if (last == '*') { + auto first = true; + while (true) { if (reader_.ended()) @@ -137,13 +145,14 @@ auto lexer::lex() -> token loc_.lines(); loc_.step(); } - else if (last == '*' && curr == '/') + else if (last == '*' && curr == '/' && !first) { advance(); break; } advance(); + first = false; } } else if (last == '/') diff --git a/src/gsc/lexer.cpp b/src/gsc/lexer.cpp index 344b4218..759fbf32 100644 --- a/src/gsc/lexer.cpp +++ b/src/gsc/lexer.cpp @@ -84,6 +84,8 @@ auto lexer::lex() -> token } else { + auto first = true; + while (true) { if (reader_.ended()) @@ -94,18 +96,21 @@ auto lexer::lex() -> token loc_.lines(); loc_.step(); } - else if (last == '#' && curr == '/') + else if (last == '#' && curr == '/' && !first) { advance(); break; } advance(); + first = false; } } } else if (last == '@') { + auto first = true; + while (true) { if (reader_.ended()) @@ -116,17 +121,20 @@ auto lexer::lex() -> token loc_.lines(); loc_.step(); } - else if (last == '@' && curr == '/') + else if (last == '@' && curr == '/' && !first) { advance(); break; } advance(); + first = false; } } else if (last == '*') { + auto first = true; + while (true) { if (reader_.ended()) @@ -137,13 +145,14 @@ auto lexer::lex() -> token loc_.lines(); loc_.step(); } - else if (last == '*' && curr == '/') + else if (last == '*' && curr == '/' && !first) { advance(); break; } advance(); + first = false; } } else if (last == '/') diff --git a/src/tool/main.cpp b/src/tool/main.cpp index 3653b723..8f4170b0 100644 --- a/src/tool/main.cpp +++ b/src/tool/main.cpp @@ -781,6 +781,13 @@ auto assemble_file(game game, mach mach, fs::path const& file, fs::path rel) -> rel = fs::path{ games_rev.at(game) } / rel / file.filename().replace_extension((file.extension() == ".gscasm" ? ".gsc" : ".csc")); auto data = utils::file::read(file); + + if (data.size() >= 4 && !std::memcmp(&data[0], "\x80GSC", 4)) + { + std::cerr << std::format("{} at {}\n", "already assembled", file.generic_string()); + return result::success; + } + auto outasm = contexts[game][mach]->source().parse_assembly(data); auto outbin = contexts[game][mach]->assembler().assemble(*outasm); @@ -834,7 +841,7 @@ auto compile_file(game game, mach mach, fs::path const& file, fs::path rel) -> r auto data = utils::file::read(file); - if (!std::memcmp(&data[0], "\x80GSC", 4)) + if (data.size() >= 4 && !std::memcmp(&data[0], "\x80GSC", 4)) { std::cerr << std::format("{} at {}\n", "already compiled", file.generic_string()); return result::success; @@ -904,7 +911,7 @@ auto parse_file(game game, mach mach, fs::path file, fs::path rel) -> result auto data = utils::file::read(file); - if (!std::memcmp(&data[0], "\x80GSC", 4)) + if (data.size() >= 4 && !std::memcmp(&data[0], "\x80GSC", 4)) { std::cerr << std::format("{} at {}\n", "already compiled", file.generic_string()); return result::success;