mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-03-30 13:05:25 -05:00
patterns: Added default parameters
This commit is contained in:
@@ -406,6 +406,8 @@ namespace hex::pl {
|
||||
// Parse parameter list
|
||||
bool hasParams = !peek(SEPARATOR_ROUNDBRACKETCLOSE);
|
||||
u32 unnamedParamCount = 0;
|
||||
std::vector<std::unique_ptr<ASTNode>> defaultParameters;
|
||||
|
||||
while (hasParams) {
|
||||
if (MATCHES(sequence(VALUETYPE_AUTO, SEPARATOR_DOT, SEPARATOR_DOT, SEPARATOR_DOT, IDENTIFIER))) {
|
||||
parameterPack = getValue<Token::Identifier>(-1).get();
|
||||
@@ -424,6 +426,14 @@ namespace hex::pl {
|
||||
unnamedParamCount++;
|
||||
}
|
||||
|
||||
if (MATCHES(sequence(OPERATOR_ASSIGNMENT))) {
|
||||
// Parse default parameters
|
||||
defaultParameters.push_back(parseMathematicalExpression());
|
||||
} else {
|
||||
if (!defaultParameters.empty())
|
||||
throwParserError(hex::format("default argument missing for parameter {}", params.size()));
|
||||
}
|
||||
|
||||
if (!MATCHES(sequence(SEPARATOR_COMMA))) {
|
||||
break;
|
||||
}
|
||||
@@ -444,7 +454,7 @@ namespace hex::pl {
|
||||
body.push_back(this->parseFunctionStatement());
|
||||
}
|
||||
|
||||
return create(new ASTNodeFunctionDefinition(getNamespacePrefixedName(functionName), std::move(params), std::move(body), parameterPack));
|
||||
return create(new ASTNodeFunctionDefinition(getNamespacePrefixedName(functionName), std::move(params), std::move(body), parameterPack, std::move(defaultParameters)));
|
||||
}
|
||||
|
||||
std::unique_ptr<ASTNode> Parser::parseFunctionVariableDecl() {
|
||||
|
||||
Reference in New Issue
Block a user