mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-29 18:44:59 +01:00
Handle malformed subscript expressions (#3064)
Closes #3063 --------- Co-authored-by: Richard Smith <richard@metafoo.co.uk>
This commit is contained in:
co-authored by
Richard Smith
parent
7feaed312a
commit
049fbc1ee4
@@ -89,23 +89,24 @@ auto ParserContext::ConsumeAndAddOpenParen(TokenizedBuffer::Token default_token,
|
||||
}
|
||||
}
|
||||
|
||||
auto ParserContext::ConsumeAndAddCloseParen(StateStackEntry state,
|
||||
ParseNodeKind close_kind) -> void {
|
||||
// state.token should point at the introducer, with the paren one after the
|
||||
// introducer.
|
||||
auto expected_paren = *(TokenizedBuffer::TokenIterator(state.token) + 1);
|
||||
auto ParserContext::ConsumeAndAddCloseSymbol(
|
||||
TokenizedBuffer::Token expected_open, StateStackEntry state,
|
||||
ParseNodeKind close_kind) -> void {
|
||||
TokenKind open_token_kind = tokens().GetKind(expected_open);
|
||||
|
||||
if (tokens().GetKind(expected_paren) != TokenKind::OpenParen) {
|
||||
if (!open_token_kind.is_opening_symbol()) {
|
||||
AddNode(close_kind, state.token, state.subtree_start, /*has_error=*/true);
|
||||
} else if (auto close_token = ConsumeIf(TokenKind::CloseParen)) {
|
||||
} else if (auto close_token = ConsumeIf(open_token_kind.closing_symbol())) {
|
||||
AddNode(close_kind, *close_token, state.subtree_start, state.has_error);
|
||||
} else {
|
||||
// TODO: Include the location of the matching open_paren in the diagnostic.
|
||||
CARBON_DIAGNOSTIC(ExpectedCloseParen, Error,
|
||||
"Unexpected tokens before `)`.");
|
||||
emitter_->Emit(*position_, ExpectedCloseParen);
|
||||
// TODO: Include the location of the matching opening delimiter in the
|
||||
// diagnostic.
|
||||
CARBON_DIAGNOSTIC(ExpectedCloseSymbol, Error,
|
||||
"Unexpected tokens before `{0}`.", llvm::StringRef);
|
||||
emitter_->Emit(*position_, ExpectedCloseSymbol,
|
||||
open_token_kind.closing_symbol().fixed_spelling());
|
||||
|
||||
SkipTo(tokens().GetMatchedClosingToken(expected_paren));
|
||||
SkipTo(tokens().GetMatchedClosingToken(expected_open));
|
||||
AddNode(close_kind, Consume(), state.subtree_start, /*has_error=*/true);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user