notationGlossaryDefinitionLine function

String notationGlossaryDefinitionLine(
  1. NotationDefinition d
)

d as the glossary of signatures lists it: its signature with its defaults shortened to their kind (fill=#…, items=[]; a text's is left out), its slots and what its // line says it is, in a few words.

Implementation

String notationGlossaryDefinitionLine(NotationDefinition d) {
  String shown(String? v) {
    if (v == null) return '';
    if (v == 'true' || v == 'false' || RegExp(r'^-?\d+(\.\d+)?$').hasMatch(v)) return '=$v';
    if (v.startsWith('[')) return '=[]';
    if (RegExp(r'^\{\s*"').hasMatch(v)) return '={}';
    if (v.startsWith('#')) return '=#…';
    return '';
  }

  final parts = [
    '${d.word}${d.variants.map((v) => '.$v').join()}',
    for (final s in d.strings) '"$s"',
    if (d.bind != null) '@${d.bind}${shown(d.bindDefault)}',
    for (final e in d.parameters.entries)
      d.bindables.contains(e.key) ? '${e.key}=@${shown(e.value).replaceFirst('=', '')}' : (d.required.contains(e.key) ? '${e.key}!' : '${e.key}${shown(e.value)}'),
    ...d.events,
    for (final s in d.slots) '...$s',
  ];
  return d.doc.isEmpty ? parts.join(' ') : '${parts.join(' ')} : ${_gist(d.doc)}';
}