mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-04-24 15:37:23 +00:00
function improvements
* use $ for args inside macros * allow to use screened brackets inside functions
This commit is contained in:
parent
2f88c7ae60
commit
3497922928
@ -96,8 +96,8 @@ AWPatternFunctions::findFunctionCalls(const QString function,
|
||||
// $aw_function_name<some args here if any>{{function body}}
|
||||
// * args should be always comma separated (e.g. commas are not supported
|
||||
// in this field if they are not screened by $, i.e. '$,'
|
||||
// * body depends on the function name, double brackets (i.e. {{ or }}) are
|
||||
// not supported
|
||||
// * body depends on the function name, double brackets should be screened
|
||||
// by using $, e.g. ${
|
||||
QRegularExpression regex(
|
||||
QString("\\$%1\\<(?<args>.*?)\\>\\{\\{(?<body>.*?)\\}\\}")
|
||||
.arg(function));
|
||||
@ -125,6 +125,9 @@ AWPatternFunctions::findFunctionCalls(const QString function,
|
||||
// other variables
|
||||
metadata.body = match.captured(QString("body"));
|
||||
metadata.what = match.captured();
|
||||
// replace brackets
|
||||
metadata.body.replace(QString("${"), QString("{"));
|
||||
metadata.body.replace(QString("$}"), QString("}"));
|
||||
foundFunctions.append(metadata);
|
||||
}
|
||||
|
||||
@ -238,10 +241,12 @@ QString AWPatternFunctions::insertMacros(QString code)
|
||||
}
|
||||
// generate body to replace
|
||||
QString result = macro.body;
|
||||
for (auto arg : macro.args) {
|
||||
int index = macro.args.indexOf(arg);
|
||||
result.replace(arg, function.args.at(index));
|
||||
}
|
||||
std::for_each(macro.args.cbegin(), macro.args.cend(),
|
||||
[&result, macro, function](const QString &arg) {
|
||||
int index = macro.args.indexOf(arg);
|
||||
result.replace(QString("$%1").arg(arg),
|
||||
function.args.at(index));
|
||||
});
|
||||
// do replace
|
||||
code.replace(function.what, result);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user