docs: function earley(tokens, grammar) {
    let states  = Array.apply(null, Array(tokens.length + 1)).map(() => []);
    var i, j;
  
    let rulePairs = grammar.map((rule) => ({
      name    : rule.lhs.name,
      rule    : rule,
      position: 0,
      origin  : 0
    }));
  
    [].push.apply(states[0], rulePairs);
  
    for (i = 0; i <= tokens.length; i += 1) {
      for (j = 0; j < states[i].length; j += 1) {
        predict(tokens, states, i, j, grammar);
        scan(tokens, states, i, j);
        complete(tokens, states, i, j);
      }
    }
  
    return swap(removeUnfinishedItems(states));
  }