Move 'export name' out of the import section. (#3950)

This implements recent updates to #3938
This commit is contained in:
Jon Ross-Perkins
2024-05-17 18:26:14 +00:00
committed by GitHub
parent 40b2217421
commit ecb300ee5e
12 changed files with 208 additions and 74 deletions
+22 -13
View File
@@ -21,11 +21,14 @@ static auto TryHandleEndOrPackagingDecl(Context& context) -> bool {
}
// Packaging-related keywords manage their packaging state.
case Lex::TokenKind::Export: {
context.PushState(State::Export);
if (!context.PositionIs(Lex::TokenKind::Import, Lookahead::NextToken)) {
break;
}
context.PushState(State::ImportAsExport);
return true;
}
case Lex::TokenKind::Import: {
context.PushState(State::Import);
context.PushState(State::ImportAsRegular);
return true;
}
case Lex::TokenKind::Library: {
@@ -37,18 +40,19 @@ static auto TryHandleEndOrPackagingDecl(Context& context) -> bool {
return true;
}
default:
// Because a non-packaging keyword was encountered, packaging is complete.
// Misplaced packaging keywords may lead to this being re-triggered.
if (context.packaging_state() !=
Context::PackagingState::AfterNonPackagingDecl) {
if (!context.first_non_packaging_token().is_valid()) {
context.set_first_non_packaging_token(*context.position());
}
context.set_packaging_state(
Context::PackagingState::AfterNonPackagingDecl);
}
return false;
break;
}
// Because a non-packaging keyword was encountered, packaging is complete.
// Misplaced packaging keywords may lead to this being re-triggered.
if (context.packaging_state() !=
Context::PackagingState::AfterNonPackagingDecl) {
if (!context.first_non_packaging_token().is_valid()) {
context.set_first_non_packaging_token(*context.position());
}
context.set_packaging_state(Context::PackagingState::AfterNonPackagingDecl);
}
return false;
}
// Finishes an invalid declaration, skipping past its end.
@@ -142,6 +146,11 @@ static auto TryHandleAsDecl(Context& context, Context::StateStackEntry state,
State::TypeAfterIntroducerAsNamedConstraint);
return true;
}
case Lex::TokenKind::Export: {
ApplyIntroducer(context, state, NodeKind::ExportIntroducer,
State::ExportName);
return true;
}
case Lex::TokenKind::Extend: {
// TODO: Treat this `extend` token as a declaration introducer
HandleUnrecognizedDecl(context, state.subtree_start);