Add initial parsing for 'extern library' (#4173)

This commit is contained in:
Jon Ross-Perkins
2024-07-26 20:47:25 +00:00
committed by GitHub
parent 37a8bfa488
commit ae675e61bd
14 changed files with 268 additions and 59 deletions
@@ -177,6 +177,7 @@ static auto ResolveAmbiguousTokenAsDeclaration(Context& context,
case Lex::TokenKind::Alias:
case Lex::TokenKind::Class:
case Lex::TokenKind::Constraint:
case Lex::TokenKind::Extern:
case Lex::TokenKind::Fn:
case Lex::TokenKind::Import:
case Lex::TokenKind::Interface:
@@ -221,6 +222,23 @@ static auto TryHandleAsModifier(Context& context) -> bool {
return true;
#include "toolchain/parse/node_kind.def"
case Lex::TokenKind::Extern: {
auto extern_token = context.Consume();
if (context.PositionIs(Lex::TokenKind::Library)) {
// `extern library <owning_library>` syntax.
auto subtree_start = context.tree().size();
context.ParseLibrarySpecifier(/*accept_default=*/true);
// TODO: Consider error recovery when a non-declaration token is next,
// like a typo of the library name.
context.AddNode(NodeKind::ExternModifierWithLibrary, extern_token,
subtree_start, /*has_error=*/false);
} else {
// `extern` syntax without a library.
context.AddLeafNode(NodeKind::ExternModifier, extern_token);
}
return true;
}
default:
return false;
}