diff options
| author | _ov4 <ov4@ov4.org> | 2026-09-17 08:10:52 +0000 |
|---|---|---|
| committer | _ov4 <ov4@ov4.org> | 2026-09-17 08:10:52 +0000 |
| commit | cf117c70277fab4d3de170b55fe8248d9cc36927 (patch) | |
| tree | 78efc40129e6cd93365950ffe3385e6dcd193ba5 | |
| parent | a692ff50c9c0ef169a2c672ad5d9a063a3818f9e (diff) | |
add throw for unmatched brackets
| -rw-r--r-- | module-test/lexer_test.cc | 7 | ||||
| -rw-r--r-- | src/lexer/token.cc | 7 | ||||
| -rw-r--r-- | src/option.cc | 2 |
3 files changed, 12 insertions, 4 deletions
diff --git a/module-test/lexer_test.cc b/module-test/lexer_test.cc index 50b6da0..20e9556 100644 --- a/module-test/lexer_test.cc +++ b/module-test/lexer_test.cc @@ -37,7 +37,7 @@ constexpr int MAXLINE = 1024; int main() { verbose = true; - int test_case = 16; + int test_case = 17; string s; switch (test_case) @@ -121,6 +121,11 @@ int main() s = "(ls)"; break; + // more LEFT brackets than RIGHT + case 17: + s = "((alpha)"; + break; + default: return 0; } diff --git a/src/lexer/token.cc b/src/lexer/token.cc index ab9f263..26ad1f2 100644 --- a/src/lexer/token.cc +++ b/src/lexer/token.cc @@ -54,8 +54,7 @@ void T_lexer::bracket_depth_changer(char c, int &bracket_depth) loggerln("changed depth: {}", bracket_depth); if (bracket_depth < 0) { - cerr << "Ooooops bracket unmatched, quitting" << endl; - exit(-1); // TODO: std::expected or what, rather than quitting + throw T_error{error_code::TOKEN_UNMATCHED_BRACKET, "tokenizer: unmatched bracket(s)"}; } return; } @@ -194,6 +193,10 @@ int T_lexer::tokenizer(const string &s) continue; } } + + if (bracket_depth != 0) + throw T_error{error_code::TOKEN_UNMATCHED_BRACKET, "tokenizer: unmatched bracket(s)"}; + return 0; } diff --git a/src/option.cc b/src/option.cc index 2cae4ef..9396dad 100644 --- a/src/option.cc +++ b/src/option.cc @@ -58,7 +58,7 @@ Usage: ccshell [-hvp] \n\ -v(=<bool>) print additional diagnostic information \n\ -p(=<bool>) do not emit a command prompt \ " << endl; - exit(1); + exit(0); } } |
