diff options
author | Benji Dial <benji@benjidial.net> | 2023-05-30 14:02:35 -0400 |
---|---|---|
committer | Benji Dial <benji@benjidial.net> | 2023-05-30 14:02:35 -0400 |
commit | d97c1a6497cc41c30edb6d5322a6deac56fd2293 (patch) | |
tree | 07920c6b83e687b75b268db44937f5fa362febd0 /score | |
parent | 6678dccccdfffb9c40f64a828fd769c53bb2d29f (diff) | |
download | lib94-d97c1a6497cc41c30edb6d5322a6deac56fd2293.tar.gz |
rewrite compiler, add for/rof support
Diffstat (limited to 'score')
-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]); |