diff --git a/addon/runmode/runmode.node.js b/addon/runmode/runmode.node.js index 93487b6bd47f283864668a96687eecfd0026710d..01d08ffed89e727e7ea7a2f5ba676b0b61fdfb5c 100644 --- a/addon/runmode/runmode.node.js +++ b/addon/runmode/runmode.node.js @@ -22,12 +22,13 @@ var countColumn = function(string, end, tabSize, startIndex, startValue) { } }; -function StringStream(string, tabSize) { +function StringStream(string, tabSize, context) { this.pos = this.start = 0; this.string = string; this.tabSize = tabSize || 8; this.lastColumnPos = this.lastColumnValue = 0; this.lineStart = 0; + this.context = context }; StringStream.prototype = { @@ -92,7 +93,10 @@ StringStream.prototype = { try { return inner(); } finally { this.lineStart -= n; } }, - lookAhead: function() { return null } + lookAhead: function(n) { + let line = this.context.line + n + return line >= this.context.lines.length ? null : this.context.lines[line] + } }; exports.StringStream = StringStream; @@ -164,9 +168,10 @@ exports.registerHelper = exports.registerGlobalHelper = Math.min; exports.runMode = function(string, modespec, callback, options) { var mode = exports.getMode({indentUnit: 2}, modespec); var lines = splitLines(string), state = (options && options.state) || exports.startState(mode); - for (var i = 0, e = lines.length; i < e; ++i) { + var context = {lines: lines, line: 0} + for (var i = 0, e = lines.length; i < e; ++i, ++context.line) { if (i) callback("\n"); - var stream = new exports.StringStream(lines[i]); + var stream = new exports.StringStream(lines[i], 4, context); if (!stream.string && mode.blankLine) mode.blankLine(state); while (!stream.eol()) { var style = mode.token(stream, state);