toNfa method

  1. @override
Nfa toNfa()
override

Implementation

@override
Nfa toNfa() {
  final start = NfaState(isEnd: false);
  final end = NfaState(isEnd: true);
  final childNfa = child.toNfa();
  if (min == 0 && max == null) {
    start.epsilons.add(end);
    start.epsilons.add(childNfa.start);
    childNfa.end.epsilons.add(end);
    childNfa.end.epsilons.add(childNfa.start);
    childNfa.end.isEnd = false;
  } else if (min == 0 && max == 1) {
    start.epsilons.add(end);
    start.epsilons.add(childNfa.start);
    childNfa.end.epsilons.add(end);
    childNfa.end.isEnd = false;
  } else if (min == 1 && max == null) {
    start.epsilons.add(childNfa.start);
    childNfa.end.epsilons.add(end);
    childNfa.end.epsilons.add(childNfa.start);
    childNfa.end.isEnd = false;
  } else {
    throw UnsupportedError(toString());
  }
  return Nfa(start: start, end: end);
}