mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-21 20:36:39 +00:00
Improve diagnosis of mismatched brackets. (#3282)
Move handling of mismatched brackets out of the main lexing loop into a separate pass that is only run if there are mismatched brackets This is done in preparation for using both lookahead and lookbehind to work out how to match brackets, and to get this code far away from the hot lexing loop. Fix bracket insertion location to be immediately after the token that we're inserting the bracket after, rather than potentially at the end of a comment. When there are open brackets at the end of the file, say that there are open brackets, not that there's a closing bracket without a matching opening bracket.
This commit is contained in:
1 parent
3d260b92f1
commit
0a06fceb5f
13 files changed
+330
-149
No files matched your search
@@ -508,13 +508,11 @@ TEST_F(LexerTest, MatchingGroups) {
|
||||
TEST_F(LexerTest, MismatchedGroups) {
|
||||
auto buffer = Lex("{");
|
||||
EXPECT_TRUE(buffer.has_errors());
|
||||
EXPECT_THAT(buffer,
|
||||
HasTokens(llvm::ArrayRef<ExpectedToken>{
|
||||
{TokenKind::FileStart},
|
||||
{TokenKind::OpenCurlyBrace},
|
||||
{.kind = TokenKind::CloseCurlyBrace, .recovery = true},
|
||||
{TokenKind::FileEnd},
|
||||
}));
|
||||
EXPECT_THAT(buffer, HasTokens(llvm::ArrayRef<ExpectedToken>{
|
||||
{TokenKind::FileStart},
|
||||
{.kind = TokenKind::Error, .text = "{"},
|
||||
{TokenKind::FileEnd},
|
||||
}));
|
||||
|
||||
buffer = Lex("}");
|
||||
EXPECT_TRUE(buffer.has_errors());
|
||||
@@ -567,13 +565,9 @@ TEST_F(LexerTest, Whitespace) {
|
||||
true,
|
||||
// }
|
||||
true,
|
||||
// {
|
||||
// error {
|
||||
false,
|
||||
// (
|
||||
true,
|
||||
// inserted )
|
||||
true,
|
||||
// inserted }
|
||||
// error (
|
||||
true,
|
||||
// EOF
|
||||
false};
|
||||
|
||||
Reference in new issue
Block a user