mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-01 06:24:59 +01:00
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:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user