@lancc/cmark 1.2.0 → 1.2.1

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.
Files changed (127) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/LICENSE +21 -21
  3. package/README.md +47 -107
  4. package/assets/abnfDiagram-WEYOIA3C-CKV_7Upb.js +1 -0
  5. package/assets/architectureDiagram-ZHVYKT53-BvLudDvk.js +1 -0
  6. package/assets/blockDiagram-RJAE7QA3--gzkMGi2.js +1 -0
  7. package/assets/c4Diagram-XDPPPE54-ByfRiJGR.js +1 -0
  8. package/assets/chunk-2E7WHVMD-TfbC_dmh.js +1 -0
  9. package/assets/chunk-2Q5K7J3B-0YJgChVo.js +1 -0
  10. package/assets/chunk-4EMNKR2T-DHoYW7g5.js +1 -0
  11. package/assets/chunk-55XCU76K-Cq25Yw_G.js +1 -0
  12. package/assets/chunk-5VM5RSS4-CJaRXFHK.js +1 -0
  13. package/assets/chunk-JWPE2WC7-BP2iXBhe.js +1 -0
  14. package/assets/chunk-VQ5W62QI-B95zur4F.js +1 -0
  15. package/assets/chunk-XXDRQBXY-Ct0MhvQo.js +1 -0
  16. package/assets/chunk-ZCHMQSOR-C5VhW-wL.js +2 -0
  17. package/assets/classDiagram-v2-4MYWR3UA-C1G-Vkj0.js +1 -0
  18. package/assets/cose-bilkent-JH36ORCC-qIQoIBv0.js +1 -0
  19. package/assets/cynefin-EF2NZ3EQ-CR1E3YiZ.js +1 -0
  20. package/assets/cynefinDiagram-WF24UDRP-DaJFvZ3b.js +1 -0
  21. package/assets/cytoscape.esm-SjxgSg6I.js +9 -0
  22. package/assets/dagre-NK4GIZVX-BFRQhpii.js +1 -0
  23. package/assets/diagram-CBK3MWTC-DlueL6XZ.js +1 -0
  24. package/assets/diagram-I5XIIV2D-bITyafYX.js +1 -0
  25. package/assets/diagram-ODIL2UCW-Dlb4hg_-.js +1 -0
  26. package/assets/diagram-PFBEJUXE-CRfen0O7.js +1 -0
  27. package/assets/diagram-RJA3I4VV-CK-FlhGV.js +1 -0
  28. package/assets/diagram-TYUNFSNR-DmgVsxqa.js +1 -0
  29. package/assets/ebnfDiagram-V4P3TTPT-B9KGI9eQ.js +1 -0
  30. package/assets/echarts-CytsvCdp.js +25 -0
  31. package/assets/elk-QONTBCTQ-VgDftvsU.js +1 -0
  32. package/assets/erDiagram-KYQIGQAA-DkpP7sS4.js +1 -0
  33. package/assets/flowDiagram-IUGLLWBU-CRXa9Kxy.js +1 -0
  34. package/assets/ganttDiagram-R7GPNTJY-Cu2I55Wb.js +1 -0
  35. package/assets/gitGraphDiagram-PDYL7XHY-CwSo663I.js +1 -0
  36. package/assets/graph-Dz7AM1Q5.js +1 -0
  37. package/assets/index-BJ-NdQc4.js +100 -0
  38. package/assets/infoDiagram-MVDRKAX5-D3Qknzuo.js +1 -0
  39. package/assets/ishikawaDiagram-HPEHV2GE-9qYT75tk.js +1 -0
  40. package/assets/journeyDiagram-BOSHW7O7-DeSrJg9o.js +1 -0
  41. package/assets/kanban-definition-FNSA4HC5-DINkB6G7.js +1 -0
  42. package/assets/katex-DN8cTsI3.js +1 -0
  43. package/assets/markdown-S2mWvoE-.js +5 -0
  44. package/assets/mermaid-T_6Ze_cT.js +7 -0
  45. package/assets/mindmap-definition-6OY57UG3-DW5hqiAe.js +1 -0
  46. package/assets/pegDiagram-ECIUJNBX-BWy_tkzy.js +1 -0
  47. package/assets/pieDiagram-GNMPY74T-CniJbr6l.js +1 -0
  48. package/assets/quadrantDiagram-D57K4MC3-BVnDJkCv.js +1 -0
  49. package/assets/railroadDiagram-Y72NRBL7-BNKZpJJb.js +1 -0
  50. package/assets/requirementDiagram-EQYSW5RA-BETipHj0.js +1 -0
  51. package/assets/sankeyDiagram-SY24JHO5-ByEYqT7T.js +1 -0
  52. package/assets/sequenceDiagram-BLEHNHQU-BqCJ2tKG.js +1 -0
  53. package/assets/sizeCapture-INFHLROL-DlhrWFj-.js +1 -0
  54. package/assets/stateDiagram-v2-A6IESKWZ-DJUBWLTP.js +1 -0
  55. package/assets/swimlanes-B3ENRKFQ-D7k7tF5U.js +1 -0
  56. package/assets/swimlanesDiagram-AYQRV4AK-DoQBgB9o.js +1 -0
  57. package/assets/timeline-definition-JXYKGLGB-BCNhwnn6.js +1 -0
  58. package/assets/usecaseDiagram-WPOLBNNX-DRa_Rgl3.js +1 -0
  59. package/assets/vennDiagram-Q3Y3IDCW-Ba2eaO68.js +1 -0
  60. package/assets/wardleyDiagram-IVAIDKWA-W_i9vzY-.js +1 -0
  61. package/assets/xychartDiagram-4URNHDU4-ByfaGjvc.js +1 -0
  62. package/index.html +3 -3
  63. package/package.json +1 -1
  64. package/plugin.json +1 -1
  65. package/preload/git-panel.js +29 -5
  66. package/preload/git-service.js +48 -15
  67. package/preload/remote-setup.js +66 -33
  68. package/preload/remote-wizard.js +2 -0
  69. package/preload.js +30 -0
  70. package/assets/abnfDiagram-WEYOIA3C-BgXsTF7a.js +0 -1
  71. package/assets/architectureDiagram-ZHVYKT53-BsCWa_qC.js +0 -36
  72. package/assets/blockDiagram-RJAE7QA3-wbIxEiYN.js +0 -140
  73. package/assets/c4Diagram-XDPPPE54-5zdyxFvA.js +0 -38
  74. package/assets/chunk-2E7WHVMD-F85Lca-i.js +0 -88
  75. package/assets/chunk-2Q5K7J3B-CjpAZ0OI.js +0 -1
  76. package/assets/chunk-4EMNKR2T-C8Kbh83c.js +0 -1
  77. package/assets/chunk-55XCU76K-BINcFiLN.js +0 -1
  78. package/assets/chunk-5VM5RSS4-Diy5h2LS.js +0 -15
  79. package/assets/chunk-JWPE2WC7-BXnjDdh1.js +0 -1
  80. package/assets/chunk-VQ5W62QI-BM7ZZo1I.js +0 -1
  81. package/assets/chunk-XXDRQBXY-CW8CjB1w.js +0 -1
  82. package/assets/chunk-ZCHMQSOR-C7ATz1L1.js +0 -2
  83. package/assets/classDiagram-v2-4MYWR3UA-CMoqNk-b.js +0 -217
  84. package/assets/cose-bilkent-JH36ORCC-6rqR5iJk.js +0 -1
  85. package/assets/cynefin-EF2NZ3EQ-DypLIJxl.js +0 -141
  86. package/assets/cynefinDiagram-WF24UDRP-8b2CEBlR.js +0 -62
  87. package/assets/cytoscape.esm-CjX6Hyah.js +0 -331
  88. package/assets/dagre-NK4GIZVX-Dv6vuUbR.js +0 -4
  89. package/assets/diagram-CBK3MWTC-DJgMDeYd.js +0 -24
  90. package/assets/diagram-I5XIIV2D-BB9cMoRW.js +0 -24
  91. package/assets/diagram-ODIL2UCW-BVcRtsdy.js +0 -30
  92. package/assets/diagram-PFBEJUXE-BbGSOtJx.js +0 -3
  93. package/assets/diagram-RJA3I4VV-CzkY_8Fo.js +0 -41
  94. package/assets/diagram-TYUNFSNR-YTl5QdfL.js +0 -200
  95. package/assets/ebnfDiagram-V4P3TTPT-COVjPAjE.js +0 -1
  96. package/assets/echarts-BAPDkhe3.js +0 -61
  97. package/assets/elk-QONTBCTQ-DHsjY8Z_.js +0 -27
  98. package/assets/erDiagram-KYQIGQAA-CUAbTUl1.js +0 -99
  99. package/assets/flowDiagram-IUGLLWBU-CWsiqTQC.js +0 -213
  100. package/assets/ganttDiagram-R7GPNTJY-DetBW0Wm.js +0 -292
  101. package/assets/gitGraphDiagram-PDYL7XHY-ByrdgJmw.js +0 -106
  102. package/assets/graph-D8UmR1vK.js +0 -1
  103. package/assets/index-B17NCAw4.js +0 -758
  104. package/assets/infoDiagram-MVDRKAX5-BM48fjhU.js +0 -2
  105. package/assets/ishikawaDiagram-HPEHV2GE-DtHYywHZ.js +0 -70
  106. package/assets/journeyDiagram-BOSHW7O7-DJ1LiRh3.js +0 -139
  107. package/assets/kanban-definition-FNSA4HC5-DPPt8pwJ.js +0 -89
  108. package/assets/katex-CQL9J12G.js +0 -257
  109. package/assets/markdown-DVehI1Sg.js +0 -314
  110. package/assets/mermaid-C_q9pug0.js +0 -312
  111. package/assets/mindmap-definition-6OY57UG3-zbqYOEY6.js +0 -98
  112. package/assets/pegDiagram-ECIUJNBX-e7QG7TMq.js +0 -1
  113. package/assets/pieDiagram-GNMPY74T-Duf6YP0N.js +0 -39
  114. package/assets/quadrantDiagram-D57K4MC3-B2eYoUUy.js +0 -7
  115. package/assets/railroadDiagram-Y72NRBL7-BWCzPcI_.js +0 -1
  116. package/assets/requirementDiagram-EQYSW5RA-HhPMEqB1.js +0 -84
  117. package/assets/sankeyDiagram-SY24JHO5-CMUTwFBB.js +0 -40
  118. package/assets/sequenceDiagram-BLEHNHQU-C9wR2ll7.js +0 -169
  119. package/assets/sizeCapture-INFHLROL-DXfz37S6.js +0 -1
  120. package/assets/stateDiagram-v2-A6IESKWZ-D_gtonhE.js +0 -291
  121. package/assets/swimlanes-B3ENRKFQ-DdJOuuMV.js +0 -1
  122. package/assets/swimlanesDiagram-AYQRV4AK-BWt3HxHV.js +0 -8
  123. package/assets/timeline-definition-JXYKGLGB-DQsdwJe-.js +0 -120
  124. package/assets/usecaseDiagram-WPOLBNNX-DTRyFq7d.js +0 -370
  125. package/assets/vennDiagram-Q3Y3IDCW-dihYszm0.js +0 -34
  126. package/assets/wardleyDiagram-IVAIDKWA-BoPpgYfK.js +0 -78
  127. package/assets/xychartDiagram-4URNHDU4-DoLjYxeB.js +0 -7
@@ -1,370 +0,0 @@
1
- import{g as yi}from"./chunk-XXDRQBXY-CW8CjB1w.js";import{s as Ri}from"./chunk-VQ5W62QI-BM7ZZo1I.js";import{g as zs,s as Ut,a as Hs,b as Pt,t as Oi,q as Li,_ as c,C as Ue,l as Ii,c as Xs,p as ki,r as Ni,u as Ci,j as bi,z as vi,O as _i,B as xi,L as Mi,D as wi,I as Ui,bb as Pi,k as Di}from"./mermaid-C_q9pug0.js";import"./markdown-DVehI1Sg.js";function Dt(t){console&&console.error&&console.error(`Error: ${t}`)}function Ys(t){console&&console.warn&&console.warn(`Warning: ${t}`)}function qs(t){const e=new Date().getTime(),s=t();return{time:new Date().getTime()-e,value:s}}function Js(t){function e(){}e.prototype=t;const s=new e;function n(){return typeof s.bar}return n(),n(),t}function Fi(t){return Bi(t)?t.LABEL:t.name}function Bi(t){return typeof t.LABEL=="string"&&t.LABEL!==""}class te{get definition(){return this._definition}set definition(e){this._definition=e}constructor(e){this._definition=e}accept(e){e.visit(this),this.definition.forEach(s=>{s.accept(e)})}}class K extends te{constructor(e){super([]),this.idx=1,Object.assign(this,ie(e))}set definition(e){}get definition(){return this.referencedRule!==void 0?this.referencedRule.definition:[]}accept(e){e.visit(this)}}class Ie extends te{constructor(e){super(e.definition),this.orgText="",Object.assign(this,ie(e))}}class W extends te{constructor(e){super(e.definition),this.ignoreAmbiguities=!1,Object.assign(this,ie(e))}}class G extends te{constructor(e){super(e.definition),this.idx=1,Object.assign(this,ie(e))}}class se extends te{constructor(e){super(e.definition),this.idx=1,Object.assign(this,ie(e))}}class ne extends te{constructor(e){super(e.definition),this.idx=1,Object.assign(this,ie(e))}}class M extends te{constructor(e){super(e.definition),this.idx=1,Object.assign(this,ie(e))}}class J extends te{constructor(e){super(e.definition),this.idx=1,Object.assign(this,ie(e))}}class Z extends te{get definition(){return this._definition}set definition(e){this._definition=e}constructor(e){super(e.definition),this.idx=1,this.ignoreAmbiguities=!1,this.hasPredicates=!1,Object.assign(this,ie(e))}}class k{constructor(e){this.idx=1,Object.assign(this,ie(e))}accept(e){e.visit(this)}}function $i(t){return t.map(Qe)}function Qe(t){function e(s){return s.map(Qe)}if(t instanceof K){const s={type:"NonTerminal",name:t.nonTerminalName,idx:t.idx};return typeof t.label=="string"&&(s.label=t.label),s}else{if(t instanceof W)return{type:"Alternative",definition:e(t.definition)};if(t instanceof G)return{type:"Option",idx:t.idx,definition:e(t.definition)};if(t instanceof se)return{type:"RepetitionMandatory",idx:t.idx,definition:e(t.definition)};if(t instanceof ne)return{type:"RepetitionMandatoryWithSeparator",idx:t.idx,separator:Qe(new k({terminalType:t.separator})),definition:e(t.definition)};if(t instanceof J)return{type:"RepetitionWithSeparator",idx:t.idx,separator:Qe(new k({terminalType:t.separator})),definition:e(t.definition)};if(t instanceof M)return{type:"Repetition",idx:t.idx,definition:e(t.definition)};if(t instanceof Z)return{type:"Alternation",idx:t.idx,definition:e(t.definition)};if(t instanceof k){const s={type:"Terminal",name:t.terminalType.name,label:Fi(t.terminalType),idx:t.idx};typeof t.label=="string"&&(s.terminalLabel=t.label);const n=t.terminalType.PATTERN;return t.terminalType.PATTERN&&(s.pattern=n instanceof RegExp?n.source:n),s}else{if(t instanceof Ie)return{type:"Rule",name:t.name,orgText:t.orgText,definition:e(t.definition)};throw Error("non exhaustive match")}}}function ie(t){return Object.fromEntries(Object.entries(t).filter(([,e])=>e!==void 0))}class ke{visit(e){const s=e;switch(s.constructor){case K:return this.visitNonTerminal(s);case W:return this.visitAlternative(s);case G:return this.visitOption(s);case se:return this.visitRepetitionMandatory(s);case ne:return this.visitRepetitionMandatoryWithSeparator(s);case J:return this.visitRepetitionWithSeparator(s);case M:return this.visitRepetition(s);case Z:return this.visitAlternation(s);case k:return this.visitTerminal(s);case Ie:return this.visitRule(s);default:throw Error("non exhaustive match")}}visitNonTerminal(e){}visitAlternative(e){}visitOption(e){}visitRepetition(e){}visitRepetitionMandatory(e){}visitRepetitionMandatoryWithSeparator(e){}visitRepetitionWithSeparator(e){}visitAlternation(e){}visitTerminal(e){}visitRule(e){}}function ji(t){return t instanceof W||t instanceof G||t instanceof M||t instanceof se||t instanceof ne||t instanceof J||t instanceof k||t instanceof Ie}function ut(t,e=[]){return t instanceof G||t instanceof M||t instanceof J?!0:t instanceof Z?t.definition.some(n=>ut(n,e)):t instanceof K&&e.includes(t)?!1:t instanceof te?(t instanceof K&&e.push(t),t.definition.every(n=>ut(n,e))):!1}function Gi(t){return t instanceof Z}function ee(t){if(t instanceof K)return"SUBRULE";if(t instanceof G)return"OPTION";if(t instanceof Z)return"OR";if(t instanceof se)return"AT_LEAST_ONE";if(t instanceof ne)return"AT_LEAST_ONE_SEP";if(t instanceof J)return"MANY_SEP";if(t instanceof M)return"MANY";if(t instanceof k)return"CONSUME";throw Error("non exhaustive match")}class St{walk(e,s=[]){e.definition.forEach((n,i)=>{const a=e.definition.slice(i+1);if(n instanceof K)this.walkProdRef(n,a,s);else if(n instanceof k)this.walkTerminal(n,a,s);else if(n instanceof W)this.walkFlat(n,a,s);else if(n instanceof G)this.walkOption(n,a,s);else if(n instanceof se)this.walkAtLeastOne(n,a,s);else if(n instanceof ne)this.walkAtLeastOneSep(n,a,s);else if(n instanceof J)this.walkManySep(n,a,s);else if(n instanceof M)this.walkMany(n,a,s);else if(n instanceof Z)this.walkOr(n,a,s);else throw Error("non exhaustive match")})}walkTerminal(e,s,n){}walkProdRef(e,s,n){}walkFlat(e,s,n){const i=s.concat(n);this.walk(e,i)}walkOption(e,s,n){const i=s.concat(n);this.walk(e,i)}walkAtLeastOne(e,s,n){const i=[new G({definition:e.definition})].concat(s,n);this.walk(e,i)}walkAtLeastOneSep(e,s,n){const i=ms(e,s,n);this.walk(e,i)}walkMany(e,s,n){const i=[new G({definition:e.definition})].concat(s,n);this.walk(e,i)}walkManySep(e,s,n){const i=ms(e,s,n);this.walk(e,i)}walkOr(e,s,n){const i=s.concat(n);e.definition.forEach(a=>{const o=new W({definition:[a]});this.walk(o,i)})}}function ms(t,e,s){return[new G({definition:[new k({terminalType:t.separator})].concat(t.definition)})].concat(e,s)}function Ke(t){if(t instanceof K)return Ke(t.referencedRule);if(t instanceof k)return Vi(t);if(ji(t))return Wi(t);if(Gi(t))return Ki(t);throw Error("non exhaustive match")}function Wi(t){let e=[];const s=t.definition;let n=0,i=s.length>n,a,o=!0;for(;i&&o;)a=s[n],o=ut(a),e=e.concat(Ke(a)),n=n+1,i=s.length>n;return[...new Set(e)]}function Ki(t){const e=t.definition.map(s=>Ke(s));return[...new Set(e.flat())]}function Vi(t){return[t.terminalType]}const Zs="_~IN~_";class zi extends St{constructor(e){super(),this.topProd=e,this.follows={}}startWalking(){return this.walk(this.topProd),this.follows}walkTerminal(e,s,n){}walkProdRef(e,s,n){const i=Xi(e.referencedRule,e.idx)+this.topProd.name,a=s.concat(n),o=new W({definition:a}),l=Ke(o);this.follows[i]=l}}function Hi(t){const e={};return t.forEach(s=>{const n=new zi(s).startWalking();Object.assign(e,n)}),e}function Xi(t,e){return t.name+e+Zs}function S(t){return t.charCodeAt(0)}function vt(t,e){Array.isArray(t)?t.forEach(function(s){e.push(s)}):e.push(t)}function xe(t,e){if(t[e]===!0)throw"duplicate flag "+e;t[e],t[e]=!0}function Se(t){if(t===void 0)throw Error("Internal Error - Should never get here!");return!0}function Yi(){throw Error("Internal Error - Should never get here!")}function Es(t){return t.type==="Character"}const dt=[];for(let t=S("0");t<=S("9");t++)dt.push(t);const ft=[S("_")].concat(dt);for(let t=S("a");t<=S("z");t++)ft.push(t);for(let t=S("A");t<=S("Z");t++)ft.push(t);const Ts=[S(" "),S("\f"),S(`
2
- `),S("\r"),S(" "),S("\v"),S(" "),S(" "),S(" "),S(" "),S(" "),S(" "),S(" "),S(" "),S(" "),S(" "),S(" "),S(" "),S(" "),S(" "),S("\u2028"),S("\u2029"),S(" "),S(" "),S(" "),S("\uFEFF")],qi=/[0-9a-fA-F]/,Ye=/[0-9]/,Ji=/[1-9]/;class Zi{constructor(){this.idx=0,this.input="",this.groupIdx=0}saveState(){return{idx:this.idx,input:this.input,groupIdx:this.groupIdx}}restoreState(e){this.idx=e.idx,this.input=e.input,this.groupIdx=e.groupIdx}pattern(e){this.idx=0,this.input=e,this.groupIdx=0,this.consumeChar("/");const s=this.disjunction();this.consumeChar("/");const n={type:"Flags",loc:{begin:this.idx,end:e.length},global:!1,ignoreCase:!1,multiLine:!1,unicode:!1,sticky:!1};for(;this.isRegExpFlag();)switch(this.popChar()){case"g":xe(n,"global");break;case"i":xe(n,"ignoreCase");break;case"m":xe(n,"multiLine");break;case"u":xe(n,"unicode");break;case"y":xe(n,"sticky");break}if(this.idx!==this.input.length)throw Error("Redundant input: "+this.input.substring(this.idx));return{type:"Pattern",flags:n,value:s,loc:this.loc(0)}}disjunction(){const e=[],s=this.idx;for(e.push(this.alternative());this.peekChar()==="|";)this.consumeChar("|"),e.push(this.alternative());return{type:"Disjunction",value:e,loc:this.loc(s)}}alternative(){const e=[],s=this.idx;for(;this.isTerm();)e.push(this.term());return{type:"Alternative",value:e,loc:this.loc(s)}}term(){return this.isAssertion()?this.assertion():this.atom()}assertion(){const e=this.idx;switch(this.popChar()){case"^":return{type:"StartAnchor",loc:this.loc(e)};case"$":return{type:"EndAnchor",loc:this.loc(e)};case"\\":switch(this.popChar()){case"b":return{type:"WordBoundary",loc:this.loc(e)};case"B":return{type:"NonWordBoundary",loc:this.loc(e)}}throw Error("Invalid Assertion Escape");case"(":this.consumeChar("?");let s;switch(this.popChar()){case"=":s="Lookahead";break;case"!":s="NegativeLookahead";break;case"<":{switch(this.popChar()){case"=":s="Lookbehind";break;case"!":s="NegativeLookbehind"}break}}Se(s);const n=this.disjunction();return this.consumeChar(")"),{type:s,value:n,loc:this.loc(e)}}return Yi()}quantifier(e=!1){let s;const n=this.idx;switch(this.popChar()){case"*":s={atLeast:0,atMost:1/0};break;case"+":s={atLeast:1,atMost:1/0};break;case"?":s={atLeast:0,atMost:1};break;case"{":const i=this.integerIncludingZero();switch(this.popChar()){case"}":s={atLeast:i,atMost:i};break;case",":let a;this.isDigit()?(a=this.integerIncludingZero(),s={atLeast:i,atMost:a}):s={atLeast:i,atMost:1/0},this.consumeChar("}");break}if(e===!0&&s===void 0)return;Se(s);break}if(!(e===!0&&s===void 0)&&Se(s))return this.peekChar(0)==="?"?(this.consumeChar("?"),s.greedy=!1):s.greedy=!0,s.type="Quantifier",s.loc=this.loc(n),s}atom(){let e;const s=this.idx;switch(this.peekChar()){case".":e=this.dotAll();break;case"\\":e=this.atomEscape();break;case"[":e=this.characterClass();break;case"(":e=this.group();break}if(e===void 0&&this.isPatternCharacter()&&(e=this.patternCharacter()),Se(e))return e.loc=this.loc(s),this.isQuantifier()&&(e.quantifier=this.quantifier()),e}dotAll(){return this.consumeChar("."),{type:"Set",complement:!0,value:[S(`
3
- `),S("\r"),S("\u2028"),S("\u2029")]}}atomEscape(){switch(this.consumeChar("\\"),this.peekChar()){case"1":case"2":case"3":case"4":case"5":case"6":case"7":case"8":case"9":return this.decimalEscapeAtom();case"d":case"D":case"s":case"S":case"w":case"W":return this.characterClassEscape();case"f":case"n":case"r":case"t":case"v":return this.controlEscapeAtom();case"c":return this.controlLetterEscapeAtom();case"0":return this.nulCharacterAtom();case"x":return this.hexEscapeSequenceAtom();case"u":return this.regExpUnicodeEscapeSequenceAtom();default:return this.identityEscapeAtom()}}decimalEscapeAtom(){return{type:"GroupBackReference",value:this.positiveInteger()}}characterClassEscape(){let e,s=!1;switch(this.popChar()){case"d":e=dt;break;case"D":e=dt,s=!0;break;case"s":e=Ts;break;case"S":e=Ts,s=!0;break;case"w":e=ft;break;case"W":e=ft,s=!0;break}if(Se(e))return{type:"Set",value:e,complement:s}}controlEscapeAtom(){let e;switch(this.popChar()){case"f":e=S("\f");break;case"n":e=S(`
4
- `);break;case"r":e=S("\r");break;case"t":e=S(" ");break;case"v":e=S("\v");break}if(Se(e))return{type:"Character",value:e}}controlLetterEscapeAtom(){this.consumeChar("c");const e=this.popChar();if(/[a-zA-Z]/.test(e)===!1)throw Error("Invalid ");return{type:"Character",value:e.toUpperCase().charCodeAt(0)-64}}nulCharacterAtom(){return this.consumeChar("0"),{type:"Character",value:S("\0")}}hexEscapeSequenceAtom(){return this.consumeChar("x"),this.parseHexDigits(2)}regExpUnicodeEscapeSequenceAtom(){return this.consumeChar("u"),this.parseHexDigits(4)}identityEscapeAtom(){const e=this.popChar();return{type:"Character",value:S(e)}}classPatternCharacterAtom(){switch(this.peekChar()){case`
5
- `:case"\r":case"\u2028":case"\u2029":case"\\":case"]":throw Error("TBD");default:const e=this.popChar();return{type:"Character",value:S(e)}}}characterClass(){const e=[];let s=!1;for(this.consumeChar("["),this.peekChar(0)==="^"&&(this.consumeChar("^"),s=!0);this.isClassAtom();){const n=this.classAtom();if(n.type,Es(n)&&this.isRangeDash()){this.consumeChar("-");const i=this.classAtom();if(i.type,Es(i)){if(i.value<n.value)throw Error("Range out of order in character class");e.push({from:n.value,to:i.value})}else vt(n.value,e),e.push(S("-")),vt(i.value,e)}else vt(n.value,e)}return this.consumeChar("]"),{type:"Set",complement:s,value:e}}classAtom(){switch(this.peekChar()){case"]":case`
6
- `:case"\r":case"\u2028":case"\u2029":throw Error("TBD");case"\\":return this.classEscape();default:return this.classPatternCharacterAtom()}}classEscape(){switch(this.consumeChar("\\"),this.peekChar()){case"b":return this.consumeChar("b"),{type:"Character",value:S("\b")};case"d":case"D":case"s":case"S":case"w":case"W":return this.characterClassEscape();case"f":case"n":case"r":case"t":case"v":return this.controlEscapeAtom();case"c":return this.controlLetterEscapeAtom();case"0":return this.nulCharacterAtom();case"x":return this.hexEscapeSequenceAtom();case"u":return this.regExpUnicodeEscapeSequenceAtom();default:return this.identityEscapeAtom()}}group(){let e=!0;switch(this.consumeChar("("),this.peekChar(0)){case"?":this.consumeChar("?"),this.consumeChar(":"),e=!1;break;default:this.groupIdx++;break}const s=this.disjunction();this.consumeChar(")");const n={type:"Group",capturing:e,value:s};return e&&(n.idx=this.groupIdx),n}positiveInteger(){let e=this.popChar();if(Ji.test(e)===!1)throw Error("Expecting a positive integer");for(;Ye.test(this.peekChar(0));)e+=this.popChar();return parseInt(e,10)}integerIncludingZero(){let e=this.popChar();if(Ye.test(e)===!1)throw Error("Expecting an integer");for(;Ye.test(this.peekChar(0));)e+=this.popChar();return parseInt(e,10)}patternCharacter(){const e=this.popChar();switch(e){case`
7
- `:case"\r":case"\u2028":case"\u2029":case"^":case"$":case"\\":case".":case"*":case"+":case"?":case"(":case")":case"[":case"|":throw Error("TBD");default:return{type:"Character",value:S(e)}}}isRegExpFlag(){switch(this.peekChar(0)){case"g":case"i":case"m":case"u":case"y":return!0;default:return!1}}isRangeDash(){return this.peekChar()==="-"&&this.isClassAtom(1)}isDigit(){return Ye.test(this.peekChar(0))}isClassAtom(e=0){switch(this.peekChar(e)){case"]":case`
8
- `:case"\r":case"\u2028":case"\u2029":return!1;default:return!0}}isTerm(){return this.isAtom()||this.isAssertion()}isAtom(){if(this.isPatternCharacter())return!0;switch(this.peekChar(0)){case".":case"\\":case"[":case"(":return!0;default:return!1}}isAssertion(){switch(this.peekChar(0)){case"^":case"$":return!0;case"\\":switch(this.peekChar(1)){case"b":case"B":return!0;default:return!1}case"(":return this.peekChar(1)==="?"&&(this.peekChar(2)==="="||this.peekChar(2)==="!"||this.peekChar(2)==="<"&&(this.peekChar(3)==="="||this.peekChar(3)==="!"));default:return!1}}isQuantifier(){const e=this.saveState();try{return this.quantifier(!0)!==void 0}catch{return!1}finally{this.restoreState(e)}}isPatternCharacter(){switch(this.peekChar()){case"^":case"$":case"\\":case".":case"*":case"+":case"?":case"(":case")":case"[":case"|":case"/":case`
9
- `:case"\r":case"\u2028":case"\u2029":return!1;default:return!0}}parseHexDigits(e){let s="";for(let i=0;i<e;i++){const a=this.popChar();if(qi.test(a)===!1)throw Error("Expecting a HexDecimal digits");s+=a}return{type:"Character",value:parseInt(s,16)}}peekChar(e=0){return this.input[this.idx+e]}popChar(){const e=this.peekChar(0);return this.consumeChar(void 0),e}consumeChar(e){if(e!==void 0&&this.input[this.idx]!==e)throw Error("Expected: '"+e+"' but found: '"+this.input[this.idx]+"' at offset: "+this.idx);if(this.idx>=this.input.length)throw Error("Unexpected end of input");this.idx++}loc(e){return{begin:e,end:this.idx}}}class ts{visitChildren(e){for(const s in e){const n=e[s];e.hasOwnProperty(s)&&(n.type!==void 0?this.visit(n):Array.isArray(n)&&n.forEach(i=>{this.visit(i)},this))}}visit(e){switch(e.type){case"Pattern":this.visitPattern(e);break;case"Flags":this.visitFlags(e);break;case"Disjunction":this.visitDisjunction(e);break;case"Alternative":this.visitAlternative(e);break;case"StartAnchor":this.visitStartAnchor(e);break;case"EndAnchor":this.visitEndAnchor(e);break;case"WordBoundary":this.visitWordBoundary(e);break;case"NonWordBoundary":this.visitNonWordBoundary(e);break;case"Lookahead":this.visitLookahead(e);break;case"NegativeLookahead":this.visitNegativeLookahead(e);break;case"Lookbehind":this.visitLookbehind(e);break;case"NegativeLookbehind":this.visitNegativeLookbehind(e);break;case"Character":this.visitCharacter(e);break;case"Set":this.visitSet(e);break;case"Group":this.visitGroup(e);break;case"GroupBackReference":this.visitGroupBackReference(e);break;case"Quantifier":this.visitQuantifier(e);break}this.visitChildren(e)}visitPattern(e){}visitFlags(e){}visitDisjunction(e){}visitAlternative(e){}visitStartAnchor(e){}visitEndAnchor(e){}visitWordBoundary(e){}visitNonWordBoundary(e){}visitLookahead(e){}visitNegativeLookahead(e){}visitLookbehind(e){}visitNegativeLookbehind(e){}visitCharacter(e){}visitSet(e){}visitGroup(e){}visitGroupBackReference(e){}visitQuantifier(e){}}let et={};const Qi=new Zi;function Ve(t){const e=t.toString();if(et.hasOwnProperty(e))return et[e];{const s=Qi.pattern(e);return et[e]=s,s}}function ea(){et={}}const Qs="Complement Sets are not supported for first char optimization",pt=`Unable to use "first char" lexer optimizations:
10
- `;function ta(t,e=!1){try{const s=Ve(t);return Ft(s.value,{},s.flags.ignoreCase)}catch(s){if(s.message===Qs)e&&Ys(`${pt} Unable to optimize: < ${t.toString()} >
11
- Complement Sets cannot be automatically optimized.
12
- This will disable the lexer's first char optimizations.
13
- See: https://chevrotain.io/docs/guide/resolving_lexer_errors.html#COMPLEMENT for details.`);else{let n="";e&&(n=`
14
- This will disable the lexer's first char optimizations.
15
- See: https://chevrotain.io/docs/guide/resolving_lexer_errors.html#REGEXP_PARSING for details.`),Dt(`${pt}
16
- Failed parsing: < ${t.toString()} >
17
- Using the @chevrotain/regexp-to-ast library
18
- Please open an issue at: https://github.com/chevrotain/chevrotain/issues`+n)}}return[]}function Ft(t,e,s){switch(t.type){case"Disjunction":for(let i=0;i<t.value.length;i++)Ft(t.value[i],e,s);break;case"Alternative":const n=t.value;for(let i=0;i<n.length;i++){const a=n[i];switch(a.type){case"EndAnchor":case"GroupBackReference":case"Lookahead":case"NegativeLookahead":case"Lookbehind":case"NegativeLookbehind":case"StartAnchor":case"WordBoundary":case"NonWordBoundary":continue}const o=a;switch(o.type){case"Character":qe(o.value,e,s);break;case"Set":if(o.complement===!0)throw Error(Qs);o.value.forEach(r=>{if(typeof r=="number")qe(r,e,s);else{const h=r;if(s===!0)for(let d=h.from;d<=h.to;d++)qe(d,e,s);else{for(let d=h.from;d<=h.to&&d<De;d++)qe(d,e,s);if(h.to>=De){const d=h.from>=De?h.from:De,u=h.to,f=ue(d),E=ue(u);for(let y=f;y<=E;y++)e[y]=y}}}});break;case"Group":Ft(o.value,e,s);break;default:throw Error("Non Exhaustive Match")}const l=o.quantifier!==void 0&&o.quantifier.atLeast===0;if(o.type==="Group"&&Bt(o)===!1||o.type!=="Group"&&l===!1)break}break;default:throw Error("non exhaustive match!")}return Object.values(e)}function qe(t,e,s){const n=ue(t);e[n]=n,s===!0&&sa(t,e)}function sa(t,e){const s=String.fromCharCode(t),n=s.toUpperCase();if(n!==s){const i=ue(n.charCodeAt(0));e[i]=i}else{const i=s.toLowerCase();if(i!==s){const a=ue(i.charCodeAt(0));e[a]=a}}}function gs(t,e){return t.value.find(s=>{if(typeof s=="number")return e.includes(s);{const n=s;return e.find(i=>n.from<=i&&i<=n.to)!==void 0}})}function Bt(t){const e=t.quantifier;return e&&e.atLeast===0?!0:t.value?Array.isArray(t.value)?t.value.every(Bt):Bt(t.value):!1}class na extends ts{constructor(e){super(),this.targetCharCodes=e,this.found=!1}visitChildren(e){if(this.found!==!0){switch(e.type){case"Lookahead":this.visitLookahead(e);return;case"NegativeLookahead":this.visitNegativeLookahead(e);return;case"Lookbehind":this.visitLookbehind(e);return;case"NegativeLookbehind":this.visitNegativeLookbehind(e);return}super.visitChildren(e)}}visitCharacter(e){this.targetCharCodes.includes(e.value)&&(this.found=!0)}visitSet(e){e.complement?gs(e,this.targetCharCodes)===void 0&&(this.found=!0):gs(e,this.targetCharCodes)!==void 0&&(this.found=!0)}}function ss(t,e){if(e instanceof RegExp){const s=Ve(e),n=new na(t);return n.visit(s),n.found}else{for(const s of e){const n=s.charCodeAt(0);if(t.includes(n))return!0}return!1}}const Te="PATTERN",Pe="defaultMode",Je="modes",$t=0,tt=1,jt=2,Gt=3;function ia(t,e){e=Object.assign({safeMode:!1,positionTracking:"full",lineTerminatorCharacters:["\r",`
19
- `],tracer:(T,p)=>p()},e);const s=e.tracer;s("initCharCodeToOptimizedIndexMap",()=>{Ca()});let n;s("Reject Lexer.NA",()=>{n=t.filter(T=>T[Te]!==F.NA)});let i=!1,a;s("Transform Patterns",()=>{i=!1,a=n.map(T=>{const p=T[Te];if(p instanceof RegExp){const m=p.source;return m.length===1&&m!=="^"&&m!=="$"&&m!=="."&&!p.ignoreCase?m:m.length===2&&m[0]==="\\"&&!["d","D","s","S","t","r","n","t","0","c","b","B","f","v","w","W"].includes(m[1])?m[1]:As(p)}else{if(typeof p=="function")return i=!0,{exec:p};if(typeof p=="object")return i=!0,p;if(typeof p=="string"){if(p.length===1)return p;{const m=p.replace(/[\\^$.*+?()[\]{}|]/g,"\\$&"),v=new RegExp(m);return As(v)}}else throw Error("non exhaustive match")}})});let o,l,r,h,d;s("misc mapping",()=>{o=n.map(T=>T.tokenTypeIdx),l=n.map(T=>{const p=T.GROUP;if(p!==F.SKIPPED){if(typeof p=="string")return p;if(p===void 0)return!1;throw Error("non exhaustive match")}}),r=n.map(T=>{const p=T.LONGER_ALT;if(p)return Array.isArray(p)?p.map(v=>n.indexOf(v)):[n.indexOf(p)]}),h=n.map(T=>T.PUSH_MODE),d=n.map(T=>Object.hasOwn(T,"POP_MODE"))});let u;s("Line Terminator Handling",()=>{const T=sn(e.lineTerminatorCharacters);u=n.map(p=>!1),e.positionTracking!=="onlyOffset"&&(u=n.map(p=>Object.hasOwn(p,"LINE_BREAKS")?!!p.LINE_BREAKS:tn(p,T)===!1&&ss(T,p.PATTERN)))});let f,E,y,R;s("Misc Mapping #2",()=>{f=n.map(en),E=a.map(Ia),y=n.reduce((T,p)=>{const m=p.GROUP;return typeof m=="string"&&m!==F.SKIPPED&&(T[m]=[]),T},{}),R=a.map((T,p)=>{const m=l[p]===void 0&&r[p]===void 0?aa(n[p].PATTERN):void 0;return{pattern:a[p],asciiClass:m,longerAlt:r[p],canLineTerminator:u[p],matchType:m!==void 0?Gt:E[p]!==!1?$t:f[p]?tt:jt,short:E[p],group:l[p],push:h[p],pop:d[p],tokenTypeIdx:o[p],tokenType:n[p]}})});let L=!0,g=[];return e.safeMode||s("First Char Optimization",()=>{g=n.reduce((T,p,m)=>{if(typeof p.PATTERN=="string"){const v=p.PATTERN.charCodeAt(0),Y=ue(v);_t(T,Y,R[m])}else if(Array.isArray(p.START_CHARS_HINT)){let v;p.START_CHARS_HINT.forEach(Y=>{const he=typeof Y=="string"?Y.charCodeAt(0):Y,de=ue(he);v!==de&&(v=de,_t(T,de,R[m]))})}else if(p.PATTERN instanceof RegExp)if(p.PATTERN.unicode)L=!1,e.ensureOptimizations&&Dt(`${pt} Unable to analyze < ${p.PATTERN.toString()} > pattern.
20
- The regexp unicode flag is not currently supported by the regexp-to-ast library.
21
- This will disable the lexer's first char optimizations.
22
- For details See: https://chevrotain.io/docs/guide/resolving_lexer_errors.html#UNICODE_OPTIMIZE`);else{const v=ta(p.PATTERN,e.ensureOptimizations);v.length===0&&(L=!1),v.forEach(Y=>{_t(T,Y,R[m])})}else e.ensureOptimizations&&Dt(`${pt} TokenType: <${p.name}> is using a custom token pattern without providing <start_chars_hint> parameter.
23
- This will disable the lexer's first char optimizations.
24
- For details See: https://chevrotain.io/docs/guide/resolving_lexer_errors.html#CUSTOM_OPTIMIZE`),L=!1;return T},[])}),{emptyGroups:y,patternIdxToConfig:R,charCodeToPatternIdxToConfig:g,hasCustom:i,canBeOptimized:L}}function aa(t){var e,s;if(!(t instanceof RegExp)||t.flags!=="")return;let n;try{n=Ve(t)}catch{return}if(n.value.value.length!==1||n.value.value[0].value.length!==1)return;let i=n.value.value[0].value[0],a;for(;i.type==="Group";){if(i.capturing||i.quantifier!==void 0&&a!==void 0||i.value.value.length!==1||i.value.value[0].value.length!==1)return;a=(e=i.quantifier)!==null&&e!==void 0?e:a,i=i.value.value[0].value[0]}if(i.type!=="Set"||i.complement||i.quantifier!==void 0&&a!==void 0||(a=(s=i.quantifier)!==null&&s!==void 0?s:a,a?.atLeast!==1||a.atMost!==1/0||!a.greedy))return;const o=new Uint8Array(128);for(const l of i.value){const r=typeof l=="number"?l:l.from,h=typeof l=="number"?l:l.to;if(r<0||h>=o.length)return;o.fill(1,r,h+1)}return o}function ra(t,e){let s=[];const n=la(t);s=s.concat(n.errors);const i=ca(n.valid),a=i.valid;return s=s.concat(i.errors),s=s.concat(oa(a)),s=s.concat(Ta(a)),s=s.concat(ga(a,e)),s=s.concat(Aa(a)),s}function oa(t){let e=[];const s=t.filter(n=>n[Te]instanceof RegExp);return e=e.concat(ua(s)),e=e.concat(pa(s)),e=e.concat(ma(s)),e=e.concat(Ea(s)),e=e.concat(da(s)),e}function la(t){const e=t.filter(i=>!Object.hasOwn(i,Te)),s=e.map(i=>({message:"Token Type: ->"+i.name+"<- missing static 'PATTERN' property",type:b.MISSING_PATTERN,tokenTypes:[i]})),n=t.filter(i=>!e.includes(i));return{errors:s,valid:n}}function ca(t){const e=t.filter(i=>{const a=i[Te];return!(a instanceof RegExp)&&typeof a!="function"&&!Object.hasOwn(a,"exec")&&typeof a!="string"}),s=e.map(i=>({message:"Token Type: ->"+i.name+"<- static 'PATTERN' can only be a RegExp, a Function matching the {CustomPatternMatcherFunc} type or an Object matching the {ICustomPattern} interface.",type:b.INVALID_PATTERN,tokenTypes:[i]})),n=t.filter(i=>!e.includes(i));return{errors:s,valid:n}}const ha=/[^\\][$]/;function ua(t){class e extends ts{constructor(){super(...arguments),this.found=!1}visitEndAnchor(a){this.found=!0}}return t.filter(i=>{const a=i.PATTERN;try{const o=Ve(a),l=new e;return l.visit(o),l.found}catch{return ha.test(a.source)}}).map(i=>({message:`Unexpected RegExp Anchor Error:
25
- Token Type: ->`+i.name+`<- static 'PATTERN' cannot contain end of input anchor '$'
26
- See chevrotain.io/docs/guide/resolving_lexer_errors.html#ANCHORS for details.`,type:b.EOI_ANCHOR_FOUND,tokenTypes:[i]}))}function da(t){return t.filter(n=>n.PATTERN.test("")).map(n=>({message:"Token Type: ->"+n.name+"<- static 'PATTERN' must not match an empty string",type:b.EMPTY_MATCH_PATTERN,tokenTypes:[n]}))}const fa=/[^\\[][\^]|^\^/;function pa(t){class e extends ts{constructor(){super(...arguments),this.found=!1}visitStartAnchor(a){this.found=!0}}return t.filter(i=>{const a=i.PATTERN;try{const o=Ve(a),l=new e;return l.visit(o),l.found}catch{return fa.test(a.source)}}).map(i=>({message:`Unexpected RegExp Anchor Error:
27
- Token Type: ->`+i.name+`<- static 'PATTERN' cannot contain start of input anchor '^'
28
- See https://chevrotain.io/docs/guide/resolving_lexer_errors.html#ANCHORS for details.`,type:b.SOI_ANCHOR_FOUND,tokenTypes:[i]}))}function ma(t){return t.filter(n=>{const i=n[Te];return i instanceof RegExp&&(i.multiline||i.global)}).map(n=>({message:"Token Type: ->"+n.name+"<- static 'PATTERN' may NOT contain global('g') or multiline('m')",type:b.UNSUPPORTED_FLAGS_FOUND,tokenTypes:[n]}))}function Ea(t){const e=[];let s=t.map(a=>t.reduce((o,l)=>(a.PATTERN.source===l.PATTERN.source&&!e.includes(l)&&l.PATTERN!==F.NA&&(e.push(l),o.push(l)),o),[]));return s=s.filter(Boolean),s.filter(a=>a.length>1).map(a=>{const o=a.map(r=>r.name);return{message:`The same RegExp pattern ->${a[0].PATTERN}<-has been used in all of the following Token Types: ${o.join(", ")} <-`,type:b.DUPLICATE_PATTERNS_FOUND,tokenTypes:a}})}function Ta(t){return t.filter(n=>{if(!Object.hasOwn(n,"GROUP"))return!1;const i=n.GROUP;return i!==F.SKIPPED&&i!==F.NA&&typeof i!="string"}).map(n=>({message:"Token Type: ->"+n.name+"<- static 'GROUP' can only be Lexer.SKIPPED/Lexer.NA/A String",type:b.INVALID_GROUP_TYPE_FOUND,tokenTypes:[n]}))}function ga(t,e){return t.filter(i=>i.PUSH_MODE!==void 0&&!e.includes(i.PUSH_MODE)).map(i=>({message:`Token Type: ->${i.name}<- static 'PUSH_MODE' value cannot refer to a Lexer Mode ->${i.PUSH_MODE}<-which does not exist`,type:b.PUSH_MODE_DOES_NOT_EXIST,tokenTypes:[i]}))}function Aa(t){const e=[],s=t.reduce((n,i,a)=>{const o=i.PATTERN;return o===F.NA||(typeof o=="string"?n.push({str:o,idx:a,tokenType:i}):o instanceof RegExp&&ya(o)&&n.push({str:o.source,idx:a,tokenType:i})),n},[]);return t.forEach((n,i)=>{s.forEach(({str:a,idx:o,tokenType:l})=>{if(i<o&&Sa(a,n.PATTERN)){const r=`Token: ->${l.name}<- can never be matched.
29
- Because it appears AFTER the Token Type ->${n.name}<-in the lexer's definition.
30
- See https://chevrotain.io/docs/guide/resolving_lexer_errors.html#UNREACHABLE`;e.push({message:r,type:b.UNREACHABLE_PATTERN,tokenTypes:[n,l]})}})}),e}function Sa(t,e){if(e instanceof RegExp){if(Ra(e))return!1;const s=e.exec(t);return s!==null&&s.index===0}else{if(typeof e=="function")return e(t,0,[],{});if(Object.hasOwn(e,"exec"))return e.exec(t,0,[],{});if(typeof e=="string")return e===t;throw Error("non exhaustive match")}}function ya(t){return[".","\\","[","]","|","^","$","(",")","?","*","+","{"].find(s=>t.source.indexOf(s)!==-1)===void 0}function Ra(t){return/(\(\?=)|(\(\?!)|(\(\?<=)|(\(\?<!)/.test(t.source)}function As(t){const e=t.ignoreCase?"iy":"y";return new RegExp(`${t.source}`,e)}function Oa(t,e,s){const n=[];return Object.hasOwn(t,Pe)||n.push({message:"A MultiMode Lexer cannot be initialized without a <"+Pe+`> property in its definition
31
- `,type:b.MULTI_MODE_LEXER_WITHOUT_DEFAULT_MODE}),Object.hasOwn(t,Je)||n.push({message:"A MultiMode Lexer cannot be initialized without a <"+Je+`> property in its definition
32
- `,type:b.MULTI_MODE_LEXER_WITHOUT_MODES_PROPERTY}),Object.hasOwn(t,Je)&&Object.hasOwn(t,Pe)&&!Object.hasOwn(t.modes,t.defaultMode)&&n.push({message:`A MultiMode Lexer cannot be initialized with a ${Pe}: <${t.defaultMode}>which does not exist
33
- `,type:b.MULTI_MODE_LEXER_DEFAULT_MODE_VALUE_DOES_NOT_EXIST}),Object.hasOwn(t,Je)&&Object.keys(t.modes).forEach(i=>{const a=t.modes[i];a.forEach((o,l)=>{o===void 0?n.push({message:`A Lexer cannot be initialized using an undefined Token Type. Mode:<${i}> at index: <${l}>
34
- `,type:b.LEXER_DEFINITION_CANNOT_CONTAIN_UNDEFINED}):Object.hasOwn(o,"LONGER_ALT")&&(Array.isArray(o.LONGER_ALT)?o.LONGER_ALT:[o.LONGER_ALT]).forEach(h=>{h!==void 0&&!a.includes(h)&&n.push({message:`A MultiMode Lexer cannot be initialized with a longer_alt <${h.name}> on token <${o.name}> outside of mode <${i}>
35
- `,type:b.MULTI_MODE_LEXER_LONGER_ALT_NOT_IN_CURRENT_MODE})})})}),n}function La(t,e,s){const n=[];let i=!1;const o=Object.values(t.modes||{}).flat().filter(Boolean).filter(r=>r[Te]!==F.NA),l=sn(s);return e&&o.forEach(r=>{const h=tn(r,l);if(h!==!1){const u={message:Na(r,h),type:h.issue,tokenType:r};n.push(u)}else Object.hasOwn(r,"LINE_BREAKS")?r.LINE_BREAKS===!0&&(i=!0):ss(l,r.PATTERN)&&(i=!0)}),e&&!i&&n.push({message:`Warning: No LINE_BREAKS Found.
36
- This Lexer has been defined to track line and column information,
37
- But none of the Token Types can be identified as matching a line terminator.
38
- See https://chevrotain.io/docs/guide/resolving_lexer_errors.html#LINE_BREAKS
39
- for details.`,type:b.NO_LINE_BREAKS_FLAGS}),n}function en(t){const e=t.PATTERN;if(e instanceof RegExp)return!1;if(typeof e=="function")return!0;if(Object.hasOwn(e,"exec"))return!0;if(typeof e=="string")return!1;throw Error("non exhaustive match")}function Ia(t){return typeof t=="string"&&t.length===1?t.charCodeAt(0):!1}const ka={test:function(t){const e=t.length;for(let s=this.lastIndex;s<e;s++){const n=t.charCodeAt(s);if(n===10)return this.lastIndex=s+1,!0;if(n===13)return t.charCodeAt(s+1)===10?this.lastIndex=s+2:this.lastIndex=s+1,!0}return!1},lastIndex:0};function tn(t,e){if(Object.hasOwn(t,"LINE_BREAKS"))return!1;if(t.PATTERN instanceof RegExp){try{ss(e,t.PATTERN)}catch(s){return{issue:b.IDENTIFY_TERMINATOR,errMsg:s.message}}return!1}else{if(typeof t.PATTERN=="string")return!1;if(en(t))return{issue:b.CUSTOM_LINE_BREAK};throw Error("non exhaustive match")}}function Na(t,e){if(e.issue===b.IDENTIFY_TERMINATOR)return`Warning: unable to identify line terminator usage in pattern.
40
- The problem is in the <${t.name}> Token Type
41
- Root cause: ${e.errMsg}.
42
- For details See: https://chevrotain.io/docs/guide/resolving_lexer_errors.html#IDENTIFY_TERMINATOR`;if(e.issue===b.CUSTOM_LINE_BREAK)return`Warning: A Custom Token Pattern should specify the <line_breaks> option.
43
- The problem is in the <${t.name}> Token Type
44
- For details See: https://chevrotain.io/docs/guide/resolving_lexer_errors.html#CUSTOM_LINE_BREAK`;throw Error("non exhaustive match")}function sn(t){return t.map(s=>typeof s=="string"?s.charCodeAt(0):s)}function _t(t,e,s){t[e]===void 0?t[e]=[s]:t[e].push(s)}const De=256;let st=[];function ue(t){return t<De?t:st[t]}function Ca(){if(st.length===0){st=new Array(65536);for(let t=0;t<65536;t++)st[t]=t>255?255+~~(t/255):t}}function ze(t,e){const s=t.tokenTypeIdx;return s===e.tokenTypeIdx?!0:e.isParent===!0&&e.categoryMatchesMap[s]===!0}function mt(t,e){return t.tokenTypeIdx===e.tokenTypeIdx}let Ss=1;const nn={};function He(t){const e=ba(t);va(e),xa(e),_a(e),e.forEach(s=>{s.isParent=s.categoryMatches.length>0})}function ba(t){let e=[...t],s=t,n=!0;for(;n;){s=s.map(a=>a.CATEGORIES).flat().filter(Boolean);const i=s.filter(a=>!e.includes(a));e=e.concat(i),i.length===0?n=!1:s=i}return e}function va(t){t.forEach(e=>{rn(e)||(nn[Ss]=e,e.tokenTypeIdx=Ss++),ys(e)&&!Array.isArray(e.CATEGORIES)&&(e.CATEGORIES=[e.CATEGORIES]),ys(e)||(e.CATEGORIES=[]),Ma(e)||(e.categoryMatches=[]),wa(e)||(e.categoryMatchesMap={})})}function _a(t){t.forEach(e=>{e.categoryMatches=[],Object.keys(e.categoryMatchesMap).forEach(s=>{e.categoryMatches.push(nn[s].tokenTypeIdx)})})}function xa(t){t.forEach(e=>{an([],e)})}function an(t,e){t.forEach(s=>{e.categoryMatchesMap[s.tokenTypeIdx]=!0}),e.CATEGORIES.forEach(s=>{const n=t.concat(e);n.includes(s)||an(n,s)})}function rn(t){return Object.hasOwn(t??{},"tokenTypeIdx")}function ys(t){return Object.hasOwn(t??{},"CATEGORIES")}function Ma(t){return Object.hasOwn(t??{},"categoryMatches")}function wa(t){return Object.hasOwn(t??{},"categoryMatchesMap")}function Ua(t){return Object.hasOwn(t??{},"tokenTypeIdx")}const Pa={buildUnableToPopLexerModeMessage(t){return`Unable to pop Lexer Mode after encountering Token ->${t.image}<- The Mode Stack is empty`},buildUnexpectedCharactersMessage(t,e,s,n,i,a){return`unexpected character: ->${t.charAt(e)}<- at offset: ${e}, skipped ${s} characters.`}};var b;(function(t){t[t.MISSING_PATTERN=0]="MISSING_PATTERN",t[t.INVALID_PATTERN=1]="INVALID_PATTERN",t[t.EOI_ANCHOR_FOUND=2]="EOI_ANCHOR_FOUND",t[t.UNSUPPORTED_FLAGS_FOUND=3]="UNSUPPORTED_FLAGS_FOUND",t[t.DUPLICATE_PATTERNS_FOUND=4]="DUPLICATE_PATTERNS_FOUND",t[t.INVALID_GROUP_TYPE_FOUND=5]="INVALID_GROUP_TYPE_FOUND",t[t.PUSH_MODE_DOES_NOT_EXIST=6]="PUSH_MODE_DOES_NOT_EXIST",t[t.MULTI_MODE_LEXER_WITHOUT_DEFAULT_MODE=7]="MULTI_MODE_LEXER_WITHOUT_DEFAULT_MODE",t[t.MULTI_MODE_LEXER_WITHOUT_MODES_PROPERTY=8]="MULTI_MODE_LEXER_WITHOUT_MODES_PROPERTY",t[t.MULTI_MODE_LEXER_DEFAULT_MODE_VALUE_DOES_NOT_EXIST=9]="MULTI_MODE_LEXER_DEFAULT_MODE_VALUE_DOES_NOT_EXIST",t[t.LEXER_DEFINITION_CANNOT_CONTAIN_UNDEFINED=10]="LEXER_DEFINITION_CANNOT_CONTAIN_UNDEFINED",t[t.SOI_ANCHOR_FOUND=11]="SOI_ANCHOR_FOUND",t[t.EMPTY_MATCH_PATTERN=12]="EMPTY_MATCH_PATTERN",t[t.NO_LINE_BREAKS_FLAGS=13]="NO_LINE_BREAKS_FLAGS",t[t.UNREACHABLE_PATTERN=14]="UNREACHABLE_PATTERN",t[t.IDENTIFY_TERMINATOR=15]="IDENTIFY_TERMINATOR",t[t.CUSTOM_LINE_BREAK=16]="CUSTOM_LINE_BREAK",t[t.MULTI_MODE_LEXER_LONGER_ALT_NOT_IN_CURRENT_MODE=17]="MULTI_MODE_LEXER_LONGER_ALT_NOT_IN_CURRENT_MODE"})(b||(b={}));const Fe={deferDefinitionErrorsHandling:!1,positionTracking:"full",lineTerminatorsPattern:/\n|\r\n?/g,lineTerminatorCharacters:[`
45
- `,"\r"],ensureOptimizations:!1,safeMode:!1,errorMessageProvider:Pa,traceInitPerf:!1,skipValidations:!1,recoveryEnabled:!0};Object.freeze(Fe);class F{constructor(e,s=Fe){if(this.lexerDefinition=e,this.lexerDefinitionErrors=[],this.lexerDefinitionWarning=[],this.patternIdxToConfig={},this.charCodeToPatternIdxToConfig={},this.modes=[],this.emptyGroups={},this.cachedGroupKeys=[],this.trackStartLines=!0,this.trackEndLines=!0,this.hasCustom=!1,this.canModeBeOptimized={},this.TRACE_INIT=(i,a)=>{if(this.traceInitPerf===!0){this.traceInitIndent++;const o=new Array(this.traceInitIndent+1).join(" ");this.traceInitIndent<this.traceInitMaxIdent&&console.log(`${o}--> <${i}>`);const{time:l,value:r}=qs(a),h=l>10?console.warn:console.log;return this.traceInitIndent<this.traceInitMaxIdent&&h(`${o}<-- <${i}> time: ${l}ms`),this.traceInitIndent--,r}else return a()},typeof s=="boolean")throw Error(`The second argument to the Lexer constructor is now an ILexerConfig Object.
46
- a boolean 2nd argument is no longer supported`);this.config=Object.assign({},Fe,s);const n=this.config.traceInitPerf;n===!0?(this.traceInitMaxIdent=1/0,this.traceInitPerf=!0):typeof n=="number"&&(this.traceInitMaxIdent=n,this.traceInitPerf=!0),this.traceInitIndent=-1,this.TRACE_INIT("Lexer Constructor",()=>{let i,a=!0;this.TRACE_INIT("Lexer Config handling",()=>{if(this.config.lineTerminatorsPattern===Fe.lineTerminatorsPattern)this.config.lineTerminatorsPattern=ka;else if(this.config.lineTerminatorCharacters===Fe.lineTerminatorCharacters)throw Error(`Error: Missing <lineTerminatorCharacters> property on the Lexer config.
47
- For details See: https://chevrotain.io/docs/guide/resolving_lexer_errors.html#MISSING_LINE_TERM_CHARS`);if(s.safeMode&&s.ensureOptimizations)throw Error('"safeMode" and "ensureOptimizations" flags are mutually exclusive.');this.trackStartLines=/full|onlyStart/i.test(this.config.positionTracking),this.trackEndLines=/full/i.test(this.config.positionTracking),Array.isArray(e)?i={modes:{defaultMode:[...e]},defaultMode:Pe}:(a=!1,i=Object.assign({},e))}),this.config.skipValidations===!1&&(this.TRACE_INIT("performRuntimeChecks",()=>{this.lexerDefinitionErrors=this.lexerDefinitionErrors.concat(Oa(i,this.trackStartLines,this.config.lineTerminatorCharacters))}),this.TRACE_INIT("performWarningRuntimeChecks",()=>{this.lexerDefinitionWarning=this.lexerDefinitionWarning.concat(La(i,this.trackStartLines,this.config.lineTerminatorCharacters))})),i.modes=i.modes?i.modes:{},Object.entries(i.modes).forEach(([l,r])=>{i.modes[l]=r.filter(h=>h!==void 0)});const o=Object.keys(i.modes);if(Object.entries(i.modes).forEach(([l,r])=>{this.TRACE_INIT(`Mode: <${l}> processing`,()=>{if(this.modes.push(l),this.config.skipValidations===!1&&this.TRACE_INIT("validatePatterns",()=>{this.lexerDefinitionErrors=this.lexerDefinitionErrors.concat(ra(r,o))}),this.lexerDefinitionErrors.length===0){He(r);let h;this.TRACE_INIT("analyzeTokenTypes",()=>{h=ia(r,{lineTerminatorCharacters:this.config.lineTerminatorCharacters,positionTracking:s.positionTracking,ensureOptimizations:s.ensureOptimizations,safeMode:s.safeMode,tracer:this.TRACE_INIT})}),this.patternIdxToConfig[l]=h.patternIdxToConfig,this.charCodeToPatternIdxToConfig[l]=h.charCodeToPatternIdxToConfig,this.emptyGroups=Object.assign({},this.emptyGroups,h.emptyGroups),this.hasCustom=h.hasCustom||this.hasCustom,this.canModeBeOptimized[l]=h.canBeOptimized}})}),this.defaultMode=i.defaultMode,this.cachedGroupKeys=Object.keys(this.emptyGroups),this.lexerDefinitionErrors.length>0&&!this.config.deferDefinitionErrorsHandling){const r=this.lexerDefinitionErrors.map(h=>h.message).join(`-----------------------
48
- `);throw new Error(`Errors detected in definition of Lexer:
49
- `+r)}this.lexerDefinitionWarning.forEach(l=>{Ys(l.message)}),this.TRACE_INIT("Choosing sub-methods implementations",()=>{if(a&&(this.handleModes=()=>{}),this.trackStartLines===!1&&(this.computeNewColumn=l=>l),this.trackEndLines===!1&&(this.updateTokenEndLineColumnLocation=()=>{}),/full/i.test(this.config.positionTracking))this.createTokenInstance=this.createFullToken;else if(/onlyStart/i.test(this.config.positionTracking))this.createTokenInstance=this.createStartOnlyToken;else if(/onlyOffset/i.test(this.config.positionTracking))this.createTokenInstance=this.createOffsetOnlyToken;else throw Error(`Invalid <positionTracking> config option: "${this.config.positionTracking}"`);this.hasCustom?(this.addToken=this.addTokenUsingPush,this.handlePayload=this.handlePayloadWithCustom):(this.addToken=this.addTokenUsingMemberAccess,this.handlePayload=this.handlePayloadNoCustom)}),this.TRACE_INIT("Failed Optimization Warnings",()=>{const l=Object.entries(this.canModeBeOptimized).reduce((r,[h,d])=>(d===!1&&r.push(h),r),[]);if(s.ensureOptimizations&&l.length>0)throw Error(`Lexer Modes: < ${l.join(", ")} > cannot be optimized.
50
- Disable the "ensureOptimizations" lexer config flag to silently ignore this and run the lexer in an un-optimized mode.
51
- Or inspect the console log for details on how to resolve these issues.`)}),this.TRACE_INIT("clearRegExpParserCache",()=>{ea()}),this.TRACE_INIT("toFastProperties",()=>{Js(this)})})}tokenize(e,s=this.defaultMode){if(this.lexerDefinitionErrors.length>0){const i=this.lexerDefinitionErrors.map(a=>a.message).join(`-----------------------
52
- `);throw new Error(`Unable to Tokenize because Errors detected in definition of Lexer:
53
- `+i)}return this.tokenizeInternal(e,s)}tokenizeInternal(e,s){let n,i,a,o,l,r,h,d,u,f,E,y,R,L,g;const T=e,p=T.length;let m=0,v=0;const Y=this.hasCustom?0:Math.floor(e.length/10),he=new Array(Y),de=[];let Ce=this.trackStartLines?1:void 0,Q=this.trackStartLines?1:void 0;const Ae={};for(let x=0;x<this.cachedGroupKeys.length;x++)Ae[this.cachedGroupKeys[x]]=[];const Ai=this.trackStartLines,It=this.config.lineTerminatorsPattern;let kt=0,fe=[],be=[];const ve=[],ds=[];Object.freeze(ds);let _e=!1;const Si=x=>{if(ve.length===1&&x.tokenType.PUSH_MODE===void 0){const z=this.config.errorMessageProvider.buildUnableToPopLexerModeMessage(x);de.push({offset:x.startOffset,line:x.startLine,column:x.startColumn,length:x.image.length,message:z})}else{ve.pop();const z=ve.at(-1);fe=this.patternIdxToConfig[z],be=this.charCodeToPatternIdxToConfig[z],kt=fe.length;const Nt=this.canModeBeOptimized[z]&&this.config.safeMode===!1;be&&Nt?_e=!0:_e=!1}};function fs(x){ve.push(x),be=this.charCodeToPatternIdxToConfig[x],fe=this.patternIdxToConfig[x],kt=fe.length;const z=this.canModeBeOptimized[x]&&this.config.safeMode===!1;be&&z?_e=!0:_e=!1}fs.call(this,s);let V;const ps=this.config.recoveryEnabled;for(;m<p;){r=null,u=-1;const x=T.charCodeAt(m);let z;if(_e){const U=ue(x),j=be[U];z=j!==void 0?j:ds}else z=fe;const Nt=z.length;for(n=0;n<Nt;n++){V=z[n];const U=V.pattern;switch(h=null,V.matchType){case $t:x===V.short&&(u=1,r=U);break;case tt:g=U.exec(T,m,he,Ae),g!==null?(r=g[0],u=r.length,g.payload!==void 0&&(h=g.payload)):r=null;break;case Gt:{const j=V.asciiClass;if(j[x]!==1){U.lastIndex=0;break}let B=m+1;for(;j[T.charCodeAt(B)]===1;)B++;u=B-m,U.lastIndex=B;break}case jt:U.lastIndex=m,u=this.matchLength(U,e,m);break}if(u!==-1){if(l=V.longerAlt,l!==void 0){r=e.substring(m,m+u);const j=l.length;for(a=0;a<j;a++){const B=fe[l[a]],ae=B.pattern;if(d=null,B.matchType===tt?(g=ae.exec(T,m,he,Ae),g!==null?(o=g[0],g.payload!==void 0&&(d=g.payload)):o=null):(ae.lastIndex=m,o=this.match(ae,e,m)),o&&o.length>r.length){r=o,u=o.length,h=d,V=B;break}}}break}}if(u!==-1){if(f=V.group,f!==void 0&&(r=r!==null?r:e.substring(m,m+u),E=V.tokenTypeIdx,y=this.createTokenInstance(r,m,E,V.tokenType,Ce,Q,u),this.handlePayload(y,h),f===!1?v=this.addToken(he,v,y):Ae[f].push(y)),Ai===!0&&V.canLineTerminator===!0){let U=0,j,B;It.lastIndex=0;do r=r!==null?r:e.substring(m,m+u),j=It.test(r),j===!0&&(B=It.lastIndex-1,U++);while(j===!0);U!==0?(Ce=Ce+U,Q=u-B,this.updateTokenEndLineColumnLocation(y,f,B,U,Ce,Q,u)):Q=this.computeNewColumn(Q,u)}else Q=this.computeNewColumn(Q,u);m=m+u,this.handleModes(V,Si,fs,y)}else{const U=m,j=Ce,B=Q;let ae=ps===!1;for(;ae===!1&&m<p;)for(m++,i=0;i<kt;i++){const Ct=fe[i],bt=Ct.pattern;switch(Ct.matchType){case $t:T.charCodeAt(m)===Ct.short&&(ae=!0);break;case tt:ae=bt.exec(T,m,he,Ae)!==null;break;case Gt:case jt:bt.lastIndex=m,ae=bt.exec(e)!==null;break}if(ae===!0)break}if(R=m-U,Q=this.computeNewColumn(Q,R),L=this.config.errorMessageProvider.buildUnexpectedCharactersMessage(T,U,R,j,B,ve.at(-1)),de.push({offset:U,line:j,column:B,length:R,message:L}),ps===!1)break}}return this.hasCustom||(he.length=v),{tokens:he,groups:Ae,errors:de}}handleModes(e,s,n,i){if(e.pop===!0){const a=e.push;s(i),a!==void 0&&n.call(this,a)}else e.push!==void 0&&n.call(this,e.push)}updateTokenEndLineColumnLocation(e,s,n,i,a,o,l){let r,h;s!==void 0&&(r=n===l-1,h=r?-1:0,i===1&&r===!0||(e.endLine=a+h,e.endColumn=o-1+-h))}computeNewColumn(e,s){return e+s}createOffsetOnlyToken(e,s,n,i){return{image:e,startOffset:s,tokenTypeIdx:n,tokenType:i}}createStartOnlyToken(e,s,n,i,a,o){return{image:e,startOffset:s,startLine:a,startColumn:o,tokenTypeIdx:n,tokenType:i}}createFullToken(e,s,n,i,a,o,l){return{image:e,startOffset:s,endOffset:s+l-1,startLine:a,endLine:a,startColumn:o,endColumn:o+l-1,tokenTypeIdx:n,tokenType:i}}addTokenUsingPush(e,s,n){return e.push(n),s}addTokenUsingMemberAccess(e,s,n){return e[s]=n,s++,s}handlePayloadNoCustom(e,s){}handlePayloadWithCustom(e,s){s!==null&&(e.payload=s)}match(e,s,n){return e.test(s)===!0?s.substring(n,e.lastIndex):null}matchLength(e,s,n){return e.test(s)===!0?e.lastIndex-n:-1}}F.SKIPPED="This marks a skipped Token pattern, this means each token identified by it will be consumed and then thrown into oblivion, this can be used to for example to completely ignore whitespace.";F.NA=/NOT_APPLICABLE/;function We(t){return on(t)?t.LABEL:t.name}function on(t){return typeof t.LABEL=="string"&&t.LABEL!==""}const Da="parent",Rs="categories",Os="label",Ls="group",Is="push_mode",ks="pop_mode",Ns="longer_alt",Cs="line_breaks",bs="start_chars_hint";function A(t){return Fa(t)}function Fa(t){const e=t.pattern,s={};if(s.name=t.name,e!==void 0&&(s.PATTERN=e),Object.hasOwn(t,Da))throw`The parent property is no longer supported.
54
- See: https://github.com/chevrotain/chevrotain/issues/564#issuecomment-349062346 for details.`;return Object.hasOwn(t,Rs)&&(s.CATEGORIES=t[Rs]),He([s]),Object.hasOwn(t,Os)&&(s.LABEL=t[Os]),Object.hasOwn(t,Ls)&&(s.GROUP=t[Ls]),Object.hasOwn(t,ks)&&(s.POP_MODE=t[ks]),Object.hasOwn(t,Is)&&(s.PUSH_MODE=t[Is]),Object.hasOwn(t,Ns)&&(s.LONGER_ALT=t[Ns]),Object.hasOwn(t,Cs)&&(s.LINE_BREAKS=t[Cs]),Object.hasOwn(t,bs)&&(s.START_CHARS_HINT=t[bs]),s}const le=A({name:"EOF",pattern:F.NA});He([le]);function ns(t,e,s,n,i,a,o,l){return{image:e,startOffset:s,endOffset:n,startLine:i,endLine:a,startColumn:o,endColumn:l,tokenTypeIdx:t.tokenTypeIdx,tokenType:t}}function ln(t,e){return ze(t,e)}const cn={buildMismatchTokenMessage({expected:t,actual:e,previous:s,ruleName:n}){return`Expecting ${on(t)?`--> ${We(t)} <--`:`token of type --> ${t.name} <--`} but found --> '${e.image}' <--`},buildNotAllInputParsedMessage({firstRedundant:t,ruleName:e}){return"Redundant input, expecting EOF but found: "+t.image},buildNoViableAltMessage({expectedPathsPerAlt:t,actual:e,previous:s,customUserDescription:n,ruleName:i}){const a="Expecting: ",l=`
55
- but found: '`+e[0].image+"'";if(n)return a+n+l;{const u=`one of these possible Token sequences:
56
- ${t.reduce((f,E)=>f.concat(E),[]).map(f=>`[${f.map(E=>We(E)).join(", ")}]`).map((f,E)=>` ${E+1}. ${f}`).join(`
57
- `)}`;return a+u+l}},buildEarlyExitMessage({expectedIterationPaths:t,actual:e,customUserDescription:s,ruleName:n}){const i="Expecting: ",o=`
58
- but found: '`+e[0].image+"'";if(s)return i+s+o;{const r=`expecting at least one iteration which starts with one of these possible Token sequences::
59
- <${t.map(h=>`[${h.map(d=>We(d)).join(",")}]`).join(" ,")}>`;return i+r+o}}};Object.freeze(cn);const Ba={buildRuleNotFoundError(t,e){return"Invalid grammar, reference to a rule which is not defined: ->"+e.nonTerminalName+`<-
60
- inside top level rule: ->`+t.name+"<-"}},Ee={buildDuplicateFoundError(t,e){function s(d){return d instanceof k?d.terminalType.name:d instanceof K?d.nonTerminalName:""}const n=t.name,i=e[0],a=i.idx,o=ee(i),l=s(i),r=a>0;let h=`->${o}${r?a:""}<- ${l?`with argument: ->${l}<-`:""}
61
- appears more than once (${e.length} times) in the top level rule: ->${n}<-.
62
- For further details see: https://chevrotain.io/docs/FAQ.html#NUMERICAL_SUFFIXES
63
- `;return h=h.replace(/[ \t]+/g," "),h=h.replace(/\s\s+/g,`
64
- `),h},buildNamespaceConflictError(t){return`Namespace conflict found in grammar.
65
- The grammar has both a Terminal(Token) and a Non-Terminal(Rule) named: <${t.name}>.
66
- To resolve this make sure each Terminal and Non-Terminal names are unique
67
- This is easy to accomplish by using the convention that Terminal names start with an uppercase letter
68
- and Non-Terminal names start with a lower case letter.`},buildAlternationPrefixAmbiguityError(t){const e=t.prefixPath.map(i=>We(i)).join(", "),s=t.alternation.idx===0?"":t.alternation.idx;return`Ambiguous alternatives: <${t.ambiguityIndices.join(" ,")}> due to common lookahead prefix
69
- in <OR${s}> inside <${t.topLevelRule.name}> Rule,
70
- <${e}> may appears as a prefix path in all these alternatives.
71
- See: https://chevrotain.io/docs/guide/resolving_grammar_errors.html#COMMON_PREFIX
72
- For Further details.`},buildAlternationAmbiguityError(t){const e=t.alternation.idx===0?"":t.alternation.idx,s=t.prefixPath.length===0;let n=`Ambiguous Alternatives Detected: <${t.ambiguityIndices.join(" ,")}> in <OR${e}> inside <${t.topLevelRule.name}> Rule,
73
- `;if(s)n+=`These alternatives are all empty (match no tokens), making them indistinguishable.
74
- Only the last alternative may be empty.
75
- `;else{const i=t.prefixPath.map(a=>We(a)).join(", ");n+=`<${i}> may appears as a prefix path in all these alternatives.
76
- `}return n+=`See: https://chevrotain.io/docs/guide/resolving_grammar_errors.html#AMBIGUOUS_ALTERNATIVES
77
- For Further details.`,n},buildEmptyRepetitionError(t){let e=ee(t.repetition);return t.repetition.idx!==0&&(e+=t.repetition.idx),`The repetition <${e}> within Rule <${t.topLevelRule.name}> can never consume any tokens.
78
- This could lead to an infinite loop.`},buildTokenNameError(t){return"deprecated"},buildEmptyAlternationError(t){return`Ambiguous empty alternative: <${t.emptyChoiceIdx+1}> in <OR${t.alternation.idx}> inside <${t.topLevelRule.name}> Rule.
79
- Only the last alternative may be an empty alternative.`},buildTooManyAlternativesError(t){return`An Alternation cannot have more than 256 alternatives:
80
- <OR${t.alternation.idx}> inside <${t.topLevelRule.name}> Rule.
81
- has ${t.alternation.definition.length+1} alternatives.`},buildLeftRecursionError(t){const e=t.topLevelRule.name,s=t.leftRecursionPath.map(a=>a.name),n=`${e} --> ${s.concat([e]).join(" --> ")}`;return`Left Recursion found in grammar.
82
- rule: <${e}> can be invoked from itself (directly or indirectly)
83
- without consuming any Tokens. The grammar path that causes this is:
84
- ${n}
85
- To fix this refactor your grammar to remove the left recursion.
86
- see: https://en.wikipedia.org/wiki/LL_parser#Left_factoring.`},buildInvalidRuleNameError(t){return"deprecated"},buildDuplicateRuleNameError(t){let e;return t.topLevelRule instanceof Ie?e=t.topLevelRule.name:e=t.topLevelRule,`Duplicate definition, rule: ->${e}<- is already defined in the grammar: ->${t.grammarName}<-`}};function $a(t,e){const s=new ja(t,e);return s.resolveRefs(),s.errors}class ja extends ke{constructor(e,s){super(),this.nameToTopRule=e,this.errMsgProvider=s,this.errors=[]}resolveRefs(){Object.values(this.nameToTopRule).forEach(e=>{this.currTopLevel=e,e.accept(this)})}visitNonTerminal(e){const s=this.nameToTopRule[e.nonTerminalName];if(s)e.referencedRule=s;else{const n=this.errMsgProvider.buildRuleNotFoundError(this.currTopLevel,e);this.errors.push({message:n,type:$.UNRESOLVED_SUBRULE_REF,ruleName:this.currTopLevel.name,unresolvedRefName:e.nonTerminalName})}}}class Ga extends St{constructor(e,s){super(),this.topProd=e,this.path=s,this.possibleTokTypes=[],this.nextProductionName="",this.nextProductionOccurrence=0,this.found=!1,this.isAtEndOfPath=!1}startWalking(){if(this.found=!1,this.path.ruleStack[0]!==this.topProd.name)throw Error("The path does not start with the walker's top Rule!");return this.ruleStack=[...this.path.ruleStack].reverse(),this.occurrenceStack=[...this.path.occurrenceStack].reverse(),this.ruleStack.pop(),this.occurrenceStack.pop(),this.updateExpectedNext(),this.walk(this.topProd),this.possibleTokTypes}walk(e,s=[]){this.found||super.walk(e,s)}walkProdRef(e,s,n){if(e.referencedRule.name===this.nextProductionName&&e.idx===this.nextProductionOccurrence){const i=s.concat(n);this.updateExpectedNext(),this.walk(e.referencedRule,i)}}updateExpectedNext(){this.ruleStack.length===0?(this.nextProductionName="",this.nextProductionOccurrence=0,this.isAtEndOfPath=!0):(this.nextProductionName=this.ruleStack.pop(),this.nextProductionOccurrence=this.occurrenceStack.pop())}}class Wa extends Ga{constructor(e,s){super(e,s),this.path=s,this.nextTerminalName="",this.nextTerminalOccurrence=0,this.nextTerminalName=this.path.lastTok.name,this.nextTerminalOccurrence=this.path.lastTokOccurrence}walkTerminal(e,s,n){if(this.isAtEndOfPath&&e.terminalType.name===this.nextTerminalName&&e.idx===this.nextTerminalOccurrence&&!this.found){const i=s.concat(n),a=new W({definition:i});this.possibleTokTypes=Ke(a),this.found=!0}}}class yt extends St{constructor(e,s){super(),this.topRule=e,this.occurrence=s,this.result={token:void 0,occurrence:void 0,isEndOfRule:void 0}}startWalking(){return this.walk(this.topRule),this.result}}class Ka extends yt{walkMany(e,s,n){if(e.idx===this.occurrence){const i=s.concat(n)[0];this.result.isEndOfRule=i===void 0,i instanceof k&&(this.result.token=i.terminalType,this.result.occurrence=i.idx)}else super.walkMany(e,s,n)}}class vs extends yt{walkManySep(e,s,n){if(e.idx===this.occurrence){const i=s.concat(n)[0];this.result.isEndOfRule=i===void 0,i instanceof k&&(this.result.token=i.terminalType,this.result.occurrence=i.idx)}else super.walkManySep(e,s,n)}}class Va extends yt{walkAtLeastOne(e,s,n){if(e.idx===this.occurrence){const i=s.concat(n)[0];this.result.isEndOfRule=i===void 0,i instanceof k&&(this.result.token=i.terminalType,this.result.occurrence=i.idx)}else super.walkAtLeastOne(e,s,n)}}class _s extends yt{walkAtLeastOneSep(e,s,n){if(e.idx===this.occurrence){const i=s.concat(n)[0];this.result.isEndOfRule=i===void 0,i instanceof k&&(this.result.token=i.terminalType,this.result.occurrence=i.idx)}else super.walkAtLeastOneSep(e,s,n)}}function Wt(t,e,s=[]){s=[...s];let n=[],i=0;function a(l){return l.concat(t.slice(i+1))}function o(l){const r=Wt(a(l),e,s);return n.concat(r)}for(;s.length<e&&i<t.length;){const l=t[i];if(l instanceof W)return o(l.definition);if(l instanceof K)return o(l.definition);if(l instanceof G)n=o(l.definition);else if(l instanceof se){const r=l.definition.concat([new M({definition:l.definition})]);return o(r)}else if(l instanceof ne){const r=[new W({definition:l.definition}),new M({definition:[new k({terminalType:l.separator})].concat(l.definition)})];return o(r)}else if(l instanceof J){const r=l.definition.concat([new M({definition:[new k({terminalType:l.separator})].concat(l.definition)})]);n=o(r)}else if(l instanceof M){const r=l.definition.concat([new M({definition:l.definition})]);n=o(r)}else{if(l instanceof Z)return l.definition.forEach(r=>{r.definition.length!==0&&(n=o(r.definition))}),n;if(l instanceof k)s.push(l.terminalType);else throw Error("non exhaustive match")}i++}return n.push({partialPath:s,suffixDef:t.slice(i)}),n}function za(t,e,s,n){const i="EXIT_NONE_TERMINAL",a=[i],o="EXIT_ALTERNATIVE";let l=!1;const r=e.length,h=r-n-1,d=[],u=[];for(u.push({idx:-1,def:t,ruleStack:[],occurrenceStack:[]});u.length!==0;){const f=u.pop();if(f===o){l&&u.at(-1).idx<=h&&u.pop();continue}const E=f.def,y=f.idx,R=f.ruleStack,L=f.occurrenceStack;if(E.length===0)continue;const g=E[0];if(g===i){const T={idx:y,def:E.slice(1),ruleStack:R.slice(0,-1),occurrenceStack:L.slice(0,-1)};u.push(T)}else if(g instanceof k)if(y<r-1){const T=y+1,p=e[T];if(s(p,g.terminalType)){const m={idx:T,def:E.slice(1),ruleStack:R,occurrenceStack:L};u.push(m)}}else if(y===r-1)d.push({nextTokenType:g.terminalType,nextTokenOccurrence:g.idx,ruleStack:R,occurrenceStack:L}),l=!0;else throw Error("non exhaustive match");else if(g instanceof K){const T=[...R];T.push(g.nonTerminalName);const p=[...L];p.push(g.idx);const m={idx:y,def:g.definition.concat(a,E.slice(1)),ruleStack:T,occurrenceStack:p};u.push(m)}else if(g instanceof G){const T={idx:y,def:E.slice(1),ruleStack:R,occurrenceStack:L};u.push(T),u.push(o);const p={idx:y,def:g.definition.concat(E.slice(1)),ruleStack:R,occurrenceStack:L};u.push(p)}else if(g instanceof se){const T=new M({definition:g.definition,idx:g.idx}),p=g.definition.concat([T],E.slice(1)),m={idx:y,def:p,ruleStack:R,occurrenceStack:L};u.push(m)}else if(g instanceof ne){const T=new k({terminalType:g.separator}),p=new M({definition:[T].concat(g.definition),idx:g.idx}),m=g.definition.concat([p],E.slice(1)),v={idx:y,def:m,ruleStack:R,occurrenceStack:L};u.push(v)}else if(g instanceof J){const T={idx:y,def:E.slice(1),ruleStack:R,occurrenceStack:L};u.push(T),u.push(o);const p=new k({terminalType:g.separator}),m=new M({definition:[p].concat(g.definition),idx:g.idx}),v=g.definition.concat([m],E.slice(1)),Y={idx:y,def:v,ruleStack:R,occurrenceStack:L};u.push(Y)}else if(g instanceof M){const T={idx:y,def:E.slice(1),ruleStack:R,occurrenceStack:L};u.push(T),u.push(o);const p=new M({definition:g.definition,idx:g.idx}),m=g.definition.concat([p],E.slice(1)),v={idx:y,def:m,ruleStack:R,occurrenceStack:L};u.push(v)}else if(g instanceof Z)for(let T=g.definition.length-1;T>=0;T--){const p=g.definition[T],m={idx:y,def:p.definition.concat(E.slice(1)),ruleStack:R,occurrenceStack:L};u.push(m),u.push(o)}else if(g instanceof W)u.push({idx:y,def:g.definition.concat(E.slice(1)),ruleStack:R,occurrenceStack:L});else if(g instanceof Ie)u.push(Ha(g,y,R,L));else throw Error("non exhaustive match")}return d}function Ha(t,e,s,n){const i=[...s];i.push(t.name);const a=[...n];return a.push(1),{idx:e,def:t.definition,ruleStack:i,occurrenceStack:a}}var C;(function(t){t[t.OPTION=0]="OPTION",t[t.REPETITION=1]="REPETITION",t[t.REPETITION_MANDATORY=2]="REPETITION_MANDATORY",t[t.REPETITION_MANDATORY_WITH_SEPARATOR=3]="REPETITION_MANDATORY_WITH_SEPARATOR",t[t.REPETITION_WITH_SEPARATOR=4]="REPETITION_WITH_SEPARATOR",t[t.ALTERNATION=5]="ALTERNATION"})(C||(C={}));function hn(t){if(t instanceof G||t==="Option")return C.OPTION;if(t instanceof M||t==="Repetition")return C.REPETITION;if(t instanceof se||t==="RepetitionMandatory")return C.REPETITION_MANDATORY;if(t instanceof ne||t==="RepetitionMandatoryWithSeparator")return C.REPETITION_MANDATORY_WITH_SEPARATOR;if(t instanceof J||t==="RepetitionWithSeparator")return C.REPETITION_WITH_SEPARATOR;if(t instanceof Z||t==="Alternation")return C.ALTERNATION;throw Error("non exhaustive match")}function Xa(t,e,s,n,i,a){const o=is(t,e,s),l=fn(o)?mt:ze;return a(o,n,l,i)}function Ya(t,e,s,n,i,a){const o=as(t,e,i,s),l=fn(o)?mt:ze;return a(o[0],l,n)}function qa(t,e,s,n){const i=t.length,a=t.every(o=>o.every(l=>l.length===1));if(e)return function(o){const l=o.map(r=>r.GATE);for(let r=0;r<i;r++){const h=t[r],d=h.length,u=l[r];if(!(u!==void 0&&u.call(this)===!1))e:for(let f=0;f<d;f++){const E=h[f],y=E.length;for(let R=0;R<y;R++){const L=this.LA_FAST(R+1);if(s(L,E[R])===!1)continue e}return r}}};if(a&&!n){const l=t.map(r=>r.flat()).reduce((r,h,d)=>(h.forEach(u=>{u.tokenTypeIdx in r||(r[u.tokenTypeIdx]=d),u.categoryMatches.forEach(f=>{Object.hasOwn(r,f)||(r[f]=d)})}),r),{});return function(){const r=this.LA_FAST(1);return l[r.tokenTypeIdx]}}else return function(){for(let o=0;o<i;o++){const l=t[o],r=l.length;e:for(let h=0;h<r;h++){const d=l[h],u=d.length;for(let f=0;f<u;f++){const E=this.LA_FAST(f+1);if(s(E,d[f])===!1)continue e}return o}}}}function Ja(t,e,s){const n=t.every(a=>a.length===1),i=t.length;if(n&&!s){const a=t.flat();if(a.length===1&&a[0].categoryMatches.length===0){const l=a[0].tokenTypeIdx;return function(){return this.LA_FAST(1).tokenTypeIdx===l}}else{const o=a.reduce((l,r,h)=>(l[r.tokenTypeIdx]=!0,r.categoryMatches.forEach(d=>{l[d]=!0}),l),[]);return function(){const l=this.LA_FAST(1);return o[l.tokenTypeIdx]===!0}}}else return function(){e:for(let a=0;a<i;a++){const o=t[a],l=o.length;for(let r=0;r<l;r++){const h=this.LA_FAST(r+1);if(e(h,o[r])===!1)continue e}return!0}return!1}}class Za extends St{constructor(e,s,n){super(),this.topProd=e,this.targetOccurrence=s,this.targetProdType=n}startWalking(){return this.walk(this.topProd),this.restDef}checkIsTarget(e,s,n,i){return e.idx===this.targetOccurrence&&this.targetProdType===s?(this.restDef=n.concat(i),!0):!1}walkOption(e,s,n){this.checkIsTarget(e,C.OPTION,s,n)||super.walkOption(e,s,n)}walkAtLeastOne(e,s,n){this.checkIsTarget(e,C.REPETITION_MANDATORY,s,n)||super.walkOption(e,s,n)}walkAtLeastOneSep(e,s,n){this.checkIsTarget(e,C.REPETITION_MANDATORY_WITH_SEPARATOR,s,n)||super.walkOption(e,s,n)}walkMany(e,s,n){this.checkIsTarget(e,C.REPETITION,s,n)||super.walkOption(e,s,n)}walkManySep(e,s,n){this.checkIsTarget(e,C.REPETITION_WITH_SEPARATOR,s,n)||super.walkOption(e,s,n)}}class un extends ke{constructor(e,s,n){super(),this.targetOccurrence=e,this.targetProdType=s,this.targetRef=n,this.result=[]}checkIsTarget(e,s){e.idx===this.targetOccurrence&&this.targetProdType===s&&(this.targetRef===void 0||e===this.targetRef)&&(this.result=e.definition)}visitOption(e){this.checkIsTarget(e,C.OPTION)}visitRepetition(e){this.checkIsTarget(e,C.REPETITION)}visitRepetitionMandatory(e){this.checkIsTarget(e,C.REPETITION_MANDATORY)}visitRepetitionMandatoryWithSeparator(e){this.checkIsTarget(e,C.REPETITION_MANDATORY_WITH_SEPARATOR)}visitRepetitionWithSeparator(e){this.checkIsTarget(e,C.REPETITION_WITH_SEPARATOR)}visitAlternation(e){this.checkIsTarget(e,C.ALTERNATION)}}function xs(t){const e=new Array(t);for(let s=0;s<t;s++)e[s]=[];return e}function xt(t){let e=[""];for(let s=0;s<t.length;s++){const n=t[s],i=[];for(let a=0;a<e.length;a++){const o=e[a];i.push(o+"_"+n.tokenTypeIdx);for(let l=0;l<n.categoryMatches.length;l++){const r="_"+n.categoryMatches[l];i.push(o+r)}}e=i}return e}function Qa(t,e,s){for(let n=0;n<t.length;n++){if(n===s)continue;const i=t[n];for(let a=0;a<e.length;a++){const o=e[a];if(i[o]===!0)return!1}}return!0}function dn(t,e){const s=t.map(o=>Wt([o],1)),n=xs(s.length),i=s.map(o=>{const l={};return o.forEach(r=>{xt(r.partialPath).forEach(d=>{l[d]=!0})}),l});let a=s;for(let o=1;o<=e;o++){const l=a;a=xs(l.length);for(let r=0;r<l.length;r++){const h=l[r];for(let d=0;d<h.length;d++){const u=h[d].partialPath,f=h[d].suffixDef,E=xt(u);if(Qa(i,E,r)||f.length===0||u.length===e){const R=n[r];if(Kt(R,u)===!1){R.push(u);for(let L=0;L<E.length;L++){const g=E[L];i[r][g]=!0}}}else{const R=Wt(f,o+1,u);a[r]=a[r].concat(R),R.forEach(L=>{xt(L.partialPath).forEach(T=>{i[r][T]=!0})})}}}}return n}function is(t,e,s,n){const i=new un(t,C.ALTERNATION,n);return e.accept(i),dn(i.result,s)}function as(t,e,s,n){const i=new un(t,s);e.accept(i);const a=i.result,l=new Za(e,t,s).startWalking(),r=new W({definition:a}),h=new W({definition:l});return dn([r,h],n)}function Kt(t,e){e:for(let s=0;s<t.length;s++){const n=t[s];if(n.length===e.length){for(let i=0;i<n.length;i++){const a=e[i],o=n[i];if((a===o||o.categoryMatchesMap[a.tokenTypeIdx]!==void 0)===!1)continue e}return!0}}return!1}function er(t,e){return t.length<e.length&&t.every((s,n)=>{const i=e[n];return s===i||i.categoryMatchesMap[s.tokenTypeIdx]})}function fn(t){return t.every(e=>e.every(s=>s.every(n=>n.categoryMatches.length===0)))}function tr(t){return t.lookaheadStrategy.validate({rules:t.rules,tokenTypes:t.tokenTypes,grammarName:t.grammarName}).map(s=>Object.assign({type:$.CUSTOM_LOOKAHEAD_VALIDATION},s))}function sr(t,e,s,n){const i=t.flatMap(r=>nr(r,s)),a=mr(t,e,s),o=t.flatMap(r=>ur(r,s)),l=t.flatMap(r=>rr(r,t,n,s));return i.concat(a,o,l)}function nr(t,e){const s=new ar;t.accept(s);const n=s.allProductions,i=Object.groupBy(n,ir),a=Object.fromEntries(Object.entries(i).filter(([l,r])=>r.length>1));return Object.values(a).map(l=>{const r=l[0],h=e.buildDuplicateFoundError(t,l),d=ee(r),u={message:h,type:$.DUPLICATE_PRODUCTIONS,ruleName:t.name,dslName:d,occurrence:r.idx},f=pn(r);return f&&(u.parameter=f),u})}function ir(t){return`${ee(t)}_#_${t.idx}_#_${pn(t)}`}function pn(t){return t instanceof k?t.terminalType.name:t instanceof K?t.nonTerminalName:""}class ar extends ke{constructor(){super(...arguments),this.allProductions=[]}visitNonTerminal(e){this.allProductions.push(e)}visitOption(e){this.allProductions.push(e)}visitRepetitionWithSeparator(e){this.allProductions.push(e)}visitRepetitionMandatory(e){this.allProductions.push(e)}visitRepetitionMandatoryWithSeparator(e){this.allProductions.push(e)}visitRepetition(e){this.allProductions.push(e)}visitAlternation(e){this.allProductions.push(e)}visitTerminal(e){this.allProductions.push(e)}}function rr(t,e,s,n){const i=[];if(e.reduce((o,l)=>l.name===t.name?o+1:o,0)>1){const o=n.buildDuplicateRuleNameError({topLevelRule:t,grammarName:s});i.push({message:o,type:$.DUPLICATE_RULE_NAME,ruleName:t.name})}return i}function or(t,e,s){const n=[];let i;return e.includes(t)||(i=`Invalid rule override, rule: ->${t}<- cannot be overridden in the grammar: ->${s}<-as it is not defined in any of the super grammars `,n.push({message:i,type:$.INVALID_RULE_OVERRIDE,ruleName:t})),n}function mn(t,e,s,n=[]){const i=[],a=nt(e.definition);if(a.length===0)return[];{const o=t.name;a.includes(t)&&i.push({message:s.buildLeftRecursionError({topLevelRule:t,leftRecursionPath:n}),type:$.LEFT_RECURSION,ruleName:o});const r=n.concat([t]),d=a.filter(u=>!r.includes(u)).flatMap(u=>{const f=[...n];return f.push(u),mn(t,u,s,f)});return i.concat(d)}}function nt(t){let e=[];if(t.length===0)return e;const s=t[0];if(s instanceof K)e.push(s.referencedRule);else if(s instanceof W||s instanceof G||s instanceof se||s instanceof ne||s instanceof J||s instanceof M)e=e.concat(nt(s.definition));else if(s instanceof Z)e=s.definition.map(a=>nt(a.definition)).flat();else if(!(s instanceof k))throw Error("non exhaustive match");const n=ut(s),i=t.length>1;if(n&&i){const a=t.slice(1);return e.concat(nt(a))}else return e}class rs extends ke{constructor(){super(...arguments),this.alternations=[]}visitAlternation(e){this.alternations.push(e)}}function lr(t,e){const s=new rs;return t.accept(s),s.alternations.flatMap(a=>a.definition.slice(0,-1).flatMap((l,r)=>za([l],[],ze,1).length===0?[{message:e.buildEmptyAlternationError({topLevelRule:t,alternation:a,emptyChoiceIdx:r}),type:$.NONE_LAST_EMPTY_ALT,ruleName:t.name,occurrence:a.idx,alternative:r+1}]:[]))}function cr(t,e,s){const n=new rs;t.accept(n);let i=n.alternations;return i=i.filter(o=>o.ignoreAmbiguities!==!0),i.flatMap(o=>{const l=o.idx,r=o.maxLookahead||e,h=is(l,t,r,o),d=fr(h,o,t,s),u=pr(h,o,t,s);return d.concat(u)})}class hr extends ke{constructor(){super(...arguments),this.allProductions=[]}visitRepetitionWithSeparator(e){this.allProductions.push(e)}visitRepetitionMandatory(e){this.allProductions.push(e)}visitRepetitionMandatoryWithSeparator(e){this.allProductions.push(e)}visitRepetition(e){this.allProductions.push(e)}}function ur(t,e){const s=new rs;return t.accept(s),s.alternations.flatMap(a=>a.definition.length>255?[{message:e.buildTooManyAlternativesError({topLevelRule:t,alternation:a}),type:$.TOO_MANY_ALTS,ruleName:t.name,occurrence:a.idx}]:[])}function dr(t,e,s){const n=[];return t.forEach(i=>{const a=new hr;i.accept(a),a.allProductions.forEach(l=>{const r=hn(l),h=l.maxLookahead||e,d=l.idx;if(as(d,i,r,h)[0].flat().length===0){const E=s.buildEmptyRepetitionError({topLevelRule:i,repetition:l});n.push({message:E,type:$.NO_NON_EMPTY_LOOKAHEAD,ruleName:i.name})}})}),n}function fr(t,e,s,n){const i=[];return t.reduce((l,r,h)=>(e.definition[h].ignoreAmbiguities===!0||r.forEach(d=>{const u=[h];t.forEach((f,E)=>{h!==E&&Kt(f,d)&&e.definition[E].ignoreAmbiguities!==!0&&u.push(E)}),u.length>1&&!Kt(i,d)&&(i.push(d),l.push({alts:u,path:d}))}),l),[]).map(l=>{const r=l.alts.map(d=>d+1);return{message:n.buildAlternationAmbiguityError({topLevelRule:s,alternation:e,ambiguityIndices:r,prefixPath:l.path}),type:$.AMBIGUOUS_ALTS,ruleName:s.name,occurrence:e.idx,alternatives:l.alts}})}function pr(t,e,s,n){const i=t.reduce((o,l,r)=>{const h=l.map(d=>({idx:r,path:d}));return o.concat(h)},[]);return i.flatMap(o=>{if(e.definition[o.idx].ignoreAmbiguities===!0)return[];const r=o.idx,h=o.path;return i.filter(f=>e.definition[f.idx].ignoreAmbiguities!==!0&&f.idx<r&&er(f.path,h)).map(f=>{const E=[f.idx+1,r+1],y=e.idx===0?"":e.idx;return{message:n.buildAlternationPrefixAmbiguityError({topLevelRule:s,alternation:e,ambiguityIndices:E,prefixPath:f.path}),type:$.AMBIGUOUS_PREFIX_ALTS,ruleName:s.name,occurrence:y,alternatives:E}})})}function mr(t,e,s){const n=[],i=e.map(a=>a.name);return t.forEach(a=>{const o=a.name;if(i.includes(o)){const l=s.buildNamespaceConflictError(a);n.push({message:l,type:$.CONFLICT_TOKENS_RULES_NAMESPACE,ruleName:o})}}),n}function Er(t){const e=Object.assign({errMsgProvider:Ba},t),s={};return t.rules.forEach(n=>{s[n.name]=n}),$a(s,e.errMsgProvider)}function Tr(t){var e;const s=(e=t.errMsgProvider)!==null&&e!==void 0?e:Ee;return sr(t.rules,t.tokenTypes,s,t.grammarName)}const En="MismatchedTokenException",Tn="NoViableAltException",gn="EarlyExitException",An="NotAllInputParsedException",Sn=[En,Tn,gn,An];Object.freeze(Sn);function Et(t){return Sn.includes(t.name)}class Rt extends Error{constructor(e,s){super(e),this.token=s,this.resyncedTokens=[],Object.setPrototypeOf(this,new.target.prototype),Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor)}}class yn extends Rt{constructor(e,s,n){super(e,s),this.previousToken=n,this.name=En}}class gr extends Rt{constructor(e,s,n){super(e,s),this.previousToken=n,this.name=Tn}}class Ar extends Rt{constructor(e,s){super(e,s),this.name=An}}class Sr extends Rt{constructor(e,s,n){super(e,s),this.previousToken=n,this.name=gn}}const Mt={},Rn="InRuleRecoveryException";class yr extends Error{constructor(e){super(e),this.name=Rn}}class Rr{initRecoverable(e){this.firstAfterRepMap=[],this.resyncFollows={},this.recoveryEnabled=Object.hasOwn(e,"recoveryEnabled")?e.recoveryEnabled:ce.recoveryEnabled,this.recoveryEnabled&&(this.attemptInRepetitionRecovery=Or)}getTokenToInsert(e){const s=ns(e,"",-1,-1,-1,-1,-1,-1);return s.isInsertedInRecovery=!0,s}canTokenTypeBeInsertedInRecovery(e){return!0}canTokenTypeBeDeletedInRecovery(e){return!0}tryInRepetitionRecovery(e,s,n,i){const a=this.findReSyncTokenType(),o=this.exportLexerState(),l=[];let r=!1;const h=this.LA_FAST(1);let d=this.LA_FAST(1);const u=()=>{const f=this.LA(0),E=this.errorMessageProvider.buildMismatchTokenMessage({expected:i,actual:h,previous:f,ruleName:this.getCurrRuleFullName()}),y=new yn(E,h,this.LA(0));y.resyncedTokens=l.slice(0,-1),this.SAVE_ERROR(y)};for(;!r;)if(this.tokenMatcher(d,i)){u();return}else if(n.call(this)){u(),e.apply(this,s);return}else this.tokenMatcher(d,a)?r=!0:(d=this.SKIP_TOKEN(),this.addToResyncTokens(d,l));this.importLexerState(o)}shouldInRepetitionRecoveryBeTried(e,s,n){return!(n===!1||this.tokenMatcher(this.LA_FAST(1),e)||this.isBackTracking()||this.canPerformInRuleRecovery(e,this.getFollowsForInRuleRecovery(e,s)))}getNextPossibleTokenTypes(e){const s=e.ruleStack[0],i=this.getGAstProductions()[s];return new Wa(i,e).startWalking()}getFollowsForInRuleRecovery(e,s){const n=this.getCurrentGrammarPath(e,s);return this.getNextPossibleTokenTypes(n)}tryInRuleRecovery(e,s){if(this.canRecoverWithSingleTokenInsertion(e,s))return this.getTokenToInsert(e);if(this.canRecoverWithSingleTokenDeletion(e)){const n=this.SKIP_TOKEN();return this.consumeToken(),n}throw new yr("sad sad panda")}canPerformInRuleRecovery(e,s){return this.canRecoverWithSingleTokenInsertion(e,s)||this.canRecoverWithSingleTokenDeletion(e)}canRecoverWithSingleTokenInsertion(e,s){if(!this.canTokenTypeBeInsertedInRecovery(e)||s.length===0)return!1;const n=this.LA_FAST(1);return s.find(a=>this.tokenMatcher(n,a))!==void 0}canRecoverWithSingleTokenDeletion(e){return this.canTokenTypeBeDeletedInRecovery(e)?this.tokenMatcher(this.LA(2),e):!1}isInCurrentRuleReSyncSet(e){const s=this.getCurrFollowKey();return this.getFollowSetFromFollowKey(s).includes(e)}findReSyncTokenType(){const e=this.flattenFollowSet();let s=this.LA_FAST(1),n=2;for(;;){const i=e.find(a=>ln(s,a));if(i!==void 0)return i;s=this.LA(n),n++}}getCurrFollowKey(){if(this.RULE_STACK_IDX===0)return Mt;const e=this.currRuleShortName,s=this.getLastExplicitRuleOccurrenceIndex(),n=this.getPreviousExplicitRuleShortName();return{ruleName:this.shortRuleNameToFullName(e),idxInCallingRule:s,inRule:this.shortRuleNameToFullName(n)}}buildFullFollowKeyStack(){const e=this.RULE_STACK,s=this.RULE_OCCURRENCE_STACK,n=this.RULE_STACK_IDX+1,i=new Array(n);for(let a=0;a<n;a++)a===0?i[a]=Mt:i[a]={ruleName:this.shortRuleNameToFullName(e[a]),idxInCallingRule:s[a],inRule:this.shortRuleNameToFullName(e[a-1])};return i}flattenFollowSet(){return this.buildFullFollowKeyStack().map(s=>this.getFollowSetFromFollowKey(s)).flat()}getFollowSetFromFollowKey(e){if(e===Mt)return[le];const s=e.ruleName+e.idxInCallingRule+Zs+e.inRule;return this.resyncFollows[s]}addToResyncTokens(e,s){return this.tokenMatcher(e,le)||s.push(e),s}reSyncTo(e){const s=[];let n=this.LA_FAST(1);for(;this.tokenMatcher(n,e)===!1;)n=this.SKIP_TOKEN(),this.addToResyncTokens(n,s);return s.slice(0,-1)}attemptInRepetitionRecovery(e,s,n,i,a,o,l){}getCurrentGrammarPath(e,s){const n=this.getHumanReadableRuleStack(),i=this.RULE_OCCURRENCE_STACK.slice(0,this.RULE_OCCURRENCE_STACK_IDX+1);return{ruleStack:n,occurrenceStack:i,lastTok:e,lastTokOccurrence:s}}getHumanReadableRuleStack(){const e=this.RULE_STACK_IDX+1,s=new Array(e);for(let n=0;n<e;n++)s[n]=this.shortRuleNameToFullName(this.RULE_STACK[n]);return s}}function Or(t,e,s,n,i,a,o){var l,r,h;const d=n|i,u=(l=(r=this.firstAfterRepMap)[h=this.currRuleShortName])!==null&&l!==void 0?l:r[h]=[];let f=u[d];if(f===void 0){const L=this.getCurrRuleFullName(),g=this.getGAstProductions()[L];f=new a(g,i).startWalking(),u[d]=f}let E=f.token,y=f.occurrence;const R=f.isEndOfRule;this.RULE_STACK_IDX===0&&R&&E===void 0&&(E=le,y=1),!(E===void 0||y===void 0)&&this.shouldInRepetitionRecoveryBeTried(E,y,o)&&this.tryInRepetitionRecovery(t,e,s,E)}const Ne=8,On=1<<Ne,Ln=2<<Ne,Vt=3<<Ne,zt=4<<Ne,Ht=5<<Ne,it=6<<Ne;class Lr{constructor(e){var s;this.maxLookahead=(s=e?.maxLookahead)!==null&&s!==void 0?s:ce.maxLookahead}validate(e){const s=this.validateNoLeftRecursion(e.rules);if(s.length===0){const n=this.validateEmptyOrAlternatives(e.rules),i=this.validateAmbiguousAlternationAlternatives(e.rules,this.maxLookahead),a=this.validateSomeNonEmptyLookaheadPath(e.rules,this.maxLookahead);return[...s,...n,...i,...a]}return s}validateNoLeftRecursion(e){return e.flatMap(s=>mn(s,s,Ee))}validateEmptyOrAlternatives(e){return e.flatMap(s=>lr(s,Ee))}validateAmbiguousAlternationAlternatives(e,s){return e.flatMap(n=>cr(n,s,Ee))}validateSomeNonEmptyLookaheadPath(e,s){return dr(e,s,Ee)}buildLookaheadForAlternation(e){return Xa(e.prodOccurrence,e.rule,e.maxLookahead,e.hasPredicates,e.dynamicTokensEnabled,qa)}buildLookaheadForOptional(e){return Ya(e.prodOccurrence,e.rule,e.maxLookahead,e.dynamicTokensEnabled,hn(e.prodType),Ja)}}class Ir{initLooksAhead(e){this.dynamicTokensEnabled=Object.hasOwn(e,"dynamicTokensEnabled")?e.dynamicTokensEnabled:ce.dynamicTokensEnabled,this.maxLookahead=Object.hasOwn(e,"maxLookahead")?e.maxLookahead:ce.maxLookahead,this.lookaheadStrategy=Object.hasOwn(e,"lookaheadStrategy")?e.lookaheadStrategy:new Lr({maxLookahead:this.maxLookahead}),this.lookAheadFuncsCache=[],this.currRuleLookaheadFuncs=[]}preComputeLookaheadFunctions(e){e.forEach(s=>{this.TRACE_INIT(`${s.name} Rule Lookahead`,()=>{const{alternation:n,repetition:i,option:a,repetitionMandatory:o,repetitionMandatoryWithSeparator:l,repetitionWithSeparator:r}=Nr(s);n.forEach(h=>{const d=h.idx===0?"":h.idx;this.TRACE_INIT(`${ee(h)}${d}`,()=>{const u=this.lookaheadStrategy.buildLookaheadForAlternation({prodOccurrence:h.idx,rule:s,maxLookahead:h.maxLookahead||this.maxLookahead,hasPredicates:h.hasPredicates,dynamicTokensEnabled:this.dynamicTokensEnabled});this.setLaFuncCache(this.fullRuleNameToShort[s.name],On|h.idx,u)})}),i.forEach(h=>{this.computeLookaheadFunc(s,h.idx,Vt,"Repetition",h.maxLookahead,ee(h))}),a.forEach(h=>{this.computeLookaheadFunc(s,h.idx,Ln,"Option",h.maxLookahead,ee(h))}),o.forEach(h=>{this.computeLookaheadFunc(s,h.idx,zt,"RepetitionMandatory",h.maxLookahead,ee(h))}),l.forEach(h=>{this.computeLookaheadFunc(s,h.idx,it,"RepetitionMandatoryWithSeparator",h.maxLookahead,ee(h))}),r.forEach(h=>{this.computeLookaheadFunc(s,h.idx,Ht,"RepetitionWithSeparator",h.maxLookahead,ee(h))})})})}computeLookaheadFunc(e,s,n,i,a,o){this.TRACE_INIT(`${o}${s===0?"":s}`,()=>{const l=this.lookaheadStrategy.buildLookaheadForOptional({prodOccurrence:s,rule:e,maxLookahead:a||this.maxLookahead,dynamicTokensEnabled:this.dynamicTokensEnabled,prodType:i});this.setLaFuncCache(this.fullRuleNameToShort[e.name],n|s,l)})}setLaFuncCache(e,s,n){let i=this.lookAheadFuncsCache[e];i===void 0&&(i=[],this.lookAheadFuncsCache[e]=i),i[s]=n}}class kr extends ke{constructor(){super(...arguments),this.dslMethods={option:[],alternation:[],repetition:[],repetitionWithSeparator:[],repetitionMandatory:[],repetitionMandatoryWithSeparator:[]}}reset(){this.dslMethods={option:[],alternation:[],repetition:[],repetitionWithSeparator:[],repetitionMandatory:[],repetitionMandatoryWithSeparator:[]}}visitOption(e){this.dslMethods.option.push(e)}visitRepetitionWithSeparator(e){this.dslMethods.repetitionWithSeparator.push(e)}visitRepetitionMandatory(e){this.dslMethods.repetitionMandatory.push(e)}visitRepetitionMandatoryWithSeparator(e){this.dslMethods.repetitionMandatoryWithSeparator.push(e)}visitRepetition(e){this.dslMethods.repetition.push(e)}visitAlternation(e){this.dslMethods.alternation.push(e)}}const Ze=new kr;function Nr(t){Ze.reset(),t.accept(Ze);const e=Ze.dslMethods;return Ze.reset(),e}function Ms(t,e){t.startOffset===-1?(t.startOffset=e.startOffset,t.endOffset=e.endOffset):t.endOffset<e.endOffset&&(t.endOffset=e.endOffset)}function ws(t,e){t.startOffset===-1?(t.startOffset=e.startOffset,t.startColumn=e.startColumn,t.startLine=e.startLine,t.endOffset=e.endOffset,t.endColumn=e.endColumn,t.endLine=e.endLine):t.endOffset<e.endOffset&&(t.endOffset=e.endOffset,t.endColumn=e.endColumn,t.endLine=e.endLine)}function Cr(t,e,s){t.children[s]===void 0?t.children[s]=[e]:t.children[s].push(e)}function br(t,e,s){t.children[e]===void 0?t.children[e]=[s]:t.children[e].push(s)}const vr="name";function In(t,e){Object.defineProperty(t,vr,{enumerable:!1,configurable:!0,writable:!1,value:e})}function _r(t,e){const s=Object.keys(t),n=s.length;for(let i=0;i<n;i++){const a=s[i],o=t[a],l=o.length;for(let r=0;r<l;r++){const h=o[r];h.tokenTypeIdx===void 0&&this[h.name](h.children,e)}}}function xr(t,e){const s=function(){};In(s,t+"BaseSemantics");const n={visit:function(i,a){if(Array.isArray(i)&&(i=i[0]),i!==void 0)return this[i.name](i.children,a)},validateVisitor:function(){const i=wr(this,e);if(i.length!==0){const a=i.map(o=>o.msg);throw Error(`Errors Detected in CST Visitor <${this.constructor.name}>:
87
- ${a.join(`
88
-
89
- `).replace(/\n/g,`
90
- `)}`)}}};return s.prototype=n,s.prototype.constructor=s,s._RULE_NAMES=e,s}function Mr(t,e,s){const n=function(){};In(n,t+"BaseSemanticsWithDefaults");const i=Object.create(s.prototype);return e.forEach(a=>{i[a]=_r}),n.prototype=i,n.prototype.constructor=n,n}var Xt;(function(t){t[t.REDUNDANT_METHOD=0]="REDUNDANT_METHOD",t[t.MISSING_METHOD=1]="MISSING_METHOD"})(Xt||(Xt={}));function wr(t,e){return Ur(t,e)}function Ur(t,e){return e.filter(i=>typeof t[i]!="function").map(i=>({msg:`Missing visitor method: <${i}> on ${t.constructor.name} CST Visitor.`,type:Xt.MISSING_METHOD,methodName:i})).filter(Boolean)}class Pr{initTreeBuilder(e){if(this.CST_STACK=[],this.outputCst=e.outputCst,this.nodeLocationTracking=Object.hasOwn(e,"nodeLocationTracking")?e.nodeLocationTracking:ce.nodeLocationTracking,!this.outputCst)this.cstInvocationStateUpdate=()=>{},this.cstFinallyStateUpdate=()=>{},this.cstPostTerminal=()=>{},this.cstPostNonTerminal=()=>{},this.cstPostRule=()=>{};else if(/full/i.test(this.nodeLocationTracking))this.recoveryEnabled?(this.setNodeLocationFromToken=ws,this.setNodeLocationFromNode=ws,this.cstPostRule=()=>{},this.setInitialNodeLocation=this.setInitialNodeLocationFullRecovery):(this.setNodeLocationFromToken=()=>{},this.setNodeLocationFromNode=()=>{},this.cstPostRule=this.cstPostRuleFull,this.setInitialNodeLocation=this.setInitialNodeLocationFullRegular);else if(/onlyOffset/i.test(this.nodeLocationTracking))this.recoveryEnabled?(this.setNodeLocationFromToken=Ms,this.setNodeLocationFromNode=Ms,this.cstPostRule=()=>{},this.setInitialNodeLocation=this.setInitialNodeLocationOnlyOffsetRecovery):(this.setNodeLocationFromToken=()=>{},this.setNodeLocationFromNode=()=>{},this.cstPostRule=this.cstPostRuleOnlyOffset,this.setInitialNodeLocation=this.setInitialNodeLocationOnlyOffsetRegular);else if(/none/i.test(this.nodeLocationTracking))this.setNodeLocationFromToken=()=>{},this.setNodeLocationFromNode=()=>{},this.cstPostRule=()=>{},this.setInitialNodeLocation=()=>{};else throw Error(`Invalid <nodeLocationTracking> config option: "${e.nodeLocationTracking}"`)}setInitialNodeLocationOnlyOffsetRecovery(e){e.location={startOffset:-1,endOffset:-1}}setInitialNodeLocationOnlyOffsetRegular(e){e.location={startOffset:this.LA_FAST(1).startOffset,endOffset:-1}}setInitialNodeLocationFullRecovery(e){e.location={startOffset:-1,startLine:-1,startColumn:-1,endOffset:-1,endLine:-1,endColumn:-1}}setInitialNodeLocationFullRegular(e){const s=this.LA_FAST(1);e.location={startOffset:s.startOffset,startLine:s.startLine,startColumn:s.startColumn,endOffset:-1,endLine:-1,endColumn:-1}}cstInvocationStateUpdate(e){const s={name:e,children:Object.create(null)};this.setInitialNodeLocation(s),this.CST_STACK.push(s)}cstFinallyStateUpdate(){this.CST_STACK.pop()}cstPostRuleFull(e){const s=this.LA(0),n=e.location;n.startOffset!==-1&&n.startOffset<=s.startOffset?(n.endOffset=s.endOffset,n.endLine=s.endLine,n.endColumn=s.endColumn):(n.startOffset=-1,n.startLine=-1,n.startColumn=-1)}cstPostRuleOnlyOffset(e){const s=this.LA(0),n=e.location;n.startOffset!==-1&&n.startOffset<=s.startOffset?n.endOffset=s.endOffset:n.startOffset=-1}cstPostTerminal(e,s){const n=this.CST_STACK[this.CST_STACK.length-1];Cr(n,s,e),this.setNodeLocationFromToken(n.location,s)}cstPostNonTerminal(e,s){const n=this.CST_STACK[this.CST_STACK.length-1];br(n,s,e),this.setNodeLocationFromNode(n.location,e.location)}get currCSTNode(){const e=this;return e.CST_STACK[e.CST_STACK.length-1]}getBaseCstVisitorConstructor(){if(this.baseCstVisitorConstructor===void 0){const e=xr(this.className,Object.keys(this.gastProductionsCache));return this.baseCstVisitorConstructor=e,e}return this.baseCstVisitorConstructor}getBaseCstVisitorConstructorWithDefaults(){if(this.baseCstVisitorWithDefaultsConstructor===void 0){const e=Mr(this.className,Object.keys(this.gastProductionsCache),this.getBaseCstVisitorConstructor());return this.baseCstVisitorWithDefaultsConstructor=e,e}return this.baseCstVisitorWithDefaultsConstructor}getPreviousExplicitRuleShortName(){return this.RULE_STACK[this.RULE_STACK_IDX-1]}getLastExplicitRuleOccurrenceIndex(){return this.RULE_OCCURRENCE_STACK[this.RULE_OCCURRENCE_STACK_IDX]}}class Dr{initLexerAdapter(){this.tokVector=[],this.tokVectorLength=0,this.currIdx=-1}set input(e){if(this.selfAnalysisDone!==!0)throw Error("Missing <performSelfAnalysis> invocation at the end of the Parser's constructor.");this.reset(),this.tokVector=e,this.tokVectorLength=e.length}get input(){return this.tokVector}SKIP_TOKEN(){return this.currIdx<=this.tokVectorLength-2?(this.consumeToken(),this.LA_FAST(1)):Le}LA_FAST(e){const s=this.currIdx+e;return this.tokVector[s]}LA(e){const s=this.currIdx+e;return s<0||this.tokVectorLength<=s?Le:this.tokVector[s]}consumeToken(){this.currIdx++}exportLexerState(){return this.currIdx}importLexerState(e){this.currIdx=e}resetLexerState(){this.currIdx=-1}moveToTerminatedState(){this.currIdx=this.tokVectorLength-1}getLexerPosition(){return this.exportLexerState()}}class Fr{ACTION(e){return e.call(this)}consume(e,s,n){return this.consumeInternal(s,e,n)}subrule(e,s,n){return this.subruleInternal(s,e,n)}option(e,s){return this.optionInternal(s,e)}or(e,s){return this.orInternal(s,e)}many(e,s){return this.manyInternal(e,s)}atLeastOne(e,s){return this.atLeastOneInternal(e,s)}CONSUME(e,s){return this.consumeInternal(e,0,s)}CONSUME1(e,s){return this.consumeInternal(e,1,s)}CONSUME2(e,s){return this.consumeInternal(e,2,s)}CONSUME3(e,s){return this.consumeInternal(e,3,s)}CONSUME4(e,s){return this.consumeInternal(e,4,s)}CONSUME5(e,s){return this.consumeInternal(e,5,s)}CONSUME6(e,s){return this.consumeInternal(e,6,s)}CONSUME7(e,s){return this.consumeInternal(e,7,s)}CONSUME8(e,s){return this.consumeInternal(e,8,s)}CONSUME9(e,s){return this.consumeInternal(e,9,s)}SUBRULE(e,s){return this.subruleInternal(e,0,s)}SUBRULE1(e,s){return this.subruleInternal(e,1,s)}SUBRULE2(e,s){return this.subruleInternal(e,2,s)}SUBRULE3(e,s){return this.subruleInternal(e,3,s)}SUBRULE4(e,s){return this.subruleInternal(e,4,s)}SUBRULE5(e,s){return this.subruleInternal(e,5,s)}SUBRULE6(e,s){return this.subruleInternal(e,6,s)}SUBRULE7(e,s){return this.subruleInternal(e,7,s)}SUBRULE8(e,s){return this.subruleInternal(e,8,s)}SUBRULE9(e,s){return this.subruleInternal(e,9,s)}OPTION(e){return this.optionInternal(e,0)}OPTION1(e){return this.optionInternal(e,1)}OPTION2(e){return this.optionInternal(e,2)}OPTION3(e){return this.optionInternal(e,3)}OPTION4(e){return this.optionInternal(e,4)}OPTION5(e){return this.optionInternal(e,5)}OPTION6(e){return this.optionInternal(e,6)}OPTION7(e){return this.optionInternal(e,7)}OPTION8(e){return this.optionInternal(e,8)}OPTION9(e){return this.optionInternal(e,9)}OR(e){return this.orInternal(e,0)}OR1(e){return this.orInternal(e,1)}OR2(e){return this.orInternal(e,2)}OR3(e){return this.orInternal(e,3)}OR4(e){return this.orInternal(e,4)}OR5(e){return this.orInternal(e,5)}OR6(e){return this.orInternal(e,6)}OR7(e){return this.orInternal(e,7)}OR8(e){return this.orInternal(e,8)}OR9(e){return this.orInternal(e,9)}MANY(e){this.manyInternal(0,e)}MANY1(e){this.manyInternal(1,e)}MANY2(e){this.manyInternal(2,e)}MANY3(e){this.manyInternal(3,e)}MANY4(e){this.manyInternal(4,e)}MANY5(e){this.manyInternal(5,e)}MANY6(e){this.manyInternal(6,e)}MANY7(e){this.manyInternal(7,e)}MANY8(e){this.manyInternal(8,e)}MANY9(e){this.manyInternal(9,e)}MANY_SEP(e){this.manySepFirstInternal(0,e)}MANY_SEP1(e){this.manySepFirstInternal(1,e)}MANY_SEP2(e){this.manySepFirstInternal(2,e)}MANY_SEP3(e){this.manySepFirstInternal(3,e)}MANY_SEP4(e){this.manySepFirstInternal(4,e)}MANY_SEP5(e){this.manySepFirstInternal(5,e)}MANY_SEP6(e){this.manySepFirstInternal(6,e)}MANY_SEP7(e){this.manySepFirstInternal(7,e)}MANY_SEP8(e){this.manySepFirstInternal(8,e)}MANY_SEP9(e){this.manySepFirstInternal(9,e)}AT_LEAST_ONE(e){this.atLeastOneInternal(0,e)}AT_LEAST_ONE1(e){return this.atLeastOneInternal(1,e)}AT_LEAST_ONE2(e){this.atLeastOneInternal(2,e)}AT_LEAST_ONE3(e){this.atLeastOneInternal(3,e)}AT_LEAST_ONE4(e){this.atLeastOneInternal(4,e)}AT_LEAST_ONE5(e){this.atLeastOneInternal(5,e)}AT_LEAST_ONE6(e){this.atLeastOneInternal(6,e)}AT_LEAST_ONE7(e){this.atLeastOneInternal(7,e)}AT_LEAST_ONE8(e){this.atLeastOneInternal(8,e)}AT_LEAST_ONE9(e){this.atLeastOneInternal(9,e)}AT_LEAST_ONE_SEP(e){this.atLeastOneSepFirstInternal(0,e)}AT_LEAST_ONE_SEP1(e){this.atLeastOneSepFirstInternal(1,e)}AT_LEAST_ONE_SEP2(e){this.atLeastOneSepFirstInternal(2,e)}AT_LEAST_ONE_SEP3(e){this.atLeastOneSepFirstInternal(3,e)}AT_LEAST_ONE_SEP4(e){this.atLeastOneSepFirstInternal(4,e)}AT_LEAST_ONE_SEP5(e){this.atLeastOneSepFirstInternal(5,e)}AT_LEAST_ONE_SEP6(e){this.atLeastOneSepFirstInternal(6,e)}AT_LEAST_ONE_SEP7(e){this.atLeastOneSepFirstInternal(7,e)}AT_LEAST_ONE_SEP8(e){this.atLeastOneSepFirstInternal(8,e)}AT_LEAST_ONE_SEP9(e){this.atLeastOneSepFirstInternal(9,e)}RULE(e,s,n=gt){if(this.definedRulesNames.includes(e)){const o={message:Ee.buildDuplicateRuleNameError({topLevelRule:e,grammarName:this.className}),type:$.DUPLICATE_RULE_NAME,ruleName:e};this.definitionErrors.push(o)}this.definedRulesNames.push(e);const i=this.defineRule(e,s,n);return this[e]=i,i}OVERRIDE_RULE(e,s,n=gt){const i=or(e,this.definedRulesNames,this.className);this.definitionErrors=this.definitionErrors.concat(i);const a=this.defineRule(e,s,n);return this[e]=a,a}BACKTRACK(e,s){var n;const i=(n=e.coreRule)!==null&&n!==void 0?n:e;return function(){this.isBackTrackingStack.push(1);const a=this.saveRecogState();try{return i.apply(this,s),!0}catch(o){if(Et(o))return!1;throw o}finally{this.reloadRecogState(a),this.isBackTrackingStack.pop()}}}getGAstProductions(){return this.gastProductionsCache}getSerializedGastProductions(){return $i(Object.values(this.gastProductionsCache))}}class Br{initRecognizerEngine(e,s){if(this.className=this.constructor.name,this.shortRuleNameToFull=[],this.fullRuleNameToShort={},this.ruleShortNameIdx=0,this.tokenMatcher=mt,this.subruleIdx=0,this.currRuleShortName=-1,this.definedRulesNames=[],this.tokensMap={},this.isBackTrackingStack=[],this.RULE_STACK=[],this.RULE_STACK_IDX=-1,this.RULE_OCCURRENCE_STACK=[],this.RULE_OCCURRENCE_STACK_IDX=-1,this.gastProductionsCache={},Object.hasOwn(s,"serializedGrammar"))throw Error(`The Parser's configuration can no longer contain a <serializedGrammar> property.
91
- See: https://chevrotain.io/docs/changes/BREAKING_CHANGES.html#_6-0-0
92
- For Further details.`);if(Array.isArray(e)){if(e.length===0)throw Error(`A Token Vocabulary cannot be empty.
93
- Note that the first argument for the parser constructor
94
- is no longer a Token vector (since v4.0).`);if(typeof e[0].startOffset=="number")throw Error(`The Parser constructor no longer accepts a token vector as the first argument.
95
- See: https://chevrotain.io/docs/changes/BREAKING_CHANGES.html#_4-0-0
96
- For Further details.`)}if(Array.isArray(e))this.tokensMap=e.reduce((a,o)=>(a[o.name]=o,a),{});else if(Object.hasOwn(e,"modes")&&Object.values(e.modes).flat().every(Ua)){const a=Object.values(e.modes).flat(),o=[...new Set(a)];this.tokensMap=o.reduce((l,r)=>(l[r.name]=r,l),{})}else if(typeof e=="object"&&e!==null)this.tokensMap=Object.assign({},e);else throw new Error("<tokensDictionary> argument must be An Array of Token constructors, A dictionary of Token constructors or an IMultiModeLexerDefinition");this.tokensMap.EOF=le;const i=(Object.hasOwn(e,"modes")?Object.values(e.modes).flat():Object.values(e)).every(a=>{var o;return((o=a.categoryMatches)===null||o===void 0?void 0:o.length)==0});this.tokenMatcher=i?mt:ze,He(Object.values(this.tokensMap))}defineRule(e,s,n){if(this.selfAnalysisDone)throw Error(`Grammar rule <${e}> may not be defined after the 'performSelfAnalysis' method has been called'
97
- Make sure that all grammar rule definitions are done before 'performSelfAnalysis' is called.`);const i=Object.hasOwn(n,"resyncEnabled")?n.resyncEnabled:gt.resyncEnabled,a=Object.hasOwn(n,"recoveryValueFunc")?n.recoveryValueFunc:gt.recoveryValueFunc,o=this.ruleShortNameIdx++;this.shortRuleNameToFull[o]=e,this.fullRuleNameToShort[e]=o;let l;return this.outputCst===!0?l=function(...u){try{this.ruleInvocationStateUpdate(o,e,this.subruleIdx),s.apply(this,u);const f=this.CST_STACK[this.CST_STACK.length-1];return this.cstPostRule(f),f}catch(f){return this.invokeRuleCatch(f,i,a)}finally{this.ruleFinallyStateUpdate()}}:l=function(...u){try{return this.ruleInvocationStateUpdate(o,e,this.subruleIdx),s.apply(this,u)}catch(f){return this.invokeRuleCatch(f,i,a)}finally{this.ruleFinallyStateUpdate()}},Object.assign(function(...u){this.onBeforeParse(e);try{return l.apply(this,u)}finally{this.onAfterParse(e)}},{ruleName:e,originalGrammarAction:s,coreRule:l})}invokeRuleCatch(e,s,n){const i=this.RULE_STACK_IDX===0,a=s&&!this.isBackTracking()&&this.recoveryEnabled;if(Et(e)){const o=e;if(a){const l=this.findReSyncTokenType();if(this.isInCurrentRuleReSyncSet(l))if(o.resyncedTokens=this.reSyncTo(l),this.outputCst){const r=this.CST_STACK[this.CST_STACK.length-1];return r.recoveredNode=!0,r}else return n(e);else{if(this.outputCst){const r=this.CST_STACK[this.CST_STACK.length-1];r.recoveredNode=!0,o.partialCstResult=r}throw o}}else{if(i)return this.moveToTerminatedState(),n(e);throw o}}else throw e}optionInternal(e,s){const n=Ln|s;return this.optionInternalLogic(e,s,n)}optionInternalLogic(e,s,n){let i=this.currRuleLookaheadFuncs[n],a;if(typeof e!="function"){a=e.DEF;const o=e.GATE;if(o!==void 0){const l=i;i=()=>o.call(this)&&l.call(this)}}else a=e;if(i.call(this)===!0)return a.call(this)}atLeastOneInternal(e,s){const n=zt|e;return this.atLeastOneInternalLogic(e,s,n)}atLeastOneInternalLogic(e,s,n){let i=this.currRuleLookaheadFuncs[n],a;if(typeof s!="function"){a=s.DEF;const o=s.GATE;if(o!==void 0){const l=i;i=()=>o.call(this)&&l.call(this)}}else a=s;if(i.call(this)===!0){let o=this.doSingleRepetition(a);for(;i.call(this)===!0&&o===!0;)o=this.doSingleRepetition(a)}else throw this.raiseEarlyExitException(e,C.REPETITION_MANDATORY,s.ERR_MSG);this.attemptInRepetitionRecovery(this.atLeastOneInternal,[e,s],i,zt,e,Va)}atLeastOneSepFirstInternal(e,s){const n=it|e;this.atLeastOneSepFirstInternalLogic(e,s,n)}atLeastOneSepFirstInternalLogic(e,s,n){const i=s.DEF,a=s.SEP;if(this.currRuleLookaheadFuncs[n].call(this)===!0){i.call(this);const l=()=>this.tokenMatcher(this.LA_FAST(1),a);for(;this.tokenMatcher(this.LA_FAST(1),a)===!0;)this.CONSUME(a),i.call(this);this.attemptInRepetitionRecovery(this.repetitionSepSecondInternal,[e,a,l,i,_s],l,it,e,_s)}else throw this.raiseEarlyExitException(e,C.REPETITION_MANDATORY_WITH_SEPARATOR,s.ERR_MSG)}manyInternal(e,s){const n=Vt|e;return this.manyInternalLogic(e,s,n)}manyInternalLogic(e,s,n){let i=this.currRuleLookaheadFuncs[n],a;if(typeof s!="function"){a=s.DEF;const l=s.GATE;if(l!==void 0){const r=i;i=()=>l.call(this)&&r.call(this)}}else a=s;let o=!0;for(;i.call(this)===!0&&o===!0;)o=this.doSingleRepetition(a);this.attemptInRepetitionRecovery(this.manyInternal,[e,s],i,Vt,e,Ka,o)}manySepFirstInternal(e,s){const n=Ht|e;this.manySepFirstInternalLogic(e,s,n)}manySepFirstInternalLogic(e,s,n){const i=s.DEF,a=s.SEP;if(this.currRuleLookaheadFuncs[n].call(this)===!0){i.call(this);const l=()=>this.tokenMatcher(this.LA_FAST(1),a);for(;this.tokenMatcher(this.LA_FAST(1),a)===!0;)this.CONSUME(a),i.call(this);this.attemptInRepetitionRecovery(this.repetitionSepSecondInternal,[e,a,l,i,vs],l,Ht,e,vs)}}repetitionSepSecondInternal(e,s,n,i,a){for(;n();)this.CONSUME(s),i.call(this);this.attemptInRepetitionRecovery(this.repetitionSepSecondInternal,[e,s,n,i,a],n,it,e,a)}doSingleRepetition(e){const s=this.getLexerPosition();return e.call(this),this.getLexerPosition()>s}orInternal(e,s){const n=On|s,i=Array.isArray(e)?e:e.DEF,o=this.currRuleLookaheadFuncs[n].call(this,i);if(o!==void 0)return i[o].ALT.call(this);this.raiseNoAltException(s,e.ERR_MSG)}ruleFinallyStateUpdate(){this.RULE_STACK_IDX--,this.RULE_OCCURRENCE_STACK_IDX--,this.RULE_STACK_IDX>=0&&(this.currRuleShortName=this.RULE_STACK[this.RULE_STACK_IDX],this.currRuleLookaheadFuncs=this.lookAheadFuncsCache[this.currRuleShortName]),this.cstFinallyStateUpdate()}subruleInternal(e,s,n){let i;try{const a=n!==void 0?n.ARGS:void 0;return this.subruleIdx=s,i=e.coreRule.apply(this,a),this.cstPostNonTerminal(i,n!==void 0&&n.LABEL!==void 0?n.LABEL:e.ruleName),i}catch(a){throw this.subruleInternalError(a,n,e.ruleName)}}subruleInternalError(e,s,n){throw Et(e)&&e.partialCstResult!==void 0&&(this.cstPostNonTerminal(e.partialCstResult,s!==void 0&&s.LABEL!==void 0?s.LABEL:n),delete e.partialCstResult),e}consumeInternal(e,s,n){let i;try{const a=this.LA_FAST(1);this.tokenMatcher(a,e)===!0?(this.consumeToken(),i=a):this.consumeInternalError(e,a,n)}catch(a){i=this.consumeInternalRecovery(e,s,a)}return this.cstPostTerminal(n!==void 0&&n.LABEL!==void 0?n.LABEL:e.name,i),i}consumeInternalError(e,s,n){let i;const a=this.LA(0);throw n!==void 0&&n.ERR_MSG?i=n.ERR_MSG:i=this.errorMessageProvider.buildMismatchTokenMessage({expected:e,actual:s,previous:a,ruleName:this.getCurrRuleFullName()}),this.SAVE_ERROR(new yn(i,s,a))}consumeInternalRecovery(e,s,n){if(this.recoveryEnabled&&n.name==="MismatchedTokenException"&&!this.isBackTracking()){const i=this.getFollowsForInRuleRecovery(e,s);try{return this.tryInRuleRecovery(e,i)}catch(a){throw a.name===Rn?n:a}}else throw n}saveRecogState(){const e=this.errors,s=this.RULE_STACK.slice(0,this.RULE_STACK_IDX+1);return{errors:e,lexerState:this.exportLexerState(),RULE_STACK:s,CST_STACK:this.CST_STACK}}reloadRecogState(e){this.errors=e.errors,this.importLexerState(e.lexerState);const s=e.RULE_STACK;for(let n=0;n<s.length;n++)this.RULE_STACK[n]=s[n];this.RULE_STACK_IDX=s.length-1,this.RULE_STACK_IDX>=0&&(this.currRuleShortName=this.RULE_STACK[this.RULE_STACK_IDX],this.currRuleLookaheadFuncs=this.lookAheadFuncsCache[this.currRuleShortName])}ruleInvocationStateUpdate(e,s,n){this.RULE_OCCURRENCE_STACK[++this.RULE_OCCURRENCE_STACK_IDX]=n,this.RULE_STACK[++this.RULE_STACK_IDX]=e,this.currRuleShortName=e,this.currRuleLookaheadFuncs=this.lookAheadFuncsCache[e],this.cstInvocationStateUpdate(s)}isBackTracking(){return this.isBackTrackingStack.length!==0}getCurrRuleFullName(){const e=this.currRuleShortName;return this.shortRuleNameToFull[e]}shortRuleNameToFullName(e){return this.shortRuleNameToFull[e]}isAtEndOfInput(){return this.tokenMatcher(this.LA(1),le)}reset(){this.resetLexerState(),this.subruleIdx=0,this.currRuleShortName=-1,this.currRuleLookaheadFuncs=[],this.isBackTrackingStack=[],this.errors=[],this.RULE_STACK_IDX=-1,this.RULE_OCCURRENCE_STACK_IDX=-1,this.CST_STACK=[]}onBeforeParse(e){for(let s=0;s<this.maxLookahead+1;s++)this.tokVector.push(Le)}onAfterParse(e){if(this.isAtEndOfInput()===!1){const s=this.LA(1),n=this.errorMessageProvider.buildNotAllInputParsedMessage({firstRedundant:s,ruleName:this.getCurrRuleFullName()});this.SAVE_ERROR(new Ar(n,s))}for(;this.tokVector.at(-1)===Le;)this.tokVector.pop()}}class $r{initErrorHandler(e){this._errors=[],this.errorMessageProvider=Object.hasOwn(e,"errorMessageProvider")?e.errorMessageProvider:ce.errorMessageProvider}SAVE_ERROR(e){if(Et(e))return e.context={ruleStack:this.getHumanReadableRuleStack(),ruleOccurrenceStack:this.RULE_OCCURRENCE_STACK.slice(0,this.RULE_OCCURRENCE_STACK_IDX+1)},this._errors.push(e),e;throw Error("Trying to save an Error which is not a RecognitionException")}get errors(){return[...this._errors]}set errors(e){this._errors=e}raiseEarlyExitException(e,s,n){const i=this.getCurrRuleFullName(),a=this.getGAstProductions()[i],l=as(e,a,s,this.maxLookahead)[0],r=[];for(let d=1;d<=this.maxLookahead;d++)r.push(this.LA(d));const h=this.errorMessageProvider.buildEarlyExitMessage({expectedIterationPaths:l,actual:r,previous:this.LA(0),customUserDescription:n,ruleName:i});throw this.SAVE_ERROR(new Sr(h,this.LA(1),this.LA(0)))}raiseNoAltException(e,s){const n=this.getCurrRuleFullName(),i=this.getGAstProductions()[n],a=is(e,i,this.maxLookahead),o=[];for(let h=1;h<=this.maxLookahead;h++)o.push(this.LA(h));const l=this.LA(0),r=this.errorMessageProvider.buildNoViableAltMessage({expectedPathsPerAlt:a,actual:o,previous:l,customUserDescription:s,ruleName:this.getCurrRuleFullName()});throw this.SAVE_ERROR(new gr(r,this.LA(1),l))}}const Ot={description:"This Object indicates the Parser is during Recording Phase"};Object.freeze(Ot);const Us=!0,Ps=255,kn=A({name:"RECORDING_PHASE_TOKEN",pattern:F.NA});He([kn]);const Nn=ns(kn,`This IToken indicates the Parser is in Recording Phase
98
- See: https://chevrotain.io/docs/guide/internals.html#grammar-recording for details`,-1,-1,-1,-1,-1,-1);Object.freeze(Nn);const jr={name:`This CSTNode indicates the Parser is in Recording Phase
99
- See: https://chevrotain.io/docs/guide/internals.html#grammar-recording for details`,children:{}};class Gr{initGastRecorder(e){this.recordingProdStack=[],this.RECORDING_PHASE=!1}enableRecording(){this.RECORDING_PHASE=!0,this.TRACE_INIT("Enable Recording",()=>{for(let e=0;e<10;e++){const s=e>0?e:"";this[`CONSUME${s}`]=function(n,i){return this.consumeInternalRecord(n,e,i)},this[`SUBRULE${s}`]=function(n,i){return this.subruleInternalRecord(n,e,i)},this[`OPTION${s}`]=function(n){return this.optionInternalRecord(n,e)},this[`OR${s}`]=function(n){return this.orInternalRecord(n,e)},this[`MANY${s}`]=function(n){this.manyInternalRecord(e,n)},this[`MANY_SEP${s}`]=function(n){this.manySepFirstInternalRecord(e,n)},this[`AT_LEAST_ONE${s}`]=function(n){this.atLeastOneInternalRecord(e,n)},this[`AT_LEAST_ONE_SEP${s}`]=function(n){this.atLeastOneSepFirstInternalRecord(e,n)}}this.consume=function(e,s,n){return this.consumeInternalRecord(s,e,n)},this.subrule=function(e,s,n){return this.subruleInternalRecord(s,e,n)},this.option=function(e,s){return this.optionInternalRecord(s,e)},this.or=function(e,s){return this.orInternalRecord(s,e)},this.many=function(e,s){this.manyInternalRecord(e,s)},this.atLeastOne=function(e,s){this.atLeastOneInternalRecord(e,s)},this.ACTION=this.ACTION_RECORD,this.BACKTRACK=this.BACKTRACK_RECORD,this.LA=this.LA_RECORD})}disableRecording(){this.RECORDING_PHASE=!1,this.TRACE_INIT("Deleting Recording methods",()=>{const e=this;for(let s=0;s<10;s++){const n=s>0?s:"";delete e[`CONSUME${n}`],delete e[`SUBRULE${n}`],delete e[`OPTION${n}`],delete e[`OR${n}`],delete e[`MANY${n}`],delete e[`MANY_SEP${n}`],delete e[`AT_LEAST_ONE${n}`],delete e[`AT_LEAST_ONE_SEP${n}`]}delete e.consume,delete e.subrule,delete e.option,delete e.or,delete e.many,delete e.atLeastOne,delete e.ACTION,delete e.BACKTRACK,delete e.LA})}ACTION_RECORD(e){}BACKTRACK_RECORD(e,s){return()=>!0}LA_RECORD(e){return Le}topLevelRuleRecord(e,s){try{const n=new Ie({definition:[],name:e});return n.name=e,this.recordingProdStack.push(n),s.call(this),this.recordingProdStack.pop(),n}catch(n){if(n.KNOWN_RECORDER_ERROR!==!0)try{n.message=n.message+`
100
- This error was thrown during the "grammar recording phase" For more info see:
101
- https://chevrotain.io/docs/guide/internals.html#grammar-recording`}catch{throw n}throw n}}optionInternalRecord(e,s){return Me.call(this,G,e,s)}atLeastOneInternalRecord(e,s){Me.call(this,se,s,e)}atLeastOneSepFirstInternalRecord(e,s){Me.call(this,ne,s,e,Us)}manyInternalRecord(e,s){Me.call(this,M,s,e)}manySepFirstInternalRecord(e,s){Me.call(this,J,s,e,Us)}orInternalRecord(e,s){return Wr.call(this,e,s)}subruleInternalRecord(e,s,n){if(Tt(s),!e||!Object.hasOwn(e,"ruleName")){const l=new Error(`<SUBRULE${Ds(s)}> argument is invalid expecting a Parser method reference but got: <${JSON.stringify(e)}>
102
- inside top level rule: <${this.recordingProdStack[0].name}>`);throw l.KNOWN_RECORDER_ERROR=!0,l}const i=this.recordingProdStack.at(-1),a=e.ruleName,o=new K({idx:s,nonTerminalName:a,label:n?.LABEL,referencedRule:void 0});return i.definition.push(o),this.outputCst?jr:Ot}consumeInternalRecord(e,s,n){if(Tt(s),!rn(e)){const o=new Error(`<CONSUME${Ds(s)}> argument is invalid expecting a TokenType reference but got: <${JSON.stringify(e)}>
103
- inside top level rule: <${this.recordingProdStack[0].name}>`);throw o.KNOWN_RECORDER_ERROR=!0,o}const i=this.recordingProdStack.at(-1),a=new k({idx:s,terminalType:e,label:n?.LABEL});return i.definition.push(a),Nn}}function Me(t,e,s,n=!1){Tt(s);const i=this.recordingProdStack.at(-1),a=typeof e=="function"?e:e.DEF,o=new t({definition:[],idx:s});return n&&(o.separator=e.SEP),Object.hasOwn(e,"MAX_LOOKAHEAD")&&(o.maxLookahead=e.MAX_LOOKAHEAD),this.recordingProdStack.push(o),a.call(this),i.definition.push(o),this.recordingProdStack.pop(),Ot}function Wr(t,e){Tt(e);const s=this.recordingProdStack.at(-1),n=Array.isArray(t)===!1,i=n===!1?t:t.DEF,a=new Z({definition:[],idx:e,ignoreAmbiguities:n&&t.IGNORE_AMBIGUITIES===!0});Object.hasOwn(t,"MAX_LOOKAHEAD")&&(a.maxLookahead=t.MAX_LOOKAHEAD);const o=i.some(l=>typeof l.GATE=="function");return a.hasPredicates=o,s.definition.push(a),i.forEach(l=>{const r=new W({definition:[]});a.definition.push(r),Object.hasOwn(l,"IGNORE_AMBIGUITIES")?r.ignoreAmbiguities=l.IGNORE_AMBIGUITIES:Object.hasOwn(l,"GATE")&&(r.ignoreAmbiguities=!0),this.recordingProdStack.push(r),l.ALT.call(this),this.recordingProdStack.pop()}),Ot}function Ds(t){return t===0?"":`${t}`}function Tt(t){if(t<0||t>Ps){const e=new Error(`Invalid DSL Method idx value: <${t}>
104
- Idx value must be a none negative value smaller than ${Ps+1}`);throw e.KNOWN_RECORDER_ERROR=!0,e}}class Kr{initPerformanceTracer(e){if(Object.hasOwn(e,"traceInitPerf")){const s=e.traceInitPerf,n=typeof s=="number";this.traceInitMaxIdent=n?s:1/0,this.traceInitPerf=n?s>0:s}else this.traceInitMaxIdent=0,this.traceInitPerf=ce.traceInitPerf;this.traceInitIndent=-1}TRACE_INIT(e,s){if(this.traceInitPerf===!0){this.traceInitIndent++;const n=new Array(this.traceInitIndent+1).join(" ");this.traceInitIndent<this.traceInitMaxIdent&&console.log(`${n}--> <${e}>`);const{time:i,value:a}=qs(s),o=i>10?console.warn:console.log;return this.traceInitIndent<this.traceInitMaxIdent&&o(`${n}<-- <${e}> time: ${i}ms`),this.traceInitIndent--,a}else return s()}}function Vr(t,e){e.forEach(s=>{const n=s.prototype;Object.getOwnPropertyNames(n).forEach(i=>{if(i==="constructor")return;const a=Object.getOwnPropertyDescriptor(n,i);a&&(a.get||a.set)?Object.defineProperty(t.prototype,i,a):t.prototype[i]=s.prototype[i]})})}const Le=ns(le,"",-1,-1,-1,-1,-1,-1);Object.freeze(Le);const ce=Object.freeze({recoveryEnabled:!1,maxLookahead:3,dynamicTokensEnabled:!1,outputCst:!0,errorMessageProvider:cn,nodeLocationTracking:"none",traceInitPerf:!1,skipValidations:!1}),gt=Object.freeze({recoveryValueFunc:()=>{},resyncEnabled:!0});var $;(function(t){t[t.INVALID_RULE_NAME=0]="INVALID_RULE_NAME",t[t.DUPLICATE_RULE_NAME=1]="DUPLICATE_RULE_NAME",t[t.INVALID_RULE_OVERRIDE=2]="INVALID_RULE_OVERRIDE",t[t.DUPLICATE_PRODUCTIONS=3]="DUPLICATE_PRODUCTIONS",t[t.UNRESOLVED_SUBRULE_REF=4]="UNRESOLVED_SUBRULE_REF",t[t.LEFT_RECURSION=5]="LEFT_RECURSION",t[t.NONE_LAST_EMPTY_ALT=6]="NONE_LAST_EMPTY_ALT",t[t.AMBIGUOUS_ALTS=7]="AMBIGUOUS_ALTS",t[t.CONFLICT_TOKENS_RULES_NAMESPACE=8]="CONFLICT_TOKENS_RULES_NAMESPACE",t[t.INVALID_TOKEN_NAME=9]="INVALID_TOKEN_NAME",t[t.NO_NON_EMPTY_LOOKAHEAD=10]="NO_NON_EMPTY_LOOKAHEAD",t[t.AMBIGUOUS_PREFIX_ALTS=11]="AMBIGUOUS_PREFIX_ALTS",t[t.TOO_MANY_ALTS=12]="TOO_MANY_ALTS",t[t.CUSTOM_LOOKAHEAD_VALIDATION=13]="CUSTOM_LOOKAHEAD_VALIDATION"})($||($={}));class Xe{static performSelfAnalysis(e){throw Error("The **static** `performSelfAnalysis` method has been deprecated. \nUse the **instance** method with the same name instead.")}performSelfAnalysis(){this.TRACE_INIT("performSelfAnalysis",()=>{let e;this.selfAnalysisDone=!0;const s=this.className;this.TRACE_INIT("toFastProps",()=>{Js(this)}),this.TRACE_INIT("Grammar Recording",()=>{try{this.enableRecording(),this.definedRulesNames.forEach(i=>{const o=this[i].originalGrammarAction;let l;this.TRACE_INIT(`${i} Rule`,()=>{l=this.topLevelRuleRecord(i,o)}),this.gastProductionsCache[i]=l})}finally{this.disableRecording()}});let n=[];if(this.TRACE_INIT("Grammar Resolving",()=>{n=Er({rules:Object.values(this.gastProductionsCache)}),this.definitionErrors=this.definitionErrors.concat(n)}),this.TRACE_INIT("Grammar Validations",()=>{if(n.length===0&&this.skipValidations===!1){const i=Tr({rules:Object.values(this.gastProductionsCache),tokenTypes:Object.values(this.tokensMap),errMsgProvider:Ee,grammarName:s}),a=tr({lookaheadStrategy:this.lookaheadStrategy,rules:Object.values(this.gastProductionsCache),tokenTypes:Object.values(this.tokensMap),grammarName:s});this.definitionErrors=this.definitionErrors.concat(i,a)}}),this.definitionErrors.length===0&&(this.recoveryEnabled&&this.TRACE_INIT("computeAllProdsFollows",()=>{const i=Hi(Object.values(this.gastProductionsCache));this.resyncFollows=i}),this.TRACE_INIT("ComputeLookaheadFunctions",()=>{var i,a;(a=(i=this.lookaheadStrategy).initialize)===null||a===void 0||a.call(i,{rules:Object.values(this.gastProductionsCache)}),this.preComputeLookaheadFunctions(Object.values(this.gastProductionsCache))})),!Xe.DEFER_DEFINITION_ERRORS_HANDLING&&this.definitionErrors.length!==0)throw e=this.definitionErrors.map(i=>i.message),new Error(`Parser Definition Errors detected:
105
- ${e.join(`
106
- -------------------------------
107
- `)}`)})}constructor(e,s){this.definitionErrors=[],this.selfAnalysisDone=!1;const n=this;if(n.initErrorHandler(s),n.initLexerAdapter(),n.initLooksAhead(s),n.initRecognizerEngine(e,s),n.initRecoverable(s),n.initTreeBuilder(s),n.initGastRecorder(s),n.initPerformanceTracer(s),Object.hasOwn(s,"ignoredIssues"))throw new Error(`The <ignoredIssues> IParserConfig property has been deprecated.
108
- Please use the <IGNORE_AMBIGUITIES> flag on the relevant DSL method instead.
109
- See: https://chevrotain.io/docs/guide/resolving_grammar_errors.html#IGNORING_AMBIGUITIES
110
- For further details.`);this.skipValidations=Object.hasOwn(s,"skipValidations")?s.skipValidations:ce.skipValidations}}Xe.DEFER_DEFINITION_ERRORS_HANDLING=!1;Vr(Xe,[Rr,Ir,Pr,Dr,Br,Fr,$r,Gr,Kr]);class zr extends Xe{constructor(e,s=ce){const n=Object.assign({},s);n.outputCst=!0,super(e,n)}}var Re=c(t=>t!==void 0&&t>=0,"isKnownLocation");function Cn(t,e){const s=t.lexer.tokenize(e);if(s.errors.length>0){const i=s.errors[0],a=Re(i.offset)?i.offset:e.length,o=a+(Re(i.length)?i.length:0);throw new Error(`Error lexing ${t.diagramType} diagram: ${i.message} at line ${i.line??1}, column ${i.column??1} [${a},${o})`)}t.parser.input=s.tokens;const n=t.entry();if(t.parser.errors.length>0)throw new Error(`Error parsing ${t.diagramType} diagram: ${t.parser.errors[0].message}`);t.visit(n)}c(Cn,"runChevrotainParse");var I={SOLID_ARROW:0,BACK_ARROW:1,LINE_SOLID:2,CIRCLE_ARROW:3,CROSS_ARROW:4,CIRCLE_ARROW_REVERSED:5,CROSS_ARROW_REVERSED:6},Hr="LR",Xr=_i.usecase,os=c(()=>({actors:new Map,useCases:new Map,systemBoundaries:new Map,relationships:[],notes:new Map,jsonNodes:new Map,classDefs:new Map,symbols:new Map,direction:Hr,relationshipCounter:0,noteCounter:0,accTitle:"",accDescription:"",ast:void 0,config:structuredClone(Xr)}),"createModel"),Yr=c(t=>{if(!(t.actors instanceof Map)||!(t.useCases instanceof Map)||!(t.systemBoundaries instanceof Map)||!Array.isArray(t.relationships)||!(t.notes instanceof Map)||!(t.jsonNodes instanceof Map)||!(t.classDefs instanceof Map)||!(t.symbols instanceof Map)||!["TB","TD","BT","RL","LR"].includes(t.direction)||!Number.isSafeInteger(t.relationshipCounter)||t.relationshipCounter<0||!Number.isSafeInteger(t.noteCounter)||t.noteCounter<0||typeof t.accTitle!="string"||typeof t.accDescription!="string"||!t.config)throw new Error("Cannot commit an incomplete usecase model")},"assertCompleteModel"),O=os(),qr=c(()=>structuredClone(O.config),"getConfig"),Jr=c(()=>O.ast,"getAST"),Zr=c(t=>{const e=structuredClone(t);Yr(e);const s=Hs(),n=zs();try{Pt(e.accTitle),Ut(e.accDescription),O=e}catch(i){throw Pt(s),Ut(n),i}},"commit"),Qr=c(()=>{O=os(),vi()},"clear"),eo=c(()=>O.actors,"getActors"),to=c(t=>O.actors.get(t),"getActor"),so=c(()=>O.useCases,"getUseCases"),no=c(t=>O.useCases.get(t),"getUseCase"),io=c(()=>O.systemBoundaries,"getSystemBoundaries"),ao=c(t=>O.systemBoundaries.get(t),"getSystemBoundary"),ro=c(()=>O.relationships,"getRelationships"),oo=c(()=>O.notes,"getNotes"),lo=c(t=>O.notes.get(t),"getNote"),co=c(()=>O.jsonNodes,"getJsonNodes"),ho=c(t=>O.jsonNodes.get(t),"getJsonNode"),uo=c(()=>O.classDefs,"getClassDefs"),fo=c(t=>O.classDefs.get(t),"getClassDef"),bn=c(()=>O.direction,"getDirection"),pe=c(t=>{const e=new Map;for(const s of["default",...t]){const n=O.classDefs.get(s);if(n)for(const i of n.styles){const a=i.trim(),o=a.indexOf(":"),l=(o===-1?a:a.slice(0,o)).trim();l&&e.set(l,a)}}return[...e.values()]},"getCompiledStyles"),po=c(t=>t.replaceAll("~","~0").replaceAll("/","~1"),"escapeJsonPointerPart"),Fs=c(t=>typeof t=="string"?t:t===null?"null":String(t),"displayJsonScalar"),mo=c((t,e,s=n=>n)=>{const n=[],i=c((o,l,r)=>{n.push({key:s(o),accessibleKey:s(l),value:s(r)})},"append"),a=c((o,l,r)=>{if(Array.isArray(o)){if(o.length===0){i(l,l,"[]");return}if(o.every(d=>d===null||["string","number","boolean"].includes(typeof d))){for(const[d,u]of o.entries())i(d===0?l:"",l,Fs(u));return}for(const[d,u]of o.entries())a(u,`${l}[${d}]`,`${r}/${d}`);return}if(o!==null&&typeof o=="object"){const h=o,d=e[r]??Object.keys(h);if(d.length===0){i(l,l,"{}");return}for(const u of d){const f=l?`${l}.${u}`:u;a(h[u],f,`${r}/${po(u)}`)}return}i(l,l,Fs(o))},"visit");return a(t,"",""),n},"flattenJsonRows"),Eo=c(t=>{switch(t.type){case"hollow":return"usecaseActorHollow";case"awesome":return"usecaseActorAwesome";case"icon":return"usecaseActorIcon";case"normal":return"usecaseActor"}},"actorShape"),To=c(t=>t.shape==="ellipse"?t.business?"usecaseBusiness":"usecaseEllipse":t.shape,"useCaseShape"),go=c(t=>{switch(t){case I.SOLID_ARROW:return{arrowTypeStart:"none",arrowTypeEnd:"arrow_point"};case I.BACK_ARROW:return{arrowTypeStart:"arrow_point",arrowTypeEnd:"none"};case I.CIRCLE_ARROW:return{arrowTypeStart:"none",arrowTypeEnd:"arrow_circle"};case I.CROSS_ARROW:return{arrowTypeStart:"none",arrowTypeEnd:"arrow_cross"};case I.CIRCLE_ARROW_REVERSED:return{arrowTypeStart:"arrow_circle",arrowTypeEnd:"none"};case I.CROSS_ARROW_REVERSED:return{arrowTypeStart:"arrow_cross",arrowTypeEnd:"none"};case I.LINE_SOLID:return{arrowTypeStart:"none",arrowTypeEnd:"none"}}},"associationMarkers"),Ao=c(t=>{switch(t.type){case"include":case"extend":return{arrowTypeStart:"none",arrowTypeEnd:"arrow_point",pattern:"dotted",label:t.type,labelType:"text"};case"generalization":return{arrowTypeStart:"none",arrowTypeEnd:"extension",pattern:"solid"};case"association":return{...go(t.arrowType),pattern:"solid",...t.label?{label:t.label}:{},...t.labelType?{labelType:t.labelType}:{}}}},"relationshipVisuals"),So=c(t=>t.animate||t.animation?[`edge-animation-${t.animation??"fast"}`]:[],"animationClasses"),we=c((...t)=>t.filter(e=>!!e).join(" "),"classNames"),yo=c(()=>{const t=Xs(),e={...O.config,...t.usecase},s=c(r=>bi(r,t),"sanitize"),n=c(r=>s(O.actors.get(r)?.label??O.useCases.get(r)?.label??O.jsonNodes.get(r)?.id??O.notes.get(r)?.label??r),"endpointLabel"),i=[],a=[];let o=0,l=0;for(const r of O.actors.values())i.push({id:r.id,label:s(r.label),labelType:r.labelType,shape:Eo(r),isGroup:!1,padding:10,look:t.look,colorIndex:o++,cssClasses:we("default","usecase-actor",`usecase-actor-${r.type}`,r.business&&"usecase-business",...r.classes),cssStyles:[...r.styles],cssCompiledStyles:pe(r.classes),actorType:r.type,business:r.business,...r.icon?{icon:r.icon}:{},...r.stereotype?{stereotype:s(r.stereotype)}:{},...r.parentId?{parentId:r.parentId}:{}});for(const r of O.useCases.values())i.push({id:r.id,label:s(r.label),labelType:r.labelType,shape:To(r),isGroup:!1,padding:r.shape==="ellipse"?20:10,look:t.look,colorIndex:o++,cssClasses:we("default","usecase-element",`usecase-${r.shape}`,r.business&&"usecase-business",...r.classes),cssStyles:[...r.styles],cssCompiledStyles:pe(r.classes),business:r.business,...r.stereotype?{stereotype:s(r.stereotype)}:{},...r.parentId?{parentId:r.parentId}:{}});for(const r of O.notes.values())i.push({id:r.id,label:s(r.label),labelType:r.labelType,shape:"note",isGroup:!1,padding:10,look:t.look,cssClasses:"default usecase-note",cssStyles:[],cssCompiledStyles:pe([]),noteTarget:r.target,noteTargetLabel:s(O.actors.get(r.target)?.label??O.useCases.get(r.target)?.label??O.jsonNodes.get(r.target)?.id??r.target)});for(const r of O.jsonNodes.values())i.push({id:r.id,label:s(r.id),labelType:"text",shape:"usecaseJsonTable",isGroup:!1,padding:10,look:t.look,cssClasses:we("default","usecase-json-table",...r.classes),cssStyles:[...r.styles],cssCompiledStyles:pe(r.classes),jsonRows:mo(r.value,r.propertyOrder,s)});for(const r of O.systemBoundaries.values())i.push({id:r.id,label:s(r.label),labelType:r.labelType,shape:"usecaseSystemBoundary",isGroup:!0,padding:20,look:t.look,colorIndex:l++,cssClasses:we("default","system-boundary",`system-boundary-${r.type}`,...r.classes),cssStyles:[...r.styles],cssCompiledStyles:pe(r.classes),boundaryType:r.type});for(const r of O.relationships){const{label:h,...d}=Ao(r);a.push({id:r.id,start:r.source,end:r.target,source:r.source,target:r.target,sourceLabel:n(r.source),targetLabel:n(r.target),type:"edge",relationshipType:r.type,internal:!1,...d,...h!==void 0?{label:s(h)}:{},labelpos:"c",classes:we("default","relationship",`relationship-${r.type}`,...r.classes,...So(r)),style:[...r.styles],cssCompiledStyles:pe(r.classes),animate:r.animate,...r.animation?{animation:r.animation}:{},look:t.look,thickness:"normal",minlen:r.minlen,isUserDefinedId:r.explicitId})}for(const r of O.notes.values())a.push({id:`${r.id}-edge`,start:r.id,end:r.target,source:r.id,target:r.target,type:"edge",relationshipType:"note",sourceLabel:n(r.id),targetLabel:n(r.target),internal:!0,pattern:"dotted",arrowTypeStart:"none",arrowTypeEnd:"none",labelpos:"c",classes:"default relationship relationship-note",style:[],cssCompiledStyles:pe([]),animate:!1,look:t.look,thickness:"normal",minlen:1,isUserDefinedId:!1});for(const r of i)r.wrappingWidth??=e.wrappingWidth,!r.isGroup&&!r.shape.startsWith("usecaseActor")&&(r.minWidth??=e.minNodeWidth),(r.shape==="usecaseEllipse"||r.shape==="usecaseBusiness")&&(r.spreadPorts=!0);return{nodes:i,edges:a,config:t,type:"usecase",layoutAlgorithm:"dagre",direction:bn(),nodeSpacing:e.nodeSpacing,rankSpacing:e.rankSpacing,actorFontSize:e.actorFontSize,actorFontFamily:e.actorFontFamily,actorFontWeight:e.actorFontWeight,usecaseFontSize:e.usecaseFontSize,usecaseFontFamily:e.usecaseFontFamily,usecaseFontWeight:e.usecaseFontWeight,diagramPadding:e.diagramPadding,useMaxWidth:e.useMaxWidth,markers:["point","circle","cross","extension"]}},"getData"),At={getConfig:qr,createModel:os,commit:Zr,getAST:Jr,clear:Qr,setDiagramTitle:Li,getDiagramTitle:Oi,setAccTitle:Pt,getAccTitle:Hs,setAccDescription:Ut,getAccDescription:zs,getActors:eo,getActor:to,getUseCases:so,getUseCase:no,getSystemBoundaries:io,getSystemBoundary:ao,getRelationships:ro,getNotes:oo,getNote:lo,getJsonNodes:co,getJsonNode:ho,getClassDefs:uo,getClassDef:fo,getDirection:bn,getData:yo};function ge(t,e,s){const n=[s];return n.index=e,n.input=t,n}c(ge,"customMatch");var Ro=c((t,e)=>{if(t[e]!=='"'||t[e+1]!=="`")return null;for(let s=e+2;s<t.length-1;s++)if(t[s]==="`"&&t[s+1]==='"')return ge(t,e,t.slice(e,s+2));return null},"matchMarkdownString"),Oo=c((t,e)=>{if(t[e]!=="%"||t[e+1]!=="%")return null;for(let n=e-1;n>=0;n--){const i=t[n];if(i===`
111
- `||i==="\r")break;if(i!==" "&&i!==" ")return null}let s=e+2;for(;s<t.length&&t[s]!==`
112
- `&&t[s]!=="\r";)s++;return ge(t,e,t.slice(e,s))},"matchComment"),vn=c((t,e)=>{for(let s=e-1;s>=0;s--){const n=t[s];if(n===`
113
- `||n==="\r")return!0;if(n!==" "&&n!==" ")return!1}return!0},"isIndentedLineStart"),_n=c((t,e,s)=>{if(!vn(t,e))return null;const n=s.exec(t.slice(e));return n?ge(t,e,n[0]):null},"matchAccessibilityLine"),Lo=c((t,e)=>{if(!vn(t,e))return null;const s=/^accDescr[\t ]*{/.exec(t.slice(e));if(!s)return null;const n=t.indexOf("}",e+s[0].length);return n===-1?null:ge(t,e,t.slice(e,n+1))},"matchAccDescrBlock"),Io=c((t,e)=>{if(t[e]!=="{")return null;let s=0,n=!1,i=!1;for(let a=e;a<t.length;a++){const o=t[a];if(n){i?i=!1:o==="\\"?i=!0:o==='"'&&(n=!1);continue}if(o==='"')n=!0;else if(o==="{")s++;else if(o==="}"&&--s===0)return ge(t,e,t.slice(e,a+1))}return null},"matchJsonObject"),ko=c((t,e)=>{const s=t.indexOf(">>",e);if(s===-1||/[\n\r]/.test(t.slice(e,s)))return null;const n=t.slice(e,s);return n.trim()?ge(t,e,n):null},"matchStereotypeText"),w=A({name:"LABEL_TEXT",pattern:F.NA}),Oe=A({name:"WORD",pattern:F.NA,categories:w}),ls=A({name:"NUMBER",pattern:/(?:\d+\.\d+|\d+|\.\d+)(?:[A-Za-z]+)?/,categories:w}),N=A({name:"IDENTIFIER",pattern:/\w+/,longer_alt:ls,categories:Oe}),No=A({name:"HWS",pattern:/[\t ]+/,group:F.SKIPPED}),oe=A({name:"MARKDOWN_STRING",pattern:Ro,start_chars_hint:['"'],line_breaks:!0}),Co=A({name:"UNCLOSED_MARKDOWN_STRING",pattern:/"`[^]*/,line_breaks:!0}),Yt=A({name:"COMMENT",pattern:Oo,start_chars_hint:["%"],line_breaks:!1}),re=A({name:"NEWLINE",pattern:/\r\n|\n|\r/,line_breaks:!0}),xn=A({name:"ACC_DESCR_BLOCK",pattern:Lo,start_chars_hint:["a"],line_breaks:!0}),bo=/^accTitle[\t ]*:[^\n\r]*/,vo=/^accDescr[\t ]*:[^\n\r]*/,Mn=A({name:"ACC_TITLE_LINE",pattern:c((t,e)=>_n(t,e,bo),"pattern"),start_chars_hint:["a"],line_breaks:!1}),wn=A({name:"ACC_DESCR_LINE",pattern:c((t,e)=>_n(t,e,vo),"pattern"),start_chars_hint:["a"],line_breaks:!1}),Un=A({name:"JSON_DECLARATION_START",pattern:/json[\t ]+\w+[\t ]*@[\t ]*(?={)/,push_mode:"jsonBody"}),cs=A({name:"JSON_OBJECT_LITERAL",pattern:Io,start_chars_hint:["{"],line_breaks:!0,pop_mode:!0}),Pn=A({name:"UNCLOSED_JSON_OBJECT_LITERAL",pattern:/{[^]*/,line_breaks:!0,pop_mode:!0}),_=c((t,e)=>A({name:t,pattern:e,longer_alt:N,categories:Oe}),"keyword"),Dn=_("USECASE",/usecase-beta/),qt=_("ACTOR",/actor/),Fn=_("SYSTEM_BOUNDARY",/systemBoundary/),Bn=_("END",/end/),$n=_("DIRECTION",/direction/),jn=_("TD",/TD/),Gn=_("TB",/TB/),Wn=_("BT",/BT/),Kn=_("LR",/LR/),Vn=_("RL",/RL/),zn=_("NOTE",/note/),Hn=_("FOR",/for/),_o=_("JSON",/json/),Xn=_("CLASS_DEF",/classDef/),Yn=_("CLASS",/class/),qn=_("STYLE",/style/),Jn=_("INCLUDE",/include/i),Zn=_("EXTEND",/extend/i),Qn=_("TRUE",/true/),ei=_("FALSE",/false/),ti=A({name:"GENERALIZATION",pattern:/--\|>/}),si=A({name:"DEPENDENCY_ARROW",pattern:/\.\.>/}),ni=A({name:"STEREOTYPE_START",pattern:/<</,push_mode:"stereotype"}),hs=A({name:"STEREOTYPE_END",pattern:/>>/,pop_mode:!0}),us=A({name:"STEREOTYPE_TEXT",pattern:ko,line_breaks:!1}),ii=A({name:"UNCLOSED_STEREOTYPE_TEXT",pattern:/[^\n\r]+/,line_breaks:!1,pop_mode:!0}),ai=A({name:"CLASS_SEPARATOR",pattern:/:::/}),at=A({name:"FORWARD_SOLID",pattern:/--+>/}),ri=A({name:"BACKWARD_SOLID",pattern:/<--+/}),rt=A({name:"FORWARD_CIRCLE",pattern:/--o/}),oi=A({name:"BACKWARD_CIRCLE",pattern:/o--/}),ot=A({name:"FORWARD_CROSS",pattern:/--x/}),li=A({name:"BACKWARD_CROSS",pattern:/x--/}),H=A({name:"MARKERLESS_SOLID",pattern:/--+/}),Jt=A({name:"METADATA_START",pattern:/@{/}),lt=A({name:"AT",pattern:/@/,categories:w}),ci=A({name:"LBRACE",pattern:/{/}),Zt=A({name:"RBRACE",pattern:/}/}),ct=A({name:"LBRACKET",pattern:/\[/}),ht=A({name:"RBRACKET",pattern:/]/}),Be=A({name:"LPAREN",pattern:/\(/}),$e=A({name:"RPAREN",pattern:/\)/}),q=A({name:"COMMA",pattern:/,/,categories:w}),je=A({name:"COLON",pattern:/:/,categories:w}),hi=A({name:"HASH_COLOR",pattern:/#[\dA-Fa-f]+/,categories:w}),X=A({name:"PLAIN_STRING",pattern:/"[^\n\r"]*"|'[^\n\r']*'/}),Qt=A({name:"CSS_IDENTIFIER",pattern:/--[A-Z_a-z][\w-]*|[A-Z_a-z]\w*(?:-\w+)+/,categories:w}),ui=A({name:"CSS_ESCAPED_COMMA",pattern:/\\,/,categories:w}),di=A({name:"DASH",pattern:/-/,categories:w}),fi=A({name:"DOT",pattern:/\./,categories:w}),pi=A({name:"PERCENT",pattern:/%/,categories:w}),mi=A({name:"CSS_PUNCTUATION",pattern:/[!#$&*+/=?^_|~]/,categories:w}),xo=A({name:"LABEL_PUNCTUATION",pattern:/[;<>\\`]/,categories:w}),Mo=A({name:"LABEL_SYMBOL",pattern:/[^\t\n\r !-~]+/,categories:w}),Ei=[w,Oe,No,oe,Co,Yt,re,xn,Mn,wn,Un,Dn,qt,Fn,Bn,$n,jn,Gn,Wn,Kn,Vn,zn,Hn,_o,Xn,Yn,qn,Jn,Zn,Qn,ei,ti,si,ni,ai,at,ri,rt,oi,ot,li,H,Jt,lt,ci,Zt,ct,ht,Be,$e,q,je,hi,X,Qt,N,ls,ui,di,fi,pi,mi,xo,Mo],wo={defaultMode:"defaultMode",modes:{defaultMode:[...Ei],jsonBody:[cs,Pn],stereotype:[hs,us,ii]}},Uo=[...Ei,cs,Pn,hs,us,ii],Po=new F(wo),Bs=c(t=>ln(t,w)||t.tokenType===X||t.tokenType===oe,"isLabelToken"),Do={allowmixing:!0,newpage:!0,package:!0,rectangle:!0,skinparam:!0},Fo=class extends zr{static{c(this,"UsecaseParser")}constructor(){super(Uo,{nodeLocationTracking:"full"}),this.RULE("start",()=>{this.CONSUME(Dn),this.SUBRULE(this.lineEnd),this.MANY(()=>this.SUBRULE(this.line))}),this.RULE("line",()=>{this.OR([{ALT:c(()=>this.SUBRULE(this.blankLine),"ALT")},{ALT:c(()=>this.SUBRULE(this.commentLine),"ALT")},{GATE:c(()=>this.isStatementStart(),"GATE"),ALT:c(()=>this.SUBRULE(this.statement),"ALT")}])}),this.RULE("statement",()=>{this.OR([{ALT:c(()=>this.SUBRULE(this.accTitleStatement),"ALT")},{ALT:c(()=>this.SUBRULE(this.accDescrStatement),"ALT")},{ALT:c(()=>this.SUBRULE(this.directionStatement),"ALT")},{ALT:c(()=>this.SUBRULE(this.actorStatement),"ALT")},{ALT:c(()=>this.SUBRULE(this.systemBoundaryStatement),"ALT")},{ALT:c(()=>this.SUBRULE(this.noteStatement),"ALT")},{ALT:c(()=>this.SUBRULE(this.jsonStatement),"ALT")},{ALT:c(()=>this.SUBRULE(this.classDefStatement),"ALT")},{ALT:c(()=>this.SUBRULE(this.classStatement),"ALT")},{ALT:c(()=>this.SUBRULE(this.styleStatement),"ALT")},{GATE:c(()=>this.isMetadataAssignment(),"GATE"),ALT:c(()=>this.SUBRULE(this.metadataAssignmentStatement),"ALT")},{GATE:c(()=>!this.isForbiddenPlantUmlStatement(),"GATE"),ALT:c(()=>this.SUBRULE(this.entityStatement),"ALT")}])}),this.RULE("lineEnd",()=>{this.OR([{ALT:c(()=>this.CONSUME(re),"ALT")},{ALT:c(()=>this.CONSUME(le),"ALT")}])}),this.RULE("blankLine",()=>{this.CONSUME(re)}),this.RULE("commentLine",()=>{this.CONSUME(Yt),this.SUBRULE(this.lineEnd)}),this.RULE("accTitleStatement",()=>{this.CONSUME(Mn),this.SUBRULE(this.lineEnd)}),this.RULE("accDescrStatement",()=>{this.OR([{ALT:c(()=>this.CONSUME(wn),"ALT")},{ALT:c(()=>this.CONSUME(xn),"ALT")}]),this.SUBRULE(this.lineEnd)}),this.RULE("actorStatement",()=>{this.CONSUME(qt),this.SUBRULE(this.actorItem),this.OPTION(()=>{this.OR([{ALT:c(()=>this.AT_LEAST_ONE(()=>{this.CONSUME(q),this.SUBRULE2(this.actorItem)}),"ALT")},{ALT:c(()=>this.SUBRULE(this.relationTail),"ALT")}])}),this.SUBRULE(this.lineEnd)}),this.RULE("actorItem",()=>{this.SUBRULE(this.actorName),this.OPTION(()=>this.SUBRULE(this.metadata)),this.OPTION2(()=>this.SUBRULE(this.stereotype)),this.OPTION3(()=>this.SUBRULE(this.classSuffix))}),this.RULE("actorName",()=>{this.OR([{ALT:c(()=>{this.CONSUME(N),this.OPTION(()=>{this.CONSUME(Be),this.SUBRULE(this.nodeLabel),this.CONSUME($e)})},"ALT")},{ALT:c(()=>this.CONSUME(X),"ALT")},{ALT:c(()=>this.CONSUME(oe),"ALT")}])}),this.RULE("actorDeclarationOnly",()=>{this.CONSUME(qt),this.SUBRULE(this.actorItem),this.MANY(()=>{this.CONSUME(q),this.SUBRULE2(this.actorItem)}),this.SUBRULE(this.lineEnd)}),this.RULE("entityStatement",()=>{this.SUBRULE(this.entityName),this.OPTION(()=>this.SUBRULE(this.relationTail)),this.SUBRULE(this.lineEnd)}),this.RULE("entityName",()=>{this.OR([{ALT:c(()=>{this.CONSUME(N),this.OPTION(()=>{this.OR2([{ALT:c(()=>{this.CONSUME(Be),this.SUBRULE(this.nodeLabel),this.CONSUME($e)},"ALT")},{ALT:c(()=>{this.CONSUME(ct),this.SUBRULE2(this.nodeLabel),this.CONSUME(ht)},"ALT")}])})},"ALT")},{ALT:c(()=>this.CONSUME(X),"ALT")},{ALT:c(()=>this.CONSUME(oe),"ALT")}]),this.OPTION2(()=>this.SUBRULE(this.useCaseMetadata)),this.OPTION3(()=>this.SUBRULE(this.stereotype)),this.OPTION4(()=>this.SUBRULE(this.classSuffix))}),this.RULE("nodeLabel",()=>{this.OR([{ALT:c(()=>this.CONSUME(X),"ALT")},{ALT:c(()=>this.CONSUME(oe),"ALT")},{ALT:c(()=>this.AT_LEAST_ONE(()=>this.CONSUME(w)),"ALT")}])}),this.RULE("useCaseMetadata",()=>{this.SUBRULE(this.metadata)}),this.RULE("relationTail",()=>{this.OPTION({GATE:c(()=>this.LA(1).tokenType===N&&this.LA(2).tokenType===lt,"GATE"),DEF:c(()=>{this.CONSUME(N),this.CONSUME(lt)},"DEF")}),this.SUBRULE(this.arrow),this.SUBRULE(this.entityName)}),this.RULE("arrow",()=>{this.OR([{ALT:c(()=>this.SUBRULE(this.semanticRelation),"ALT")},{ALT:c(()=>this.SUBRULE(this.forwardSolidOperator),"ALT")},{ALT:c(()=>this.SUBRULE(this.backwardSolidOperator),"ALT")},{ALT:c(()=>this.SUBRULE(this.markerlessSolidOperator),"ALT")},{ALT:c(()=>this.SUBRULE(this.forwardCircleOperator),"ALT")},{ALT:c(()=>this.SUBRULE(this.backwardCircleOperator),"ALT")},{ALT:c(()=>this.SUBRULE(this.forwardCrossOperator),"ALT")},{ALT:c(()=>this.SUBRULE(this.backwardCrossOperator),"ALT")}])}),this.RULE("forwardSolidOperator",()=>{this.CONSUME(at)}),this.RULE("backwardSolidOperator",()=>{this.CONSUME(ri),this.OPTION({GATE:c(()=>this.LA(0).image==="<--"&&this.hasLabeledRight([H]),"GATE"),DEF:c(()=>{this.SUBRULE(this.edgeLabel),this.CONSUME(H)},"DEF")})}),this.RULE("markerlessSolidOperator",()=>{this.CONSUME(H),this.OPTION({GATE:c(()=>this.LA(0).image==="--"&&this.hasLabeledRight([at,H,rt,ot]),"GATE"),DEF:c(()=>{this.SUBRULE(this.edgeLabel),this.OR([{ALT:c(()=>this.CONSUME(at),"ALT")},{ALT:c(()=>this.CONSUME2(H),"ALT")},{ALT:c(()=>this.CONSUME(rt),"ALT")},{ALT:c(()=>this.CONSUME(ot),"ALT")}])},"DEF")})}),this.RULE("forwardCircleOperator",()=>{this.CONSUME(rt)}),this.RULE("backwardCircleOperator",()=>{this.CONSUME(oi),this.OPTION({GATE:c(()=>this.hasLabeledRight([H]),"GATE"),DEF:c(()=>{this.SUBRULE(this.edgeLabel),this.CONSUME(H)},"DEF")})}),this.RULE("forwardCrossOperator",()=>{this.CONSUME(ot)}),this.RULE("backwardCrossOperator",()=>{this.CONSUME(li),this.OPTION({GATE:c(()=>this.hasLabeledRight([H]),"GATE"),DEF:c(()=>{this.SUBRULE(this.edgeLabel),this.CONSUME(H)},"DEF")})}),this.RULE("edgeLabel",()=>{this.OR([{ALT:c(()=>this.CONSUME(X),"ALT")},{ALT:c(()=>this.CONSUME(oe),"ALT")},{ALT:c(()=>this.AT_LEAST_ONE(()=>this.CONSUME(w)),"ALT")}])}),this.RULE("semanticRelation",()=>{this.OR([{ALT:c(()=>{this.CONSUME(si),this.CONSUME(je),this.OR2([{ALT:c(()=>this.CONSUME(Jn),"ALT")},{ALT:c(()=>this.CONSUME(Zn),"ALT")}])},"ALT")},{ALT:c(()=>this.CONSUME(ti),"ALT")}])}),this.RULE("metadata",()=>{this.CONSUME(Jt),this.MANY(()=>this.CONSUME(re)),this.OPTION(()=>{this.SUBRULE(this.metadataProperty),this.MANY2(()=>{this.SUBRULE(this.metadataSeparator),this.SUBRULE2(this.metadataProperty)}),this.OPTION2(()=>this.CONSUME(q)),this.MANY3(()=>this.CONSUME2(re))}),this.CONSUME(Zt)}),this.RULE("metadataProperty",()=>{this.OR([{ALT:c(()=>this.CONSUME(N),"ALT")},{ALT:c(()=>this.CONSUME(X),"ALT")}]),this.CONSUME(je),this.OR2([{ALT:c(()=>this.CONSUME2(N),"ALT")},{ALT:c(()=>this.CONSUME2(X),"ALT")},{ALT:c(()=>this.CONSUME(Qn),"ALT")},{ALT:c(()=>this.CONSUME(ei),"ALT")}])}),this.RULE("metadataSeparator",()=>{this.OR([{ALT:c(()=>{this.CONSUME(q),this.MANY(()=>this.CONSUME(re))},"ALT")},{ALT:c(()=>{this.AT_LEAST_ONE(()=>this.CONSUME2(re)),this.OPTION(()=>this.CONSUME2(q)),this.MANY2(()=>this.CONSUME3(re))},"ALT")}])}),this.RULE("systemBoundaryStatement",()=>{this.CONSUME(Fn),this.SUBRULE(this.systemBoundaryName),this.OPTION(()=>this.SUBRULE(this.metadata)),this.OPTION2(()=>this.SUBRULE(this.classSuffix)),this.SUBRULE(this.lineEnd),this.SUBRULE(this.systemBoundaryContent),this.CONSUME(Bn),this.SUBRULE2(this.lineEnd)}),this.RULE("systemBoundaryName",()=>{this.OR([{ALT:c(()=>{this.CONSUME(N),this.OPTION(()=>{this.OR2([{ALT:c(()=>{this.CONSUME(Be),this.SUBRULE(this.nodeLabel),this.CONSUME($e)},"ALT")},{ALT:c(()=>{this.CONSUME(ct),this.SUBRULE2(this.nodeLabel),this.CONSUME(ht)},"ALT")}])})},"ALT")},{ALT:c(()=>this.CONSUME(X),"ALT")},{ALT:c(()=>this.CONSUME(oe),"ALT")}])}),this.RULE("systemBoundaryContent",()=>{this.MANY(()=>{this.OR([{ALT:c(()=>this.SUBRULE(this.blankLine),"ALT")},{ALT:c(()=>this.SUBRULE(this.commentLine),"ALT")},{ALT:c(()=>this.SUBRULE(this.boundaryElement),"ALT")}])})}),this.RULE("boundaryElement",()=>{this.OR([{ALT:c(()=>this.SUBRULE(this.actorDeclarationOnly),"ALT")},{ALT:c(()=>{this.SUBRULE(this.entityName),this.SUBRULE(this.lineEnd)},"ALT")}])}),this.RULE("metadataAssignmentStatement",()=>{this.SUBRULE(this.metadataAssignmentTarget),this.SUBRULE(this.metadata),this.SUBRULE(this.lineEnd)}),this.RULE("metadataAssignmentTarget",()=>{this.OR([{ALT:c(()=>this.CONSUME(N),"ALT")},{ALT:c(()=>this.CONSUME(X),"ALT")},{ALT:c(()=>this.CONSUME(oe),"ALT")}])}),this.RULE("noteStatement",()=>{this.CONSUME(zn),this.CONSUME(Hn),this.CONSUME(N),this.SUBRULE(this.nodeLabel),this.SUBRULE(this.lineEnd)}),this.RULE("stereotype",()=>{this.CONSUME(ni),this.CONSUME(us),this.CONSUME(hs)}),this.RULE("classSuffix",()=>{this.CONSUME(ai),this.CONSUME(N),this.MANY(()=>{this.CONSUME(q),this.CONSUME2(N)})}),this.RULE("jsonStatement",()=>{this.CONSUME(Un),this.CONSUME(cs),this.OPTION(()=>this.SUBRULE(this.classSuffix)),this.SUBRULE(this.lineEnd)}),this.RULE("directionStatement",()=>{this.CONSUME($n),this.OR([{ALT:c(()=>this.CONSUME(jn),"ALT")},{ALT:c(()=>this.CONSUME(Gn),"ALT")},{ALT:c(()=>this.CONSUME(Wn),"ALT")},{ALT:c(()=>this.CONSUME(Kn),"ALT")},{ALT:c(()=>this.CONSUME(Vn),"ALT")}]),this.SUBRULE(this.lineEnd)}),this.RULE("classDefStatement",()=>{this.CONSUME(Xn),this.CONSUME(N),this.MANY(()=>{this.CONSUME(q),this.CONSUME2(N)}),this.SUBRULE(this.styles),this.SUBRULE(this.lineEnd)}),this.RULE("classStatement",()=>{this.CONSUME(Yn),this.CONSUME(N),this.MANY(()=>{this.CONSUME(q),this.CONSUME2(N)}),this.CONSUME3(N),this.MANY2(()=>{this.CONSUME2(q),this.CONSUME4(N)}),this.SUBRULE(this.lineEnd)}),this.RULE("styleStatement",()=>{this.CONSUME(qn),this.CONSUME(N),this.SUBRULE(this.styles),this.SUBRULE(this.lineEnd)}),this.RULE("styles",()=>{this.SUBRULE(this.styleValue),this.MANY(()=>{this.CONSUME(q),this.SUBRULE2(this.styleValue)})}),this.RULE("styleValue",()=>{this.OR([{ALT:c(()=>this.CONSUME(Oe),"ALT")},{ALT:c(()=>this.CONSUME(Qt),"ALT")},{ALT:c(()=>{this.CONSUME(H),this.CONSUME2(Oe)},"ALT")}]),this.CONSUME(je),this.AT_LEAST_ONE(()=>this.SUBRULE(this.styleComponent))}),this.RULE("styleComponent",()=>{this.OR([{ALT:c(()=>this.CONSUME(Oe),"ALT")},{ALT:c(()=>this.CONSUME(X),"ALT")},{ALT:c(()=>this.CONSUME(ls),"ALT")},{ALT:c(()=>this.CONSUME(hi),"ALT")},{ALT:c(()=>this.CONSUME(Qt),"ALT")},{ALT:c(()=>this.CONSUME(ui),"ALT")},{ALT:c(()=>this.CONSUME(di),"ALT")},{ALT:c(()=>this.CONSUME(fi),"ALT")},{ALT:c(()=>this.CONSUME(pi),"ALT")},{ALT:c(()=>this.CONSUME(mi),"ALT")},{ALT:c(()=>this.CONSUME(je),"ALT")},{ALT:c(()=>this.CONSUME(Be),"ALT")},{ALT:c(()=>this.CONSUME($e),"ALT")},{ALT:c(()=>this.CONSUME(ct),"ALT")},{ALT:c(()=>this.CONSUME(ht),"ALT")},{ALT:c(()=>this.CONSUME(ci),"ALT")},{ALT:c(()=>this.CONSUME(Zt),"ALT")},{ALT:c(()=>this.CONSUME(lt),"ALT")},{ALT:c(()=>this.CONSUME(H),"ALT")}])}),this.performSelfAnalysis()}isMetadataAssignment(){const t=this.LA(1).tokenType;return(t===N||t===X||t===oe)&&this.LA(2).tokenType===Jt}isStatementStart(){const t=this.LA(1).tokenType;return t!==le&&t!==re&&t!==Yt}isForbiddenPlantUmlStatement(){return this.LA(1).tokenType===N&&Do[this.LA(1).image.toLowerCase()]===!0}hasLabeledRight(t){if(!Bs(this.LA(1)))return!1;for(let e=2;;e++){const s=this.LA(e);if(t.includes(s.tokenType))return!0;if(!Bs(s))return!1}}},Ge=new Fo,$s=class extends Error{constructor(t,e,s){super(`${t} (line ${e}, column ${s})`),this.line=e,this.column=s,this.name="UsecaseJsonError"}static{c(this,"UsecaseJsonError")}},es=c((t,e,s,n)=>{let i=s,a=n;const o=Math.min(Math.max(e,0),t.length);for(let l=0;l<o;l++){const r=t[l];r==="\r"?(i++,a=1):r===`
114
- `?(l===0||t[l-1]!=="\r")&&(i++,a=1):a++}return{line:i,column:a}},"locationAtOffset"),Bo=c((t,e,s,n)=>{const i=/\bposition (\d+)\b/u.exec(t);if(i)return es(e,Number.parseInt(i[1],10),s,n);const a=/\bline (\d+) column (\d+)\b/u.exec(t);if(a){const o=Number.parseInt(a[1],10),l=Number.parseInt(a[2],10);return{line:s+o-1,column:o===1?n+l-1:l}}if(/unexpected end|end of json input/iu.test(t))return es(e,e.length,s,n)},"locationFromErrorMessage"),P=class extends Error{constructor(t){super("Invalid JSON token"),this.offset=t}static{c(this,"JsonWalkError")}},js=class{constructor(t){this.text=t,this.offset=0,this.propertyOrder={}}static{c(this,"PropertyOrderCollector")}collect(){if(this.skipWhitespace(),this.collectValue(""),this.skipWhitespace(),this.offset!==this.text.length)throw new P(this.offset);return this.propertyOrder}collectValue(t){this.skipWhitespace();const e=this.text[this.offset];if(e==="{")this.collectObject(t);else if(e==="[")this.collectArray(t);else if(e==='"')this.readString(!1);else if(e==="t")this.consumeLiteral("true");else if(e==="f")this.consumeLiteral("false");else if(e==="n")this.consumeLiteral("null");else if(e==="-"||e>="0"&&e<="9")this.consumeNumber();else throw new P(this.offset)}collectObject(t){this.offset++;const e=[],s=new Set;if(this.propertyOrder[t]=e,this.skipWhitespace(),this.text[this.offset]==="}"){this.offset++;return}for(;this.offset<this.text.length;){if(this.text[this.offset]!=='"')throw new P(this.offset);const n=this.readString(!0),i=`${t}/${n.replaceAll("~","~0").replaceAll("/","~1")}`;if(s.has(n)?this.deletePointerSubtree(i):(s.add(n),e.push(n)),this.skipWhitespace(),this.text[this.offset]!==":")throw new P(this.offset);if(this.offset++,this.collectValue(i),this.skipWhitespace(),this.text[this.offset]==="}"){this.offset++;return}if(this.text[this.offset]!==",")throw new P(this.offset);this.offset++,this.skipWhitespace()}throw new P(this.offset)}collectArray(t){if(this.offset++,this.skipWhitespace(),this.text[this.offset]==="]"){this.offset++;return}let e=0;for(;this.offset<this.text.length;){if(this.collectValue(`${t}/${e}`),e++,this.skipWhitespace(),this.text[this.offset]==="]"){this.offset++;return}if(this.text[this.offset]!==",")throw new P(this.offset);this.offset++,this.skipWhitespace()}throw new P(this.offset)}readString(t){this.offset++;let e="";for(;this.offset<this.text.length;){const s=this.offset,n=this.text[this.offset++];if(n==='"')return e;if(n.charCodeAt(0)<32)throw new P(s);if(n!=="\\"){t&&(e+=n);continue}const i=this.offset,a=this.text[this.offset++];switch(a){case'"':case"\\":case"/":t&&(e+=a);break;case"b":t&&(e+="\b");break;case"f":t&&(e+="\f");break;case"n":t&&(e+=`
115
- `);break;case"r":t&&(e+="\r");break;case"t":t&&(e+=" ");break;case"u":{const o=this.text.slice(this.offset,this.offset+4);if(!/^[\dA-Fa-f]{4}$/u.test(o))throw new P(this.offset);t&&(e+=String.fromCharCode(Number.parseInt(o,16))),this.offset+=4;break}default:throw new P(i)}}throw new P(this.offset)}consumeLiteral(t){let e=0;for(const s of t){if(this.text[this.offset+e]!==s)throw new P(this.offset+e);e++}this.offset+=t.length}consumeNumber(){if(this.text[this.offset]==="-"&&this.offset++,this.text[this.offset]==="0")this.offset++;else if(this.text[this.offset]>="1"&&this.text[this.offset]<="9")for(;this.text[this.offset]>="0"&&this.text[this.offset]<="9";)this.offset++;else throw new P(this.offset);if(this.text[this.offset]==="."){if(this.offset++,this.text[this.offset]<"0"||this.text[this.offset]>"9")throw new P(this.offset);for(;this.text[this.offset]>="0"&&this.text[this.offset]<="9";)this.offset++}if(this.text[this.offset]==="e"||this.text[this.offset]==="E"){if(this.offset++,(this.text[this.offset]==="+"||this.text[this.offset]==="-")&&this.offset++,this.text[this.offset]<"0"||this.text[this.offset]>"9")throw new P(this.offset);for(;this.text[this.offset]>="0"&&this.text[this.offset]<="9";)this.offset++}}skipWhitespace(){for(;this.offset<this.text.length;){const t=this.text[this.offset];if(t!==" "&&t!==" "&&t!==`
116
- `&&t!=="\r")return;this.offset++}}deletePointerSubtree(t){const e=`${t}/`;for(const s of Object.keys(this.propertyOrder))(s===t||s.startsWith(e))&&delete this.propertyOrder[s]}};function Ti(t,e,s){let n;try{n=JSON.parse(t)}catch(i){const a=i instanceof Error?i.message:String(i);let o=Bo(a,t,e,s);if(!o){let l=0;try{new js(t).collect()}catch(r){r instanceof P&&(l=r.offset)}o=es(t,l,e,s)}throw new $s(`Invalid JSON: ${a}`,o.line,o.column)}if(typeof n!="object"||n===null||Array.isArray(n))throw new $s("JSON value must have an object root",e,s);return{value:n,propertyOrder:new js(t).collect()}}c(Ti,"parseOrderedJsonObject");var $o=c(t=>({shape:t.type==="normal"?"actor":t.type==="hollow"?"actor-hollow":t.type==="awesome"?"actor-awesome":"actor-icon",...t.label===t.id?{}:{label:t.label},...t.classes.length?{classes:[...t.classes]}:{},...t.styles.length?{styles:[...t.styles]}:{},attrs:{kind:"actor",actorType:t.type,business:t.business,labelType:t.labelType,...t.icon?{icon:t.icon}:{},...t.stereotype?{stereotype:t.stereotype}:{},...t.parentId?{parentId:t.parentId}:{}}}),"actorNode"),jo=c(t=>({shape:t.shape,...t.label===t.id?{}:{label:t.label},...t.classes.length?{classes:[...t.classes]}:{},...t.styles.length?{styles:[...t.styles]}:{},attrs:{kind:"usecase",useCaseShape:t.shape,business:t.business,labelType:t.labelType,...t.stereotype?{stereotype:t.stereotype}:{},...t.parentId?{parentId:t.parentId}:{}}}),"useCaseNode"),Go=c(t=>({label:t.label,shape:"note",attrs:{kind:"note",target:t.target,labelType:t.labelType}}),"noteNode"),Wo=c(t=>({label:t.id,shape:"json-table",...t.classes.length?{classes:[...t.classes]}:{},...t.styles.length?{styles:[...t.styles]}:{},attrs:{kind:"json",value:t.value,propertyOrder:t.propertyOrder,labelType:"text"}}),"jsonNode"),Ko=c(t=>({id:t.id,source:t.source,target:t.target,...t.label?{label:t.label}:{},...t.classes.length?{classes:[...t.classes]}:{},...t.styles.length?{styles:[...t.styles]}:{},attrs:{relationshipType:t.type,arrowType:t.arrowType,minlen:t.minlen,explicitId:t.explicitId,animate:t.animate,...t.animation?{animation:t.animation}:{},...t.labelType?{labelType:t.labelType}:{}}}),"relationshipEdge"),Vo=c(t=>({id:`${t.id}-edge`,source:t.id,target:t.target,attrs:{relationshipType:"note",arrowType:I.LINE_SOLID,pattern:"dotted",minlen:1,explicitId:!1,animate:!1,internal:!0}}),"noteEdge"),zo=c((t,e,s,n)=>{const i={};for(const r of t.getActors().values())i[r.id]=$o(r);for(const r of t.getUseCases().values())i[r.id]=jo(r);for(const r of t.getNotes().values())i[r.id]=Go(r);for(const r of t.getJsonNodes().values())i[r.id]=Wo(r);const a={};for(const r of t.getSystemBoundaries().values())a[r.id]={...r.label===r.id?{}:{title:r.label},nodes:[...r.members],...r.classes.length?{classes:[...r.classes]}:{},...r.styles.length?{styles:[...r.styles]}:{},attrs:{kind:"systemBoundary",boundaryType:r.type,labelType:r.labelType}};const o={};for(const r of t.getClassDefs().values())o[r.id]={styles:[...r.styles]};const l=t.getDirection();return{version:1,diagramType:"usecase",source:e,header:{keyword:"usecase",direction:l==="TD"?"TB":l,span:s},...t.getAccTitle()?{accTitle:t.getAccTitle()}:{},...t.getAccDescription()?{accDescr:t.getAccDescription()}:{},nodes:i,edges:[...t.getRelationships().map(Ko),...[...t.getNotes().values()].map(Vo)],groups:a,classDefs:o,statements:n}},"buildUsecaseGraphAST"),D=c(t=>`line ${t.line}, column ${t.column} [${t.span[0]},${t.span[1]})`,"locationText"),Gs=c(t=>t===void 0?"":` (label "${t}")`,"labelSuffix"),me=c(t=>t.generated?t.label:void 0,"generatedFrom"),wt=c((t,e)=>{for(const s of e)t.includes(s)||t.push(s)},"pushUnique"),Ho=class{constructor(t){this.db=t,this.source="",this.statements=[],this.elements=[],this.boundaries=[],this.jsonDrafts=[],this.relationshipDrafts=[],this.noteDrafts=[],this.metadataAssignments=[],this.classAssignments=[],this.styleAssignments=[],this.classDefinitions=[],this.directions=[],this.model=t.createModel()}static{c(this,"UsecaseModelBuilder")}reset(t){this.model=this.db.createModel(),this.source=t,this.statements=[],this.elements.length=0,this.boundaries.length=0,this.jsonDrafts.length=0,this.relationshipDrafts.length=0,this.noteDrafts.length=0,this.metadataAssignments.length=0,this.classAssignments.length=0,this.styleAssignments.length=0,this.classDefinitions.length=0,this.directions.length=0}addElement(t){this.elements.push(t)}addBoundary(t){this.boundaries.push(t)}addJson(t){this.jsonDrafts.push(t)}addRelationship(t){this.relationshipDrafts.push(t)}addNote(t){this.noteDrafts.push(t)}addMetadataAssignment(t,e,s,n){this.metadataAssignments.push({target:t,targetLocation:e,metadata:s,statement:n})}addClassDef(t,e){this.classDefinitions.push({ids:t,styles:e})}addClassAssignment(t,e){this.classAssignments.push({targets:t,classes:e})}addStyleAssignment(t,e,s){this.styleAssignments.push({target:t,location:e,styles:s})}setDirection(t){this.directions.push(t==="TD"?"TB":t)}setAccTitle(t){this.model.accTitle=t}setAccDescription(t){this.model.accDescription=t}setStatements(t){this.statements=t}getActors(){return this.model.actors}getUseCases(){return this.model.useCases}getSystemBoundaries(){return this.model.systemBoundaries}getRelationships(){return this.model.relationships}getNotes(){return this.model.notes}getJsonNodes(){return this.model.jsonNodes}getClassDefs(){return this.model.classDefs}getDirection(){return this.model.direction}getAccTitle(){return this.model.accTitle}getAccDescription(){return this.model.accDescription}finalize(t){const e=new Map,s=new Map,n=new Map,i=new Map;for(const r of this.relationshipDrafts)this.recordFirst(i,r.source.id,r.source.location.span[0]),this.recordFirst(i,r.target.id,r.target.location.span[0]);for(const r of this.elements)this.recordFirst(i,r.id,r.location.span[0]);for(const r of this.boundaries)this.recordFirst(i,r.id,r.location.span[0]);for(const r of this.jsonDrafts)this.recordFirst(i,r.id,r.location.span[0]);const a=[...this.elements.map(r=>({offset:r.location.span[0],type:"element",value:r})),...this.boundaries.map(r=>({offset:r.location.span[0],type:"boundary",value:r})),...this.jsonDrafts.map(r=>({offset:r.location.span[0],type:"json",value:r})),...this.relationshipDrafts.filter(r=>r.explicitId).map(r=>({offset:r.explicitIdLocation.span[0],type:"edge",value:r}))].sort((r,h)=>r.offset-h.offset);for(const r of a)r.type==="element"?this.collectElement(r.value,e,s):r.type==="boundary"?this.collectBoundary(r.value,e,n):r.type==="json"?this.registerUnique(e,r.value.id,"json",r.value.location,!1):this.registerUnique(e,r.value.explicitId,"edge",r.value.explicitIdLocation,!1);this.materializeElements(s,i),this.materializeBoundaries(n,i),this.materializeJson(i);const o=this.materializeRelationships(e,s,i);this.reorderElements(s,i),this.applyMetadataAssignments(e,s,n,o),this.validateAndRefreshElements(s),this.refreshBoundaries(n,s),this.materializeNotes(e),this.applyClassDefinitions(),this.applyClassesAndStyles(e,o),this.model.direction=this.directions.at(-1)??this.model.direction,this.model.symbols=new Map([...e].map(([r,h])=>[r,h.kind]));const l=zo(this,this.source,t,this.statements);return this.model.ast=l,this.db.commit(this.model),l}collectElement(t,e,s){const n=e.get(t.id),i=me({generated:t.generated,label:t.label.text});n&&n.kind!==t.kind&&this.conflict(`ID '${t.id}' is declared as both ${n.kind} and ${t.kind}`,t.location,n.location,i,me(n)),n&&(n.generated||t.generated)&&this.conflict(`Generated ID '${t.id}' collides with another declaration`,t.location,n.location,i,me(n));const a=s.get(t.id);if(!a){const o={kind:t.kind,id:t.id,label:t.label,location:t.location,generated:t.generated,classes:[...t.classes],...t.parentId?{parentId:t.parentId,parentLocation:t.parentLocation}:{},...t.shape?{shape:t.shape}:{},...t.stereotype?{stereotype:t.stereotype,stereotypeLocation:t.location}:{}};this.applyDeclarationMetadata(o,t.metadata),s.set(t.id,o),e.set(t.id,{kind:t.kind,location:t.location,generated:t.generated,label:t.label.text});return}(a.label.text!==t.label.text||a.label.type!==t.label.type)&&this.conflict(`ID '${t.id}' has conflicting labels`,t.location,a.location),t.shape&&a.shape&&t.shape!==a.shape&&this.conflict(`Use case '${t.id}' has conflicting shapes`,t.location,a.location),t.parentId&&a.parentId&&t.parentId!==a.parentId&&this.conflict(`Element '${t.id}' belongs to more than one system boundary`,t.parentLocation??t.location,a.parentLocation??a.location),t.stereotype&&a.stereotype&&t.stereotype!==a.stereotype&&this.conflict(`Element '${t.id}' has conflicting stereotypes`,t.location,a.stereotypeLocation??a.location),a.shape??=t.shape,a.parentId??=t.parentId,a.parentLocation??=t.parentLocation,a.stereotype??=t.stereotype,a.stereotypeLocation??=t.stereotype?t.location:void 0,wt(a.classes,t.classes),this.applyDeclarationMetadata(a,t.metadata)}collectBoundary(t,e,s){const n=e.get(t.id),i=me({generated:t.generated,label:t.label.text});n&&n.kind!=="boundary"&&this.conflict(`ID '${t.id}' is declared as both ${n.kind} and boundary`,t.location,n.location,i,me(n)),n&&(n.generated||t.generated)&&this.conflict(`Generated ID '${t.id}' collides with another declaration`,t.location,n.location,i,me(n));const a=s.get(t.id);if(a){(a.label.text!==t.label.text||a.label.type!==t.label.type)&&this.conflict(`Boundary '${t.id}' has conflicting titles`,t.location,a.location),wt(a.classes,t.classes);return}s.set(t.id,{id:t.id,label:t.label,location:t.location,generated:t.generated,classes:[...t.classes],styles:[],members:[]}),e.set(t.id,{kind:"boundary",location:t.location,generated:t.generated,label:t.label.text})}materializeElements(t,e){for(const s of[...t.values()].sort((n,i)=>(e.get(n.id)??0)-(e.get(i.id)??0)))this.setElementModel(s)}materializeBoundaries(t,e){for(const s of[...t.values()].sort((n,i)=>(e.get(n.id)??0)-(e.get(i.id)??0)))this.model.systemBoundaries.set(s.id,{id:s.id,label:s.label.text,labelType:s.label.type,type:s.type??"rect",members:[],classes:[...s.classes],styles:[...s.styles]})}materializeJson(t){for(const e of[...this.jsonDrafts].sort((s,n)=>(t.get(s.id)??0)-(t.get(n.id)??0)))this.model.jsonNodes.set(e.id,{id:e.id,value:e.value,propertyOrder:e.propertyOrder,classes:[...e.classes],styles:[]})}materializeRelationships(t,e,s){const n=new Map;let i=0;for(const a of this.relationshipDrafts){const o=this.resolveEndpoint(a.source,t,e,s),l=this.resolveEndpoint(a.target,t,e,s);this.validateRelationship(a,o,l,t);const r=a.explicitId??`edge-${i++}`,h={id:r,explicitId:!!a.explicitId,source:a.source.id,target:a.target.id,type:a.type,arrowType:a.arrowType,...a.label?{label:a.label.text,labelType:a.label.type}:{},minlen:a.minlen,classes:[],styles:[],animate:!1};this.model.relationships.push(h),n.set(r,{draft:a,relationship:h})}return this.model.relationshipCounter=i,n}resolveEndpoint(t,e,s,n){if(t.classesOnReference&&!t.declaration)throw new Error(`Relationship endpoint '${t.id}' uses ::: without declaring the node at ${D(t.location)}`);const i=e.get(t.id);return i?i.kind:(s.set(t.id,{kind:"usecase",id:t.id,label:t.label,location:t.location,generated:t.generated,shape:"ellipse",classes:[]}),e.set(t.id,{kind:"usecase",location:t.location,generated:t.generated,label:t.label.text}),this.recordFirst(n,t.id,t.location.span[0]),"usecase")}reorderElements(t,e){const s=new Map(this.model.actors),n=new Map(this.model.useCases);this.model.actors.clear(),this.model.useCases.clear();for(const i of[...t.values()].sort((a,o)=>(e.get(a.id)??0)-(e.get(o.id)??0))){!s.has(i.id)&&!n.has(i.id)&&this.setElementModel(i);const a=s.get(i.id)??this.model.actors.get(i.id),o=n.get(i.id)??this.model.useCases.get(i.id);a?this.model.actors.set(i.id,a):o&&this.model.useCases.set(i.id,o)}}applyMetadataAssignments(t,e,s,n){for(const i of this.metadataAssignments){const a=t.get(i.target);if(!a){const o=this.inferMetadataKind(i.metadata);throw new Error(`Metadata target '${i.target}' is unresolved${o?` (metadata implies ${o})`:""} at ${D(i.targetLocation)}`)}if(a.kind==="actor"||a.kind==="usecase")this.applyStandaloneElementMetadata(e.get(i.target),i.metadata);else if(a.kind==="boundary"){const o=s.get(i.target);for(const l of i.metadata.properties)(l.key!=="type"||l.value!=="rect"&&l.value!=="package")&&this.invalidMetadata(i.target,a.kind,l),o.type=l.value}else if(a.kind==="edge"){const o=n.get(i.target);if(!o)throw new Error(`Metadata target '${i.target}' is not an explicit edge at ${D(i.targetLocation)}`);i.statement.kind="edgeMetadata",i.statement.edges=[{id:i.target,span:i.statement.span,idSpan:i.targetLocation.span,...i.statement.metadata?{metadata:i.statement.metadata}:{}}],delete i.statement.nodes;for(const l of i.metadata.properties)l.key==="animate"&&typeof l.value=="boolean"?o.relationship.animate=l.value:l.key==="animation"&&(l.value==="fast"||l.value==="slow")?(o.relationship.animation=l.value,o.relationship.animate=!0):this.invalidMetadata(i.target,a.kind,l)}else for(const o of i.metadata.properties)this.invalidMetadata(i.target,a.kind,o)}for(const{relationship:i}of n.values())i.animation&&(i.animate=!0)}applyStandaloneElementMetadata(t,e){for(const s of e.properties)t.kind==="actor"?this.applyActorProperty(t,s,!0):s.key==="business"&&typeof s.value=="boolean"?t.business=s.value:this.invalidMetadata(t.id,t.kind,s)}applyDeclarationMetadata(t,e){if(e)for(const s of e.properties)t.kind==="actor"?this.applyActorProperty(t,s,!1):s.key==="business"&&typeof s.value=="boolean"?(t.business!==void 0&&t.business!==s.value&&this.conflict(`Use case '${t.id}' has conflicting business metadata`,s.location,t.location),t.business=s.value):this.invalidMetadata(t.id,t.kind,s)}applyActorProperty(t,e,s){e.key==="type"&&(e.value==="normal"||e.value==="hollow"||e.value==="awesome")?(!s&&t.actorType!==void 0&&t.actorType!==e.value&&this.conflict(`Actor '${t.id}' has conflicting type metadata`,e.location,t.location),t.actorType=e.value):e.key==="icon"&&typeof e.value=="string"?(!s&&t.icon!==void 0&&t.icon!==e.value&&this.conflict(`Actor '${t.id}' has conflicting icon metadata`,e.location,t.location),t.icon=e.value):e.key==="business"&&typeof e.value=="boolean"?(!s&&t.business!==void 0&&t.business!==e.value&&this.conflict(`Actor '${t.id}' has conflicting business metadata`,e.location,t.location),t.business=e.value):this.invalidMetadata(t.id,t.kind,e)}validateAndRefreshElements(t){for(const e of t.values()){const s=e.icon?"icon":e.actorType??"normal";if(e.kind==="actor"){if(e.icon&&e.actorType&&e.actorType!=="normal")throw new Error(`Actor '${e.id}' cannot combine icon with type '${e.actorType}' at ${D(e.location)}`);if(e.business&&(s==="icon"||s==="awesome"))throw new Error(`Business actor '${e.id}' must use normal or hollow geometry at ${D(e.location)}`)}else if((e.shape??"ellipse")==="rect"&&e.business)throw new Error(`Rectangular use case '${e.id}' cannot be a business use case at ${D(e.location)}`);this.setElementModel(e)}}refreshBoundaries(t,e){for(const s of t.values())s.members.length=0;for(const s of[...this.elements].sort((n,i)=>n.location.span[0]-i.location.span[0])){if(!s.parentId)continue;const n=t.get(s.parentId);if(!n)throw new Error(`Parent boundary '${s.parentId}' for '${s.id}' is unresolved at ${D(s.parentLocation??s.location)}`);n.members.includes(s.id)||n.members.push(s.id)}for(const s of e.values())if(s.parentId&&!t.has(s.parentId))throw new Error(`Parent boundary '${s.parentId}' for '${s.id}' is unresolved at ${D(s.parentLocation??s.location)}`);for(const s of t.values()){const n=this.model.systemBoundaries.get(s.id);n.type=s.type??"rect",n.members=[...s.members],n.classes=[...s.classes],n.styles=[...s.styles]}}materializeNotes(t){let e=0;for(const s of this.noteDrafts){const n=t.get(s.target);if(!n)throw new Error(`Note target '${s.target}' is unresolved at ${D(s.targetLocation)}`);n.kind!=="actor"&&n.kind!=="usecase"&&this.conflict(`Note target '${s.target}' must be an actor or use case, not ${n.kind}`,s.targetLocation,n.location);const i=`note-${e++}`;this.model.notes.set(i,{id:i,target:s.target,label:s.label.text,labelType:s.label.type})}this.model.noteCounter=e}applyClassDefinitions(){for(const t of this.classDefinitions)for(const e of t.ids)this.model.classDefs.set(e,{id:e,styles:[...t.styles]})}applyClassesAndStyles(t,e){for(const s of this.classAssignments)for(const n of s.targets)wt(this.getStylable(n.id,t,e,n.location).classes,s.classes);for(const s of this.styleAssignments)this.getStylable(s.target,t,e,s.location).styles.push(...s.styles)}getStylable(t,e,s,n){const i=e.get(t)?.kind,a=i==="actor"?this.model.actors.get(t):i==="usecase"?this.model.useCases.get(t):i==="boundary"?this.model.systemBoundaries.get(t):i==="json"?this.model.jsonNodes.get(t):i==="edge"?s.get(t)?.relationship:void 0;if(!a)throw new Error(`Class/style target '${t}' is unresolved or anonymous at ${D(n)}`);return a}validateRelationship(t,e,s,n){const i=c(a=>a==="actor"||a==="usecase"||a==="json","allowed");if(i(e)||this.conflict(`Relationship source '${t.source.id}' cannot be ${e}`,t.source.location,n.get(t.source.id).location),i(s)||this.conflict(`Relationship target '${t.target.id}' cannot be ${s}`,t.target.location,n.get(t.target.id).location),(t.type==="include"||t.type==="extend")&&(e!=="usecase"||s!=="usecase"))throw new Error(`${t.type} relationship requires use-case endpoints at ${D(t.location)}`);if(t.type==="generalization"&&(e!=="actor"&&e!=="usecase"||e!==s))throw new Error(`Generalization requires actor-to-actor or use-case-to-use-case endpoints at ${D(t.location)}`);if(t.type==="association"&&(e==="json"||s==="json")&&![0,1,2].includes(t.arrowType))throw new Error(`JSON relationship '${t.source.id}' to '${t.target.id}' permits only point, reversed-point, or markerless solid association at ${D(t.location)}`)}setElementModel(t){if(t.kind==="actor"){const e=t.icon?"icon":t.actorType??"normal";this.model.useCases.delete(t.id),this.model.actors.set(t.id,{id:t.id,label:t.label.text,labelType:t.label.type,type:e,...t.icon?{icon:t.icon}:{},business:t.business??!1,...t.stereotype?{stereotype:t.stereotype}:{},...t.parentId?{parentId:t.parentId}:{},classes:[...t.classes],styles:this.model.actors.get(t.id)?.styles??[]})}else this.model.actors.delete(t.id),this.model.useCases.set(t.id,{id:t.id,label:t.label.text,labelType:t.label.type,shape:t.shape??"ellipse",business:t.business??!1,...t.stereotype?{stereotype:t.stereotype}:{},...t.parentId?{parentId:t.parentId}:{},classes:[...t.classes],styles:this.model.useCases.get(t.id)?.styles??[]})}inferMetadataKind(t){const e=new Set(["actor","usecase","boundary","edge"]);for(const s of t.properties)if(s.key==="icon")e.clear(),e.add("actor");else if(s.key==="animate"||s.key==="animation")e.clear(),e.add("edge");else if(s.key==="type")e.clear(),s.value==="rect"||s.value==="package"?e.add("boundary"):(s.value==="normal"||s.value==="hollow"||s.value==="awesome")&&e.add("actor");else if(s.key==="business")e.delete("boundary"),e.delete("edge");else return;return e.size===1?[...e][0]:void 0}invalidMetadata(t,e,s){throw new Error(`Metadata property '${s.key}' is invalid for ${e} '${t}' at ${D(s.location)}`)}registerUnique(t,e,s,n,i){const a=t.get(e);a&&this.conflict(`ID '${e}' is declared more than once (${a.kind} and ${s})`,n,a.location,void 0,me(a)),t.set(e,{kind:s,location:n,generated:i})}recordFirst(t,e,s){const n=t.get(e);(n===void 0||s<n)&&t.set(e,s)}conflict(t,e,s,n,i){throw new Error(`${t} at ${D(e)}${Gs(n)}; previous declaration at ${D(s)}${Gs(i)}`)}},Xo=Ge.getBaseCstVisitorConstructor(),Yo=class extends Xo{constructor(){super(),this.builder=new Ho(At),this.source="",this.anonymousEdge=0,this.anonymousNote=0,this.validateVisitor()}static{c(this,"UsecaseVisitor")}build(t,e){this.source=e,this.parentBoundary=void 0,this.anonymousEdge=0,this.anonymousNote=0,this.builder.reset(e),this.visit(t)}start(t){const e=this.tokens(t,"USECASE")[0],s=[];for(const n of this.nodes(t,"line"))s.push(this.visit(n));this.builder.setStatements(s),this.builder.finalize(this.tokenSpan(e))}line(t){const e=this.firstNode(t,"blankLine","commentLine","statement");return this.wrap(e,this.visit(e))}statement(t){return this.visit(this.firstNode(t,"accTitleStatement","accDescrStatement","directionStatement","actorStatement","systemBoundaryStatement","noteStatement","jsonStatement","classDefStatement","classStatement","styleStatement","metadataAssignmentStatement","entityStatement"))}lineEnd(t){}blankLine(t){return{kind:"blank",span:this.tokenSpan(this.tokens(t,"NEWLINE")[0])}}commentLine(t){return{kind:"comment",span:this.tokenSpan(this.tokens(t,"COMMENT")[0])}}accTitleStatement(t){const e=this.tokens(t,"ACC_TITLE_LINE")[0].image;return this.builder.setAccTitle(e.slice(e.indexOf(":")+1).trim()),{kind:"accTitle",span:[0,0]}}accDescrStatement(t){const e=this.tokens(t,"ACC_DESCR_LINE")[0],s=this.tokens(t,"ACC_DESCR_BLOCK")[0],n=e?e.image.slice(e.image.indexOf(":")+1).trim():s.image.slice(s.image.indexOf("{")+1,s.image.lastIndexOf("}")).trim();return this.builder.setAccDescription(n),{kind:"accDescr",span:[0,0]}}actorStatement(t){const e=this.nodes(t,"actorItem"),s=e.map(r=>this.visit(r)),n=this.nodes(t,"relationTail")[0],i=s.map((r,h)=>this.actorOccurrence(e[h],r,!0));for(const r of s)this.builder.addElement(this.actorDraft(r));if(!n)return{kind:"node",span:[0,0],nodes:i};const a=this.visit(n);a.target.explicitDeclaration&&this.builder.addElement(this.entityDraft(a.target));const o=this.relationshipDraft(s[0],a,this.nodeLocation(n));this.builder.addRelationship(o);const l=o.explicitId??`edge-${this.anonymousEdge++}`;return i.push(this.entityOccurrence(this.nodes(n.children,"entityName")[0],a.target,a.target.explicitDeclaration)),{kind:"edge",span:[0,0],nodes:i,edges:[{id:l,span:[0,0],...o.explicitIdLocation?{idSpan:o.explicitIdLocation.span}:{},...o.label?{labelSpan:o.label.span}:{}}]}}actorItem(t){const e=this.visit(this.nodes(t,"actorName")[0]),s=this.nodes(t,"metadata")[0],n=this.nodes(t,"stereotype")[0],i=this.nodes(t,"classSuffix")[0],a=i?this.visit(i):{classes:[],spans:[]};return{...e,...s?{metadata:this.visit(s)}:{},...n?{stereotype:this.visit(n)}:{},classes:a.classes,classSpans:a.spans}}actorName(t){const e=this.tokens(t,"IDENTIFIER")[0],s=this.tokens(t,"PLAIN_STRING")[0]??this.tokens(t,"MARKDOWN_STRING")[0];if(e){const i=this.nodes(t,"nodeLabel")[0],a=i?this.visit(i):this.tokenLabel(e);return{id:e.image,label:a,location:this.tokenLocation(e),generated:!1,classes:[],classSpans:[]}}const n=this.tokenLabel(s);return{id:this.generateId(n.text),label:n,location:this.tokenLocation(s),generated:!0,classes:[],classSpans:[]}}actorDeclarationOnly(t){const e=this.nodes(t,"actorItem"),s=e.map(n=>this.visit(n));for(const n of s)this.builder.addElement(this.actorDraft(n));return{kind:"node",span:[0,0],nodes:s.map((n,i)=>this.actorOccurrence(e[i],n,!0))}}entityStatement(t){const e=this.nodes(t,"entityName"),s=this.visit(e[0]),n=this.nodes(t,"relationTail")[0];if(!n)return s.explicitDeclaration=!0,s.shape??="ellipse",this.builder.addElement(this.entityDraft(s)),{kind:"node",span:[0,0],nodes:[this.entityOccurrence(e[0],s,!0)]};s.explicitDeclaration&&this.builder.addElement(this.entityDraft(s));const i=this.visit(n);i.target.explicitDeclaration&&this.builder.addElement(this.entityDraft(i.target));const a={source:this.endpoint(s),target:this.endpoint(i.target),location:this.nodeLocation(n),...i.explicitId?{explicitId:i.explicitId,explicitIdLocation:i.explicitIdLocation}:{},...i.arrow};this.builder.addRelationship(a);const o=a.explicitId??`edge-${this.anonymousEdge++}`;return{kind:"edge",span:[0,0],nodes:[this.entityOccurrence(e[0],s,s.explicitDeclaration),this.entityOccurrence(this.nodes(n.children,"entityName")[0],i.target,i.target.explicitDeclaration)],edges:[{id:o,span:[0,0],...a.explicitIdLocation?{idSpan:a.explicitIdLocation.span}:{},...a.label?{labelSpan:a.label.span}:{}}]}}entityName(t){const e=this.tokens(t,"IDENTIFIER")[0],s=this.tokens(t,"PLAIN_STRING")[0]??this.tokens(t,"MARKDOWN_STRING")[0],n=this.nodes(t,"nodeLabel")[0],i=this.nodes(t,"useCaseMetadata")[0],a=this.nodes(t,"stereotype")[0],o=this.nodes(t,"classSuffix")[0],l=o?this.visit(o):{classes:[],spans:[]};if(e){const h=n?this.visit(n):this.tokenLabel(e),d=n?this.tokens(t,"LBRACKET").length?"rect":"ellipse":void 0;return{id:e.image,label:h,location:this.tokenLocation(e),generated:!1,...d?{shape:d}:{},...i?{metadata:this.visit(i)}:{},...a?{stereotype:this.visit(a)}:{},classes:l.classes,classSpans:l.spans,explicitDeclaration:!!(d||i||a)}}const r=this.tokenLabel(s);return{id:this.generateId(r.text),label:r,location:this.tokenLocation(s),generated:!0,...i?{metadata:this.visit(i)}:{},...a?{stereotype:this.visit(a)}:{},classes:l.classes,classSpans:l.spans,explicitDeclaration:!!(i||a)}}nodeLabel(t){const e=this.allTokens(t);if(e.length===1&&(e[0].tokenType.name==="PLAIN_STRING"||e[0].tokenType.name==="MARKDOWN_STRING"))return this.tokenLabel(e[0]);const s=[e[0].startOffset,(e.at(-1).endOffset??e.at(-1).startOffset)+1];return{text:this.source.slice(s[0],s[1]),type:"text",span:s}}useCaseMetadata(t){return this.visit(this.nodes(t,"metadata")[0])}relationTail(t){const e=this.tokens(t,"IDENTIFIER")[0];return{...e?{explicitId:e.image,explicitIdLocation:this.tokenLocation(e)}:{},arrow:this.visit(this.nodes(t,"arrow")[0]),target:this.visit(this.nodes(t,"entityName")[0])}}arrow(t){return this.visit(this.firstNode(t,"semanticRelation","forwardSolidOperator","backwardSolidOperator","markerlessSolidOperator","forwardCircleOperator","backwardCircleOperator","forwardCrossOperator","backwardCrossOperator"))}edgeLabel(t){return this.nodeLabel(t)}semanticRelation(t){if(this.tokens(t,"GENERALIZATION").length)return{type:"generalization",arrowType:I.SOLID_ARROW,minlen:1};const e=this.tokens(t,"INCLUDE").length?"include":"extend",s=this.tokens(t,e==="include"?"INCLUDE":"EXTEND")[0];return{type:e,arrowType:I.SOLID_ARROW,label:{text:e,type:"text",span:this.tokenSpan(s)},minlen:1}}metadata(t){return{properties:this.nodes(t,"metadataProperty").map(e=>this.visit(e)),location:this.ctxLocation(t)}}metadataProperty(t){const e=this.allTokens(t).filter(o=>o.tokenType.name!=="COLON"),s=e[0],n=e[1],i=n.tokenType.name==="TRUE"?!0:n.tokenType.name==="FALSE"?!1:this.decodePlain(n),a=[s.startOffset,(n.endOffset??n.startOffset)+1];return{key:this.decodePlain(s),value:i,span:a,keySpan:this.contentSpan(s),valueSpan:this.contentSpan(n),location:this.tokenLocation(s)}}metadataSeparator(t){}systemBoundaryStatement(t){const e=this.visit(this.nodes(t,"systemBoundaryName")[0]),s=this.nodes(t,"classSuffix")[0],n=s?this.visit(s):{classes:[],spans:[]};e.classes=n.classes,this.builder.addBoundary(e);const i=this.parentBoundary;this.parentBoundary={id:e.id,location:e.location};const a=this.nodes(t,"systemBoundaryContent")[0],o=a?this.visit(a):[];this.parentBoundary=i;const l=this.tokens(t,"END")[0],r=this.nodes(t,"metadata")[0],h=r?this.visit(r):void 0,d={kind:"group",span:[0,0],group:e.id,idSpan:e.location.span,titleSpan:e.label.span,endSpan:this.tokenSpan(l),classSpans:n.spans,...h?{metadata:h.properties.map(({key:u,span:f,keySpan:E,valueSpan:y})=>({key:u,span:f,keySpan:E,valueSpan:y}))}:{},...o.length?{children:o}:{}};return h&&this.builder.addMetadataAssignment(e.id,e.location,h,d),d}systemBoundaryName(t){const e=this.tokens(t,"IDENTIFIER")[0];if(e){const i=this.nodes(t,"nodeLabel")[0];return{id:e.image,label:i?this.visit(i):this.tokenLabel(e),location:this.tokenLocation(e),generated:!1,classes:[]}}const s=this.tokens(t,"PLAIN_STRING")[0]??this.tokens(t,"MARKDOWN_STRING")[0],n=this.tokenLabel(s);return{id:this.generateId(n.text),label:n,location:this.tokenLocation(s),generated:!0,classes:[]}}systemBoundaryContent(t){return[...this.nodes(t,"blankLine"),...this.nodes(t,"commentLine"),...this.nodes(t,"boundaryElement")].sort((s,n)=>(s.location?.startOffset??0)-(n.location?.startOffset??0)).map(s=>this.wrap(s,this.visit(s)))}boundaryElement(t){const e=this.nodes(t,"actorDeclarationOnly")[0];if(e)return this.visit(e);const s=this.nodes(t,"entityName")[0],n=this.visit(s);return n.explicitDeclaration=!0,n.shape??="ellipse",this.builder.addElement(this.entityDraft(n)),{kind:"node",span:[0,0],nodes:[this.entityOccurrence(s,n,!0)]}}metadataAssignmentStatement(t){const e=this.visit(this.nodes(t,"metadataAssignmentTarget")[0]),s=this.visit(this.nodes(t,"metadata")[0]),n={kind:"metadata",span:[0,0],nodes:[{id:e.id,span:e.location.span,idSpan:e.location.span}],metadata:s.properties.map(({key:i,span:a,keySpan:o,valueSpan:l})=>({key:i,span:a,keySpan:o,valueSpan:l}))};return this.builder.addMetadataAssignment(e.id,e.location,s,n),n}metadataAssignmentTarget(t){const e=this.allTokens(t)[0],s=this.tokenLabel(e);return{id:e.tokenType.name==="IDENTIFIER"?e.image:this.generateId(s.text),location:this.tokenLocation(e)}}noteStatement(t){const e=this.tokens(t,"IDENTIFIER")[0],s=this.visit(this.nodes(t,"nodeLabel")[0]);return this.builder.addNote({target:e.image,targetLocation:this.tokenLocation(e),label:s,location:this.ctxLocation(t)}),{kind:"note",span:[0,0],ref:`note-${this.anonymousNote++}`,refSpan:s.span,nodes:[{id:e.image,span:this.tokenSpan(e),idSpan:this.tokenSpan(e)}]}}stereotype(t){const e=this.tokens(t,"STEREOTYPE_TEXT")[0];return{value:e.image.trim(),span:this.tokenSpan(e)}}classSuffix(t){const e=this.tokens(t,"IDENTIFIER");return{classes:e.map(s=>s.image),spans:e.map(s=>this.tokenSpan(s))}}jsonStatement(t){const e=this.tokens(t,"JSON_DECLARATION_START")[0],s=this.tokens(t,"JSON_OBJECT_LITERAL")[0],n=/^json[\t ]+(\w+)/.exec(e.image),i=n[1],a=n[0].length-i.length,o={span:[e.startOffset+a,e.startOffset+a+i.length],line:e.startLine??1,column:(e.startColumn??1)+a},l=Ti(s.image,s.startLine??1,s.startColumn??1),r=this.nodes(t,"classSuffix")[0],h=r?this.visit(r):{classes:[],spans:[]},d={id:i,value:l.value,propertyOrder:l.propertyOrder,location:o,classes:h.classes};return this.builder.addJson(d),{kind:"json",span:[0,0],nodes:[{id:i,span:o.span,idSpan:o.span,defines:!0,classSpans:h.spans}],classSpans:h.spans}}directionStatement(t){const e=this.allTokens(t).find(s=>["TD","TB","BT","RL","LR"].includes(s.tokenType.name));return this.builder.setDirection(e.image),{kind:"direction",span:[0,0]}}classDefStatement(t){const e=this.tokens(t,"IDENTIFIER"),s=this.visit(this.nodes(t,"styles")[0]);return this.builder.addClassDef(e.map(n=>n.image),s),{kind:"classDef",span:[0,0],ref:e[0].image,refSpan:this.tokenSpan(e[0])}}classStatement(t){const e=this.tokens(t,"IDENTIFIER");let s=1;for(;s<e.length&&this.source.slice((e[s-1].endOffset??e[s-1].startOffset)+1,e[s].startOffset).includes(",");s++);const n=e.slice(0,s).map(a=>({id:a.image,location:this.tokenLocation(a)})),i=e.slice(s).map(a=>a.image);return this.builder.addClassAssignment(n,i),{kind:"classAssign",span:[0,0],ref:i[0],refSpan:this.tokenSpan(e[s]),nodes:n.map(({id:a,location:o})=>({id:a,span:o.span,idSpan:o.span}))}}styleStatement(t){const e=this.tokens(t,"IDENTIFIER")[0],s=this.visit(this.nodes(t,"styles")[0]);return this.builder.addStyleAssignment(e.image,this.tokenLocation(e),s),{kind:"style",span:[0,0],nodes:[{id:e.image,span:this.tokenSpan(e),idSpan:this.tokenSpan(e)}]}}styles(t){return this.nodes(t,"styleValue").map(e=>this.visit(e))}styleValue(t){const e=this.allTokens(t),s=[e[0].startOffset,(e.at(-1).endOffset??e.at(-1).startOffset)+1];return this.source.slice(s[0],s[1]).replaceAll("\\,",",")}styleComponent(t){return this.allTokens(t).map(e=>e.image).join("")}forwardSolidOperator(t){const e=this.tokens(t,"FORWARD_SOLID")[0];return{type:"association",arrowType:I.SOLID_ARROW,minlen:this.solidMinlen(e)}}backwardSolidOperator(t){const e=this.tokens(t,"BACKWARD_SOLID")[0],s=this.nodes(t,"edgeLabel")[0],n=s?this.tokens(t,"MARKERLESS_SOLID").at(-1):e;return{type:"association",arrowType:I.BACK_ARROW,minlen:this.solidMinlen(n),...s?{label:this.visit(s)}:{}}}markerlessSolidOperator(t){const e=this.nodes(t,"edgeLabel")[0],s=this.allTokens(t);if(!e)return{type:"association",arrowType:I.LINE_SOLID,minlen:this.solidMinlen(this.tokens(t,"MARKERLESS_SOLID")[0])};const n=s.at(-1),i=n.tokenType.name==="FORWARD_SOLID"?I.SOLID_ARROW:n.tokenType.name==="FORWARD_CIRCLE"?I.CIRCLE_ARROW:n.tokenType.name==="FORWARD_CROSS"?I.CROSS_ARROW:I.LINE_SOLID;return{type:"association",arrowType:i,label:this.visit(e),minlen:i===I.SOLID_ARROW||i===I.LINE_SOLID?this.solidMinlen(n):1}}forwardCircleOperator(t){return{type:"association",arrowType:I.CIRCLE_ARROW,minlen:1}}backwardCircleOperator(t){const e=this.nodes(t,"edgeLabel")[0];return{type:"association",arrowType:I.CIRCLE_ARROW_REVERSED,minlen:1,...e?{label:this.visit(e)}:{}}}forwardCrossOperator(t){return{type:"association",arrowType:I.CROSS_ARROW,minlen:1}}backwardCrossOperator(t){const e=this.nodes(t,"edgeLabel")[0];return{type:"association",arrowType:I.CROSS_ARROW_REVERSED,minlen:1,...e?{label:this.visit(e)}:{}}}actorDraft(t){return{id:t.id,kind:"actor",label:t.label,location:t.location,generated:t.generated,...this.parentBoundary?{parentId:this.parentBoundary.id,parentLocation:this.parentBoundary.location}:{},...t.metadata?{metadata:t.metadata}:{},...t.stereotype?{stereotype:t.stereotype.value,stereotypeSpan:t.stereotype.span}:{},classes:t.classes}}entityDraft(t){return{id:t.id,kind:"usecase",label:t.label,location:t.location,generated:t.generated,...this.parentBoundary?{parentId:this.parentBoundary.id,parentLocation:this.parentBoundary.location}:{},...t.shape?{shape:t.shape}:{},...t.metadata?{metadata:t.metadata}:{},...t.stereotype?{stereotype:t.stereotype.value,stereotypeSpan:t.stereotype.span}:{},classes:t.classes}}endpoint(t,e=t.explicitDeclaration??!0){return{id:t.id,label:t.label,location:t.location,generated:t.generated,declaration:e,classesOnReference:t.classes.length>0}}relationshipDraft(t,e,s){return{source:this.endpoint(t,!0),target:this.endpoint(e.target),location:s,...e.explicitId?{explicitId:e.explicitId,explicitIdLocation:e.explicitIdLocation}:{},...e.arrow}}actorOccurrence(t,e,s){return{id:e.id,span:this.nodeSpan(t),idSpan:e.location.span,labelSpan:e.label.span,...s?{defines:!0}:{},...e.stereotype?{stereotypeSpan:e.stereotype.span}:{},...e.metadata?{metadata:e.metadata.properties.map(({key:n,span:i,keySpan:a,valueSpan:o})=>({key:n,span:i,keySpan:a,valueSpan:o}))}:{},...e.classSpans.length?{classSpans:e.classSpans}:{}}}entityOccurrence(t,e,s){return this.actorOccurrence(t,e,s)}wrap(t,e){if(e.kind==="blank"||e.kind==="comment")return e;e.span=this.nodeSpan(t);for(const s of e.edges??[])s.span=e.span;return e}tokenLabel(t){const e=t.tokenType.name==="MARKDOWN_STRING"?"markdown":"text",s=e==="markdown"?2:t.tokenType.name==="PLAIN_STRING"?1:0,n=this.tokenSpan(t,s);return{text:this.source.slice(n[0],n[1]),type:e,span:n}}decodePlain(t){return t.tokenType.name==="PLAIN_STRING"?t.image.slice(1,-1):t.image}contentSpan(t){return this.tokenSpan(t,t.tokenType.name==="PLAIN_STRING"?1:t.tokenType.name==="MARKDOWN_STRING"?2:0)}generateId(t){return t.replace(/\W/g,"_")}solidMinlen(t){return Math.max(1,(t.image.match(/-/g)?.length??2)-1)}nodeLocation(t){const e=this.allTokens(t.children)[0];return{span:this.nodeSpan(t),line:e.startLine??1,column:e.startColumn??1}}ctxLocation(t){const e=this.allTokens(t).filter(i=>i.tokenType.name!=="NEWLINE"&&i.tokenType.name!=="EOF"),s=e[0],n=e.at(-1);return{span:[s.startOffset,Math.min(this.source.length,(n.endOffset??n.startOffset+n.image.length-1)+1)],line:s.startLine??1,column:s.startColumn??1}}tokenLocation(t){const e=t.tokenType.name==="PLAIN_STRING"?1:t.tokenType.name==="MARKDOWN_STRING"?2:0;return{span:this.tokenSpan(t,e),line:t.startLine??1,column:(t.startColumn??1)+e}}nodeSpan(t){const e=this.allTokens(t.children).filter(i=>i.tokenType.name!=="NEWLINE"&&i.tokenType.name!=="EOF"),s=e[0],n=e.at(-1);if(!s||!n)throw new Error("Usecase CST node has no source token");return[s.startOffset,Math.min(this.source.length,(n.endOffset??n.startOffset+n.image.length-1)+1)]}tokenSpan(t,e=0){return[t.startOffset+e,Math.min(this.source.length,(t.endOffset??t.startOffset+t.image.length-1)+1-e)]}nodes(t,e){return(t[e]??[]).filter(s=>"children"in s)}tokens(t,e){return(t[e]??[]).filter(s=>"tokenTypeIdx"in s)}firstNode(t,...e){for(const s of e){const n=this.nodes(t,s)[0];if(n)return n}throw new Error(`Usecase CST is missing one of: ${e.join(", ")}`)}allTokens(t){const e=[];for(const s of Object.values(t))for(const n of s)"tokenTypeIdx"in n?e.push(n):e.push(...this.allTokens(n.children));return e.sort((s,n)=>s.startOffset-n.startOffset)}},qo=new Yo,Jo={parse:c(async t=>{At.clear(),Ge.input=[];try{Cn({diagramType:"usecase",lexer:Po,parser:Ge,entry:c(()=>Ge.start(),"entry"),visit:c(e=>qo.build(e,t),"visit")},t)}catch(e){At.clear();const s=Ge.errors[0];if(s){const{token:n}=s,i=Re(n.startOffset)?n.startOffset:t.length,a=Re(n.endOffset)?n.endOffset+1:i,o=Re(n.startLine)?n.startLine:t.slice(0,i).split(/\r\n|\r|\n/).length,l=Math.max(t.lastIndexOf(`
117
- `,i-1),t.lastIndexOf("\r",i-1)),r=Re(n.startColumn)?n.startColumn:i-l,h=e instanceof Error?e.message:String(e);throw new Error(`${h} at line ${o}, column ${r} [${i},${a})`)}throw e}},"parse")},Zo=["point","circle","cross","extension"],gi={usecaseActor:!0,usecaseActorHollow:!0,usecaseActorAwesome:!0,usecaseActorIcon:!0},Ws=c((t,e)=>{const[s,n]=[t,e].map(i=>i.replace(/[^\w-]+/g,"_").replace(/^_+|_+$/g,"")||"element");return`usecase-${s}-${n}`},"usecaseDomId"),Qo=c(t=>`usecase-${t.replace(/[^\w-]+/g,"_").replace(/^_+|_+$/g,"")||"element"}`,"usecaseNodeDomId"),Lt=c((t,e)=>e!=="markdown"?t:Pi(t).map(s=>s.map(n=>n.content).join(" ")).join(`
118
- `),"getAccessibleLabel"),el=c(t=>{const e=Lt(t.label??t.id,t.labelType);if(gi[t.shape]){const n=t.actorType&&t.actorType!=="normal"?`${t.actorType} `:"",i=t.business?"business ":"",a=t.stereotype?`, stereotype ${t.stereotype}`:"";return`${i}${n}actor ${e}${a}`}if(t.shape==="note")return`Note for ${t.noteTargetLabel??t.noteTarget??""}: ${e}`;if(t.shape==="usecaseJsonTable"){const n=(t.jsonRows??[]).map(i=>`${i.accessibleKey}: ${i.value}`).join("; ");return n?`${e}: ${n}`:e}const s=t.stereotype?`, stereotype ${t.stereotype}`:"";return`${t.business?"business ":""}use case ${e}${s}`},"getUsecaseNodeAccessibleName"),tl=c(t=>`${t.boundaryType} system boundary ${Lt(t.label??t.id,t.labelType)}`,"getUsecaseBoundaryAccessibleName"),sl=c(t=>t.relationshipType==="note"?"":`${t.relationshipType==="association"&&t.label?`association ${Lt(t.label,t.labelType)}`:t.relationshipType} from ${t.sourceLabel} to ${t.targetLabel}`,"getUsecaseEdgeAccessibleName"),ye=c(t=>t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;"),"escapePlainLabel"),Ks=c(t=>t.replace(/([*[\\\]_`])/g,"\\$1"),"escapeMarkdownMarkers"),nl=c((t,e)=>{t.diagramId=e,t.markers=[...Zo];for(const s of t.nodes){const n=s;if(n.domId=Qo(s.id),s.label!==void 0&&s.labelType==="text"&&(s.label=ye(s.label)),s.stereotype&&(s.stereotype=ye(s.stereotype)),!s.isGroup&&s.shape==="usecaseJsonTable"&&(s.jsonRows=s.jsonRows?.map(i=>({...i,key:ye(i.key),value:ye(i.value)}))),!s.isGroup&&(s.shape==="usecaseEllipse"||s.shape==="rect")&&s.stereotype){const i=s.label??ye(s.id);s.label=`«${Ks(s.stereotype)}»<br/>${s.labelType==="text"?Ks(i):i}`,s.labelType="markdown",n.hasFoldedStereotype=!0,delete s.stereotype}}for(const s of t.edges)s.label!==void 0&&s.labelType==="text"&&(s.label=ye(s.label));return t},"prepareUsecaseLayoutData"),il=c((t,e,s)=>{for(const i of e.nodes){const a=typeof i.domId=="string"?i.domId:Ws(e.diagramId,i.id),o=t.select(`#${a}`),l=i.isGroup?"boundary":gi[i.shape]?"actor":i.shape==="note"?"note":i.shape==="usecaseJsonTable"?"json":"usecase",r=s.nodes.get(i.id)??i.id;if(o.attr("data-usecase-id",i.id).attr("data-usecase-kind",l).attr("role","img").attr("aria-label",r),!i.isGroup&&(i.shape==="usecaseEllipse"||i.shape==="rect")&&"hasFoldedStereotype"in i&&i.hasFoldedStereotype===!0){const h=o.node(),d=h?.querySelector(".nodeLabel"),u=d?.querySelector("p")??d,f=u?.firstChild;if(u&&f?.nodeType===3){const E=u.ownerDocument.createElement("span");E.className="usecase-stereotype",u.insertBefore(E,f),E.appendChild(f)}else h?.querySelector(".label tspan tspan, .label tspan")?.classList.add("usecase-stereotype")}}const n=new Map(e.edges.map(i=>[i.id,i]));t.selectAll('path[data-et="edge"]').each(function(){const i=n.get(this.getAttribute("data-id")??"");if(!i)return;const a=Di(this);a.attr("id",Ws(e.diagramId,i.id)).attr("data-usecase-id",i.id).attr("data-usecase-kind",i.internal?"note-connector":"relationship"),i.internal?a.attr("aria-hidden","true"):a.attr("role","img").attr("aria-label",s.edges.get(i.id)??i.id)})},"annotateUsecaseElements"),Vs=c((t,e)=>{t.style("--mermaid-usecase-actor-font-size",`${e.actorFontSize}px`).style("--mermaid-usecase-actor-font-family",e.actorFontFamily).style("--mermaid-usecase-actor-font-weight",e.actorFontWeight).style("--mermaid-usecase-font-size",`${e.usecaseFontSize}px`).style("--mermaid-usecase-font-family",e.usecaseFontFamily).style("--mermaid-usecase-font-weight",e.usecaseFontWeight)},"applyUsecaseFonts"),al=c(async(t,e,s,n)=>{Ii.info("Drawing usecase diagram (unified)",e);const{layout:i}=Xs(),a=n.db,o=a.getData(),l=new Map(o.nodes.map(u=>[u.id,Lt(u.label??u.id,u.labelType)])),r={nodes:new Map(o.nodes.map(u=>[u.id,u.isGroup?tl(u):el(u.shape==="note"?{...u,noteTargetLabel:l.get(u.noteTarget??"")}:u)])),edges:new Map(o.edges.map(u=>[u.id,sl({...u,sourceLabel:l.get(u.source)??u.sourceLabel,targetLabel:l.get(u.target)??u.targetLabel})]))},h=yi(e,o.config.securityLevel);o.layoutAlgorithm=ki(i),nl(o,e),Vs(h,o),await Ni(o,h),il(h,o,r);const d=o.diagramPadding;Ci.insertTitle(h,"usecaseDiagramTitleText",0,a.getDiagramTitle?.()??""),Ri(h,d,"usecaseDiagram",o.useMaxWidth),Vs(h,o)},"draw"),rl={draw:al},ol=c(t=>({actorBkg:t.usecaseActorBkg??t.actorBkg??t.mainBkg,actorBorder:t.usecaseActorBorder??t.actorBorder??t.primaryColor,bkg:t.usecaseBkg??t.mainBkg,border:t.usecaseBorder??t.nodeBorder??t.primaryColor,boundaryBkg:t.usecaseBoundaryBkg??t.clusterBkg,boundaryBorder:t.usecaseBoundaryBorder??t.clusterBorder,includeLine:t.usecaseIncludeLine??t.lineColor,extendLine:t.usecaseExtendLine??t.lineColor}),"roleColors"),ll=c(t=>{const{theme:e,bkgColorArray:s,borderColorArray:n}=t;if(!xi(e,n))return"";const i=Mi().usecase?.colorScheme==="rotate",a=Ue(t.look),o=a==="handDrawn",l=wi(s);let r="";for(let h=0;h<Ui(n);h++){const d=n[h],u=l?`fill: ${s[h%s.length]};`:"",f=`[data-look="${a}"][data-color-id="color-${h}"]`;r+=`
119
-
120
- & ${f}.system-boundary rect.boundary-body,
121
- & ${f}.system-boundary rect.boundary-tab,
122
- & ${f}.system-boundary .boundary-body path,
123
- & ${f}.system-boundary .boundary-tab path {
124
- stroke: ${d};
125
- ${u}
126
- }
127
- `,i&&(r+=`
128
-
129
- /* Use case bodies -- \`.usecase-element\` covers the ellipse form, the \`[Rect]\` form and
130
- the business variant.
131
-
132
- Element selectors only, never a bare \`path\`. Under the handDrawn look roughjs draws
133
- the body as a *pair* of paths, an outline stroked in the border colour and a hachure
134
- fill stroked in the background colour, with no class to tell them apart. Stroking
135
- both repaints the fill lines as border colour and the shape collapses into a solid
136
- block -- which is what \`.usecase-element path\` did. So handDrawn bodies keep the
137
- theme's uniform colours, exactly as handDrawn flowchart nodes do. */
138
- & ${f}.usecase-element ellipse,
139
- & ${f}.usecase-element rect {
140
- stroke: ${d};
141
- ${u}
142
- }
143
-
144
- /* The business marker is a single classed path, so it can be reached safely by name --
145
- without it the marker keeps the uniform border beside a palette-coloured body. No
146
- \`fill\`: the marker is drawn with \`fill="none"\` and has to stay that way. */
147
- & ${f}.usecase-element .usecase-business-marker {
148
- stroke: ${d};
149
- }
150
-
151
- /* Actor glyphs, mirroring the uniform rule further down. The fill goes on the glyph
152
- group, never on its children, so the hollow variant's own \`fill="none"\` keeps
153
- winning and a hollow actor stays hollow. Same reason as above for not descending
154
- into the handDrawn paths. */
155
- & ${f}.usecase-actor .usecase-actor-shape,
156
- & ${f}.usecase-actor .usecase-actor-hollow,
157
- & ${f}.usecase-actor .usecase-actor-awesome,
158
- & ${f}.usecase-actor .usecase-actor-icon {
159
- stroke: ${d};
160
- ${u}
161
- }
162
- ${o?"":`
163
- /* The group rule above reaches the glyph by inheritance, which the neo look breaks: it
164
- ships a \`[data-look="neo"].node path { stroke }\` rule that hits the glyph's own paths,
165
- and a value set directly on the child always beats one inherited from the parent,
166
- whatever the parent rule's specificity. So name the children too.
167
-
168
- Emitted for every look *except* handDrawn, where roughjs draws the glyph as an
169
- outline path plus a hachure fill path stroked in the fill colour, indistinguishable
170
- in CSS -- stroking both turns a hollow actor into a solid disc. Deliberately no
171
- \`fill\` either way, so the hollow variant's own \`fill="none"\` keeps winning. */
172
- & ${f}.usecase-actor .usecase-actor-glyph path,
173
- & ${f}.usecase-actor .usecase-actor-glyph circle {
174
- stroke: ${d};
175
- }
176
- `}
177
- `)}return r},"genColor"),cl=c(t=>{const e=ol(t),s=Ue(t.look)==="handDrawn";return`
178
- ${ll(t)}
179
- & .usecase-actor {
180
- color: ${t.actorTextColor??t.primaryTextColor};
181
- }
182
-
183
- & .usecase-actor-shape,
184
- & .usecase-actor-hollow,
185
- & .usecase-actor-awesome,
186
- & .usecase-actor-icon {
187
- fill: ${e.actorBkg};
188
- stroke: ${e.actorBorder};
189
- stroke-width: 2px;
190
- }
191
- ${s?"":`
192
- /* The rule above colours the glyph group and lets its children inherit, which the neo
193
- look breaks: it ships a \`[data-look="neo"].node path { stroke }\` rule that lands on
194
- the glyph's own paths, and a value set directly on a child always beats one inherited
195
- from its parent, whatever the parent rule's specificity. Since neo is the default look,
196
- without this every actor renders in the node border colour rather than the actor
197
- colour the rule above asks for.
198
-
199
- \`.node\` is in the selector to outrank that neo rule rather than tie with it: both
200
- would otherwise be one attribute plus one class plus one element, leaving the winner to
201
- depend on which stylesheet is concatenated last.
202
-
203
- Stroke only: the hollow variant's own \`fill="none"\` has to keep winning. */
204
- & .node.usecase-actor .usecase-actor-glyph path,
205
- & .node.usecase-actor .usecase-actor-glyph circle {
206
- stroke: ${e.actorBorder};
207
- }
208
- `}
209
- & .usecase-actor .nodeLabel,
210
- & .actor-label {
211
- color: ${t.actorTextColor??t.primaryTextColor};
212
- fill: ${t.actorTextColor??t.primaryTextColor};
213
- font-family: var(--mermaid-usecase-actor-font-family, ${t.fontFamily});
214
- font-size: var(--mermaid-usecase-actor-font-size, 14px);
215
- font-weight: var(--mermaid-usecase-actor-font-weight, normal);
216
- }
217
-
218
- & .usecase-element ellipse,
219
- & .usecase-element rect,
220
- & .usecase-business ellipse,
221
- & .usecase-business rect {
222
- fill: ${e.bkg};
223
- stroke: ${e.border};
224
- stroke-width: 2px;
225
- }
226
- ${s?"":`
227
- /* The same interception the actor glyph hits, one element down: neo ships
228
- \`[data-look="neo"].node rect { stroke: nodeBorder }\`, which outranks the plain
229
- \`.usecase-element rect\` above, so a use case written in the \`[Rect]\` form kept the node
230
- border colour while its ellipse siblings took the role colour. An \`<ellipse>\` has no
231
- equivalent neo rule and is already correct; restating it here costs nothing and means
232
- the two forms cannot drift apart again.
233
-
234
- Qualified with \`[data-look]\` *and* \`.node\` to land strictly above that rule rather than
235
- tie with it -- on a tie the later stylesheet would win, which is how neo took this in
236
- the first place. Skipped under handDrawn, where roughjs draws paths and neither element
237
- exists. */
238
- & [data-look="${Ue(t.look)}"].node.usecase-element ellipse,
239
- & [data-look="${Ue(t.look)}"].node.usecase-element rect {
240
- fill: ${e.bkg};
241
- stroke: ${e.border};
242
- }
243
-
244
- /* The business marker is a \`<path>\`, so it loses to \`[data-look="neo"].node path\` the same
245
- way. No \`fill\`: the marker is drawn with \`fill="none"\` and has to stay that way. */
246
- & [data-look="${Ue(t.look)}"].node.usecase-element .usecase-business-marker {
247
- stroke: ${e.border};
248
- }
249
- `}
250
- & .usecase-element .nodeLabel,
251
- & .usecase-label {
252
- color: ${t.primaryTextColor};
253
- fill: ${t.primaryTextColor};
254
- font-family: var(--mermaid-usecase-font-family, ${t.fontFamily});
255
- font-size: var(--mermaid-usecase-font-size, 12px);
256
- font-weight: var(--mermaid-usecase-font-weight, normal);
257
- }
258
-
259
- & .usecase-stereotype,
260
- & .usecase-business-marker {
261
- color: ${t.primaryTextColor};
262
- fill: ${t.primaryTextColor};
263
- stroke: ${e.border};
264
- }
265
-
266
- & .system-boundary rect.boundary-body,
267
- & .system-boundary rect.boundary-tab,
268
- & .system-boundary-package-tab {
269
- fill: ${e.boundaryBkg};
270
- stroke: ${e.boundaryBorder};
271
- stroke-width: 1px;
272
- }
273
-
274
- & .system-boundary-title text {
275
- fill: ${t.titleColor??t.primaryTextColor};
276
- }
277
-
278
- /* Only the span, never the <p> inside it: the renderer puts a user-supplied
279
- 'color' on the span, and that has to stay inheritable by its children. */
280
- & .system-boundary-title span {
281
- color: ${t.titleColor??t.primaryTextColor};
282
- }
283
-
284
- & .usecase-note {
285
- fill: ${t.noteBkgColor};
286
- stroke: ${t.noteBorderColor};
287
- color: ${t.noteTextColor};
288
- }
289
-
290
- & .usecase-note .nodeLabel {
291
- color: ${t.noteTextColor};
292
- fill: ${t.noteTextColor};
293
- }
294
-
295
- & .usecase-json-table,
296
- & .usecase-json-table rect,
297
- & .usecase-json-cell {
298
- fill: ${t.mainBkg};
299
- stroke: ${t.nodeBorder??t.primaryColor};
300
- }
301
-
302
- & .usecase-json-title,
303
- & .usecase-json-key,
304
- & .usecase-json-value {
305
- color: ${t.primaryTextColor};
306
- fill: ${t.primaryTextColor};
307
- }
308
-
309
- & .relationship {
310
- fill: none;
311
- stroke: ${t.lineColor};
312
- }
313
-
314
- & .relationship-include,
315
- & .relationship-extend,
316
- & .relationship-note {
317
- stroke-dasharray: 3;
318
- }
319
-
320
- /* Include and extend are both dashed, which is a weak distinction at small sizes. The
321
- tokens default to \`lineColor\`, so a theme that does not set them is unchanged. */
322
- & .relationship-include {
323
- stroke: ${e.includeLine};
324
- }
325
-
326
- & .relationship-extend {
327
- stroke: ${e.extendLine};
328
- }
329
-
330
- & .relationship.edge-animation-fast,
331
- & .relationship.edge-animation-slow {
332
- stroke-linecap: round;
333
- }
334
-
335
- & .edgeLabel,
336
- & .edgeLabel p {
337
- background-color: ${t.edgeLabelBackground};
338
- }
339
-
340
- & .labelBkg {
341
- background-color: ${t.edgeLabelBackground};
342
- padding: 0 2px;
343
- }
344
-
345
- & .edgeLabel .label rect {
346
- fill: ${t.edgeLabelBackground};
347
- }
348
-
349
- & .relationship-label,
350
- & .edgeLabel {
351
- color: ${t.primaryTextColor};
352
- fill: ${t.primaryTextColor};
353
- font-family: ${t.fontFamily};
354
- font-size: 10px;
355
- font-weight: normal;
356
- }
357
-
358
- & .marker,
359
- & .marker.point,
360
- & .marker.circle,
361
- & .marker.cross {
362
- fill: ${t.lineColor};
363
- stroke: ${t.lineColor};
364
- }
365
-
366
- & .marker.extension {
367
- fill: ${t.mainBkg};
368
- stroke: ${t.lineColor};
369
- }
370
- `},"getStyles"),hl=cl,ml={parser:Jo,db:At,renderer:rl,styles:hl};export{ml as diagram};