class c extends Error {
  constructor(i, t, s, r) {
    super(), this.name = i, this.code = s, this.message = r, this.pos = t;
  }
}
class u extends c {
  constructor(i, t, s) {
    super("YAMLParseError", i, t, s);
  }
}
class p extends c {
  constructor(i, t, s) {
    super("YAMLWarning", i, t, s);
  }
}
const h = (o, i) => (t) => {
  if (t.pos[0] === -1)
    return;
  t.linePos = t.pos.map((e) => i.linePos(e));
  const { line: s, col: r } = t.linePos[0];
  t.message += ` at line ${s}, column ${r}`;
  let a = r - 1, n = o.substring(i.lineStarts[s - 1], i.lineStarts[s]).replace(/[\n\r]+$/, "");
  if (a >= 60 && n.length > 80) {
    const e = Math.min(a - 39, n.length - 79);
    n = "…" + n.substring(e), a -= e - 1;
  }
  if (n.length > 80 && (n = n.substring(0, 79) + "…"), s > 1 && /^ *$/.test(n.substring(0, a))) {
    let e = o.substring(i.lineStarts[s - 2], i.lineStarts[s - 1]);
    e.length > 80 && (e = e.substring(0, 79) + `…
`), n = e + n;
  }
  if (/[^ ]/.test(n)) {
    let e = 1;
    const l = t.linePos[1];
    l && l.line === s && l.col > r && (e = Math.max(1, Math.min(l.col - r, 80 - a)));
    const g = " ".repeat(a) + "^".repeat(e);
    t.message += `:

${n}
${g}
`;
  }
};
export {
  c as YAMLError,
  u as YAMLParseError,
  p as YAMLWarning,
  h as prettifyError
};
