vscode-tmgrammar-test
Version:
Test runner for VSCode textmate grammars
57 lines • 1.71 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.renderSnap = exports.parseSnap = void 0;
function parseSnap(s) {
let result = [];
let ls = s.split(/\r\n|\n/);
let i = 0;
while (i < ls.length) {
let l = ls[i];
if (l.startsWith('>')) {
const src = l.substring(1);
i++;
let tokens = [];
while (i < ls.length && ls[i].startsWith('#')) {
const startIndex = ls[i].indexOf('^');
const endIndex = ls[i].indexOf(' ', startIndex);
const scopes = ls[i]
.substring(endIndex + 1)
.split(/\s+/)
.filter((x) => x !== '');
tokens.push({
startIndex: startIndex - 1,
endIndex: endIndex - 1,
scopes: scopes
});
i++;
}
result.push({
src: src,
tokens: tokens
});
}
else {
i++;
}
}
return result;
}
exports.parseSnap = parseSnap;
function renderSnap(xs) {
let result = [];
xs.forEach((line) => {
result.push('>' + line.src);
if (line.src.trim().length > 0) {
line.tokens.forEach((token) => {
result.push('#' +
' '.repeat(token.startIndex) +
'^'.repeat(token.endIndex - token.startIndex) +
' ' +
token.scopes.join(' '));
});
}
});
return result.join('\n');
}
exports.renderSnap = renderSnap;
//# sourceMappingURL=parsing.js.map
;