You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
709 B
JavaScript

"use strict";
const errorChain = require("error-chain");
module.exports = {
parse: function parseText(text, parser) {
return parser.parse(text);
},
// FIXME: Force global implementation!
ParseError: errorChain.create("ParseError"),
errorResult: function (error) {
// FIXME: Validatem
if (!(error instanceof Error)) {
throw new Error(`Attempted to initialize an errorResult with a value that is not an Error; this is invalid`);
}
return {
__textParser_isErrorResult: true,
get: function () {
return error;
},
throw: function () {
throw error;
}
};
},
isErrorResult: function (value) {
return (value != null && value.__textParser_isErrorResult === true);
}
};