@informalsystems/quint
Version:
Core tool for the Quint specification language
55 lines • 2.01 kB
JavaScript
;
/* ----------------------------------------------------------------------------------
* Copyright 2022 Informal Systems
* Licensed under the Apache License, Version 2.0.
* See LICENSE in the project root for license information.
* --------------------------------------------------------------------------------- */
Object.defineProperty(exports, "__esModule", { value: true });
exports.errorTreeToString = exports.buildErrorLeaf = exports.buildErrorTree = void 0;
/*
* Builds a node in the error tree with one or more errors as children
*
* @param location a description of where these errors occurred
* @param errors one or more ErrorTree instances
*
* @returns an error tree with the given location and errors, avoiding duplication
*/
function buildErrorTree(location, errors) {
if (typeof errors === 'string') {
return buildErrorLeaf(location, errors);
}
else if (!Array.isArray(errors) && location === errors.location) {
// Avoid redundant locations
return errors;
}
return { location, children: Array.isArray(errors) ? errors : [errors] };
}
exports.buildErrorTree = buildErrorTree;
/*
* Builds a leaf with given attributes
*
* @param location the description of where the error occurred
* @param message the description of the error
*
* @returns an ErrorTree with given attributes and no children
*/
function buildErrorLeaf(location, message) {
return { location, message, children: [] };
}
exports.buildErrorLeaf = buildErrorLeaf;
/**
* Formats the string representation of an error tree
*
* @param e the ErrorTree to be formatted
*
* @returns a multiline string with the pretty printed error tree
*/
function errorTreeToString(e) {
const childrenErrors = e.children.map(errorTreeToString);
let out = childrenErrors.join('and\n');
out += e.message ? e.message + '\n' : '';
out += e.location + '\n';
return out;
}
exports.errorTreeToString = errorTreeToString;
//# sourceMappingURL=errorTree.js.map