import{createCustomError as n}from"../utils/create-custom-error.mjs";import{generate as t}from"../definition-syntax/generate.mjs";const e={offset:0,line:1,column:1};function s(n,t){const e=n&&n.loc&&n.loc[t];return e?"line"in e?o(e):e:null}function o({offset:n,line:t,column:e},s){const o={offset:n,line:t,column:e};if(s){const n=s.split(/\n|\r\n?|\f/);o.offset+=s.length,o.line+=n.length-1,o.column=1===n.length?o.column+s.length:n.pop().length+1}return o}const c=function(t,e){const s=n("SyntaxReferenceError",t+(e?" `"+e+"`":""));return s.reference=e,s},r=function(c,r,l,i){const a=n("SyntaxMatchError",c),{css:f,mismatchOffset:m,mismatchLength:u,start:h,end:g}=function(n,t){const c=n.tokens,r=n.longestMatch,l=r<c.length&&c[r].node||null,i=l!==t?l:null;let a,f,m=0,u=0,h=0,g="";for(let n=0;n<c.length;n++){const t=c[n].value;n===r&&(u=t.length,m=g.length),null!==i&&c[n].node===i&&(n<=r?h++:h=0),g+=t}return r===c.length||h>1?(a=s(i||t,"end")||o(e,g),f=o(a)):(a=s(i,"start")||o(s(t,"start")||e,g.slice(0,m)),f=s(i,"end")||o(a,g.substr(m,u))),{css:g,mismatchOffset:m,mismatchLength:u,start:a,end:f}}(i,l);return a.rawMessage=c,a.syntax=r?t(r):"<generic>",a.css=f,a.mismatchOffset=m,a.mismatchLength=u,a.message=c+"\n  syntax: "+a.syntax+"\n   value: "+(f||"<empty string>")+"\n  --------"+new Array(a.mismatchOffset+1).join("-")+"^",Object.assign(a,h),a.loc={source:l&&l.loc&&l.loc.source||"<unknown>",start:h,end:g},a};export{r as SyntaxMatchError,c as SyntaxReferenceError};