添加结构体组合, interface x : a + b {}

This commit is contained in:
2026-02-08 22:20:12 +08:00
parent 537011df32
commit 1dadaca4cc
6 changed files with 121 additions and 9 deletions

View File

@@ -386,6 +386,29 @@ namespace Fig
// entry: current is interface name
FString interfaceName = currentToken().getValue();
next(); // consume name
std::vector<Ast::Expression> bundles;
if (isThis(TokenType::Colon))
{
next(); // consume `:`
// parse bundle interfaces
if (isThis(TokenType::LeftBrace))
{
throwAddressableError<SyntaxError>(u8"expect interfaces to bundle");
}
while (true)
{
if (isThis(TokenType::LeftBrace)) { break; }
bundles.push_back(parseExpression(0, TokenType::Plus, TokenType::LeftBrace));
if (isThis(TokenType::Plus))
{
next(); // consume `+`
}
}
}
expect(TokenType::LeftBrace); // `{
next(); // consume `{`
@@ -427,7 +450,7 @@ namespace Fig
throwAddressableError<SyntaxError>(FString(u8"Invalid syntax"), currentAAI.line, currentAAI.column);
}
}
return makeAst<Ast::InterfaceDefAst>(interfaceName, methods, isPublic);
return makeAst<Ast::InterfaceDefAst>(interfaceName, bundles, methods, isPublic);
}
Ast::Implement Parser::__parseImplement()