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