From d97c1a6497cc41c30edb6d5322a6deac56fd2293 Mon Sep 17 00:00:00 2001 From: Benji Dial Date: Tue, 30 May 2023 14:02:35 -0400 Subject: rewrite compiler, add for/rof support --- score/main.cpp | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'score') 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(w1)) { - std::cout << "error compiling " << argv[1] << ": " << std::get(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(w2)) { - std::cout << "error compiling " << argv[2] << ": " << std::get(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(w1); - ws[1] = std::get(w2); + const lib94::warrior *ws[2] = {w1, w2}; print_warrior(ws[0]); print_warrior(ws[1]); -- cgit v1.2.3