tryMatch method

  1. @override
bool tryMatch(
  1. String input
)

Implementation

@override
bool tryMatch(String input) {
  var currentStates = <NfaState>{};
  _addStates(start, currentStates);
  for (final value in input.runes) {
    final nextStates = <NfaState>{};
    for (final state in currentStates) {
      final nextState = state.transitions[value];
      if (nextState != null) {
        _addStates(nextState, nextStates);
      }
      for (final nextState in state.dots) {
        _addStates(nextState, nextStates);
      }
    }
    if (nextStates.isEmpty) return false;
    currentStates = nextStates;
  }
  return currentStates.any((state) => state.isEnd);
}