findVariables function
Treats the incoming String as an Sqlite query and tries to find all used sqlite variables. Also try do identify List variables by looking at their context.
Implementation
List<VariableToken> findVariables(final String query) {
final output = <VariableToken>[];
for (final match
in RegExp(r':[\w]+| [iI][nN]\s*\((:[\w]+)\)').allMatches(query)) {
final content = match.group(0)!;
final expectsList = content.toLowerCase().startsWith(' in');
if (expectsList) {
final varname = match.group(1)!;
output.add(
VariableToken(varname, query.indexOf(varname, match.start), true));
} else {
output.add(VariableToken(content, match.start, false));
}
}
return output;
}