registryKeys function
The keys of the Map<String, <type>> <variable> registry declared in
file, skipping commented-out entries.
Returns an empty list when file has no such map.
Implementation
List<String> registryKeys(
String file, {
required String variable,
required String type,
}) {
final RegExpMatch? map =
_guardedMap(variable, type).firstMatch(file) ??
_plainMap(variable, type).firstMatch(file);
if (map == null) return const [];
// Strings and comments are matched whole, left to right, so a quote inside
// a comment or a value is never read as the start of a key.
return [
for (final RegExpMatch token in RegExp(
r'''\'([^'\n]*)'(\s*:)?|"([^"\n]*)"(\s*:)?|//[^\n]*|/\*[\s\S]*?\*/''',
).allMatches(map.group(1)!))
if (token.group(2) != null)
token.group(1)!
else if (token.group(4) != null)
token.group(3)!,
];
}