namesAThing method

bool namesAThing(
  1. NotationDefinition d,
  2. String name, [
  3. int depth = 0
])

Whether the parameter name of d is a name where its body reads it: an icon's (Icon "{icon}", icon={icon}), a page's (go {to}), or such a parameter of a defined word its body calls. A bare word given to it is that name, as it is on a line of the notation's own.

Implementation

bool namesAThing(NotationDefinition d, String name, [int depth = 0]) {
  for (final l in d.body) {
    if (_nameLine.firstMatch(l.text)?[1] == name) return true;
    if (_nameKey.allMatches(l.text).any((m) => (m[1] ?? m[2]) == name)) return true;
    if (_nameGo.allMatches(l.text).any((m) => m[1] == name)) return true;
    if (depth >= 3) continue;
    final word = RegExp(r'^[A-Z][A-Za-z0-9]*').stringMatch(l.text);
    if (word == null || word == d.word || !has(word)) continue;
    for (final m in _passed.allMatches(l.text)) {
      if ((m[2] ?? m[3]) != name) continue;
      if (meanings(word).any((inner) => inner.parameters.containsKey(m[1]) && namesAThing(inner, m[1]!, depth + 1))) return true;
    }
  }
  return false;
}