diff options
Diffstat (limited to 'score/main.cpp')
-rw-r--r-- | score/main.cpp | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/score/main.cpp b/score/main.cpp index 88536bb..85a889b 100644 --- a/score/main.cpp +++ b/score/main.cpp @@ -43,22 +43,25 @@ int main(int argc, const char **argv) { file1.close(); file2.close(); - auto w1 = lib94::compile_warrior(source1); - auto w2 = lib94::compile_warrior(source2); + lib94::warrior *w1, *w2; - if (std::holds_alternative<std::string>(w1)) { - std::cout << "error compiling " << argv[1] << ": " << std::get<std::string>(w1) << '\n'; + try { + w1 = lib94::compile_warrior(source1); + } + catch (const lib94::compiler_exception &ex) { + std::cout << "error in " << argv[1] << " on line " << ex.line_number << ": " << ex.message << '\n'; return 1; } - if (std::holds_alternative<std::string>(w2)) { - std::cout << "error compiling " << argv[2] << ": " << std::get<std::string>(w2) << '\n'; + try { + w2 = lib94::compile_warrior(source1); + } + catch (const lib94::compiler_exception &ex) { + std::cout << "error in " << argv[2] << " on line " << ex.line_number << ": " << ex.message << '\n'; return 1; } - const lib94::warrior *ws[2]; - ws[0] = std::get<lib94::warrior *>(w1); - ws[1] = std::get<lib94::warrior *>(w2); + const lib94::warrior *ws[2] = {w1, w2}; print_warrior(ws[0]); print_warrior(ws[1]); |