[Feat] 函数支持可变参数!! func (x...) 获取到的x类型为List

[Impl] Lexer现在贪心检测符号,拓展时可以直接添加到symbol_map
This commit is contained in:
2025-12-26 21:43:29 +08:00
parent 00240f1ed1
commit 8a047de1c7
5 changed files with 108 additions and 25 deletions

View File

@@ -144,6 +144,7 @@ namespace Fig
Ast::FunctionParameters::PosParasType pp;
Ast::FunctionParameters::DefParasType dp;
FString variaPara;
while (true)
{
if (isThis(TokenType::RightParen))
@@ -153,7 +154,7 @@ namespace Fig
}
expect(TokenType::Identifier, FString(u8"Identifier or `)`")); // check current
FString pname = currentToken().getValue();
next(); // skip pname
next(); // skip pname
if (isThis(TokenType::Assign)) // =
{
next();
@@ -187,6 +188,19 @@ namespace Fig
}
}
}
else if (isThis(TokenType::TripleDot))
{
variaPara = pname;
next(); // skip `...`
if (!isThis(TokenType::RightParen))
throw SyntaxError(
u8"Expects right paren, variable parameter function can only have one parameter",
currentAAI.line,
currentAAI.column
);
next(); // skip `)`
return Ast::FunctionParameters(variaPara);
}
else
{
pp.push_back({pname, ValueType::Any.name});