fix(parser): resolve generic nesting ambiguity by splitting >> tokens
Signed-off-by: erick-alcachofa <erick@artichoke.dev> 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<List<Int>>`). 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`.
This commit is contained in:
parent
5762497f56
commit
09c44f3b67
@ -299,21 +299,11 @@ namespace arti::lang {
|
|||||||
return Unexpected{ std::move(comma).error() };
|
return Unexpected{ std::move(comma).error() };
|
||||||
}
|
}
|
||||||
else if (! comma.value()) {
|
else if (! comma.value()) {
|
||||||
if (peekToken = tokenizer.peek(); ! peekToken) {
|
if (peekToken = tokenizer.peekExpect(TokenV::opGt); ! peekToken) {
|
||||||
return Unexpected{ std::move(peekToken).error() };
|
return Unexpected{ std::move(peekToken).error() };
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (peekToken->value != TokenV::opGt) {
|
keepParsing = false;
|
||||||
return langException<ExceptCode::ecUnexpectedToken>(
|
|
||||||
peekToken->line,
|
|
||||||
peekToken->column,
|
|
||||||
toString(*peekToken),
|
|
||||||
"',' or '>'"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
keepParsing = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user