ordered method

The notation components in the order they can be expanded: each after the components it calls.

Implementation

List<NotationComponentSource> ordered() {
  final calls = {for (final s in sources.values) s.type: notationCallsIn(s.text, sources.keys.toSet()..remove(s.type))};
  final out = <NotationComponentSource>[];
  final state = <String, int>{};
  void visit(String t) {
    if (state[t] != null) return;
    state[t] = 1;
    for (final c in calls[t]!.toList()..sort()) {
      visit(c);
    }
    state[t] = 2;
    out.add(sources[t]!);
  }

  for (final t in sources.keys.toList()..sort()) {
    visit(t);
  }
  return out;
}