process method

void process()

Implementation

void process() {
  var _states = this.states;
  var _wants = this.wants;
  var _completed = this.completed;

  for (var w = 0; w < _states.length; w++) {
    var state = _states[w]!;
    if (state.isComplete) {
      state.finish();
      if (state.data != fail) {
        var wantBy = state.wantedBy;

        for (var i = wantBy.length - 1; 0 <= i; i--) {
          var left = wantBy[i];
          this.complete(left, state);
        }

        if (state.reference == index) {
          var exp = state.rule.name;
          this.completed![exp] = this.completed![exp] ?? [];
          this.completed![exp].add(state);
        }
      }
    } else {
      var exp = state.rule.symbols[state.dot];
      if (!(exp is String)) {
        this.scannable.add(state);
        continue;
      }

      if (_wants![exp] != null) {
        _wants[exp].add(state);
        if (_completed!.containsKey(exp)) {
          var nulls = _completed[exp];
          for (var i = 0; i < nulls.length; i++) {
            var right = nulls[i];
            complete(state, right);
          }
        }
      } else {
        _wants[exp] = _wants[exp] is List ? _wants[exp].add(state) : [state];
        this.predict(exp);
      }
    }
  }
}