From a41729222640456323f46110c113a318cd98243d Mon Sep 17 00:00:00 2001 From: _ov4 Date: Sat, 5 Sep 2026 16:54:17 +0000 Subject: fix unmatched brackets --- include/lexer/token.h | 7 ++++++- module-test/ast.cc | 6 +++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/include/lexer/token.h b/include/lexer/token.h index 5494009..65ef830 100644 --- a/include/lexer/token.h +++ b/include/lexer/token.h @@ -1,6 +1,6 @@ #pragma once -#include lexer +#include #include "lexer/enum_type.h" #include "lexer/shared.h" @@ -72,6 +72,11 @@ void bracket_depth_changer(char c, int &bracket_depth) { bracket_depth--; println("changed depth: {}", bracket_depth); + if (bracket_depth < 0) + { + cerr << "Ooooops bracket unmatched, quitting" << endl; + exit(-1); // TODO: std::expected or what, rather than quitting + } return; } } diff --git a/module-test/ast.cc b/module-test/ast.cc index f9dcbb8..1710f23 100644 --- a/module-test/ast.cc +++ b/module-test/ast.cc @@ -28,7 +28,7 @@ constexpr int MAXLINE = 1024; int main() { - int test_case = 5; + int test_case = 6; string s; switch (test_case) @@ -51,6 +51,10 @@ int main() case 5: s = "alpha || beta && (gamma || epsilon)"; break; + case 6: + // bracket matching test + s = ")alpha && beta("; + break; default: return 0; } -- cgit v1.3.1-4-g156e