expandList method

Iterable<T> expandList(
  1. List<T> parses,
  2. Map<String, List<T>> parsesMap, {
  3. List<String>? replaceNewState,
})

Implementation

Iterable<T> expandList(List<T> parses, Map<String, List<T>> parsesMap,
    {List<String>? replaceNewState}) sync* {
  for (final p in parses) {
    if (p.token == Token.IncludeOtherParse) {
      yield* expandList(parsesMap[p.pattern]!, parsesMap,
          replaceNewState:
              _replaceOrAddNewStates(replaceNewState, p.newStates));
    } else if (replaceNewState != null) {
      /// Parse.include 批量替换 newState 避免污染原 Parse
      yield p.copy(
              newStates: _replaceOrAddNewStates(replaceNewState, p.newStates))
          as T;
    } else {
      yield p;
    }
  }
}