Urara-Blog/node_modules/.pnpm-store/v3/files/94/51ec45f0dad1f9cb3f9e2763a1084548a25016a3681bfcfb1c41aeecfca738a59f2e50c54bb97206831872674c99fdf2da9115540d31d24857d11a56443577
2022-08-14 01:14:53 +08:00

1 line
1.8 KiB
Text

class a extends Error{constructor(c){super(c),Object.setPrototypeOf(this,a.prototype)}}const A=/[\s\t\n\r]/,O=/[{}[\]=,:]/,v=/["']/,x=/[a-zA-Z_$-]/,f=/[0-9]/,N=/[a-zA-Z_$-]|[0-9]/,m=e=>{let c=0,r=0;const o=[],t=(n=0)=>e[r+n],u=()=>e[r++],l=()=>r>=e.length;function d(n){for(;t()!==n&&!l();)u();if(l())throw new a("Unterminated string");u(),o.push(e.substring(c,r))}function h(){for(;f.test(t());)u();if(t()==="-"&&f.test(t(1))){for(u();f.test(t());)u();o.push(e.substring(c,r));return}if(t()==="."&&f.test(t(1)))for(u();f.test(t());)u();o.push(parseFloat(e.substring(c,r)))}function g(){for(;N.test(t())&&!l();)u();o.push(e.substring(c,r))}function b(){for(;!l();){c=r;const n=u();if(!A.test(n))if(O.test(n))o.push(n);else if(v.test(n))d(n);else if(f.test(n))h();else if(x.test(n))g();else throw new a(`Unexpected character ${n}`)}return o}return b()},y={true:!0,false:!1,NaN:NaN,null:null,undefined:void 0},S="highlight",E=e=>typeof e=="string"&&/^(['"]).*\1$/.test(e),j=e=>{let c=0;const r=new Map,o=(s=0)=>e[c+s],t=()=>e[c++],u=()=>c>=e.length;function l(s,i,w){const p=[];if(t(),o()!==i)for(p.push(w());o()===",";){if(t(),o()===i)throw new a("Trailing comma");p.push(w())}if(t()!==i)throw new a(`Unterminated ${s}`);return p}function d(){return l("array","]",g)}function h(){return Object.fromEntries(l("object","}",()=>{const[i,w]=n(":");return[E(i)?i.slice(1,-1):String(i),w]}))}function g(){const s=o();return s==="{"?h():s==="["?d():E(s)?t().slice(1,-1):s in y?y[t()]:t()}function b(){const s=r.has(S)?r.get(S):{};return[S,{...s,...h()}]}function n(s="="){const i=t();return o()===s?(t(),[i,g()]):[i,!0]}function k(){for(;!u();){const[s,i]=o()==="{"?b():n();r.set(String(s).toLowerCase(),i)}return r}return Object.fromEntries(k())},U=e=>j(m(e));export{a as FenceparserError,U as default,m as lex,j as parse};