mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-04 15:21:04 +01:00
Start avoiding parse diagnostics on error tokens (#4431)
An invalid parse due to an error token isn't likely a great diagnostic as it will already have been diagnosed by the lexer. A common case to start handling that is when the parser encounters an invalid token when expecting an expression. This removes a number of unhelpful diagnostics after the lexer has done a good job diagnosing. This also means that there may be parse tree errors that aren't diagnosed when there are lexer-diagnosed errors, so track that. Follow-up to #4430 that almost finishes addressing its diagnostic TODO.
This commit is contained in:
@@ -45,7 +45,10 @@ auto Parse(Lex::TokenizedBuffer& tokens, DiagnosticConsumer& consumer,
|
||||
}
|
||||
|
||||
context.AddLeafNode(NodeKind::FileEnd, *context.position());
|
||||
tree.set_has_errors(err_tracker.seen_error());
|
||||
|
||||
// Mark the tree as potentially having errors if there were errors coming in
|
||||
// from the tokenized buffer or we diagnosed new errors.
|
||||
tree.set_has_errors(tokens.has_errors() || err_tracker.seen_error());
|
||||
|
||||
if (auto verify = tree.Verify(); !verify.ok()) {
|
||||
// TODO: This is temporarily printing to stderr directly during development.
|
||||
|
||||
Reference in New Issue
Block a user