This is really inefficient. Better:

    var ix = 0
    while (ix < ts.length && p.nextChar() == ts.charAt(ix)) ix += 1
    if (ix == ts.length) true
    else {
      p.reset(mark)
      false
    }