Urara-Blog/node_modules/.pnpm-store/v3/files/99/3161e0a934137d0a51ddceea9aa1eab3a9f4f9d888f58a6d8ba14de64fce5aac680d8a063253e5a949f05ab7001c0a9280ce7726abdb63b9ede079f131fbdd
2022-08-14 01:14:53 +08:00

1 line
2.2 KiB
Text

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});class FenceparserError extends Error{constructor(c){super(c),Object.setPrototypeOf(this,FenceparserError.prototype)}}const SPACES=/[\s\t\n\r]/,OPS=/[{}[\]=,:]/,QUOTES=/["']/,ALPHAS=/[a-zA-Z_$-]/,NUMBERS=/[0-9]/,ALPHANUMERIC=/[a-zA-Z_$-]|[0-9]/,lex=e=>{let c=0,r=0;const o=[],t=(n=0)=>e[r+n],u=()=>e[r++],l=()=>r>=e.length;function g(n){for(;t()!==n&&!l();)u();if(l())throw new FenceparserError("Unterminated string");u(),o.push(e.substring(c,r))}function a(){for(;NUMBERS.test(t());)u();if(t()==="-"&&NUMBERS.test(t(1))){for(u();NUMBERS.test(t());)u();o.push(e.substring(c,r));return}if(t()==="."&&NUMBERS.test(t(1)))for(u();NUMBERS.test(t());)u();o.push(parseFloat(e.substring(c,r)))}function f(){for(;ALPHANUMERIC.test(t())&&!l();)u();o.push(e.substring(c,r))}function w(){for(;!l();){c=r;const n=u();if(!SPACES.test(n))if(OPS.test(n))o.push(n);else if(QUOTES.test(n))g(n);else if(NUMBERS.test(n))a();else if(ALPHAS.test(n))f();else throw new FenceparserError(`Unexpected character ${n}`)}return o}return w()},KEYWORDS={true:!0,false:!1,NaN:NaN,null:null,undefined:void 0},HIGHLIGHT="highlight",isQuotedString=e=>typeof e=="string"&&/^(['"]).*\1$/.test(e),parse=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,h){const d=[];if(t(),o()!==i)for(d.push(h());o()===",";){if(t(),o()===i)throw new FenceparserError("Trailing comma");d.push(h())}if(t()!==i)throw new FenceparserError(`Unterminated ${s}`);return d}function g(){return l("array","]",f)}function a(){return Object.fromEntries(l("object","}",()=>{const[i,h]=n(":");return[isQuotedString(i)?i.slice(1,-1):String(i),h]}))}function f(){const s=o();return s==="{"?a():s==="["?g():isQuotedString(s)?t().slice(1,-1):s in KEYWORDS?KEYWORDS[t()]:t()}function w(){const s=r.has(HIGHLIGHT)?r.get(HIGHLIGHT):{};return[HIGHLIGHT,{...s,...a()}]}function n(s="="){const i=t();return o()===s?(t(),[i,f()]):[i,!0]}function p(){for(;!u();){const[s,i]=o()==="{"?w():n();r.set(String(s).toLowerCase(),i)}return r}return Object.fromEntries(p())},index=e=>parse(lex(e));exports.FenceparserError=FenceparserError,exports.default=index,exports.lex=lex,exports.parse=parse;