From 09c44f3b67070a0911d7f49b039efddb5e40b0de Mon Sep 17 00:00:00 2001 From: erick-alcachofa Date: Fri, 26 Dec 2025 23:54:17 -0600 Subject: [PATCH] fix(parser): resolve generic nesting ambiguity by splitting `>>` tokens Signed-off-by: erick-alcachofa Refactor the termination logic for generic parameter lists in type parsing to correctly handle nested generics. By replacing manual peeking with `peekExpect(TokenV::opGt)`, the parser now correctly handles cases where two closing angle brackets appear consecutively (e.g., `List>`). Previously, the parser manually checked for a literal `>` token. If the lexer encountered `>>` (a right-shift operator), the parser would fail to recognize it as two closing brackets. The transition to `peekExpect` allows the tokenizer to "split" the `>>` token into two individual `>` tokens when a single closing bracket is expected, resolving the classic nested template ambiguity. Key changes: - Replaced manual token validation and error reporting with `peekExpect`. - Enabled support for nested generic types without requiring spaces between closing brackets. - Simplified the `keepParsing` loop state in `lib/src/Parser/Types.cpp`. --- lib/src/Parser/Types.cpp | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/lib/src/Parser/Types.cpp b/lib/src/Parser/Types.cpp index 4d17bcf..650fe77 100644 --- a/lib/src/Parser/Types.cpp +++ b/lib/src/Parser/Types.cpp @@ -299,21 +299,11 @@ namespace arti::lang { return Unexpected{ std::move(comma).error() }; } else if (! comma.value()) { - if (peekToken = tokenizer.peek(); ! peekToken) { + if (peekToken = tokenizer.peekExpect(TokenV::opGt); ! peekToken) { return Unexpected{ std::move(peekToken).error() }; } else { - if (peekToken->value != TokenV::opGt) { - return langException( - peekToken->line, - peekToken->column, - toString(*peekToken), - "',' or '>'" - ); - } - else { - keepParsing = false; - } + keepParsing = false; } } }