definitionReads function
What definition's lines leave unused and read from outside
(DefinitionReads). A primitive's lines stand in for what no line can
express, so what they leave unused is expected: it has none.
Implementation
DefinitionReads definitionReads(NotationDefinition definition) {
final d = definition;
if (d.primitive) return DefinitionReads._(d, const [], const [], const []);
final scan = _Scan(d.events.toSet());
for (final l in d.body) {
scan.line(l.text);
}
final own = {...d.strings, ...d.parameters.keys, ?d.bind};
final used = {...scan.read, ...scan.set};
return DefinitionReads._(
d,
[
for (final n in [...d.strings, ...d.parameters.keys, ?d.bind])
if (!used.contains(n) && !scan.bound.contains(n)) n,
],
[for (final e in d.events) if (!scan.fired.contains(e)) e],
{
for (final n in used)
if (!own.contains(n) && !scan.declared.contains(n) && !d.events.contains(n) && !_given.contains(n)) n,
// A variable bound with @ is the definition's own when the signature
// names it (`@value`, `open=@`, a parameter a use may bind) or the
// lines declare it; any other is the page's.
for (final n in scan.bound)
if (!own.contains(n) && !scan.declared.contains(n) && !_given.contains(n)) n,
}.toList()
..sort(),
);
}