Add export keyword handling. (#3944)

This provides `export import` logic in lex, parse, and check; `export
name` logic is only in lex and parse, not check.

I think with `export name` I'm going to need to modify import_ref and
some consolidation logic, whereas `export import` seems feasible to keep
as primarily import logic. Given the implementations were looking like
they'd diverge more substantially, I thought it'd be helpful to cut the
PR here.
This commit is contained in:
Jon Ross-Perkins
2024-05-10 22:54:06 +00:00
committed by GitHub
parent c7e4cb2c76
commit a16842ab37
21 changed files with 1823 additions and 81 deletions
+11 -8
View File
@@ -19,7 +19,11 @@ static auto TryHandleEndOrPackagingDecl(Context& context) -> bool {
context.PopAndDiscardState();
return true;
}
// `import`, `library`, and `package` manage their packaging state.
// Packaging-related keywords manage their packaging state.
case Lex::TokenKind::Export: {
context.PushState(State::Export);
return true;
}
case Lex::TokenKind::Import: {
context.PushState(State::Import);
return true;
@@ -32,7 +36,7 @@ static auto TryHandleEndOrPackagingDecl(Context& context) -> bool {
context.PushState(State::Package);
return true;
}
default: {
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() !=
@@ -44,7 +48,6 @@ static auto TryHandleEndOrPackagingDecl(Context& context) -> bool {
Context::PackagingState::AfterNonPackagingDecl);
}
return false;
}
}
}
@@ -124,6 +127,11 @@ static auto TryHandleAsDecl(Context& context, Context::StateStackEntry state,
HandleBaseAsDecl(context, state);
return true;
}
case Lex::TokenKind::Choice: {
ApplyIntroducer(context, state, NodeKind::ChoiceIntroducer,
State::ChoiceIntroducer);
return true;
}
case Lex::TokenKind::Class: {
ApplyIntroducer(context, state, NodeKind::ClassIntroducer,
State::TypeAfterIntroducerAsClass);
@@ -168,11 +176,6 @@ static auto TryHandleAsDecl(Context& context, Context::StateStackEntry state,
State::VarAsDecl);
return true;
}
case Lex::TokenKind::Choice: {
ApplyIntroducer(context, state, NodeKind::ChoiceIntroducer,
State::ChoiceIntroducer);
return true;
}
case Lex::TokenKind::Semi: {
if (saw_modifier) {