time-to-botec/squiggle/node_modules/@rescript/std/lib/es6/printexc.js
NunoSempere b6addc7f05 feat: add the node modules
Necessary in order to clearly see the squiggle hotwiring.
2022-12-03 12:44:49 +00:00

103 lines
2.3 KiB
JavaScript

import * as Curry from "./curry.js";
import * as Pervasives from "./pervasives.js";
import * as Caml_exceptions from "./caml_exceptions.js";
import * as Caml_js_exceptions from "./caml_js_exceptions.js";
var printers = {
contents: /* [] */0
};
function locfmt(s, linum, start, finish, msg) {
return "File \"" + s + "\", line " + linum + ", characters " + start + "-" + finish + ": " + msg;
}
var fields = (function(x){
var s = ""
var index = 1
while ("_"+index in x){
s += x ["_" + index];
++ index
}
if(index === 1){
return s
}
return "(" + s + ")"
});
function to_string(x) {
var _param = printers.contents;
while(true) {
var param = _param;
if (param) {
var s;
try {
s = Curry._1(param.hd, x);
}
catch (exn){
s = undefined;
}
if (s !== undefined) {
return s;
}
_param = param.tl;
continue ;
}
if (x.RE_EXN_ID === "Match_failure") {
var match = x._1;
var $$char = match[2];
return locfmt(match[0], match[1], $$char, $$char + 5 | 0, "Pattern matching failed");
}
if (x.RE_EXN_ID === "Assert_failure") {
var match$1 = x._1;
var $$char$1 = match$1[2];
return locfmt(match$1[0], match$1[1], $$char$1, $$char$1 + 6 | 0, "Assertion failed");
}
if (x.RE_EXN_ID === "Undefined_recursive_module") {
var match$2 = x._1;
var $$char$2 = match$2[2];
return locfmt(match$2[0], match$2[1], $$char$2, $$char$2 + 6 | 0, "Undefined recursive module");
}
var constructor = Caml_exceptions.exn_slot_name(x);
return constructor + fields(x);
};
}
function print(fct, arg) {
try {
return Curry._1(fct, arg);
}
catch (raw_x){
var x = Caml_js_exceptions.internalToOCamlException(raw_x);
console.log("Uncaught exception: " + to_string(x));
throw x;
}
}
function $$catch(fct, arg) {
try {
return Curry._1(fct, arg);
}
catch (raw_x){
var x = Caml_js_exceptions.internalToOCamlException(raw_x);
console.log("Uncaught exception: " + to_string(x));
return Pervasives.exit(2);
}
}
function register_printer(fn) {
printers.contents = {
hd: fn,
tl: printers.contents
};
}
export {
to_string ,
print ,
$$catch ,
register_printer ,
}
/* No side effect */