diff --git a/lib/codemirror.js b/lib/codemirror.js
index <HASH>..<HASH> 100644
--- a/lib/codemirror.js
+++ b/lib/codemirror.js
@@ -243,11 +243,15 @@ var CodeMirror = (function() {
     },
     getTokenAt: function(mode, state, ch) {
       var txt = this.text, stream = new StringStream(txt);
-      while (stream.pos <= ch && !stream.eol()) {
+      while (stream.pos < ch && !stream.eol()) {
         stream.start = stream.pos;
         var style = mode.token(stream, state);
       }
-      return {start: stream.start, end: stream.pos, string: stream.current(), className: style || null};
+      return {start: stream.start,
+              end: stream.pos,
+              string: stream.current(),
+              className: style || null,
+              state: state};
     },
     indentation: function() {return countIndentation(this.text);},
     getHTML: function(sfrom, sto, includePre) {
revise getTokenAt to return token *before* the given pos

it now also returns the parser state at that position