code: function predict(tokens, states, i, j, grammar) {
    let curr = states[i][j];
  
    // prediction
    if (curr.rule[curr.position] instanceof rules.Sym) {
      grammar.forEach((rule) => {
        let stateHasItem = states[i].filter((earleyItem) => {
          return earleyItem.rule === rule &&
                 curr.position === 0;//earleyItem.position;
        }).length > 0;
  
        if (!stateHasItem) {
          states[i].push({
            name    : rule.lhs.name,
            rule    : rule,
            position: 0,
            origin  : i
          });
        }
      });
    }
  }
docs: Prediction stage in the earley algorithm
  {@link http://loup-vaillant.fr/tutorials/earley-parsing/recogniser}
  
  This also avoids adding duplicate rules to a state, a pitfall caused by
  left-recursive grammars
  
  @function predict
  @param {string[]} tokens - Input tokens being parsed
  @param {state[]} states - Set of lists of earley items
  @param {number} i - Index of the earley state to be processed
  @param {number} j - Index of the earley item to be processed within the state
  @param {Rule[]|CFG} grammar