@cbortech/cbor 0.26.8 → 0.27.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.ja.md +120 -28
- package/README.md +121 -29
- package/dist/ast/CborAppSeqResult.d.ts +22 -0
- package/dist/ast/CborByteString.d.ts +16 -0
- package/dist/ast/CborEmbeddedCBOR.d.ts +1 -1
- package/dist/ast/CborFloat.d.ts +1 -1
- package/dist/ast/CborIndefiniteByteString.d.ts +24 -0
- package/dist/ast/CborIndefiniteTextString.d.ts +16 -0
- package/dist/ast/CborItem.d.ts +44 -4
- package/dist/ast/CborTag.d.ts +27 -0
- package/dist/ast/CborTextString.d.ts +2 -1
- package/dist/ast/CborUnresolvedAppExt.d.ts +2 -2
- package/dist/ast/index.cjs +1 -1
- package/dist/ast/index.js +2 -2
- package/dist/cddl/index.cjs +1 -1
- package/dist/cddl/index.js +1 -1
- package/dist/cdn/index.cjs +2 -2
- package/dist/cdn/index.cjs.map +1 -1
- package/dist/cdn/index.js +18 -18
- package/dist/cdn/index.js.map +1 -1
- package/dist/cdn/serialize-utils.d.ts +207 -8
- package/dist/cdn/tokenizer.d.ts +12 -11
- package/dist/extensions/builtins.d.ts +5 -5
- package/dist/extensions/cri.d.ts +2 -2
- package/dist/extensions/ip.d.ts +1 -1
- package/dist/extensions/types.d.ts +4 -4
- package/dist/index.cjs +3 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +158 -158
- package/dist/index.js.map +1 -1
- package/dist/mapEntries-C1f7G0AM.cjs +13 -0
- package/dist/mapEntries-C1f7G0AM.cjs.map +1 -0
- package/dist/{mapEntries-Ci_dppP6.js → mapEntries-CvLdiN0h.js} +1362 -1219
- package/dist/mapEntries-CvLdiN0h.js.map +1 -0
- package/dist/{schema-y8G5mDIS.js → schema-CNfrVRYp.js} +294 -294
- package/dist/{schema-y8G5mDIS.js.map → schema-CNfrVRYp.js.map} +1 -1
- package/dist/schema-iXpYtKQl.cjs +63 -0
- package/dist/{schema-DgnkH0P6.cjs.map → schema-iXpYtKQl.cjs.map} +1 -1
- package/dist/{tokenizer-N-vAvRdj.js → serialize-utils-BuIZPaUc.js} +626 -358
- package/dist/serialize-utils-BuIZPaUc.js.map +1 -0
- package/dist/serialize-utils-CjTqQivB.cjs +37 -0
- package/dist/serialize-utils-CjTqQivB.cjs.map +1 -0
- package/dist/types.d.ts +235 -58
- package/dist/utils/base64.d.ts +1 -1
- package/dist/utils/hexfloat.d.ts +1 -1
- package/dist/utils/strip-comments.d.ts +1 -1
- package/package.json +8 -6
- package/dist/mapEntries-BJzyBUH5.cjs +0 -13
- package/dist/mapEntries-BJzyBUH5.cjs.map +0 -1
- package/dist/mapEntries-Ci_dppP6.js.map +0 -1
- package/dist/schema-DgnkH0P6.cjs +0 -63
- package/dist/tokenizer-BD08xbyd.cjs +0 -36
- package/dist/tokenizer-BD08xbyd.cjs.map +0 -1
- package/dist/tokenizer-N-vAvRdj.js.map +0 -1
package/dist/schema-DgnkH0P6.cjs
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
const e=require("./tokenizer-BD08xbyd.cjs"),t=require("./mapEntries-BJzyBUH5.cjs");var n=class extends SyntaxError{offset;line;column;endOffset;constructor(e,t){let n=t?.line===void 0?``:` at line ${t.line}, column ${t.column}`;super(`CDDL parse error${n}: ${e}`),this.name=`CddlSyntaxError`,this.offset=t?.offset,this.line=t?.line,this.column=t?.column,this.endOffset=t?.endOffset}},r=class extends Error{errors;warnings;constructor(e,t=[]){let n=e[0],r=n?.path?` at ${n.path}`:``,i=e.length>1?` (and ${e.length-1} more)`:``;super(`CDDL validation failed${r}: ${n?.message??`unknown`}${i}`),this.name=`CddlMismatchError`,this.errors=e,this.warnings=t}},i=class extends Error{warnings;constructor(e){let t=e[0],n=e.length>1?` (and ${e.length-1} more)`:``;super(`CDDL semantic error: ${t?.message??`unknown`}${n}`),this.name=`CddlSemanticError`,this.warnings=e}},a=new TextEncoder,o=e=>e>=`0`&&e<=`9`,s=e=>o(e)||e>=`a`&&e<=`f`||e>=`A`&&e<=`F`,c=e=>e>=`a`&&e<=`z`||e>=`A`&&e<=`Z`||e===`@`||e===`_`||e===`$`,l=e=>e>=160&&e<=55295||e>=57344&&e<=1114109,u=class{input;pos=0;line=1;col=1;comments=[];lastEndOffset=0;constructor(e){this.input=e}_eof(){return this.pos>=this.input.length}_ch(){return this.input[this.pos]??``}_advance(){let e=this.input[this.pos]??``;return this.pos++,e===`
|
|
2
|
-
`?(this.line++,this.col=1):this.col++,e}_fail(e,t,r){throw new n(e,{offset:this.pos,line:t??this.line,column:r??this.col})}_skipWs(){for(;;){let e=this._ch();if(e===` `||e===`
|
|
3
|
-
`||e===`\r`){this._advance();continue}if(e===` `&&this._fail(`horizontal tab is not valid whitespace in CDDL (RFC 8610 ABNF allows only space and newline)`),e===`;`){this._scanComment();continue}return}}_scanComment(){let e=this.pos,t=this.line,n=this.col;this._advance();let r=this.pos;for(;r<this.input.length;){let e=this.input[r];if(e===`
|
|
4
|
-
`||e===`\r`)break;r++}let i=this.input.slice(this.pos,r);this.col+=r-this.pos,this.pos=r,this.comments.push({text:i,start:e,end:r,line:t,col:n})}_make(e,t,n,r,i,a){let o={type:e,value:t,raw:this.input.slice(n,this.pos),line:r,col:i,offset:n,endOffset:this.pos,...a};return this.lastEndOffset=this.pos,o}consume(){this._skipWs();let e=this.pos,t=this.line,n=this.col;if(this._eof())return this._make(`EOF`,``,e,t,n);let r=this._ch();if(c(r)){let r=this._scanIdText();return(r===`h`||r===`b64`)&&this._ch()===`'`?this._scanBytes(r,e,t,n):this._make(`ID`,r,e,t,n)}if(o(r)||r===`-`)return this._scanNumber(e,t,n);if(r===`"`)return this._scanText(e,t,n);if(r===`'`)return this._scanBytes(``,e,t,n);if(r===`#`)return this._scanHash(e,t,n);switch(r){case`=`:return this._advance(),this._ch()===`>`?(this._advance(),this._make(`ARROW`,`=>`,e,t,n)):this._make(`ASSIGN`,`=`,e,t,n);case`/`:return this._advance(),this._ch()===`/`?(this._advance(),this._ch()===`=`?(this._advance(),this._make(`DSLASH_EQ`,`//=`,e,t,n)):this._make(`DSLASH`,`//`,e,t,n)):this._ch()===`=`?(this._advance(),this._make(`SLASH_EQ`,`/=`,e,t,n)):this._make(`SLASH`,`/`,e,t,n);case`.`:{if(this._advance(),this._ch()===`.`)return this._advance(),this._ch()===`.`?(this._advance(),this._make(`RANGE_EXCL`,`...`,e,t,n)):this._make(`RANGE_INCL`,`..`,e,t,n);c(this._ch())||this._fail(`expected a control operator name after '.' (e.g. .size), got ${this._eof()?`end of input`:JSON.stringify(this._ch())}`,t,n);let r=this._scanIdText();return this._make(`CTLOP`,r,e,t,n)}case`,`:return this._advance(),this._make(`COMMA`,`,`,e,t,n);case`(`:return this._advance(),this._make(`LPAREN`,`(`,e,t,n);case`)`:return this._advance(),this._make(`RPAREN`,`)`,e,t,n);case`{`:return this._advance(),this._make(`LBRACE`,`{`,e,t,n);case`}`:return this._advance(),this._make(`RBRACE`,`}`,e,t,n);case`[`:return this._advance(),this._make(`LBRACKET`,`[`,e,t,n);case`]`:return this._advance(),this._make(`RBRACKET`,`]`,e,t,n);case`<`:return this._advance(),this._make(`LT`,`<`,e,t,n);case`>`:return this._advance(),this._make(`GT`,`>`,e,t,n);case`~`:return this._advance(),this._make(`TILDE`,`~`,e,t,n);case`&`:return this._advance(),this._make(`AMP`,`&`,e,t,n);case`*`:return this._advance(),this._make(`STAR`,`*`,e,t,n);case`+`:return this._advance(),this._make(`PLUS`,`+`,e,t,n);case`?`:return this._advance(),this._make(`QUEST`,`?`,e,t,n);case`:`:return this._advance(),this._make(`COLON`,`:`,e,t,n);case`^`:return this._advance(),this._make(`CARET`,`^`,e,t,n);default:this._fail(`unexpected character ${JSON.stringify(r)}`)}}_scanIdText(){let e=this.pos;for(this._advance();;){let e=this._ch();if(c(e)||o(e)){this._advance();continue}if(e===`-`||e===`.`){let e=this.pos;for(;this.input[e]===`-`||this.input[e]===`.`;)e++;let t=this.input[e]??``;if(!(c(t)||o(t)))break;for(;this.pos<=e;)this._advance();continue}break}return this.input.slice(e,this.pos)}_scanNumber(e,t,n){this._ch()===`-`&&this._advance(),o(this._ch())||this._fail(`expected a digit after '-'`,t,n);let r=!1;if(this._ch()===`0`&&/[xX]/.test(this.input[this.pos+1]??``)){for(this._advance(),this._advance(),s(this._ch())||this._fail(`expected hex digits after 0x`,t,n);s(this._ch());)this._advance();if(this._ch()===`.`&&s(this.input[this.pos+1]??``)&&this.input[this.pos+1]!==void 0){for(this._advance();s(this._ch());)this._advance();/[pP]/.test(this._ch())||this._fail(`hexadecimal fraction requires a 'p' exponent (hexfloat)`,t,n)}if(/[pP]/.test(this._ch())){for(this._advance(),(this._ch()===`+`||this._ch()===`-`)&&this._advance(),o(this._ch())||this._fail(`expected exponent digits after 'p'`,t,n);o(this._ch());)this._advance();r=!0}}else if(this._ch()===`0`&&/[bB]/.test(this.input[this.pos+1]??``))for(this._advance(),this._advance(),/[01]/.test(this._ch())||this._fail(`expected binary digits after 0b`,t,n);/[01]/.test(this._ch());)this._advance();else{for(this._ch()===`0`&&o(this.input[this.pos+1]??``)&&this._fail(`leading zeros are not allowed in CDDL numbers`,t,n);o(this._ch());)this._advance();if(this._ch()===`.`&&o(this.input[this.pos+1]??``)){for(this._advance();o(this._ch());)this._advance();r=!0}if(/[eE]/.test(this._ch())){for(this._advance(),(this._ch()===`+`||this._ch()===`-`)&&this._advance(),o(this._ch())||this._fail(`expected exponent digits after 'e'`,t,n);o(this._ch());)this._advance();r=!0}}let i=this.input.slice(e,this.pos);return this._make(r?`FLOAT`:`INT`,i,e,t,n)}_scanUintRaw(){let e=this.pos;if(o(this._ch())||this._fail(`expected an unsigned integer head-number`),this._ch()===`0`&&/[xX]/.test(this.input[this.pos+1]??``))for(this._advance(),this._advance(),s(this._ch())||this._fail(`expected hex digits after 0x`);s(this._ch());)this._advance();else if(this._ch()===`0`&&/[bB]/.test(this.input[this.pos+1]??``))for(this._advance(),this._advance(),/[01]/.test(this._ch())||this._fail(`expected binary digits after 0b`);/[01]/.test(this._ch());)this._advance();else for(this._ch()===`0`&&o(this.input[this.pos+1]??``)&&this._fail(`leading zeros are not allowed in CDDL numbers`);o(this._ch());)this._advance();return this.input.slice(e,this.pos)}_scanHash(e,t,n){this._advance();let r={};return o(this._ch())&&(r.hashMajor=this._advance().charCodeAt(0)-48,this._ch()===`.`&&(this.input[this.pos+1]===`<`?(this._advance(),r.hashAIExpr=!0):(this._advance(),r.hashAI=BigInt(this._scanUintRaw())))),this._make(`HASH`,this.input.slice(e,this.pos),e,t,n,r)}_scanText(e,t,n){let r=this._readStringBody(`"`);return this._make(`TSTR`,r,e,t,n)}_scanBytes(r,i,o,s){let c=this._readStringBody(`'`),l;if(r===``)l=a.encode(c);else{let a=d(c);try{l=r===`h`?e.E(a):t.x(a)}catch(e){throw!(e instanceof SyntaxError)||e instanceof n?e:new n(e.message,{offset:i,line:o,column:s,endOffset:this.pos})}}return this._make(`BYTES`,c,i,o,s,{qualifier:r,bytes:l})}_readStringBody(e){let t=e===`'`;this._advance();let n=``;for(;;){this._eof()&&this._fail(`unterminated ${t?`byte`:`text`} string literal`);let r=this._ch();if(r===e)return this._advance(),n;if(r===`\\`){let e=this.line,r=this.col;this._advance();let i=this._advance();switch(i){case`"`:n+=`"`;break;case`/`:n+=`/`;break;case`\\`:n+=`\\`;break;case`b`:n+=`\b`;break;case`f`:n+=`\f`;break;case`n`:n+=`
|
|
5
|
-
`;break;case`r`:n+=`\r`;break;case`t`:n+=` `;break;case`u`:n+=this._readUnicodeEscape(e,r);break;case`'`:t||this._fail(`\\' is only valid in byte string literals; text strings do not need it`,e,r),n+=`'`;break;default:this._fail(`invalid escape sequence \\${i}`,e,r)}continue}if(r===`
|
|
6
|
-
`||r===`\r`){t||this._fail(`text string literals cannot span lines (escape the newline as \\n)`),r===`\r`?(this._advance(),this._ch()!==`
|
|
7
|
-
`&&this._fail(`bare CR is not allowed in byte string literals`),this._advance(),n+=`\r
|
|
8
|
-
`):(this._advance(),n+=`
|
|
9
|
-
`);continue}let i=this.input.codePointAt(this.pos);(i<32||i>=127&&i<=159)&&this._fail(`unescaped control character U+${i.toString(16).padStart(4,`0`).toUpperCase()} is not allowed in string literals`),i>126&&!l(i)&&this._fail(`code point U+${i.toString(16).toUpperCase()} is not allowed in CDDL source`),this._advance(),i>65535&&this._advance(),n+=String.fromCodePoint(i)}}_readUnicodeEscape(e,t){if(this._ch()===`{`){this._advance();let n=``;for(;s(this._ch());)n+=this._advance();n.length===0&&this._fail(`\\u{} escape requires at least one hex digit`,e,t),this._ch()!==`}`&&this._fail(`expected '}' to close \\u{...} escape`,e,t),this._advance();let r=parseInt(n,16);return r>1114111&&this._fail(`\\u{${n}} is above the Unicode code point maximum U+10FFFF`,e,t),r>=55296&&r<=57343&&this._fail(`\\u{${n}} is a surrogate code point, not a Unicode scalar value`,e,t),String.fromCodePoint(r)}let n=()=>{let n=``;for(let r=0;r<4;r++)s(this._ch())||this._fail(`\\u escape requires four hex digits`,e,t),n+=this._advance();return parseInt(n,16)},r=n();if(r>=55296&&r<=56319){(this._ch()!==`\\`||this.input[this.pos+1]!==`u`)&&this._fail(`high surrogate \\u escape must be followed by a low surrogate \\u escape`,e,t),this._advance(),this._advance();let i=n();return(i<56320||i>57343)&&this._fail(`high surrogate \\u escape must be followed by a low surrogate \\u escape`,e,t),String.fromCodePoint(65536+(r-55296<<10)+(i-56320))}return r>=56320&&r<=57343&&this._fail(`lone low surrogate \\u escape`,e,t),String.fromCodePoint(r)}};function d(e){let t=``,n=0;for(;n<e.length;){let r=e[n];if(r===` `||r===`
|
|
10
|
-
`||r===`\r`){n++;continue}if(r===`;`){for(;n<e.length&&e[n]!==`
|
|
11
|
-
`;)n++;continue}t+=r,n++}return t}function f(e){let t=new u(e);return{rules:new m(t).parse(),comments:t.comments}}var p=new Set([`SLASH`,`RANGE_INCL`,`RANGE_EXCL`,`CTLOP`,`ARROW`,`CARET`]),m=class{t;buf=[];constructor(e){this.t=e}peek(e=0){for(;this.buf.length<=e;)this.buf.push(this.t.consume());return this.buf[e]}consume(){return this.buf.shift()??this.t.consume()}expect(e,t){let n=this.peek();return n.type!==e&&this._fail(`expected ${t}`,n),this.consume()}_fail(e,t){throw new n(`${e}, got ${t.type===`EOF`?`end of input`:`${JSON.stringify(t.raw)}`}`,{offset:t.offset,endOffset:t.endOffset,line:t.line,column:t.col})}parse(){let e=[];for(;this.peek().type!==`EOF`;)e.push(this.parseRule());return e}parseRule(){let e=this.expect(`ID`,`a rule name`),t;if(this.peek().type===`LT`){for(this.consume(),t=[this.expect(`ID`,`a generic parameter name`).value];this.peek().type===`COMMA`;)this.consume(),t.push(this.expect(`ID`,`a generic parameter name`).value);this.expect(`GT`,`'>' after generic parameters`)}let n=this.peek(),r;n.type===`ASSIGN`?r=`=`:n.type===`SLASH_EQ`?r=`/=`:n.type===`DSLASH_EQ`?r=`//=`:this._fail(`expected '=', '/=' or '//=' after rule name`,n),this.consume();let i=r===`/=`?this.parseTypeAsEntry():this.parseGroupEntry();return{kind:`rule`,name:e.value,...t?{generics:t}:{},assign:r,body:i,start:e.offset,end:i.end}}parseTypeAsEntry(){let e=this.parseType();return{kind:`entry`,value:e,start:e.start,end:e.end}}parseGroup(e){let t=this.peek().offset,n=[[]],r=!1;for(;;){let t=this.peek();if(t.type===e)break;if(t.type===`EOF`&&this._fail(`unterminated group; expected ${JSON.stringify(e)}`,t),t.type===`DSLASH`){this.consume(),n.push([]),r=!1;continue}n[n.length-1].push(this.parseGroupEntry()),r=this.peek().type===`COMMA`,r&&this.consume()}let i=this.peek();return{kind:`group`,choices:n,...r?{trailingComma:!0}:{},start:t,end:i.offset}}parseGroupEntry(){let e=this.peek().offset,t=this.tryParseOccur();if(this.peek().type===`LPAREN`){let n=this.consume(),r=this.parseGroup(`RPAREN`),i=this.consume();if(p.has(this.peek().type)){let a=this.groupAsParenType(r,n,i),o=this.continueType1(a);return this.finishEntryFromType1(e,t,o)}return{kind:`entry-group`,...t?{occur:t}:{},group:r,start:e,end:i.endOffset}}let n=this.peek(0);if(this.peek(1).type===`COLON`&&(n.type===`ID`||this.isValueToken(n))){let r;if(n.type===`ID`){this.consume();let e=this.consume();r={kind:`bareword`,key:n.value,cut:!0,start:n.offset,end:e.endOffset}}else{let e=this.parseValue(),t=this.consume();r={kind:`value`,key:e,cut:!0,start:e.start,end:t.endOffset}}let i=this.parseType();return{kind:`entry`,...t?{occur:t}:{},memberKey:r,value:i,start:e,end:i.end}}let r=this.parseType1();return this.finishEntryFromType1(e,t,r)}finishEntryFromType1(e,t,n){let r;if(this.peek().type===`CARET`||this.peek().type===`ARROW`){let e=!1;this.peek().type===`CARET`&&(this.consume(),e=!0);let t=this.expect(`ARROW`,`'=>' after member key`);r={kind:`type1`,key:n,cut:e,start:n.start,end:t.endOffset}}let i=r?this.parseType():this.continueTypeAlternatives(n);return{kind:`entry`,...t?{occur:t}:{},...r?{memberKey:r}:{},value:i,start:e,end:i.end}}tryParseOccur(){let e=this.peek(0);if(e.type===`QUEST`)return this.consume(),{kind:`occur`,marker:`?`,start:e.offset,end:e.endOffset};if(e.type===`PLUS`)return this.consume(),{kind:`occur`,marker:`+`,start:e.offset,end:e.endOffset};if(e.type===`STAR`){this.consume();let t,n=e.endOffset,r=this.peek();return r.type===`INT`&&r.offset===e.endOffset&&(t=this.occurBound(this.consume()),n=r.endOffset),{kind:`occur`,marker:`*`,...t===void 0?{}:{max:t},start:e.offset,end:n}}if(e.type===`INT`&&!e.value.startsWith(`-`)&&this.peek(1).type===`STAR`&&this.peek(1).offset===e.endOffset){let t=this.occurBound(this.consume()),n=this.consume(),r,i=n.endOffset,a=this.peek();return a.type===`INT`&&a.offset===n.endOffset&&(r=this.occurBound(this.consume()),i=a.endOffset),{kind:`occur`,marker:`*`,min:t,max:r,start:e.offset,end:i}}}occurBound(e){e.value.startsWith(`-`)&&this._fail(`occurrence bounds must be unsigned integers`,e);let t=Number(e.value);return Number.isSafeInteger(t)||this._fail(`occurrence bound is too large`,e),t}parseType(){return this.continueTypeAlternatives(this.parseType1())}continueTypeAlternatives(e){let t=[e];for(;this.peek().type===`SLASH`;)this.consume(),t.push(this.parseType1());return{kind:`type`,alternatives:t,start:e.start,end:t[t.length-1].end}}parseType1(){return this.continueType1(this.parseType2())}continueType1(e){let t=this.peek(),n;if(t.type===`RANGE_INCL`||t.type===`RANGE_EXCL`?n={kind:`range`,inclusive:t.type===`RANGE_INCL`}:t.type===`CTLOP`&&(n={kind:`ctl`,name:t.value}),!n)return{kind:`type1`,target:e,start:e.start,end:e.end};this.consume();let r=this.parseType2();return{kind:`type1`,target:e,op:n,controller:r,start:e.start,end:r.end}}parseType2(){let e=this.peek();switch(e.type){case`INT`:case`FLOAT`:case`TSTR`:case`BYTES`:return this.parseValue();case`ID`:return this.consume(),this.parseRefTail(e);case`LPAREN`:{let e=this.consume(),t=this.parseType(),n=this.expect(`RPAREN`,`')' to close the parenthesized type`);return{kind:`paren`,type:t,start:e.offset,end:n.endOffset}}case`LBRACE`:{let e=this.consume(),t=this.parseGroup(`RBRACE`),n=this.consume();return{kind:`map`,group:t,start:e.offset,end:n.endOffset}}case`LBRACKET`:{let e=this.consume(),t=this.parseGroup(`RBRACKET`),n=this.consume();return{kind:`array`,group:t,start:e.offset,end:n.endOffset}}case`TILDE`:{let e=this.consume(),t=this.expect(`ID`,`a type name after '~'`),n=this.parseRefTail(t);return{kind:`unwrap`,ref:n,start:e.offset,end:n.end}}case`AMP`:{let e=this.consume();if(this.peek().type===`LPAREN`){this.consume();let t=this.parseGroup(`RPAREN`),n=this.consume();return{kind:`enum`,group:t,start:e.offset,end:n.endOffset}}let t=this.expect(`ID`,`a group name or '(' after '&'`),n=this.parseRefTail(t);return{kind:`enum`,group:n,start:e.offset,end:n.end}}case`HASH`:return this.parseHashType(this.consume());default:this._fail(`expected a type`,e)}}parseRefTail(e){if(this.peek().type!==`LT`)return{kind:`ref`,name:e.value,start:e.offset,end:e.endOffset};this.consume();let t=[this.parseType1()];for(;this.peek().type===`COMMA`;)this.consume(),t.push(this.parseType1());let n=this.expect(`GT`,`'>' after generic arguments`);return{kind:`ref`,name:e.value,genericArgs:t,start:e.offset,end:n.endOffset}}parseHashType(e){if(e.hashMajor===void 0)return(e.hashAIExpr||e.hashAI!==void 0)&&this._fail(`'#' without a major type cannot take a head-number`,e),{kind:`any`,start:e.offset,end:e.endOffset};let t=e.hashMajor,n=e.hashAI,r=e.endOffset;e.hashAIExpr&&(t!==6&&t!==7&&this._fail(`a <type> head-number is only allowed for #6 and #7 (RFC 9682 §3.2)`,e),this.expect(`LT`,`'<' for the head-number expression`),n=this.parseType(),r=this.expect(`GT`,`'>' after the head-number expression`).endOffset);let i=e.hashAIExpr?void 0:e.raw;if(t===6&&this.peek().type===`LPAREN`){this.consume();let t=this.parseType(),r=this.expect(`RPAREN`,`')' to close the tagged type`);return{kind:`tagged`,...n===void 0?{}:{tag:n},item:t,...i===void 0?{}:{raw:i},start:e.offset,end:r.endOffset}}return e.hashAIExpr&&t===6&&this._fail(`#6.<…> must be followed by '(' type ')'`,this.peek()),{kind:`major`,major:t,...n===void 0?{}:{ai:n},...i===void 0?{}:{raw:i},start:e.offset,end:r}}isValueToken(e){return e.type===`INT`||e.type===`FLOAT`||e.type===`TSTR`||e.type===`BYTES`}parseValue(){let e=this.consume(),n={start:e.offset,end:e.endOffset,raw:e.raw};switch(e.type){case`INT`:{let t=e.value.startsWith(`-`)?-BigInt(e.value.slice(1)):BigInt(e.value);return{kind:`value`,type:`int`,value:t>=BigInt(-(2**53-1))&&t<=BigInt(2**53-1)?Number(t):t,...n}}case`FLOAT`:return{kind:`value`,type:`float`,value:/^-?0[xX]/.test(e.value)?t.N(e.value):parseFloat(e.value),...n};case`TSTR`:return{kind:`value`,type:`text`,value:e.value,...n};case`BYTES`:return{kind:`value`,type:`bytes`,value:e.bytes,qualifier:e.qualifier,...n};default:this._fail(`expected a literal value`,e)}}groupAsParenType(e,t,n){let r=e.choices.length===1&&e.choices[0].length===1?e.choices[0][0]:void 0;return(!r||r.kind!==`entry`||r.occur||r.memberKey||e.trailingComma)&&this._fail(`this parenthesized group is used as a type (an operator follows), but it contains group syntax`,this.peek()),{kind:`paren`,type:r.value,start:t.offset,end:n.endOffset}}},h=`any = #
|
|
12
|
-
|
|
13
|
-
uint = #0
|
|
14
|
-
nint = #1
|
|
15
|
-
int = uint / nint
|
|
16
|
-
|
|
17
|
-
bstr = #2
|
|
18
|
-
bytes = bstr
|
|
19
|
-
tstr = #3
|
|
20
|
-
text = tstr
|
|
21
|
-
|
|
22
|
-
tdate = #6.0(tstr)
|
|
23
|
-
time = #6.1(number)
|
|
24
|
-
number = int / float
|
|
25
|
-
biguint = #6.2(bstr)
|
|
26
|
-
bignint = #6.3(bstr)
|
|
27
|
-
bigint = biguint / bignint
|
|
28
|
-
integer = int / bigint
|
|
29
|
-
unsigned = uint / biguint
|
|
30
|
-
decfrac = #6.4([e10: int, m: integer])
|
|
31
|
-
bigfloat = #6.5([e2: int, m: integer])
|
|
32
|
-
eb64url = #6.21(any)
|
|
33
|
-
eb64legacy = #6.22(any)
|
|
34
|
-
eb16 = #6.23(any)
|
|
35
|
-
encoded-cbor = #6.24(bstr)
|
|
36
|
-
uri = #6.32(tstr)
|
|
37
|
-
b64url = #6.33(tstr)
|
|
38
|
-
b64legacy = #6.34(tstr)
|
|
39
|
-
regexp = #6.35(tstr)
|
|
40
|
-
mime-message = #6.36(tstr)
|
|
41
|
-
cbor-any = #6.55799(any)
|
|
42
|
-
|
|
43
|
-
float16 = #7.25
|
|
44
|
-
float32 = #7.26
|
|
45
|
-
float64 = #7.27
|
|
46
|
-
float16-32 = float16 / float32
|
|
47
|
-
float32-64 = float32 / float64
|
|
48
|
-
float = float16-32 / float64
|
|
49
|
-
|
|
50
|
-
false = #7.20
|
|
51
|
-
true = #7.21
|
|
52
|
-
bool = false / true
|
|
53
|
-
nil = #7.22
|
|
54
|
-
null = nil
|
|
55
|
-
undefined = #7.23
|
|
56
|
-
`,g;function _(){if(!g){g=new Map;for(let e of f(h).rules)g.set(e.name,e)}return g}var ee={leading:[],trailing:[]};function te(e,t){let n={unit:t?.indent===void 0?null:typeof t.indent==`string`?t.indent:` `.repeat(t.indent),notes:null,endNotes:null,tail:[]};if(t?.preserveComments&&t.comments!==void 0&&t.comments.length>0&&t.source!==void 0){let r=ne(e,t.comments,t.source);n.notes=r.notes,n.endNotes=r.endNotes,n.tail=r.tail}let r=[],i=!1;e.forEach((e,t)=>{let{text:a,multiline:o}=ie(e,n);t>0&&n.unit!==null&&(o||i)&&r.push(``),r.push(a),i=o});for(let e of n.tail)r.push(`;${e}`);return r.length===0?``:r.join(`
|
|
57
|
-
`)+`
|
|
58
|
-
`}function ne(e,t,n){let r=[0];for(let e=0;e<n.length;e++)n.charCodeAt(e)===10&&r.push(e+1);let i=e=>{let t=0,n=r.length-1;for(;t<n;){let i=t+n+1>>1;r[i]<=e?t=i:n=i-1}return t+1},a=[],o=[],s=(e,t,n)=>{o.push({group:e,start:t,end:n});for(let t of e.choices)t.forEach(c)},c=e=>{if(a.push({node:e,start:e.start,end:e.end,isRule:!1}),e.kind===`entry-group`){s(e.group,e.start,e.end);return}for(let t of e.value.alternatives)l(t)},l=e=>{u(e.target),e.controller&&u(e.controller)},u=e=>{switch(e.kind){case`map`:case`array`:s(e.group,e.start,e.end);return;case`paren`:for(let t of e.type.alternatives)l(t);return;case`enum`:e.group.kind===`group`&&s(e.group,e.start,e.end);return;case`tagged`:if(typeof e.tag==`object`)for(let t of e.tag.alternatives)l(t);for(let t of e.item.alternatives)l(t);return;default:return}};for(let t of e)a.push({node:t,start:t.start,end:t.end,isRule:!0}),c(t.body);let d=[...a].sort((e,t)=>e.end-t.end||Number(e.isRule)-Number(t.isRule)),f=[...a].sort((e,t)=>e.start-t.start||Number(t.isRule)-Number(e.isRule)),p=new Map,m=new Map,h=[],g=e=>{let t=p.get(e);return t||(t={leading:[],trailing:[]},p.set(e,t)),t};for(let n of t){let t;for(let e=d.length-1;e>=0;e--){let r=d[e];if(!(r.end>n.start)){i(Math.max(r.start,r.end-1))===n.line&&(t=r);break}}if(t){g(t.node).trailing.push(n.text);continue}let r;for(let e of o)e.start<=n.start&&n.end<=e.end&&(!r||e.start>=r.start)&&(r=e);let a=e.find(e=>e.start<=n.start&&n.end<=e.end),s=f.find(e=>e.start>=n.end),c=r!==void 0&&(s===void 0||s.start>r.end),l=a!==void 0&&(s===void 0||s.start>a.end);if(s&&!c&&!l)g(s.node).leading.push(n.text);else if(c){let e=m.get(r.group)??[];e.push(n.text),m.set(r.group,e)}else l?g(a).trailing.push(n.text):s?g(s.node).leading.push(n.text):h.push(n.text)}return{notes:p,endNotes:m,tail:h}}var v=(e,t)=>e.notes?.get(t)??ee,re=e=>e.trailing.length===0?``:` `+e.trailing.map(e=>`;${e}`).join(` `);function ie(e,t){let n=v(t,e),r=v(t,e.body),i=e.generics?`<${e.generics.join(`, `)}>`:``,a=`${e.name}${i} ${e.assign}`,o=re({leading:[],trailing:[...r.trailing,...n.trailing]}),s,c=n.leading;if(r.leading.length>0&&t.unit!==null){let n=t.unit;s=[a,...r.leading.map(e=>`${n};${e}`),`${n}${y(e.body,t,1)}${o}`].join(`
|
|
59
|
-
`)}else r.leading.length>0&&(c=[...c,...r.leading]),s=`${a} ${y(e.body,t,0)}${o}`;let l=s.includes(`
|
|
60
|
-
`);return c.length===0?{text:s,multiline:l}:{text:[...c.map(e=>`;${e}`),s].join(`
|
|
61
|
-
`),multiline:l}}function y(e,t,n){let r=e.occur?`${ae(e.occur)} `:``;return e.kind===`entry-group`?`${r}${b(e.group,t,n,`(`,`)`)}`:`${r}${e.memberKey?`${oe(e.memberKey,t,n)} `:``}${x(e.value,t,n)}`}function ae(e){return e.marker===`*`?`${e.min??``}*${e.max??``}`:e.marker}function oe(e,t,n){switch(e.kind){case`bareword`:return`${e.key}:`;case`value`:return`${e.key.raw}:`;case`type1`:return`${S(e.key,t,n)} ${e.cut?`^ `:``}=>`}}function b(e,t,n,r,i){let a=e.choices.reduce((e,t)=>e+t.length,0),o=t.endNotes?.get(e)??[],s=o.length>0||t.notes!==null&&e.choices.some(e=>e.some(e=>t.notes.has(e)));if(!(t.unit!==null&&(a>1||e.choices.length>1||s)))return`${r}${e.choices.map(e=>e.map(e=>y(e,t,n)).join(`, `)).join(` // `)+(e.trailingComma?`,`:``)}${i}`;let c=t.unit,l=c.repeat(n+1),u=[r];e.choices.forEach((r,i)=>{i>0&&u.push(`${l}//`),r.forEach((a,o)=>{let s=v(t,a);for(let e of s.leading)u.push(`${l};${e}`);let c=!(i===e.choices.length-1&&o===r.length-1)||e.trailingComma?`,`:``;u.push(`${l}${y(a,t,n+1)}${c}${re(s)}`)})});for(let e of o)u.push(`${l};${e}`);return u.push(`${c.repeat(n)}${i}`),u.join(`
|
|
62
|
-
`)}function x(e,t,n){return e.alternatives.map(e=>S(e,t,n)).join(` / `)}function S(e,t,n){let r=se(e.target,t,n);if(!e.op||!e.controller)return r;let i=se(e.controller,t,n);return e.op.kind===`range`?`${r}${e.op.inclusive?`..`:`...`}${i}`:`${r} .${e.op.name} ${i}`}function C(e,t,n){let r=e.genericArgs?`<${e.genericArgs.map(e=>S(e,t,n)).join(`, `)}>`:``;return`${e.name}${r}`}function se(e,t,n){switch(e.kind){case`value`:return e.raw;case`ref`:return C(e,t,n);case`paren`:return`(${x(e.type,t,n)})`;case`map`:return b(e.group,t,n,`{`,`}`);case`array`:return b(e.group,t,n,`[`,`]`);case`unwrap`:return`~${C(e.ref,t,n)}`;case`enum`:return e.group.kind===`ref`?`&${C(e.group,t,n)}`:`&${b(e.group,t,n,`(`,`)`)}`;case`tagged`:return`${e.raw??(typeof e.tag==`object`?`#6.<${x(e.tag,t,n)}>`:`#6${e.tag===void 0?``:`.${e.tag}`}`)}(${x(e.item,t,n)})`;case`major`:return e.raw===void 0?typeof e.ai==`object`?`#${e.major}.<${x(e.ai,t,n)}>`:`#${e.major}${e.ai===void 0?``:`.${e.ai}`}`:e.raw;case`any`:return`#`}}function w(e){if(e instanceof t.F||e instanceof t.P)return e.value;if(e instanceof t.v||e instanceof t._)return e.bigValue}function T(e){if(e instanceof t.h)return e.value;if(e instanceof t.O)return e.chunks.map(e=>e.value).join(``)}function E(e){if(e instanceof t.A)return e.value;if(e instanceof t.k){let t=e.chunks.map(e=>e.value),n=t.reduce((e,t)=>e+t.length,0),r=new Uint8Array(n),i=0;for(let e of t)r.set(e,i),i+=e.length;return r}if(e instanceof t.w){let t=e.items.map(e=>e.toCBOR()),n=t.reduce((e,t)=>e+t.length,0),r=new Uint8Array(n),i=0;for(let e of t)r.set(e,i),i+=e.length;return r}}function ce(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}var le=new TextEncoder,ue=new TextDecoder(`utf-8`,{fatal:!0}),D=e=>({kind:`value`,raw:``,start:0,end:0,...e}),de=e=>{let n=w(e);if(n!==void 0)return n;if(e instanceof t.M)return e.value},O=e=>e.type===`int`||e.type===`float`?e.value:void 0,fe=(e,t)=>{if(typeof e==`bigint`&&typeof t==`bigint`)return e<t?-1:+(e>t);let n=Number(e),r=Number(t);return n<r?-1:n>r?1:n===r?0:NaN},pe=(e,n,r,i,a,o)=>{if(!e.matchType2(n,r,a))return!1;let s=t=>e.matchType2(e.uint(t),i,a)?!0:e.fail(a,n,o,`size ${t} does not match the .size constraint`),c=T(n);if(c!==void 0)return s(le.encode(c).length);let l=E(n);if(l!==void 0)return s(l.length);if(n instanceof t.F){let t=0;for(let e=n.value;e>0n;e>>=8n)t++;let r=e.existsIntGE(i,BigInt(t));if(r!==void 0)return r?!0:e.fail(a,n,o,`${n.value} does not fit the .size constraint`);e.warnOnce(`.size controller could not be analyzed; searching a bounded window of byte counts`,o);for(let n=t;n<=t+64;n++)if(e.matchType2(e.uint(n),i,a))return!0;return e.fail(a,n,o,`${n.value} does not fit the .size constraint`)}return e.fail(a,n,o,`.size applies to strings and unsigned integers`)},me=(e,n,r,i,a,o)=>{if(!e.matchType2(n,r,a))return!1;let s=[],c=E(n);if(c!==void 0)for(let e=0;e<c.length;e++)for(let t=0;t<8;t++)c[e]&1<<t&&s.push(e*8+t);else if(n instanceof t.F){let e=n.value;for(let t=0;e>0n;t++,e>>=1n)e&1n&&s.push(t)}else return e.fail(a,n,o,`.bits applies to byte strings and unsigned integers`);for(let t of s)if(!e.matchType2(e.uint(t),i,a))return e.fail(a,n,o,`bit ${t} is set but not allowed by .bits`);return!0},he=new Map,ge=(e,t,n,r,i,a)=>{if(!e.matchType2(t,n,i))return!1;let o=T(t);if(o===void 0)return e.fail(i,t,a,`.regexp applies to text strings`);let s=e.resolveValue(r);if(!s||s.type!==`text`)return e.warnOnce(`.regexp controller does not resolve to a text string; not checked`,a),!0;let c=he.get(s.value);if(c===void 0){try{c=RegExp(`^(?:${s.value})$`,`u`)}catch{c=null}he.set(s.value,c)}return c===null?(e.warnOnce(`.regexp pattern is not a valid regular expression here: ${s.value}`,a),!0):c.test(o)?!0:e.fail(i,t,a,`text does not match .regexp ${JSON.stringify(s.value)}`)},_e=e=>(n,r,i,a,o,s)=>{if(!n.matchType2(r,i,o))return!1;let c=E(r);if(c===void 0)return n.fail(o,r,s,`.cbor${e?`seq`:``} applies to byte strings`);let l;try{if(e){let e=new Uint8Array(c.length+2);e[0]=159,e.set(c,1),e[e.length-1]=255,l=t.u(e)}else l=t.u(c)}catch(e){return n.fail(o,r,s,`byte string does not contain valid CBOR: ${e instanceof Error?e.message:String(e)}`)}return n.matchEmbedded(l,a,o)?!0:n.fail(o,r,s,`embedded CBOR does not match the .cbor${e?`seq`:``} type`)},ve=(e,t,n,r,i,a)=>e.matchType2(t,n,i)?e.matchType2(t,r,i)?!0:e.fail(i,t,a,`value does not match the .within/.and constraint`):!1,k=e=>(t,n,r,i,a,o)=>{if(!t.matchType2(n,r,a))return!1;let s=t.resolveValue(i),c=s&&O(s);if(c===void 0)return t.warnOnce(`.${e} controller does not resolve to a number; not checked`,o),!0;let l=de(n);if(l===void 0)return t.fail(a,n,o,`.${e} applies to numbers`);let u=fe(l,c);return(e===`lt`?u<0:e===`le`?u<=0:e===`gt`?u>0:u>=0)?!0:t.fail(a,n,o,`${l} does not satisfy .${e} ${c}`)},ye=(e,t,n,r,i,a)=>{if(!e.matchType2(t,n,i))return!1;let o=e.resolveValue(r);return o?e.matchesLiteral(t,o)?!0:e.fail(i,t,a,`value does not equal ${o.raw||`.eq controller`}`):(e.warnOnce(`.eq controller does not resolve to a literal value; not checked`,a),!0)},be=(e,t,n,r,i,a)=>{if(!e.matchType2(t,n,i))return!1;let o=e.resolveValue(r);return o?!e.matchesLiteral(t,o)||e.fail(i,t,a,`value must not equal ${o.raw||`.ne controller`}`):(e.warnOnce(`.ne controller does not resolve to a literal value; not checked`,a),!0)},xe=(e,t,n,r,i,a)=>{if(!e.matchType2(t,n,i))return!1;let o=e.resolveValue(r);return o?!e.matchesLiteral(t,o)||e.fail(i,t,a,`value equals the default ${o.raw||`value`} (implied .ne, RFC 8610 §3.8.6)`):(e.warnOnce(`.default controller does not resolve to a literal value; the implied .ne is not checked`,a),!0)},Se=(e,t,n,r,i,a)=>{let o=e.resolveValue(n),s=e.resolveValue(r),c=o&&O(o),l=s&&O(s);if(o===void 0||c===void 0||l===void 0)return e.warnOnce(`.plus operands do not resolve to numbers; not checked`,a),e.fail(i,t,a,`.plus could not be computed`);if(o.type===`float`){let n=Number(c)+Number(l);return e.matchesLiteral(t,D({type:`float`,value:n}))?!0:e.fail(i,t,a,`expected ${n} (.plus)`)}if(typeof l==`number`&&!Number.isFinite(l))return e.fail(i,t,a,`.plus controller is not finite`);let u=(typeof c==`bigint`?c:BigInt(c))+(typeof l==`bigint`?l:BigInt(Math.floor(l)));return e.matchesLiteral(t,D({type:`int`,value:u}))?!0:e.fail(i,t,a,`expected ${u} (.plus)`)},Ce=(e,t,n,r,i,a)=>{let o=e.resolveValue(n),s=e.resolveValue(r),c=e=>e.type===`text`?le.encode(e.value):e.type===`bytes`?e.value:void 0,l=o&&c(o),u=s&&c(s);if(!o||l===void 0||u===void 0)return e.warnOnce(`.cat operands do not resolve to strings; not checked`,a),e.fail(i,t,a,`.cat could not be computed`);let d=new Uint8Array(l.length+u.length);if(d.set(l,0),d.set(u,l.length),o.type===`text`){let n;try{n=ue.decode(d)}catch{return e.fail(i,t,a,`.cat result is not valid UTF-8`)}return e.matchesLiteral(t,D({type:`text`,value:n}))?!0:e.fail(i,t,a,`expected ${JSON.stringify(n)} (.cat)`)}return e.matchesLiteral(t,D({type:`bytes`,value:d,qualifier:`h`}))?!0:e.fail(i,t,a,`byte string does not equal the .cat result`)},we=e=>{for(;e.kind===`paren`&&e.type.alternatives.length===1&&!e.type.alternatives[0].op;)e=e.type.alternatives[0].target;return e},Te=(e,t)=>{let n=we(t);if(n.kind===`array`){let e=n.group.choices[0]?.[0];if(!e||e.kind!==`entry`||e.value.alternatives.length!==1||e.value.alternatives[0].op)return;n=e.value.alternatives[0].target}let r=e.resolveValue(n);return r?.type===`text`?r.value:void 0},Ee={size:pe,bits:me,regexp:ge,cbor:_e(!1),cborseq:_e(!0),within:ve,and:ve,lt:k(`lt`),le:k(`le`),gt:k(`gt`),ge:k(`ge`),eq:ye,ne:be,default:xe,plus:Se,cat:Ce,feature:(e,t,n,r,i,a)=>{let o=Te(e,r);return o===void 0?(e.warnOnce(`.feature controller does not resolve to a feature name`,a),e.fail(i,t,a,`unresolvable .feature`)):e.features.has(o)?e.matchType2(t,n,i):(e.warnOnce(`feature "${o}" is not enabled (pass it in options.features to accept it)`,a),e.fail(i,t,a,`feature "${o}" is not enabled`))}};function De(e){return Object.prototype.hasOwnProperty.call(Ee,e)?Ee[e]:void 0}var A=class extends Error{},Oe=class{schema;maxDepth;maxSteps;features;steps=0;ruleName;embeddedDepth=0;preludeDepth=0;preludeRef;warnings=[];warned=new Set;best;constructor(e,t,n,r){this.schema=e,this.maxDepth=t,this.maxSteps=n,this.features=r}step(){if(++this.steps>this.maxSteps)throw new A(`validation aborted: step budget of ${this.maxSteps} exceeded (pathological backtracking?)`)}checkDepth(e){if(e>this.maxDepth)throw new A(`validation aborted: recursion depth ${this.maxDepth} exceeded (cyclic rules without progress?)`)}warnOnce(e,t){let n=`${e}@${t?.start??-1}`;this.warned.has(n)||(this.warned.add(n),this.warnings.push({message:e,...t?{schemaStart:t.start,schemaEnd:t.end}:{}}))}fail(e,t,n,r){let i=this.embeddedDepth>0,a=i?-1:t?.start??-1;if(!this.best||a>this.best.startKey||a===this.best.startKey&&e.length>=this.best.depth){let o=this.preludeDepth>0?this.preludeRef:n;this.best={depth:e.length,startKey:a,message:r,path:e.length===0?`/`:`/`+e.join(`/`),...!i&&t?.start!==void 0?{start:t.start,end:t.end}:{},...this.ruleName===void 0?{}:{ruleName:this.ruleName},...o?{schemaStart:o.start,schemaEnd:o.end}:{}}}return!1}};function ke(e,t,n){let r=n?.rule??e.root?.name;if(r===void 0)return{valid:!1,errors:[{message:`schema has no rules (no root to validate against)`,path:`/`}]};let i=new Oe(e,n?.maxDepth??256,n?.maxSteps??1e6,new Set(n?.features??[])),a=j(i,r)?.[0]?.generics?.length??0;if(a>0)return{valid:!1,errors:[{message:`rule '${r}' takes ${a} generic argument${a===1?``:`s`} and cannot be used as a validation target directly; reference it with concrete arguments from another rule instead`,path:`/`}]};let o;try{o=je(t,r,void 0,[],i,0)}catch(e){if(!(e instanceof A))throw e;return{valid:!1,errors:[{message:e.message,path:`/`}],...i.warnings.length?{warnings:i.warnings}:{}}}return o?{valid:!0,errors:[],...i.warnings.length?{warnings:i.warnings}:{}}:{valid:!1,errors:i.best?[(({depth:e,startKey:t,...n})=>n)(i.best)]:[{message:`value does not match rule '${r}'`,path:`/`,...t.start===void 0?{}:{start:t.start,end:t.end}}],...i.warnings.length?{warnings:i.warnings}:{}}}function j(e,t){let n=e.schema.rules.get(t);if(n)return n;let r=_().get(t);return r?[r]:void 0}function M(e){return e.kind===`entry`&&!e.occur&&!e.memberKey}function N(e){return e.kind===`entry-group`&&!e.occur?e.group.choices:[[e]]}function Ae(e){return e.some(e=>!M(e.body))}function P(e,t,n){let r=e.generics;if(!r||!t)return;let i=new Map;for(let e=0;e<r.length&&e<t.length;e++)i.set(r[e],{type1:t[e],env:n});return i}function je(e,t,n,r,i,a,o,s){let c=j(i,t);if(!c)return i.fail(r,e,o,t.startsWith(`$`)?`socket '${t}' has no definitions, so nothing matches it`:`'${t}' is not defined`);i.checkDepth(a);let l=i.ruleName;i.ruleName=t;let u=!i.schema.rules.has(t);u&&++i.preludeDepth===1&&(i.preludeRef=o);try{for(let o of c){let c=P(o,s,n);if(M(o.body)){if(I(e,o.body.value,c,r,i,a+1))return!0;continue}let l=N(o.body),u=!0;for(let e of l)if(!(e.length===1&&M(e[0]))){u=!1;break}if(!u){i.fail(r,e,o.body,`group rule '${t}' cannot be used as a type`);continue}for(let t of l){let n=t[0];if(I(e,n.value,c,r,i,a+1))return!0}}return!1}finally{i.ruleName=l,u&&--i.preludeDepth===0&&(i.preludeRef=void 0)}}function F(e){for(;e instanceof t.b;)e=e.inner;return e}function I(e,t,n,r,i,a){for(let o of t.alternatives)if(L(e,o,n,r,i,a))return!0;return!1}function L(e,t,n,r,i,a){if(i.step(),e=F(e),!t.op||!t.controller)return R(e,t.target,n,r,i,a);if(t.op.kind===`range`)return ze(e,t,n,r,i,a);let o=De(t.op.name),s=rt(n,i,a);return o?o(s,e,t.target,t.controller,r,t):(i.warnOnce(`control operator .${t.op.name} is not supported; matching the target only`,t),R(e,t.target,n,r,i,a))}function R(e,n,r,i,a,o){if(e=F(e),e instanceof t.y)return!0;switch(n.kind){case`any`:return!0;case`value`:return B(e,n)?!0:a.fail(i,e,n,`expected the value ${n.raw}`);case`ref`:{let t=r?.get(n.name);return t&&!n.genericArgs?L(e,t.type1,t.env,i,a,o+1):je(e,n.name,r,i,a,o+1,n,n.genericArgs)}case`paren`:return I(e,n.type,r,i,a,o);case`map`:return e instanceof t.E?Ze(e,n.group,r,i,a,o+1):a.fail(i,e,n,`expected a map`);case`array`:return e instanceof t.D?Je(e,n.group,r,i,a,o+1):a.fail(i,e,n,`expected an array`);case`tagged`:if(!(e instanceof t.j))return a.fail(i,e,n,`expected a tagged item`);if(typeof n.tag==`bigint`){if(e.tag!==n.tag)return a.fail(i,e,n,`expected tag ${n.tag}, got ${e.tag}`)}else if(n.tag!==void 0&&!I(new t.F(e.tag),n.tag,r,i,a,o+1))return a.fail(i,e,n,`tag number ${e.tag} does not match the head type`);return I(e.content,n.item,r,i,a,o+1);case`major`:return Ve(e,n,r,i,a,o);case`unwrap`:{let t=Ke(n.ref,r,a,0);return t?I(e,t.type,t.env,i,a,o+1):(a.warnOnce(`~${n.ref.name} is used outside of an array/map group context`,n),a.fail(i,e,n,`~${n.ref.name} cannot match here`))}case`enum`:{let t=n.group.kind===`ref`?J(n.group,r,a):q(n.group,r);return t?(a.checkDepth(o),z(e,t,i,a,o+1)?!0:a.fail(i,e,n,`no enumeration value matches`)):a.fail(i,e,n,`'&' target does not resolve to a group`)}}}function z(e,t,n,r,i){for(let{entries:a,env:o}of t)for(let t of a){if(r.step(),t.kind===`entry-group`){if(z(e,q(t.group,o),n,r,i+1))return!0;continue}let a=We(t,o,r);if(a){if(r.checkDepth(i),z(e,a,n,r,i+1))return!0;continue}if(I(e,t.value,o,n,r,i+1))return!0}return!1}function B(e,n){switch(n.type){case`int`:return w(e)===BigInt(n.value);case`float`:return e instanceof t.M&&(e.value===n.value||Number.isNaN(e.value)&&Number.isNaN(n.value));case`text`:return T(e)===n.value;case`bytes`:{let t=E(e);return t!==void 0&&ce(t,n.value)}}}function V(e,t,n,r=0){if(r>32)return;if(e.kind===`value`)return e;if(e.kind===`paren`){let i=e.type.alternatives.length===1?e.type.alternatives[0]:void 0;return!i||i.op?void 0:V(i.target,t,n,r+1)}if(e.kind!==`ref`)return;let i=t?.get(e.name);if(i&&!e.genericArgs)return i.type1.op?void 0:V(i.type1.target,i.env,n,r+1);let a=j(n,e.name);if(!a||a.length!==1)return;let o=a[0].body;if(!M(o)||o.value.alternatives.length!==1)return;let s=o.value.alternatives[0];if(s.op)return;let c=P(a[0],e.genericArgs,t);return V(s.target,c,n,r+1)}function Me(e,t,n,r,i=0){return Ne(e,t,void 0,n,r,i)}function Ne(e,t,n,r,i,a=0){let o=H(e,t,n,r,i,a);return o===void 0?void 0:o!==null}function H(e,t,n,r,i,a=0){if(n!==void 0&&t>n)return null;if(!(a>32))switch(e.kind){case`value`:if(e.type===`int`){let r=BigInt(e.value);return r>=t&&(n===void 0||r<=n)?r:null}return null;case`any`:{let e=t>0n?t:0n;return n===void 0||e<=n?e:null}case`major`:if(e.ai!==void 0)return;if(e.major===0){let e=t>0n?t:0n;return e<=18446744073709551615n&&(n===void 0||e<=n)?e:null}if(e.major===1){let e=t>-18446744073709551616n?t:-18446744073709551616n;return e<=-1n&&(n===void 0||e<=n)?e:null}return null;case`paren`:return U(e.type,t,n,r,i,a+1);case`ref`:{let o=r?.get(e.name);if(o&&!e.genericArgs)return Pe(o.type1,t,n,o.env,i,a+1);let s=j(i,e.name);if(!s)return;let c=!1,l=null;for(let o of s){if(!M(o.body)){c=!0;continue}let s=P(o,e.genericArgs,r),u=U(o.body.value,t,n,s,i,a+1);typeof u==`bigint`&&(l===null||u<l)&&(l=u),u===void 0&&(c=!0)}return l??(c?void 0:null)}case`enum`:{let o=e.group.kind===`ref`?J(e.group,r,i):q(e.group,r);if(!o)return;let s=!1,c=null;for(let{entries:e,env:r}of o)for(let o of e){if(o.kind!==`entry`){s=!0;continue}let e=U(o.value,t,n,r,i,a+1);typeof e==`bigint`&&(c===null||e<c)&&(c=e),e===void 0&&(s=!0)}return c??(s?void 0:null)}default:return}}function U(e,t,n,r,i,a){let o=!1,s=null;for(let c of e.alternatives){let e=Pe(c,t,n,r,i,a);typeof e==`bigint`&&(s===null||e<s)&&(s=e),e===void 0&&(o=!0)}return s??(o?void 0:null)}function Pe(e,t,n,r,i,a){if(!e.op)return H(e.target,t,n,r,i,a);if(e.op.kind===`ctl`){if(e.op.name===`bits`)return Ie(e.target,e.controller,t,n,r,i,a+1);if(e.op.name===`size`){let o=H(e.target,t>0n?t:0n,n,r,i,a+1);if(o==null)return o;let s=Me(e.controller,BigInt(Re(o)),r,i,a+1);return s===void 0?void 0:s?o:null}if(e.op.name===`feature`){let o=Te(rt(r,i,a),e.controller);return o===void 0?void 0:i.features.has(o)?H(e.target,t,n,r,i,a+1):(i.warnOnce(`feature "${o}" is not enabled (pass it in options.features to accept it)`,e),null)}if(e.op.name===`and`||e.op.name===`within`)return Fe(e.target,e.controller,t,n,r,i,a+1);if(e.op.name===`plus`){let a=V(e.target,r,i),o=V(e.controller,r,i);if(!a||!o||a.type===`text`||a.type===`bytes`||o.type===`text`||o.type===`bytes`)return;if(a.type===`float`)return null;let s=o.type===`int`?BigInt(a.value)+BigInt(o.value):BigInt(Math.floor(Number(a.value)+o.value));return s>=t&&(n===void 0||s<=n)?s:null}let o=V(e.controller,r,i);if(!o||o.type!==`int`)return;let s=BigInt(o.value);switch(e.op.name){case`eq`:return H(e.target,s>t?s:t,n===void 0||s<n?s:n,r,i,a+1);case`ne`:case`default`:{let o=H(e.target,t,n===void 0||s-1n<n?s-1n:n,r,i,a+1);if(typeof o==`bigint`)return o;let c=H(e.target,s+1n>t?s+1n:t,n,r,i,a+1);return typeof c==`bigint`?c:o===void 0||c===void 0?void 0:null}case`lt`:case`le`:{let o=s-(e.op.name===`lt`?1n:0n);return H(e.target,t,n===void 0||o<n?o:n,r,i,a+1)}case`gt`:case`ge`:{let o=s+(e.op.name===`gt`?1n:0n);return H(e.target,o>t?o:t,n,r,i,a+1)}default:return}}let o=V(e.target,r,i),s=V(e.controller,r,i);if(!o||!s||o.type!==`int`||s.type!==`int`)return;let c=BigInt(o.value),l=BigInt(s.value)-(e.op.inclusive?0n:1n),u=c>t?c:t;return u<=(n===void 0||l<n?l:n)?u:null}function Fe(e,t,n,r,i,a,o){let s=n;for(let n=0;n<256;n++){let n=H(e,s,r,i,a,o+1),c=H(t,s,r,i,a,o+1);if(n===null||c===null)return null;if(n===void 0||c===void 0)return;if(n===c)return n;s=n>c?n:c}}function Ie(e,t,n,r,i,a,o){let s=0n;for(let e=0;e<64;e++){let n=H(t,BigInt(e),BigInt(e),i,a,o+1);if(n===void 0)return;n!==null&&(s|=1n<<BigInt(e))}let c=n>0n?n:0n,l=r===void 0||r>18446744073709551615n?18446744073709551615n:r;for(let t=0;t<256;t++){let t=H(e,c,l,i,a,o+1),n=Le(c,l,s);if(t===void 0)return;if(t===null||n===null)return null;if(t===n)return t;c=t>n?t:n}}function Le(e,t,n){if(e<0n&&(e=0n),e>t)return null;let r=(i,a,o)=>{if(i<0)return o<=t?o:null;let s=Number(e>>BigInt(i)&1n);for(let e=0;e<=1;e++){if(e===1&&(n&1n<<BigInt(i))==0n||!a&&e<s)continue;let t=r(i-1,a||e>s,e===1?o|1n<<BigInt(i):o);if(t!==null)return t}return null};return r(63,!1,0n)}function Re(e){let t=0;for(let n=e;n>0n;n>>=8n)t++;return t}function ze(e,n,r,i,a,o){let s=n.op,c=V(n.target,r,a),l=V(n.controller,r,a);if(!c||!l)return a.warnOnce(`range endpoints do not resolve to literal values`,n),a.fail(i,e,n,`unresolvable range`);if(c.type===`int`&&l.type===`int`){let t=w(e);if(t===void 0)return a.fail(i,e,n,`expected an integer in ${W(n)}`);let r=BigInt(c.value),o=BigInt(l.value);return t>=r&&(s.inclusive?t<=o:t<o)||a.fail(i,e,n,`${t} is outside ${W(n)}`)}if(c.type===`float`&&l.type===`float`){if(!(e instanceof t.M))return a.fail(i,e,n,`expected a float in ${W(n)}`);let r=e.value;return r>=c.value&&(s.inclusive?r<=l.value:r<l.value)||a.fail(i,e,n,`${r} is outside ${W(n)}`)}return a.warnOnce(`range endpoints mix integer and float types`,n),a.fail(i,e,n,`invalid range`)}function W(e){let t=e.op;return`${G(e.target)}${t.inclusive?`..`:`...`}${G(e.controller)}`}function G(e){return e.kind===`value`?e.raw:e.kind===`ref`?e.name:`…`}var Be={half:25n,single:26n,double:27n};function Ve(e,n,r,i,a,o){let s=e=>n.ai===void 0?!0:typeof n.ai==`bigint`?n.ai===e:I(new t.F(e),n.ai,r,i,a,o+1),c=t=>a.fail(i,e,n,`expected ${t} (#${n.major})`);switch(n.major){case 0:if(!(e instanceof t.F))return c(`an unsigned integer`);break;case 1:if(!(e instanceof t.P))return c(`a negative integer`);break;case 2:if(E(e)===void 0)return c(`a byte string`);break;case 3:if(T(e)===void 0)return c(`a text string`);break;case 4:if(!(e instanceof t.D))return c(`an array`);break;case 5:if(!(e instanceof t.E))return c(`a map`);break;case 6:return e instanceof t.j?s(e.tag)?!0:a.fail(i,e,n,`tag ${e.tag} does not match ${K(n)}`):c(`a tagged item`);case 7:return e instanceof t.T?s(BigInt(e.value))?!0:a.fail(i,e,n,`simple(${e.value}) does not match ${K(n)}`):e instanceof t.M?n.ai===void 0||s(Be[e.precision??t.L(e.value)])?!0:a.fail(i,e,n,`float does not match ${K(n)}`):c(`a simple value or float`);default:return a.fail(i,e,n,`#${n.major} is not a valid major type`)}return n.ai!==void 0&&n.major<=5&&a.warnOnce(`the additional-information constraint ${K(n)} is not checked (encoding-level)`,n),!0}function K(e){return e.raw??`#${e.major}`}var q=(e,t)=>e.choices.map(e=>({entries:e,env:t})),He={min:1,max:1};function Ue(e){let t=e.occur;return t?t.marker===`?`?{min:0,max:1}:t.marker===`+`?{min:1,max:1/0}:{min:t.min??0,max:t.max??1/0}:He}function J(e,t,n){let r=j(n,e.name);if(!r||!Ae(r))return;let i=[];for(let n of r){let r=P(n,e.genericArgs,t);for(let e of N(n.body))i.push({entries:e,env:r})}return i}function We(e,t,n){if(e.kind!==`entry`||e.memberKey||e.value.alternatives.length!==1)return;let r=e.value.alternatives[0];if(r.op)return;let i=r.target;if(i.kind===`ref`)return t?.has(i.name)&&!i.genericArgs?void 0:J(i,t,n)||(i.name.startsWith(`$$`)&&!j(n,i.name)?[]:void 0);if(i.kind===`unwrap`)return Ge(i.ref,t,n,0)}function Ge(e,t,n,r){if(r>32)return;let i=j(n,e.name);if(!i||i.length!==1)return;let a=i[0].body,o=P(i[0],e.genericArgs,t);if(!M(a))return N(a).map(e=>({entries:e,env:o}));if(a.value.alternatives.length!==1)return;let s=a.value.alternatives[0];if(!s.op){if(s.target.kind===`map`||s.target.kind===`array`)return q(s.target.group,o);if(s.target.kind===`ref`)return Ge(s.target,o,n,r+1)}}function Ke(e,t,n,r){if(r>32)return;let i=j(n,e.name);if(!i||i.length!==1)return;let a=i[0].body;if(!M(a)||a.value.alternatives.length!==1)return;let o=a.value.alternatives[0];if(o.op)return;let s=P(i[0],e.genericArgs,t);if(o.target.kind===`tagged`)return{type:o.target.item,env:s};if(o.target.kind===`ref`)return Ke(o.target,s,n,r+1)}function qe(e,t,n){let r=Ue(e);if(e.kind===`entry-group`)return{kind:`group`,occur:r,choices:q(e.group,t),node:e};let i=We(e,t,n);return i?{kind:`group`,occur:r,choices:i,node:e}:{kind:`type`,occur:r,...e.memberKey?{memberKey:e.memberKey}:{},type:e.value,env:t,node:e}}function Je(e,t,n,r,i,a){return i.checkDepth(a),Y(e.items,0,q(t,n),r,i,a).has(e.items.length)?!0:i.fail(r,e,t,`array of ${e.items.length} item(s) does not match the group`)}function Y(e,t,n,r,i,a){let o=new Set;for(let s of n)Ye(e,t,s.entries.map(e=>qe(e,s.env,i)),0,r,i,a,o);return o}function Ye(e,t,n,r,i,a,o,s){if(r===n.length){s.add(t);return}let c=n[r],l=(t,u)=>{if(a.step(),t>=c.occur.min&&Ye(e,u,n,r+1,i,a,o,s),!(t>=c.occur.max||u>=e.length))for(let n of Xe(e,u,c,i,a,o))n!==u&&l(t+1,n)};l(0,t)}function Xe(e,t,n,r,i,a){return n.kind===`type`?I(e[t],n.type,n.env,[...r,t],i,a)?[t+1]:[]:(i.checkDepth(a),[...Y(e,t,n.choices,r,i,a+1)].sort((e,t)=>t-e))}function Ze(e,t,n,r,i,a){i.checkDepth(a);let o=Array(e.entries.length).fill(!1);for(let s of q(t,n))if(o.fill(!1),X(e,s.entries,0,o,s.env,r,i,a,()=>Qe(e,o,r,i,t)))return!0;return!1}function Qe(e,n,r,i,a){for(let o=0;o<n.length;o++){if(n[o])continue;let[s,c]=e.entries[o];if(!(s instanceof t.y))return i.fail([...r,tt(s,o)],c,a,`entry ${nt(s)} is not allowed by the group`),!1}return!0}function X(e,t,n,r,i,a,o,s,c){if(n===t.length)return c();let l=qe(t[n],i,o);if(l.kind===`type`){if(!l.memberKey)return o.fail(a,e,l.node,`group entry without a member key cannot match a map entry`);let u=0;for(let t=0;t<e.entries.length&&u<l.occur.max;t++){if(r[t])continue;let[n,i]=e.entries[t];if(!$e(l.memberKey,n,l.env,a,o,s))continue;let c=[...a,tt(n,t)];if(I(i,l.type,l.env,c,o,s+1)){r[t]=!0,u++;continue}if(l.memberKey.cut)return o.fail(c,i,l.node,`value for ${et(l.memberKey)} does not match`)}return u<l.occur.min?o.fail(a,e,l.node,`missing required entry ${et(l.memberKey)}`):X(e,t,n+1,r,i,a,o,s,c)}o.checkDepth(s);let u=()=>{let e=0;for(let t of r)t&&e++;return e},d=f=>{if(o.step(),f>=l.occur.min&&X(e,t,n+1,r,i,a,o,s,c))return!0;if(f>=l.occur.max)return!1;let p=r.slice(),m=u();for(let h of l.choices){if(X(e,h.entries,0,r,h.env,a,o,s+1,()=>u()===m?X(e,t,n+1,r,i,a,o,s,c):d(f+1)))return!0;for(let e=0;e<r.length;e++)r[e]=p[e]}return!1};return d(0)}function $e(e,n,r,i,a,o){if(n=F(n),n instanceof t.y)return!0;switch(e.kind){case`bareword`:return T(n)===e.key;case`value`:return B(n,e.key);case`type1`:return L(n,e.key,r,i,a,o+1)}}function et(e){switch(e.kind){case`bareword`:return`'${e.key}'`;case`value`:return e.key.raw;case`type1`:return G(e.key.target)}}function tt(e,n){let r=T(e);if(r!==void 0)return r;if(e instanceof t.F||e instanceof t.P){let t=e.value;if(t>=BigInt(-(2**53-1))&&t<=BigInt(2**53-1))return Number(t)}return n}function nt(e){let n=T(e);return n===void 0?e instanceof t.F||e instanceof t.P?e.value.toString():e.constructor.name.replace(/^Cbor/,``).toLowerCase():JSON.stringify(n)}function rt(e,n,r){return{matchType2:(t,i,a)=>R(t,i,e,a,n,r+1),matchEmbedded:(t,i,a)=>{n.embeddedDepth++;try{return R(t,i,e,a,n,r+1)}finally{n.embeddedDepth--}},resolveValue:t=>V(t,e,n),existsIntGE:(t,r)=>Me(t,r,e,n),matchesLiteral:B,fail:(e,t,r,i)=>n.fail(e,t,r,i),warnOnce:(e,t)=>n.warnOnce(e,t),features:n.features,uint:e=>new t.F(e)}}var it=class{source;comments;ast;rules;root;warnings;constructor(e,t,n,r,i,a){this.source=e,this.comments=t,this.ast=n,this.rules=r,i&&(this.root=i),a.length>0&&(this.warnings=a)}format(e){return te(this.ast,{...e,source:this.source,comments:this.comments})}validate(e,n){let r=e instanceof t.I?e:typeof e==`string`?t.g(e):t.u(e);return ke(this,r,n)}};function at(e,t){let{rules:n,comments:r}=f(e),a=[],o=_();n.length===0&&a.push({code:`no-rules`,message:`a CDDL data model needs at least one rule to provide the root of the definition`});let s=new Map;for(let e of n){let t=s.get(e.name);if(!t){s.set(e.name,[e]);continue}e.assign===`=`&&a.push({code:`duplicate-rule`,message:`rule '${e.name}' is already defined; use /= or //= to extend it`,start:e.start,end:e.end}),t.push(e)}let c=e=>{let t=s.get(e);if(t)return t[0].generics?.length??0;let n=o.get(e);if(n)return n.generics?.length??0};for(let e of n){let t=e.generics;st(e.body,{onRef(e){if(t?.includes(e.name)||e.name.startsWith(`$`))return;let n=c(e.name);if(n===void 0){a.push({code:`undefined-name`,message:`'${e.name}' is not defined (and is not a prelude name)`,start:e.start,end:e.end});return}let r=e.genericArgs?.length??0;n!==r&&a.push({code:`generic-arity`,message:`'${e.name}' takes ${n} generic argument${n===1?``:`s`} but is used with ${r}`,start:e.start,end:e.end})},onMajor(e,t,n){e>7&&a.push({code:`invalid-major`,message:`#${e} is not a CBOR major type (0–7)`,start:t,end:n})}})}let l=n[0];if(l&&!ot(l.body)&&a.push({code:`invalid-root`,message:`the first rule '${l.name}' is the root of the data model and must define a type, not a group (RFC 8610 §2.2.4)`,start:l.start,end:l.end}),(t?.strict??!0)&&a.length>0)throw new i(a);return new it(e,r,n,s,l,a)}function ot(e){if(e.kind===`entry`)return!e.occur&&!e.memberKey;if(e.occur||e.group.trailingComma)return!1;let{choices:t}=e.group;return t.length===1&&t[0].length===1&&ot(t[0][0])}function st(e,t){if(e.kind===`entry-group`){Z(e.group,t);return}e.memberKey?.kind===`type1`&&$(e.memberKey.key,t),Q(e.value,t)}function Z(e,t){for(let n of e.choices)for(let e of n)st(e,t)}function Q(e,t){for(let n of e.alternatives)$(n,t)}function $(e,t){ct(e.target,t),e.controller&&ct(e.controller,t)}function ct(e,t){switch(e.kind){case`value`:case`any`:return;case`ref`:t.onRef(e);for(let n of e.genericArgs??[])$(n,t);return;case`paren`:Q(e.type,t);return;case`map`:case`array`:Z(e.group,t);return;case`unwrap`:t.onRef(e.ref);for(let n of e.ref.genericArgs??[])$(n,t);return;case`enum`:if(e.group.kind===`ref`){t.onRef(e.group);for(let n of e.group.genericArgs??[])$(n,t)}else Z(e.group,t);return;case`tagged`:typeof e.tag==`object`&&Q(e.tag,t),Q(e.item,t);return;case`major`:t.onMajor(e.major,e.start,e.end),typeof e.ai==`object`&&Q(e.ai,t);return}}Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return f}}),Object.defineProperty(exports,"c",{enumerable:!0,get:function(){return i}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return _}}),Object.defineProperty(exports,"l",{enumerable:!0,get:function(){return n}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return at}}),Object.defineProperty(exports,"o",{enumerable:!0,get:function(){return u}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return h}}),Object.defineProperty(exports,"s",{enumerable:!0,get:function(){return r}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return it}});
|
|
63
|
-
//# sourceMappingURL=schema-DgnkH0P6.cjs.map
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
var e=class extends SyntaxError{offset;line;column;endOffset;constructor(e,t){let n=t?.line===void 0?``:` at line ${t.line}, column ${t.column}`;super(`EDN parse error${n}: ${e}`),this.name=`CdnSyntaxError`,this.offset=t?.offset,this.line=t?.line,this.column=t?.column,this.endOffset=t?.endOffset}},t=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,`0`)),n=new Int8Array(128).fill(-1);for(let e=0;e<16;e++)n[`0123456789abcdef`.charCodeAt(e)]=e,n[`0123456789ABCDEF`.charCodeAt(e)]=e;var r=typeof Uint8Array.prototype.toHex==`function`,i=typeof Uint8Array.fromHex==`function`,a=256;function o(e){if(r)return e.toHex();let n=``;for(let r=0;r<e.length;r++)n+=t[e[r]];return n}var s=Array.from({length:256},(e,t)=>t.toString(16).toUpperCase().padStart(2,`0`));function c(e){return s[e]}function l(e){let t=``;for(let n=0;n<e.length;n++)n>0&&(t+=` `),t+=s[e[n]];return t}function u(e){if(e.length%2!=0)throw SyntaxError(`hex string has odd length: ${e.length}`);if(i&&e.length>=a)return Uint8Array.fromHex(e);let t=new Uint8Array(e.length/2);for(let r=0,i=0;r<e.length;r+=2,i++){let a=e.charCodeAt(r),o=e.charCodeAt(r+1),s=a<128?n[a]:-1,c=o<128?n[o]:-1;if((s|c)<0){let t=s<0?e[r]:e[r+1];throw SyntaxError(`invalid character ${JSON.stringify(t)} in hex string`)}t[i]=s<<4|c}return t}function d(e){let t=e?.indent;if(t===void 0)return null;let n=typeof t==`number`?` `.repeat(t):t;return n===``?null:n}function f(e,t){return e.repeat(t)}function p(e,t,n,r){if(t===null)return e.join(` + `);let i=f(t,n+1),a=e[0];for(let t=1;t<e.length;t++){a+=` +
|
|
2
|
-
`;for(let e of r?.[t-1]??[])a+=`${i}${e}\n`;a+=i+e[t]}return a}function m(e){return!!(e.comments?.leading?.length||e.comments?.trailing?.length||e.comments?.dangling?.length)}function h(e){return!!e.comments?.dangling?.length}function g(e,t){if(!t)return e.text;let{marker:n,text:r}=e;if(t===`c-style`)return n===`#`?`//`+r.slice(1):n===`/`?`/*`+r.slice(1,-1)+`*/`:r;if(n===`//`)return`#`+r.slice(2);if(n===`/*`){let e=r.slice(2,-2);return e.includes(`/`)?r:`/`+(e.startsWith(`*`)||e.startsWith(`/`)?` `+e:e)+`/`}return r}function _(e,t,n){if(!e||e.length===0||!t||t.length<2)return;let r=t.slice(1).map(()=>[]),i=!1;for(let a of e)for(let e=0;e<t.length-1;e++){let o=t[e].end,s=t[e+1].start;if(o!==void 0&&s!==void 0&&a.start>=o&&a.end<=s){r[e].push(g(a,n)),i=!0;break}}return i?r:void 0}function v(e,t,n){let r=e.comments?.leading??[],i=r.length;for(;i>0&&r[i-1].sameLine;)i--;return{ownLines:r.slice(0,i).map(e=>t+g(e,n)),inlinePrefix:r.slice(i).map(e=>g(e,n)+` `).join(``)}}function y(e,t){let n=e.comments?.trailing??[];return n.length===0?``:` `+n.map(e=>g(e,t)).join(` `)}function b(e,t,n){return(e.comments?.dangling??[]).map(e=>t+g(e,n))}function x(e,t=!1){let n=e?.commas??`comma`,r=n!==`none`;return{inlineSep:r?t?`,`:`, `:` `,multilineSep:r?`,`:``,trailSep:n===`trailing`?`,`:``,colSep:t?`:`:`: `}}function S(e){let{options:t,depth:n,openChar:r,closeChar:i,count:a}=e,o=d(t),s=t?.preserveComments,c=typeof s==`string`?s:void 0,l=o!==null&&s&&(h(e.node)||e.hasEntryComments()),u=o!==null&&!!t?.preserveBlankLines,p=!1;if(u){for(let t=0;t<a;t++)if(e.entryLeadingNode(t).blankLineBefore){p=!0;break}}let{inlineSep:m,multilineSep:g,trailSep:_,colSep:y}=x(t,o===null),S=e.eiPosition??`open`,C=e.indefiniteLength?``:G(t,e.encodingWidth,()=>W(e.canonicalCount?e.canonicalCount():BigInt(a))),w=S===`open`&&C?C+` `:``,T=S===`close`?C:``,E=e.indefiniteLength&&(t?.encodingIndicators??`auto`)!==`never`,D=t=>e.indefiniteLength?E?a===0?`${r}_ ${i}`:`${r}_ ${t}${i}`:`${r}${t}${i}`:`${r}${w}${t}${i}${T}`;if(o===null||a===0&&!l){let t=``;for(let n=0;n<a;n++)n>0&&(t+=m),t+=e.renderEntry(n,y);return D(t)}let O=null;if(t?.inlineLeafContainers&&a>0&&!l&&!p){let t=[],n=!0;for(let r=0;r<a;r++){if(e.entryIsLeaf&&!e.entryIsLeaf(r)){n=!1;break}let i=e.renderEntry(r,y);if(t.push(i),i.includes(`
|
|
3
|
-
`)){n=!1;break}}if(n)return D(t.join(m));O=t}let k=f(o,n+1),A=f(o,n),j=e.indefiniteLength?E?`${r}_ `:r:`${r}${w}`,M=[];for(let t=0;t<a;t++){u&&e.entryLeadingNode(t).blankLineBefore&&M.push(``);let n=``;if(s){let{ownLines:r,inlinePrefix:i}=v(e.entryLeadingNode(t),k,c);M.push(...r),n=i}let r=t<a-1?g:_,i=O?.[t]??e.renderEntry(t,y);M.push(`${k}${n}${i}${r}${s?e.entryTrailing(t,c):``}`)}return s&&M.push(...b(e.node,k,c)),`${j}\n${M.join(`
|
|
4
|
-
`)}\n${A}${i}${T}`}function C(e,t,n,r,i,a,o){let s=d(n),c=n?.preserveComments;if(!(s!==null&&c&&(m(e)||h(t))))return`${a}${i(r)}${o}`;let l=typeof c==`string`?c:void 0,u=f(s,r+1),p=f(s,r),{ownLines:g,inlinePrefix:_}=v(e,u,l);return`${a}\n${[...g,`${u}${_}${i(r+1)}${y(e,l)}`,...b(t,u,l)].join(`
|
|
5
|
-
`)}\n${p}${o}`}var w=typeof new Uint8Array().toBase64==`function`;function T(e){if(w)return e.toBase64({omitPadding:!0});let t=``;for(let n of e)t+=String.fromCharCode(n);return btoa(t).replace(/=/g,``)}function E(e){if(w)return e.toBase64({alphabet:`base64url`,omitPadding:!0});let t=``;for(let n of e)t+=String.fromCharCode(n);return btoa(t).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=/g,``)}var D=`ABCDEFGHIJKLMNOPQRSTUVWXYZ234567`,O=`0123456789ABCDEFGHIJKLMNOPQRSTUV`;function k(e,t){let n=``,r=0,i=0;for(let a of e)for(r=r<<8|a,i+=8;i>=5;)i-=5,n+=t[r>>i&31];return i>0&&(n+=t[r<<5-i&31]),n}function A(e){for(let t of e){let e=t.codePointAt(0);if(e<32||e===127)return!0}return!1}function j(e,t,n){if(n===`string`){let t=I(e);if(t!=null)return z(t)}if(n===`printable-string`||n===void 0){let t=I(e);if(t!=null&&!A(t))return z(t)}switch(t){case`base64`:return`b64'${T(e)}'`;case`base64url`:return`b64'${E(e)}'`;case`base32`:return`b32'${k(e,D)}'`;case`base32hex`:return`h32'${k(e,O)}'`;default:return`h'${o(e)}'`}}function M(e,t){let n=0;for(;n<e.length&&e[n]!==`'`&&e[n]!=="`";)n++;if(n>=e.length)return e;let r=e[n],i=e.lastIndexOf(r);if(i<=n)return e;let a=e.slice(n+1,i),o=t===`hash-only`?N(a):P(a);return e.slice(0,n+1)+o+e.slice(i)}function N(e){let t=``,n=0;for(;n<e.length;){if(e[n]===`#`){for(;n<e.length&&e[n]!==`
|
|
6
|
-
`;)n+=e[n]===`\\`&&n+1<e.length?2:1;continue}t+=e[n],n++}return t}function P(e){let t=``,n=0;for(;n<e.length;){let r=e[n],i=e[n+1];if(r===`#`||r===`/`&&i===`/`){for(n+=r===`#`?1:2;n<e.length&&e[n]!==`
|
|
7
|
-
`;)n+=e[n]===`\\`&&n+1<e.length?2:1;continue}if(r===`/`&&i===`*`){let t=e.indexOf(`*/`,n+2);n=t===-1?e.length:t+2;continue}if(r===`/`){let t=n+1;for(;t<e.length&&e[t]!==`/`;)t+=e[t]===`\\`&&t+1<e.length?2:1;n=t<e.length?t+1:e.length;continue}t+=r,n++}return t}var F=new TextDecoder(`utf-8`,{fatal:!0});function I(e){try{return F.decode(e)}catch{return null}}function L(e,t){for(let n=0;n<e.length;n++){let r=e.charCodeAt(n);if(r===t||r===92||r<32||r===127||r>=8192&&(r===8232||r===8233||r>=8203&&r<=8205||r===65279))return!0}return!1}function R(e,t){let n=t.codePointAt(0);if(!L(e,n))return t+e+t;let r=t;for(let i of e){let e=i.codePointAt(0);switch(e){case n:r+=`\\${t}`;break;case 92:r+=`\\\\`;break;case 10:r+=`\\n`;break;case 13:r+=`\\r`;break;case 9:r+=`\\t`;break;default:e<32||e===127||e===8232||e===8233||e===8203||e===8204||e===8205||e===65279?r+=`\\u${e.toString(16).padStart(4,`0`)}`:r+=i}}return r+t}function z(e){return R(e,`'`)}function B(e){return R(e,`'`)}function V(e){return R(e,`"`)}function H(e){if(isNaN(e))return`NaN`;if(!isFinite(e))return e>0?`Infinity`:`-Infinity`;if(Object.is(e,-0))return`-0.0`;let t=e.toString();return t.includes(`.`)||t.includes(`e`)?t:t+`.0`}function U(e,t,n,r){if(r===`never`)return``;let i=t??n;return r===`always`?i===`half`?`_1`:i===`single`?`_2`:`_3`:t===void 0||t===n?``:t===`half`?`_1`:t===`single`?`_2`:`_3`}function W(e){return e<=23n?`i`:e<=255n?0:e<=65535n?1:e<=4294967295n?2:3}function G(e,t,n){let r=e?.encodingIndicators??`auto`;return r===`never`?``:r===`always`?`_${t??n()}`:t===void 0?``:`_${t}`}function K(e,t,n,r,i){if(!e?.preserveAppSequence||t===void 0||d(e)===null&&/[\r\n]/.test(t))return`normal`;if(n===void 0)return r?.byteString&&e?.preserveByteString===!1||r?.textString&&e?.preserveTextString===!1||r?.rawString&&e?.preserveRawString===!1||r?.concatenation&&e?.preserveConcatenation===!1?`normal`:`adjusted`;let a=e?.preserveComments===!1||typeof e?.preserveComments==`string`||e?.preserveComments===!0&&d(e)===null,o=e?.encodingIndicators??`auto`;return e?.preserveNumberFormat===!1||r?.byteString&&e?.preserveByteString===!1||r?.textString&&e?.preserveTextString===!1||r?.rawString&&e?.preserveRawString===!1||r?.concatenation&&e?.preserveConcatenation===!1||o!==`auto`&&i===!1?`structural`:o!==`auto`||a?`source`:`verbatim`}function q(e,t,n){let r=t>0?e[t-1]:``,i=n<e.length?e[n]:``,a=e=>e!==``&&!/[\s,]/.test(e);return a(r)&&a(i)?` `:``}function J(e,t,n,r){let i=t?.preserveComments;if(i===void 0||!n?.length)return e;let a=i===!1||d(t)===null,o=typeof i==`string`?i:void 0,s=e,c=[...n].sort((e,t)=>t.start-e.start);for(let e of c){let t=r!==void 0&&e.start>=r?-2:0,n=e.start+t,i=e.end+t,c=a?q(s,n,i):g(e,o);s=s.slice(0,n)+c+s.slice(i)}return s}function Y(e,t,n,r){let i=[],a=t?.preserveComments;if(a!==void 0&&n?.length){let r=a===!1||d(t)===null,o=typeof a==`string`?a:void 0;for(let t of n)i.push({start:t.start,end:t.end,replacement:r?q(e,t.start,t.end):g(t,o)})}let o=t?.encodingIndicators??`auto`;if(o!==`auto`&&r)for(let e of r)i.push({start:e.start,end:e.end,replacement:o===`always`?e.always:e.never});i.sort((e,t)=>t.start-e.start||t.end-e.end);let s=e;for(let e of i)s=s.slice(0,e.start)+e.replacement+s.slice(e.end);return s}function X(e,t,n,r,i){let a=e,o;if((n?.encodingIndicators??`auto`)===`never`&&r!==void 0){let e=a.slice(0,r);/_[0-3i]$/.test(e)&&(o=r-2,a=e.slice(0,-2)+a.slice(r))}return a=J(a,n,i,o),a.replace(/_[0-3i]$/,``)+t}function Z(e,t,n){let r=1,i=1;for(let a=0;a<e.length;a++){if(r===t&&i===n)return a;e[a]===`
|
|
8
|
-
`?(r++,i=1):i++}return e.length}function Q(e,t){let n=1,r=1;for(let i=0;i<t;i++)e[i]===`
|
|
9
|
-
`?(n++,r=1):r++;return{line:n,col:r}}function $(e){return e>=48&&e<=57||e>=97&&e<=102||e>=65&&e<=70}var ee=new TextEncoder,te=class{input;pos;line;col;_peeked=null;_lastConsumedEndOffset;skipRS;comments=[];onEscapeWarning;constructor(e,t){this.input=e;let n=t?.offset??0;if(this.skipRS=t?.skipRS??!1,!Number.isInteger(n)||n<0||n>e.length)throw RangeError(`EDN parse offset must be an integer between 0 and ${e.length}`);let r=Q(e,n);this.pos=n,this.line=r.line,this.col=r.col,this._lastConsumedEndOffset=n}peek(){return this._peeked===null&&(this._peeked=this._readNext()),this._peeked}consume(){let e=this._peeked===null?this._readNext():this._peeked;return this._peeked=null,this._lastConsumedEndOffset=e.endOffset,e}get lastEndOffset(){return this._lastConsumedEndOffset}get source(){return this.input}_ch(){return this.input[this.pos]??``}_eof(){return this.pos>=this.input.length}_advance(){let e=this.input[this.pos++]??``;return e===`
|
|
10
|
-
`?(this.line++,this.col=1):this.col++,e}_fail(t,n=this.line,r=this.col){let i=n===this.line&&r===this.col?this.pos:Z(this.input,n,r);throw new e(t,{offset:i,line:n,column:r,endOffset:Math.min(Math.max(this.pos,i+1),this.input.length)})}_skipWS(){for(;;){for(;;){let e=this.input[this.pos];if(e===void 0)return;if(e===` `||e===`
|
|
11
|
-
`||e===` `||e===`\r`||this.skipRS&&e===``){this._advance();continue}if(e>` `&&e<=`~`)break;if(/\s/.test(e)){this._advance();continue}break}let e=this._ch();if(e===`#`){let e=this.pos,t=this.line,n=this.col;for(;!this._eof()&&this._ch()!==`
|
|
12
|
-
`;)this._advance();this.comments.push({kind:`line`,marker:`#`,text:this.input.slice(e,this.pos),start:e,end:this.pos,line:t,col:n});continue}if(e===`/`){let e=this.input[this.pos+1]??``;if(e===`/`){let e=this.pos,t=this.line,n=this.col;for(this._advance(),this._advance();!this._eof()&&this._ch()!==`
|
|
13
|
-
`;)this._advance();this.comments.push({kind:`line`,marker:`//`,text:this.input.slice(e,this.pos),start:e,end:this.pos,line:t,col:n});continue}if(e===`*`){let e=this.pos,t=this.line,n=this.col;this._advance(),this._advance(),this._skipBlockCommentStar(),this.comments.push({kind:`block`,marker:`/*`,text:this.input.slice(e,this.pos),start:e,end:this.pos,line:t,col:n});continue}let t=this.pos,n=this.line,r=this.col;this._advance(),this._skipBlockCommentSlash(),this.comments.push({kind:`block`,marker:`/`,text:this.input.slice(t,this.pos),start:t,end:this.pos,line:n,col:r});continue}return}}_skipByteStringComment(e){let t=this._ch();if(t===`/`){let t=this.input[this.pos+1]??``;if(t===`/`){for(this._advance(),this._advance();!this._eof()&&this._ch()!==`
|
|
14
|
-
`;){if(this._ch()===`\\`){this._advance(),!this._eof()&&this._ch()!==`
|
|
15
|
-
`&&this._advance();continue}if(this._ch()===e)break;this._advance()}return!0}return t===`*`?(this._advance(),this._advance(),this._skipBlockCommentStar(),!0):(this._advance(),this._skipBlockCommentSlash(),!0)}if(t===`#`){for(;!this._eof()&&this._ch()!==`
|
|
16
|
-
`;){if(this._ch()===`\\`){if(this._advance(),this._eof()||this._ch()===`
|
|
17
|
-
`)continue;this._advance()===`u`&&this._validateHexCommentUnicodeEscape();continue}if(this._ch()===e)break;this._advance()}return!0}return!1}_validateHexCommentUnicodeEscape(){let e=this.line,t=this.col;if(!this._eof()&&this._ch()===`{`){this._advance();let n=``;for(;!this._eof()&&this._ch()!==`}`&&this._ch()!==`
|
|
18
|
-
`;)n+=this._advance();!this._eof()&&this._ch()===`}`&&this._advance();let r=parseInt(n||`0`,16);r>=55296&&r<=57343&&this._fail(`\\u{${n}} is a surrogate code point, not allowed in hex string comments`,e,t);return}let n=``;for(let e=0;e<4&&!(this._eof()||this._ch()===`
|
|
19
|
-
`||!/[0-9a-fA-F]/.test(this._ch()));e++)n+=this._advance();if(n.length<4)return;let r=parseInt(n,16);if(r>=55296&&r<=56319){(this._ch()!==`\\`||(this.input[this.pos+1]??``)!==`u`)&&this._fail(`lone high surrogate \\u${n} in hex string comment`,e,t),this._advance(),this._advance();let r=``;for(let e=0;e<4&&!(this._eof()||this._ch()===`
|
|
20
|
-
`||!/[0-9a-fA-F]/.test(this._ch()));e++)r+=this._advance();let i=parseInt(r||`0`,16);(i<56320||i>57343)&&this._fail(`\\u${n} (high surrogate) not followed by valid low surrogate in hex string comment`,e,t);return}r>=56320&&r<=57343&&this._fail(`lone low surrogate \\u${n} in hex string comment`,e,t)}_skipRawComment(e,t,n,r,i){let a=e[t];if(a===`/`){if(t++,e[t]===`/`){for(t++;t<e.length&&e[t]!==`
|
|
21
|
-
`;)t++;return t}if(e[t]===`*`){for(t++;t<e.length;){if(e[t]===`*`&&e[t+1]===`/`)return t+2;t++}return t}for(;t<e.length&&e[t]!==`/`;)t++;return t>=e.length&&this._fail(`unterminated block comment in ${n}`,r,i),t+1}if(a===`#`){for(;t<e.length&&e[t]!==`
|
|
22
|
-
`;)t++;return t}return-1}_skipBlockCommentSlash(){let e=this.line,t=this.col;for(;!this._eof();){if(this._ch()===`\\`){this._advance(),this._eof()||this._advance();continue}if(this._ch()===`/`)break;this._advance()}this._eof()&&this._fail(`unterminated block comment`,e,t),this._advance()}_skipBlockCommentStar(){let e=this.line,t=this.col;for(;!this._eof();){if(this._ch()===`*`&&(this.input[this.pos+1]??``)===`/`){this._advance(),this._advance();return}this._advance()}this._fail(`unterminated block comment`,e,t)}_readStringContent(e){this._advance();let t=e.charCodeAt(0),n=this.input.length,r=``;for(;!this._eof()&&this._ch()!==e;){let i=this.pos,a=0,o=-1;for(;i<n;){let e=this.input.charCodeAt(i);if(e===t||e===92||e===127)break;if(e<32){if(e!==10)break;a++,o=i}i++}if(i>this.pos){r+=this.input.slice(this.pos,i),a>0?(this.line+=a,this.col=i-o):this.col+=i-this.pos,this.pos=i;continue}let s=this._ch();if(s===`\r`){this._advance();continue}let c=s.codePointAt(0);if((c<32&&c!==10||c===127)&&this._fail(`unescaped control character U+${c.toString(16).padStart(4,`0`)} is not allowed in string literals`),s===`\\`){let t=this.pos,n=this.line,i=this.col;this._advance();let a=this._advance();switch(a){case`n`:r+=`
|
|
23
|
-
`;break;case`r`:r+=`\r`;break;case`t`:r+=` `;break;case`b`:r+=`\b`;break;case`f`:r+=`\f`;break;case`\\`:r+=`\\`;break;case`u`:r+=this._readUnicodeEscape(e,t,n,i);break;default:if(a===e){r+=a;break}if(a===`/`){e===`'`&&this._fail(`\\/ is not a valid escape in single-quoted byte strings (§5.1)`,n,i),r+=`/`;break}if(this.onEscapeWarning){if(a===`0`){this.onEscapeWarning(`\\0 is a non-standard escape sequence; use \\u0000 instead`,t,n,i,this.pos),r+=`\0`;break}if(a===`v`){this.onEscapeWarning(`\\v is a non-standard escape sequence; use \\u000b instead`,t,n,i,this.pos),r+=`\v`;break}if(a===`x`){let e=this._ch(),a=this.input[this.pos+1]??``;(!/[0-9a-fA-F]/.test(e)||!/[0-9a-fA-F]/.test(a))&&this._fail(`\\x escape requires exactly two hex digits`,n,i),this._advance(),this._advance();let o=parseInt(e+a,16);this.onEscapeWarning(`\\x${e}${a} is a non-standard escape sequence; use \\u00${e}${a} instead`,t,n,i,this.pos),r+=String.fromCharCode(o);break}if(a===`"`||a===`'`){this.onEscapeWarning(`\\${a} inside ${e===`"`?`double`:`single`}-quoted string is non-standard`,t,n,i,this.pos),r+=a;break}if(a===`
|
|
24
|
-
`||a===`\r`){a===`\r`&&this._ch()===`
|
|
25
|
-
`&&this._advance(),this.onEscapeWarning(`line continuation (\\<newline>) is non-standard; the newline is ignored`,t,n,i,this.pos);break}this.onEscapeWarning(`\\${a} is an unknown escape sequence; interpreted as '${a}'`,t,n,i,this.pos),r+=a;break}this._fail(`invalid escape sequence \\${a} in ${e===`"`?`double`:`single`}-quoted string`,n,i)}}else r+=this._advance()}return this._eof()&&this._fail(`unterminated string literal`),this._advance(),r}_readUnicodeEscape(e,t,n,r){let i=this.line,a=this.col,o=o=>{if(e===`'`&&o>=32&&o<=126){let e=`\\u escape for printable ASCII U+${o.toString(16).padStart(4,`0`).toUpperCase()} is not allowed in single-quoted strings (§5.1 hexchar-s)`;if(this.onEscapeWarning){this.onEscapeWarning(e,t??this.pos,n??i,r??a,this.pos);return}this._fail(e,i,a)}};if(!this._eof()&&this._ch()===`{`){this._advance();let e=``;for(;!this._eof()&&this._ch()!==`}`;){let t=this._ch();/[0-9a-fA-F]/.test(t)||this._fail(`invalid character in \\u{} escape: ${JSON.stringify(t)}`,i,a),e+=this._advance()}this._eof()&&this._fail(`unterminated \\u{} escape`,i,a),this._advance(),e.length===0&&this._fail(`empty \\u{} escape`,i,a);let t=parseInt(e,16);return t>1114111&&this._fail(`\\u{${e}} exceeds maximum Unicode code point U+10FFFF`,i,a),t>=55296&&t<=57343&&this._fail(`\\u{${e}} is a surrogate code point, which is not a valid Unicode scalar value`,i,a),o(t),String.fromCodePoint(t)}let s=``;for(let e=0;e<4;e++){this._eof()&&this._fail(`truncated \\uXXXX escape`,i,a);let e=this._ch();/[0-9a-fA-F]/.test(e)||this._fail(`invalid hex digit in \\uXXXX escape: ${JSON.stringify(e)}`,i,a),s+=this._advance()}let c=parseInt(s,16);if(c>=55296&&c<=56319){(this._ch()!==`\\`||(this.input[this.pos+1]??``)!==`u`)&&this._fail(`lone high surrogate \\u${s} must be followed by \\uDC00–\\uDFFF`,i,a),this._advance(),this._advance();let e=this.line,t=this.col,n=``;for(let r=0;r<4;r++)this._eof()&&this._fail(`truncated low-surrogate escape`,e,t),n+=this._advance();let r=parseInt(n,16);return(r<56320||r>57343)&&this._fail(`\\u${s} (high surrogate) not followed by a valid low surrogate (got \\u${n})`,i,a),String.fromCodePoint(65536+(c-55296)*1024+(r-56320))}return c>=56320&&c<=57343&&this._fail(`lone low surrogate \\u${s} is not valid`,i,a),o(c),String.fromCharCode(c)}_readRawStringContent(){let e=this.line,t=this.col,n=0;for(;!this._eof()&&this._ch()==="`";)this._advance(),n++;let r=!1;!this._eof()&&this._ch()===`\r`&&this._advance(),!this._eof()&&this._ch()===`
|
|
26
|
-
`&&(this._advance(),r=!0);let i=this.input.length,a=``;for(;!this._eof();){let o=this.pos,s=0,c=-1;for(;o<i;){let e=this.input.charCodeAt(o);if(e===96||e===127)break;if(e<32){if(e!==10)break;s++,c=o}o++}if(o>this.pos){a+=this.input.slice(this.pos,o),s>0?(this.line+=s,this.col=o-c):this.col+=o-this.pos,this.pos=o;continue}let l=this._ch();if(l===`\r`){this._advance();continue}if(l==="`"){let i=0,o=this.line,s=this.col;for(;!this._eof()&&this._ch()==="`";)this._advance(),i++;if(i===n)return!r&&a.length>=2&&a.startsWith(` `)&&a.endsWith(` `)&&(a=a.slice(1,-1)),a===``&&this._fail(`raw string must not be empty (§2.5.4)`,e,t),a;i>n&&this._fail(`raw string contains a run of ${i} backquotes, longer than the ${n}-backquote delimiter; use longer delimiters`,o,s),a+="`".repeat(i)}else{let e=l.codePointAt(0);e<32&&e!==10&&e!==13&&this._fail(`raw string content must not contain control character U+${e.toString(16).toUpperCase().padStart(4,`0`)} (§2.5.4)`,this.line,this.col),e===127&&this._fail(`raw string content must not contain DEL (U+007F) (§2.5.4)`,this.line,this.col),a+=this._advance()}}this._fail(`unterminated raw string literal`,e,t)}_processRawHexContent(e,t,n){let r=``,i=!1,a=0;for(;a<e.length;){let o=e[a];if(o===`
|
|
27
|
-
`||o===` `||o===`\r`){a++;continue}o===` `&&this._fail("horizontal tab (HT) is not allowed inside h`` raw byte string literals (§5.3.3)",t,n);let s=this._skipRawComment(e,a,"h`` raw byte string",t,n);if(s!==-1){a=s;continue}if(o===`.`&&e[a+1]===`.`&&e[a+2]===`.`){for(a+=3;a<e.length&&e[a]===`.`;)a++;r+=`...`,i=!0;continue}if($(e.charCodeAt(a))){let t=a;for(;a<e.length&&$(e.charCodeAt(a));)a++;r+=e.slice(t,a);continue}this._fail(`unexpected character ${JSON.stringify(o)} in h\`\` raw byte string`,t,n)}return{value:r,elided:i}}_processRawB64Content(e,t,n){let r=``,i=0;for(;i<e.length;){let a=e[i];if(a===`
|
|
28
|
-
`||a===` `||a===`\r`){i++;continue}if(a===` `&&this._fail("horizontal tab (HT) is not allowed inside b64`` raw byte string literals (§5.3.4)",t,n),a===`#`){for(;i<e.length&&e[i]!==`
|
|
29
|
-
`;)i++;continue}let o=i;for(;i<e.length;){let t=e[i];if(t===`
|
|
30
|
-
`||t===` `||t===`\r`||t===` `||t===`#`)break;i++}r+=e.slice(o,i)}return r}_readByteContent(e){this._advance();let t=``;for(;!this._eof()&&this._ch()!==e;){let n=this._ch();if(n===`
|
|
31
|
-
`||n===` `){this._advance();continue}if(n===`\r`){this._advance();continue}if(n===` `&&this._fail(`horizontal tab (HT) is not allowed inside byte string literals (§5.2.2)`,this.line,this.col),n===`#`){for(;!this._eof()&&this._ch()!==`
|
|
32
|
-
`;){if(this._ch()===`\\`){this._advance(),!this._eof()&&this._ch()!==`
|
|
33
|
-
`&&this._advance();continue}if(this._ch()===e)break;this._advance()}continue}let r=this.pos,i=this.pos,a=this.input.length;for(;i<a;){let t=this.input[i];if(t===e||t===`
|
|
34
|
-
`||t===` `||t===`\r`||t===` `||t===`#`)break;i++}this.col+=i-r,this.pos=i,t+=this.input.slice(r,i)}return this._eof()&&this._fail(`unterminated byte string literal`),this._advance(),t}_readHexByteContentElisionAware(e){this._advance();let t=``,n=!1;for(;!this._eof()&&this._ch()!==e;){let r=this._ch();if(r===`
|
|
35
|
-
`||r===` `||r===`\r`){this._advance();continue}if(r===` `&&this._fail(`horizontal tab (HT) is not allowed inside hex byte string literals (§5.2.1)`,this.line,this.col),!this._skipByteStringComment(e)){if(r===`.`&&(this.input[this.pos+1]??``)===`.`&&(this.input[this.pos+2]??``)===`.`){for(this._advance(),this._advance(),this._advance();!this._eof()&&this._ch()===`.`;)this._advance();t.endsWith(`...`)||(t+=`...`),n=!0;continue}if($(r.charCodeAt(0))){let e=this.pos,n=this.pos,r=this.input.length;for(;n<r&&$(this.input.charCodeAt(n));)n++;this.col+=n-e,this.pos=n,t+=this.input.slice(e,n);continue}this._fail(`unexpected character ${JSON.stringify(r)} in hex byte string`)}}return this._eof()&&this._fail(`unterminated hex byte string literal`),this._advance(),{value:t,elided:n}}_tokStart=0;_readNext(){return this._skipWS(),this._tokStart=this.pos,this._readNextCore()}_tok(e,t,n,r,i){let a=this._tokStart,o={type:e,value:t,raw:this.input.slice(a,this.pos),line:n,col:r,offset:a,endOffset:this.pos};return i!==void 0&&(o.appPrefix=i),o}_tokV(e,t,n,r){return{type:e,value:t,raw:t,line:n,col:r,offset:this._tokStart,endOffset:this.pos}}_readNextCore(){let e=this.line,t=this.col;if(this._eof())return this._tokV(`EOF`,``,e,t);let n=this._ch();switch(n){case`[`:return this._advance(),this._tokV(`LBRACKET`,`[`,e,t);case`]`:return this._advance(),this._tokV(`RBRACKET`,`]`,e,t);case`{`:return this._advance(),this._tokV(`LBRACE`,`{`,e,t);case`}`:return this._advance(),this._tokV(`RBRACE`,`}`,e,t);case`(`:return this._advance(),this._tokV(`LPAREN`,`(`,e,t);case`)`:return this._advance(),this._tokV(`RPAREN`,`)`,e,t);case`:`:return this._advance(),this._tokV(`COLON`,`:`,e,t);case`,`:return this._advance(),this._tokV(`COMMA`,`,`,e,t);case`<`:if((this.input[this.pos+1]??``)===`<`)return this._advance(),this._advance(),this._tokV(`LT_LT`,`<<`,e,t);this._fail(`unexpected character '<'`,e,t);case`>`:if((this.input[this.pos+1]??``)===`>`)return this._advance(),this._advance(),this._tokV(`GT_GT`,`>>`,e,t);this._fail(`unexpected character '>'`,e,t);case`+`:{let n=this._readSignedInfinity(`+`,e,t);if(n!==null)return n;let r=this.input[this.pos+1]??``;return r>=`0`&&r<=`9`||r===`.`?(this._advance(),this._readNumber(e,t)):(this._advance(),this._tokV(`PLUS`,`+`,e,t))}case"`":return this._tok(`RAWSTRING`,this._readRawStringContent(),e,t);case`"`:{let n=this._readStringContent(`"`);return n===``&&this._ch()===`_`&&!/[0-7i]/.test(this.input[this.pos+1]??``)?(this._advance(),this._tok(`EMPTY_INDEF_TEXT`,``,e,t)):this._tok(`TSTR`,n,e,t)}case`'`:{if((this.input[this.pos+1]??``)===`'`&&(this.input[this.pos+2]??``)===`_`&&!/[0-7i]/.test(this.input[this.pos+3]??``))return this._advance(),this._advance(),this._advance(),this._tok(`EMPTY_INDEF_BYTES`,``,e,t);let n=this._readStringContent(`'`),r=ee.encode(n),i=this._tok(`SQSTR`,o(r),e,t);return Object.defineProperty(i,"_sqstrBytes",{value:r}),i}}if(n===`-`){let n=this._readSignedInfinity(`-`,e,t);return n===null?this._readNumber(e,t):n}if(n>=`0`&&n<=`9`||n===`.`&&/[0-9]/.test(this.input[this.pos+1]??``))return this._readNumber(e,t);if(/[a-zA-Z_]/.test(n))return this._readIdent(e,t);if(n===`.`){if((this.input[this.pos+1]??``)===`.`&&(this.input[this.pos+2]??``)===`.`){for(this._advance(),this._advance(),this._advance();!this._eof()&&this._ch()===`.`;)this._advance();return this._tok(`ELLIPSIS`,`...`,e,t)}this._fail(`unexpected character '.'`,e,t)}this._fail(`unexpected character ${JSON.stringify(n)}`,e,t)}_readSignedInfinity(e,t,n){if(!this.input.startsWith(`Infinity`,this.pos+1))return null;let r=this.input[this.pos+9]??``,i=r===`_`&&/[0-7i]/.test(this.input[this.pos+10]??``)&&!/[a-zA-Z0-9_]/.test(this.input[this.pos+11]??``);if(/[a-zA-Z0-9_]/.test(r)&&!i)return null;this._advance();for(let e=0;e<8;e++)this._advance();let a=e===`-`?`-Infinity`:`Infinity`;return i&&(a+=this._advance()+this._advance()),this._tok(`FLOAT`,a,t,n)}_skipHexDigits(){let e=this.pos,t=this.input.length;for(;e<t&&$(this.input.charCodeAt(e));)e++;this.col+=e-this.pos,this.pos=e}_skipDecimalDigits(){let e=this.pos,t=this.input.length;for(;e<t;){let t=this.input.charCodeAt(e);if(t<48||t>57)break;e++}this.col+=e-this.pos,this.pos=e}_tryConsumeEncodingSuffix(){if(this._ch()!==`_`)return;let e=this.input[this.pos+1]??``,t=this.input[this.pos+2]??``;(e>=`0`&&e<=`7`||e===`i`)&&!/[0-9a-zA-Z_]/.test(t)&&(this._advance(),this._advance())}_readNumber(e,t){let n=this.pos,r=()=>this.input.slice(n,this.pos),i=i=>n===this._tokStart?this._tokV(i,r(),e,t):this._tok(i,r(),e,t);if(this._ch()===`-`&&this._advance(),this._ch()===`0`){let n=this.input[this.pos+1]??``;if(n===`x`||n===`X`){this._advance(),this._advance();let n=this.pos;this._skipHexDigits();let a=this.pos>n,o=!1,s=!1;if(!this._eof()&&this._ch()===`.`){o=!0,this._advance();let e=this.pos;this._skipHexDigits(),s=this.pos>e}if(!this._eof()&&(this._ch()===`p`||this._ch()===`P`)){o=!0,!a&&!s&&this._fail(`hex float has no mantissa digits: ${r()}`,e,t),this._advance(),!this._eof()&&(this._ch()===`+`||this._ch()===`-`)&&this._advance();let n=this.pos;this._skipDecimalDigits(),this.pos===n&&this._fail(`hex float missing exponent digits: ${r()}`,e,t)}else o&&this._fail(`hex float missing 'p' exponent: ${r()}`,e,t);return o?(this._tryConsumeEncodingSuffix(),i(`FLOAT`)):i(`INTEGER`)}if(n===`o`||n===`O`){for(this._advance(),this._advance();!this._eof()&&this._ch()>=`0`&&this._ch()<=`7`;)this._advance();return i(`INTEGER`)}if(n===`b`||n===`B`){for(this._advance(),this._advance();!this._eof()&&(this._ch()===`0`||this._ch()===`1`);)this._advance();return i(`INTEGER`)}}this._skipDecimalDigits();let a=!1;if(!this._eof()&&this._ch()===`.`&&(a=!0,this._advance(),this._skipDecimalDigits()),!this._eof()&&(this._ch()===`e`||this._ch()===`E`)){a=!0,this._advance(),!this._eof()&&(this._ch()===`+`||this._ch()===`-`)&&this._advance();let n=this.pos;this._skipDecimalDigits(),this.pos===n&&this._fail(`float exponent has no digits: ${JSON.stringify(r())}`,e,t)}return this._tryConsumeEncodingSuffix(),i(a?`FLOAT`:`INTEGER`)}_readIdent(e,t){let n=this.pos;{let e=this.pos,t=this.input.length;for(;e<t;){let t=this.input.charCodeAt(e);if(!(t>=97&&t<=122||t>=65&&t<=90||t>=48&&t<=57||t===95))break;e++}this.col+=e-this.pos,this.pos=e}let r=this.input.slice(n,this.pos);switch(r){case`true`:return this._tokV(`TRUE`,r,e,t);case`false`:return this._tokV(`FALSE`,r,e,t);case`null`:return this._tokV(`NULL`,r,e,t);case`undefined`:return this._tokV(`UNDEFINED`,r,e,t);case`NaN`:case`NaN_0`:case`NaN_1`:case`NaN_2`:case`NaN_3`:case`NaN_4`:case`NaN_5`:case`NaN_6`:case`NaN_7`:case`NaN_i`:case`Infinity`:case`Infinity_0`:case`Infinity_1`:case`Infinity_2`:case`Infinity_3`:case`Infinity_4`:case`Infinity_5`:case`Infinity_6`:case`Infinity_7`:case`Infinity_i`:return this._tokV(`FLOAT`,r,e,t);case`simple`:return this._tokV(`SIMPLE`,r,e,t);case`_`:return this._tokV(`UNDERSCORE`,`_`,e,t);case`_0`:return this._tok(`ENCODING_INDICATOR`,`0`,e,t);case`_1`:return this._tok(`ENCODING_INDICATOR`,`1`,e,t);case`_2`:return this._tok(`ENCODING_INDICATOR`,`2`,e,t);case`_3`:return this._tok(`ENCODING_INDICATOR`,`3`,e,t);case`_4`:return this._tok(`ENCODING_INDICATOR`,`4`,e,t);case`_5`:return this._tok(`ENCODING_INDICATOR`,`5`,e,t);case`_6`:return this._tok(`ENCODING_INDICATOR`,`6`,e,t);case`_7`:return this._tok(`ENCODING_INDICATOR`,`7`,e,t);case`_i`:return this._tok(`ENCODING_INDICATOR`,`i`,e,t)}let i=r[0]??``,a=i>=`a`&&i<=`z`;if(a||i>=`A`&&i<=`Z`){let n=r.slice(1);if(a?/^[a-z0-9]*$/.test(n):/^[A-Z0-9]*$/.test(n)){let n=this.pos;for(;!this._eof();){let e=this._ch();if(!(a?e>=`a`&&e<=`z`||e>=`0`&&e<=`9`||e===`-`:e>=`A`&&e<=`Z`||e>=`0`&&e<=`9`||e===`-`))break;this.pos++}this.pos>n&&(this.col+=this.pos-n,r+=this.input.slice(n,this.pos));let i=this._ch();if(i===`"`&&this._fail(`"${r}" prefix requires single quotes or backticks, not double quotes`,e,t),i===`'`)switch(r){case`h`:{let{value:n,elided:r}=this._readHexByteContentElisionAware(i);return this._tok(r?`BYTES_HEX_ELIDED`:`BYTES_HEX`,n,e,t)}case`b64`:return this._tok(`BYTES_B64`,this._readByteContent(i),e,t);default:return this._tok(`APP_STRING`,this._readStringContent(i),e,t,r)}if(i==="`"){let n=this._readRawStringContent();switch(r){case`h`:{let{value:r,elided:i}=this._processRawHexContent(n,e,t);return this._tok(i?`BYTES_HEX_ELIDED`:`BYTES_HEX`,r,e,t)}case`b64`:return this._tok(`BYTES_B64`,this._processRawB64Content(n,e,t),e,t);default:return this._tok(`APP_STRING`,n,e,t,r)}}if(i===`<`&&(this.input[this.pos+1]??``)===`<`)return this._advance(),this._advance(),this._tok(`APP_SEQUENCE`,``,e,t,r)}}this._fail(`unknown identifier ${JSON.stringify(r)}`,e,t)}};Object.defineProperty(exports,"C",{enumerable:!0,get:function(){return c}}),Object.defineProperty(exports,"D",{enumerable:!0,get:function(){return e}}),Object.defineProperty(exports,"E",{enumerable:!0,get:function(){return u}}),Object.defineProperty(exports,"S",{enumerable:!0,get:function(){return M}}),Object.defineProperty(exports,"T",{enumerable:!0,get:function(){return l}}),Object.defineProperty(exports,"_",{enumerable:!0,get:function(){return G}}),Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return g}}),Object.defineProperty(exports,"b",{enumerable:!0,get:function(){return S}}),Object.defineProperty(exports,"c",{enumerable:!0,get:function(){return B}}),Object.defineProperty(exports,"d",{enumerable:!0,get:function(){return H}}),Object.defineProperty(exports,"f",{enumerable:!0,get:function(){return y}}),Object.defineProperty(exports,"g",{enumerable:!0,get:function(){return C}}),Object.defineProperty(exports,"h",{enumerable:!0,get:function(){return p}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return W}}),Object.defineProperty(exports,"l",{enumerable:!0,get:function(){return V}}),Object.defineProperty(exports,"m",{enumerable:!0,get:function(){return f}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return X}}),Object.defineProperty(exports,"o",{enumerable:!0,get:function(){return _}}),Object.defineProperty(exports,"p",{enumerable:!0,get:function(){return m}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return Y}}),Object.defineProperty(exports,"s",{enumerable:!0,get:function(){return K}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return te}}),Object.defineProperty(exports,"u",{enumerable:!0,get:function(){return U}}),Object.defineProperty(exports,"v",{enumerable:!0,get:function(){return d}}),Object.defineProperty(exports,"w",{enumerable:!0,get:function(){return o}}),Object.defineProperty(exports,"x",{enumerable:!0,get:function(){return v}}),Object.defineProperty(exports,"y",{enumerable:!0,get:function(){return j}});
|
|
36
|
-
//# sourceMappingURL=tokenizer-BD08xbyd.cjs.map
|