Skip to content
Snippets Groups Projects
Commit 641e1197 authored by Marijn Haverbeke's avatar Marijn Haverbeke
Browse files

Add lookahead support to runmode.node.js

parent f6b6dbe9
No related branches found
No related tags found
No related merge requests found
......@@ -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);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment