mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 21:51:12 +01:00
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:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user