mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-04 12:41:03 +01:00
Add initial parsing for 'extern library' (#4173)
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user