Parse all kinds of declarations at function scope. (#4779)

These don't fully work in check and beyond yet, because they're not
added into lexical lookup, but already mostly do the right thing.

Per #3407, disallow namespace declarations anywhere other than at file
scope for now.

We don't treat statements starting with a packaging introducer keyword
(`package`, `library`, `import`) as declarations because they're
sufficiently unlikely to occur that the error recovery doesn't seem
important, and this avoids needing to disambiguate `package.` at the
start of an expression.
This commit is contained in:
Richard Smith
2025-01-10 07:03:10 +00:00
committed by GitHub
parent 1e5e2bc7e2
commit d42128ef9a
25 changed files with 1223 additions and 116 deletions
+6
View File
@@ -156,6 +156,12 @@ auto HandleExprInPostfix(Context& context) -> void {
}
case Lex::TokenKind::Package: {
context.AddLeafNode(NodeKind::PackageExpr, context.Consume());
if (context.PositionKind() != Lex::TokenKind::Period) {
CARBON_DIAGNOSTIC(ExpectedPeriodAfterPackage, Error,
"expected `.` after `package` expression");
context.emitter().Emit(*context.position(), ExpectedPeriodAfterPackage);
state.has_error = true;
}
context.PushState(state);
break;
}