matchOccurrence method

  1. @override
Set<int> matchOccurrence(
  1. String occurrenceName,
  2. int stateIndex
)
override

Try matching an occurrence name at match state stateIndex.

Returns a set of successor states. Multiple successors arise when the query is ambiguous at this point (e.g. a glob-star ** can consume zero or more levels).

An empty set means "no match — prune this subtree".

Implementation

@override
Set<int> matchOccurrence(String occurrenceName, int stateIndex) {
  if (stateIndex >= segments.length) {
    return const {};
  }
  final seg = segments[stateIndex];
  final results = <int>{};
  if (seg.isGlobStar) {
    // ** matches zero levels (skip) …
    results
      ..addAll(matchOccurrence(occurrenceName, stateIndex + 1))
      // … or consumes this node and stays at ** (one-or-more levels).
      ..add(stateIndex);
  } else if (seg.regex!.hasMatch(occurrenceName)) {
    results.add(stateIndex + 1);
  }
  return results;
}