parjs
Version:
A parser-combinator library for JavaScript.
35 lines (34 loc) • 1.04 kB
JavaScript
;
/**
* @module parjs
*/
/** */
Object.defineProperty(exports, "__esModule", { value: true });
const result_1 = require("../result");
const parser_1 = require("../parser");
/**
* Returns a parser that parses exactly `length` characters and yields the
* text that was parsed.
* @param length The number of characters to parse.
*/
function stringLen(length) {
return new class StringLen extends parser_1.ParjserBase {
constructor() {
super(...arguments);
this.type = "stringLen";
this.expecting = `expecting ${length} characters`;
}
_apply(ps) {
let { position, input } = ps;
if (input.length < position + length) {
ps.kind = result_1.ResultKind.SoftFail;
return;
}
ps.position += length;
ps.value = input.substr(position, length);
ps.kind = result_1.ResultKind.Ok;
}
}();
}
exports.stringLen = stringLen;
//# sourceMappingURL=string-len.js.map