checkDefinitions function
List<String>
checkDefinitions(
- NotationVocabulary vocabulary, {
- required Catalog catalog,
- NotationOptions options = const NotationOptions(),
Each definition expanded once with its defaults (and a line in each
slot), as the parser reads it with the vocabulary closed: what is wrong,
each as file:line: message. A design system's folder is checked with this
before a page uses it.
Implementation
List<String> checkDefinitions(NotationVocabulary vocabulary,
{required Catalog catalog, NotationOptions options = const NotationOptions()}) {
final out = <String>[];
for (final defs in vocabulary.definitions.values) {
for (final d in defs) {
final use = [
// Its strings left out (a string may be a colour or a name, which
// no sample text is): what reads one reads nothing.
'${d.word}${d.variants.isEmpty ? '' : '.${d.variants.first}'}',
for (final r in d.required) '$r="x"',
].join(' ');
final lines = ['Column', ' $use'];
for (final s in d.slots) {
if (s.isEmpty) {
lines.add(' Text "in the slot"');
} else {
lines
..add(' $s')
..add(' Text "in $s"');
}
}
// The other meanings of the word may fit this use better: each is
// checked alone.
final alone = NotationVocabulary(
types: vocabulary.types,
parameters: vocabulary.parameters,
flags: vocabulary.flags,
events: vocabulary.events,
verbs: vocabulary.verbs,
definitions: {...vocabulary.definitions, d.word: [d]},
);
final r = parseNotation(lines.join('\n'), catalog: catalog, options: options.open(openVocabulary: false, vocabulary: alone));
for (final i in r.issues) {
final m = RegExp(r'^([^\s:]+:\d+): (.*)$').firstMatch(i.message);
out.add(m != null ? '${m[1]}: ${m[2]}' : '${d.at(d.line)}: ${i.message}');
}
}
}
return out;
}