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