code: function line_number(index, source) {
    // To speed things up, remember the index until which we counted,
    // then next time just begin counting from there.  This way we
    // only count each line once.
    var i = start_index;
    var count = 0;
    while (i < index) {
      if (source[i] === "\n") {
        count++;
      }
      i++;
    }
  
    start_linenr = count + start_linenr;
    start_index = index;
  
    return start_linenr;
  }
docs: Given index inside input string, returns the corresponding line number