Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return Parsimmon(function(input: string, i: number) {
for (let len = 4; len >= 1; len--) {
const instr = input.slice(i, i + len);
if (instr in opTable) {
return Parsimmon.makeSuccess(i + len, opTable[instr]);
}
}
return Parsimmon.makeFailure(i, 'wut');
// Chain here is an interesting trick to choose parser at parse time.
}).chain((afterParsers: Parser[]) => alt.apply(alt, afterParsers) as any as Parser);
})();
const ignoreCase = str => Pa((input, i) => {
const j = i + str.length;
const head = input.slice(i, j);
if (head.toLowerCase() === str.toLowerCase()) {
return Pa.makeSuccess(j, head);
}
// wrap the expected value in single-quotes to fit the underlying Parsimmon exception format
return Pa.makeFailure(i, `'${str.toLowerCase()}'`);
});
function fail(msg) {
let expected = "foo MAJOR.MINOR";
if (msg) {
expected += ` (${msg})`;
}
return pm.makeFailure(index, expected);
}
});
return P(function(input, i) {
let str = input.substring(i);
if (matchText(str));
if (input.charAt(i) !== char) {
return P.makeSuccess(i + 1, input.charAt(i));
}
return P.makeFailure(i, 'anything different than "' + char + '"');
});
return P((stream, i) => {
let j = 0
while (stream.charAt(i + j) === ' ') {
j = j + 1
}
if (j === target) {
return P.makeSuccess(i + j, j)
} else {
return P.makeFailure(i, 'indentation error: ' + j + ' does not equal ' + target)
}
})
}