@bkm016/basalt 0.1.5 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (202) hide show
  1. package/README.md +12 -10
  2. package/{chunk-gw05p4g3.js → chunk-053vb71h.js} +1 -1
  3. package/{chunk-3c330qna.js → chunk-063vbmtp.js} +2 -2
  4. package/{chunk-bgkegf0k.js → chunk-0javrjcm.js} +4 -4
  5. package/{chunk-pjr91g6k.js → chunk-10p3mb40.js} +1 -1
  6. package/{chunk-mkp28k1x.js → chunk-39vwrg8n.js} +2 -2
  7. package/{chunk-dddsrff6.js → chunk-654cny9a.js} +123 -121
  8. package/{chunk-8xb636vr.js → chunk-6kdgk70p.js} +2 -2
  9. package/{chunk-9z7sdh5e.js → chunk-6ptv4g5e.js} +1 -1
  10. package/{chunk-zzwjt7fp.js → chunk-75434aay.js} +1 -1
  11. package/{chunk-ar3dbfp9.js → chunk-7hr6zw2m.js} +1 -1
  12. package/{chunk-h1rypb99.js → chunk-8gw5bvh3.js} +4 -4
  13. package/{chunk-a4b75ekk.js → chunk-8saewt61.js} +2 -2
  14. package/{chunk-sqaam5ak.js → chunk-8wj32837.js} +1 -1
  15. package/{chunk-539ekagy.js → chunk-8wv5t0w6.js} +5 -5
  16. package/{chunk-aw65h276.js → chunk-8x21n7y9.js} +1 -1
  17. package/{chunk-0n99m9m4.js → chunk-a0c989ky.js} +1 -1
  18. package/{chunk-srjgvdvs.js → chunk-a5apjjcn.js} +6 -6
  19. package/chunk-a81p46j7.js +2 -0
  20. package/chunk-agsfy9w7.js +2 -0
  21. package/{chunk-2qcpq99g.js → chunk-arcqjt91.js} +1 -1
  22. package/{chunk-rxj6tct8.js → chunk-bdy4jksd.js} +1 -1
  23. package/{chunk-zrkh5dw7.js → chunk-benrzwea.js} +1 -1
  24. package/chunk-bpw6q7g0.js +3 -0
  25. package/{chunk-36cqq0ga.js → chunk-c7rcw9fb.js} +5 -5
  26. package/{chunk-x89em726.js → chunk-ca982n62.js} +1 -1
  27. package/chunk-d20p02ny.js +2 -0
  28. package/{chunk-5v4g21rw.js → chunk-d6p2hgxh.js} +1 -1
  29. package/{chunk-t7sc0wwc.js → chunk-dnx91jrd.js} +2 -2
  30. package/{chunk-mat08ab1.js → chunk-dpz4hwqb.js} +2 -2
  31. package/{chunk-zn0g0859.js → chunk-ebpyvs1d.js} +2 -2
  32. package/{chunk-00gwse5r.js → chunk-ecf896fz.js} +1 -1
  33. package/{chunk-0stvywr8.js → chunk-ejsneb6f.js} +1 -1
  34. package/{chunk-7as47pcw.js → chunk-ey15ye2h.js} +1 -1
  35. package/{chunk-v4k3qmdm.js → chunk-f156y565.js} +1 -1
  36. package/{chunk-7tgqhveh.js → chunk-f544p9rh.js} +1 -1
  37. package/chunk-fmq3zwzk.js +2 -0
  38. package/{chunk-ebzkckyw.js → chunk-fx7f4m3c.js} +1 -1
  39. package/{chunk-3k7ejpkc.js → chunk-g0t9c3gv.js} +1 -1
  40. package/{chunk-7w0mefgk.js → chunk-gv7wqkey.js} +2 -2
  41. package/{chunk-1xa7d5mh.js → chunk-j7yvh0ae.js} +1 -1
  42. package/{chunk-0j0qggej.js → chunk-n85qs7cs.js} +1 -1
  43. package/{chunk-7qq99360.js → chunk-n981vx1t.js} +4 -4
  44. package/{chunk-0fwdxd45.js → chunk-peja51xv.js} +1 -1
  45. package/{chunk-6dsq0fns.js → chunk-pg5nkf1y.js} +1 -1
  46. package/{chunk-jyrwk08p.js → chunk-prgm07j4.js} +1 -1
  47. package/{chunk-jvwg4rn1.js → chunk-q9dd6fhj.js} +4 -4
  48. package/{chunk-nxkmd29x.js → chunk-r8vvcp6c.js} +1 -1
  49. package/{chunk-stj493dn.js → chunk-r9aatvwm.js} +2 -2
  50. package/chunk-rfb85nj7.js +2 -0
  51. package/{chunk-980drajf.js → chunk-rfdt992v.js} +12 -12
  52. package/{chunk-e63c1186.js → chunk-s6dejhfj.js} +1 -1
  53. package/{chunk-wfyrfvfn.js → chunk-s7skpgm2.js} +1 -1
  54. package/{chunk-2nkfxhef.js → chunk-sjjtxpg2.js} +247 -230
  55. package/{chunk-r0jc8e7t.js → chunk-w67dvqtb.js} +2 -2
  56. package/{chunk-b9fqretv.js → chunk-whj87h4r.js} +2 -2
  57. package/{chunk-vt1anydc.js → chunk-y8dkfpmj.js} +3 -3
  58. package/{chunk-nx3jnbv8.js → chunk-z02sj1je.js} +2 -2
  59. package/{chunk-hq5ke1yp.js → chunk-zxkq9m8e.js} +1 -1
  60. package/compiled.js +3 -3
  61. package/package.json +1 -1
  62. package/ui-test-worker.js +27 -27
  63. package/web/{chunk-7znyd1mj.js → chunk-079091ar.js} +1 -1
  64. package/web/{chunk-65nwc4cf.js → chunk-083r4f80.js} +1 -1
  65. package/web/{chunk-h2ag4kvz.js → chunk-0cng7r2x.js} +1 -1
  66. package/web/chunk-0k0ande6.js +1 -0
  67. package/web/{chunk-14bad871.js → chunk-14deqqhr.js} +1 -1
  68. package/web/{chunk-pyg1mr80.js → chunk-1s53190z.js} +20 -20
  69. package/web/{chunk-1pasbxwh.js → chunk-2b63adsj.js} +1 -1
  70. package/web/{chunk-zc1mk10n.js → chunk-2cem4sv7.js} +2 -2
  71. package/web/{chunk-y7jq61nv.js → chunk-30b33r2w.js} +2 -2
  72. package/web/{chunk-xsrvw7dt.js → chunk-3baypnwn.js} +3 -3
  73. package/web/{chunk-s24qs1bn.js → chunk-4067nwjp.js} +6 -6
  74. package/web/{chunk-paywgcf7.js → chunk-4fm55fgb.js} +2 -2
  75. package/web/{chunk-yvgs6bm3.js → chunk-4q7wf0wd.js} +1 -1
  76. package/web/{chunk-g5jxwkdh.js → chunk-4sve9xrj.js} +1 -1
  77. package/web/{chunk-56krfj3b.js → chunk-4vjnrz87.js} +1 -1
  78. package/web/chunk-59678wmg.js +1 -0
  79. package/web/chunk-5k8sv4f5.js +1 -0
  80. package/web/{chunk-tcp77cp2.js → chunk-5vjhvw1m.js} +1 -1
  81. package/web/{chunk-f9k3xrwb.js → chunk-5wbnjjhg.js} +1 -1
  82. package/web/chunk-6ft5pz3c.js +1 -0
  83. package/web/chunk-7c8rwqtx.js +1 -0
  84. package/web/chunk-7qzz025k.js +1 -0
  85. package/web/chunk-7xbaqqd7.css +1 -0
  86. package/web/chunk-80eyv2mk.js +1 -0
  87. package/web/chunk-89paytbk.js +4 -0
  88. package/web/chunk-8ceej2g7.js +1 -0
  89. package/web/chunk-8nyhy122.js +1 -0
  90. package/web/{chunk-01hcjafh.js → chunk-989jq2h8.js} +1 -1
  91. package/web/{chunk-bnb9xhgw.js → chunk-aangfjqc.js} +6 -6
  92. package/web/{chunk-1cfh0e2e.js → chunk-bdydzbqk.js} +7 -7
  93. package/web/chunk-cpwtt6ny.js +1 -0
  94. package/web/{chunk-dzg1pv80.js → chunk-czjk218p.js} +3 -3
  95. package/web/{chunk-m8knte9z.js → chunk-dg3p8db5.js} +1 -1
  96. package/web/chunk-dsw5t58p.js +1 -0
  97. package/web/{chunk-j34q5jn6.js → chunk-dv72fat3.js} +1 -1
  98. package/web/{chunk-affear07.js → chunk-dvvs1jjq.js} +1 -1
  99. package/web/{chunk-g9sqbafw.js → chunk-e131rg6p.js} +1 -1
  100. package/web/{chunk-4m3zdd41.js → chunk-e8yj05t1.js} +1 -1
  101. package/web/chunk-ekw54h1q.js +1 -0
  102. package/web/{chunk-0k9aec1s.js → chunk-femhej5w.js} +3 -3
  103. package/web/chunk-fmthkpff.js +1 -0
  104. package/web/{chunk-d60dpf69.js → chunk-geh05ghh.js} +1 -1
  105. package/web/{chunk-892nf39p.js → chunk-gksf7cek.js} +7 -7
  106. package/web/{chunk-abhad4zj.js → chunk-ht4mx2dt.js} +4 -4
  107. package/web/chunk-hwsvhst3.js +1 -0
  108. package/web/{chunk-d6ddkh6e.js → chunk-k02b36g1.js} +1 -1
  109. package/web/{chunk-2nht58dc.js → chunk-kjacapzd.js} +1 -1
  110. package/web/{chunk-zz397b0v.js → chunk-kkfrs7d1.js} +1 -1
  111. package/web/{chunk-aqt7kc3s.js → chunk-kkyn8yhj.js} +1 -1
  112. package/web/chunk-mh4rx5cf.js +1 -0
  113. package/web/{chunk-4a4j030b.js → chunk-n448vaba.js} +1 -1
  114. package/web/{chunk-k67v6dyg.js → chunk-n754s8xd.js} +2 -2
  115. package/web/chunk-n8j88qxy.js +1 -0
  116. package/web/{chunk-kza0t0gj.js → chunk-nfvqjzz5.js} +1 -1
  117. package/web/chunk-nmpbsvwb.js +2 -0
  118. package/web/chunk-nws1s56b.js +1 -0
  119. package/web/{chunk-12z7d0hp.js → chunk-p7126wwy.js} +2 -2
  120. package/web/chunk-phnqnhj9.js +1 -0
  121. package/web/{chunk-5shygfgb.js → chunk-pjz30xcp.js} +2 -2
  122. package/web/{chunk-vhzys0rr.js → chunk-q3jevm51.js} +1 -1
  123. package/web/{chunk-advfpyb9.js → chunk-q97hn4j5.js} +4 -4
  124. package/web/chunk-qg31p6cn.js +1 -0
  125. package/web/{chunk-jcdw85mv.js → chunk-qhm3cfq9.js} +1 -1
  126. package/web/chunk-qsd595b9.js +1 -0
  127. package/web/{chunk-9xgspn75.js → chunk-r7frwjqx.js} +2 -2
  128. package/web/chunk-rddft5ce.js +1139 -0
  129. package/web/{chunk-x7sb3bwf.js → chunk-rgbdf2m9.js} +22 -22
  130. package/web/{chunk-fnnrrzqa.js → chunk-rsbkbg6x.js} +1 -1
  131. package/web/chunk-s2bs5vxh.js +2 -0
  132. package/web/{chunk-sd22cnjy.js → chunk-sgwccs54.js} +1 -1
  133. package/web/{chunk-c53xmf48.js → chunk-sjh8gtm9.js} +1 -1
  134. package/web/{chunk-zqht0jzx.js → chunk-sn3tkwme.js} +1 -1
  135. package/web/{chunk-gcv91974.js → chunk-svh4n157.js} +1 -1
  136. package/web/{chunk-7a3c137d.js → chunk-sy7e4dmq.js} +1 -1
  137. package/web/{chunk-vttgyb5v.js → chunk-t3658ehb.js} +1 -1
  138. package/web/{chunk-h6gh63xj.js → chunk-t6sq85s6.js} +1 -1
  139. package/web/{chunk-z4aj066q.js → chunk-t81p4wqc.js} +1 -1
  140. package/web/{chunk-qq5gh5zr.js → chunk-tewmsd7t.js} +1 -1
  141. package/web/chunk-tf57s7ry.js +1 -0
  142. package/web/{chunk-gxqaa4sv.js → chunk-tfn0rqg9.js} +5 -5
  143. package/web/{chunk-0qr891eq.js → chunk-tmndcktk.js} +1 -1
  144. package/web/chunk-tqr80b5w.js +2 -0
  145. package/web/{chunk-mnzramhc.js → chunk-twdy2f67.js} +1 -1
  146. package/web/chunk-tz4twwmw.js +2 -0
  147. package/web/{chunk-crzseqbx.js → chunk-v282r683.js} +1 -1
  148. package/web/chunk-v4vjjtn7.js +1 -0
  149. package/web/chunk-vbwdwcdp.js +1 -0
  150. package/web/{chunk-6enn8p66.js → chunk-vjngfh0q.js} +1 -1
  151. package/web/{chunk-g8kkc6vz.js → chunk-wbgkwxrc.js} +1 -1
  152. package/web/{chunk-ybw6vgf6.js → chunk-wjbk50hn.js} +1 -1
  153. package/web/chunk-wjy848e2.js +1 -0
  154. package/web/{chunk-3hkgdw6f.js → chunk-wqsczy57.js} +3 -3
  155. package/web/chunk-wvfmmw1v.js +8 -0
  156. package/web/chunk-x1jm4zsg.js +1 -0
  157. package/web/{chunk-26bwh1sb.js → chunk-xbpc6x9m.js} +6 -6
  158. package/web/{chunk-xk1t58c4.js → chunk-xckxtfp8.js} +4 -4
  159. package/web/{chunk-qrdh9j62.js → chunk-xmsb2g71.js} +1 -1
  160. package/web/{chunk-ka7c5rhx.js → chunk-y99ed8rd.js} +6 -6
  161. package/web/{chunk-0p1nmj5n.js → chunk-z1geewdf.js} +1 -1
  162. package/web/index.html +1 -1
  163. package/worker.js +1 -1
  164. package/chunk-2nb3d92s.js +0 -2
  165. package/chunk-2pa1z37c.js +0 -2
  166. package/chunk-4g5f43ea.js +0 -3
  167. package/chunk-eegztdzb.js +0 -2
  168. package/chunk-wd3z74av.js +0 -2
  169. package/chunk-yna8bwqc.js +0 -2
  170. package/web/chunk-0ytga215.js +0 -1
  171. package/web/chunk-1amzv4ha.js +0 -1
  172. package/web/chunk-1s2hp6h1.js +0 -1
  173. package/web/chunk-2y0rc1fe.js +0 -1
  174. package/web/chunk-4w298aqs.js +0 -1
  175. package/web/chunk-6stt9d18.js +0 -1
  176. package/web/chunk-7e47b1sn.js +0 -1
  177. package/web/chunk-7pypx5h8.js +0 -2
  178. package/web/chunk-9dy7z3ej.js +0 -2
  179. package/web/chunk-9mq2cdtq.js +0 -1
  180. package/web/chunk-b5hah4mf.js +0 -1
  181. package/web/chunk-b8tfetd8.js +0 -1
  182. package/web/chunk-ckgpy4r4.js +0 -1
  183. package/web/chunk-dbnrfxt1.js +0 -8
  184. package/web/chunk-ddxf8e84.js +0 -1
  185. package/web/chunk-e8h45nyr.js +0 -1
  186. package/web/chunk-ej9vb61c.js +0 -1
  187. package/web/chunk-fjag6yg8.js +0 -2
  188. package/web/chunk-gxsb5tx3.js +0 -1
  189. package/web/chunk-jg6fmz2d.js +0 -1
  190. package/web/chunk-mpfgr049.js +0 -1
  191. package/web/chunk-mz1dabxh.js +0 -1
  192. package/web/chunk-p53n0hwr.js +0 -1
  193. package/web/chunk-pfcnr9tw.js +0 -1
  194. package/web/chunk-q7xkscc5.js +0 -1
  195. package/web/chunk-qmbgb79a.js +0 -1139
  196. package/web/chunk-sfq6cw45.js +0 -2
  197. package/web/chunk-svqj4az8.js +0 -1
  198. package/web/chunk-t7jwyvvr.js +0 -1
  199. package/web/chunk-tf18d2dk.css +0 -1
  200. package/web/chunk-v0g4cqc1.js +0 -4
  201. package/web/chunk-vqfz99ff.js +0 -1
  202. package/web/chunk-zazs8p6c.js +0 -1
@@ -1,4 +1,4 @@
1
- import{e,a,D,b,O,C,S,E,T,A,R,L,l,p,M,ni,ue,oe,se,ht,ye,ve}from"./chunk-pyg1mr80.js";import{ge}from"./chunk-9xgspn75.js";import{le}from"./chunk-01hcjafh.js";function tt(t){if(console&&console.error)console.error(`Error: ${t}`)}function gt(t){if(console&&console.warn)console.warn(`Warning: ${t}`)}function At(t){let s=new Date().getTime(),n=t();return{time:new Date().getTime()-s,value:n}}function St(t){function s(){}s.prototype=t;let n=new s;function i(){return typeof n.bar}return i(),i(),t;(0,eval)(t)}function Gr(t){if(Wr(t))return t.LABEL;else return t.name}function Wr(t){return typeof t.LABEL==="string"&&t.LABEL!==""}class Le{get definition(){return this._definition}set definition(t){this._definition=t}constructor(t){this._definition=t}accept(t){t.visit(this),this.definition.forEach((s)=>{s.accept(t)})}}class W extends Le{constructor(t){super([]);this.idx=1,Object.assign(this,_e(t))}set definition(t){}get definition(){if(this.referencedRule!==void 0)return this.referencedRule.definition;return[]}accept(t){t.visit(this)}}class Ee extends Le{constructor(t){super(t.definition);this.orgText="",Object.assign(this,_e(t))}}class j extends Le{constructor(t){super(t.definition);this.ignoreAmbiguities=!1,Object.assign(this,_e(t))}}class K extends Le{constructor(t){super(t.definition);this.idx=1,Object.assign(this,_e(t))}}class Z extends Le{constructor(t){super(t.definition);this.idx=1,Object.assign(this,_e(t))}}class Q extends Le{constructor(t){super(t.definition);this.idx=1,Object.assign(this,_e(t))}}class G extends Le{constructor(t){super(t.definition);this.idx=1,Object.assign(this,_e(t))}}class q extends Le{constructor(t){super(t.definition);this.idx=1,Object.assign(this,_e(t))}}class J extends Le{get definition(){return this._definition}set definition(t){this._definition=t}constructor(t){super(t.definition);this.idx=1,this.ignoreAmbiguities=!1,this.hasPredicates=!1,Object.assign(this,_e(t))}}class F{constructor(t){this.idx=1,Object.assign(this,_e(t))}accept(t){t.visit(this)}}function Wt(t){return t.map(st)}function st(t){function s(n){return n.map(st)}if(t instanceof W){let n={type:"NonTerminal",name:t.nonTerminalName,idx:t.idx};if(typeof t.label==="string")n.label=t.label;return n}else if(t instanceof j)return{type:"Alternative",definition:s(t.definition)};else if(t instanceof K)return{type:"Option",idx:t.idx,definition:s(t.definition)};else if(t instanceof Z)return{type:"RepetitionMandatory",idx:t.idx,definition:s(t.definition)};else if(t instanceof Q)return{type:"RepetitionMandatoryWithSeparator",idx:t.idx,separator:st(new F({terminalType:t.separator})),definition:s(t.definition)};else if(t instanceof q)return{type:"RepetitionWithSeparator",idx:t.idx,separator:st(new F({terminalType:t.separator})),definition:s(t.definition)};else if(t instanceof G)return{type:"Repetition",idx:t.idx,definition:s(t.definition)};else if(t instanceof J)return{type:"Alternation",idx:t.idx,definition:s(t.definition)};else if(t instanceof F){let n={type:"Terminal",name:t.terminalType.name,label:Gr(t.terminalType),idx:t.idx};if(typeof t.label==="string")n.terminalLabel=t.label;let i=t.terminalType.PATTERN;if(t.terminalType.PATTERN)n.pattern=i instanceof RegExp?i.source:i;return n}else if(t instanceof Ee)return{type:"Rule",name:t.name,orgText:t.orgText,definition:s(t.definition)};else throw Error("non exhaustive match")}function _e(t){return Object.fromEntries(Object.entries(t).filter(([,s])=>s!==void 0))}class Te{visit(t){let s=t;switch(s.constructor){case W:return this.visitNonTerminal(s);case j:return this.visitAlternative(s);case K:return this.visitOption(s);case Z:return this.visitRepetitionMandatory(s);case Q:return this.visitRepetitionMandatoryWithSeparator(s);case q:return this.visitRepetitionWithSeparator(s);case G:return this.visitRepetition(s);case J:return this.visitAlternation(s);case F:return this.visitTerminal(s);case Ee:return this.visitRule(s);default:throw Error("non exhaustive match")}}visitNonTerminal(t){}visitAlternative(t){}visitOption(t){}visitRepetition(t){}visitRepetitionMandatory(t){}visitRepetitionMandatoryWithSeparator(t){}visitRepetitionWithSeparator(t){}visitAlternation(t){}visitTerminal(t){}visitRule(t){}}function vs(t){return t instanceof j||t instanceof K||t instanceof G||t instanceof Z||t instanceof Q||t instanceof q||t instanceof F||t instanceof Ee}function je(t,s=[]){if(t instanceof K||t instanceof G||t instanceof q)return!0;if(t instanceof J)return t.definition.some((i)=>je(i,s));else if(t instanceof W&&s.includes(t))return!1;else if(t instanceof Le){if(t instanceof W)s.push(t);return t.definition.every((i)=>je(i,s))}else return!1}function Ms(t){return t instanceof J}function Ae(t){if(t instanceof W)return"SUBRULE";else if(t instanceof K)return"OPTION";else if(t instanceof J)return"OR";else if(t instanceof Z)return"AT_LEAST_ONE";else if(t instanceof Q)return"AT_LEAST_ONE_SEP";else if(t instanceof q)return"MANY_SEP";else if(t instanceof G)return"MANY";else if(t instanceof F)return"CONSUME";else throw Error("non exhaustive match")}class $e{walk(t,s=[]){t.definition.forEach((n,i)=>{let r=t.definition.slice(i+1);if(n instanceof W)this.walkProdRef(n,r,s);else if(n instanceof F)this.walkTerminal(n,r,s);else if(n instanceof j)this.walkFlat(n,r,s);else if(n instanceof K)this.walkOption(n,r,s);else if(n instanceof Z)this.walkAtLeastOne(n,r,s);else if(n instanceof Q)this.walkAtLeastOneSep(n,r,s);else if(n instanceof q)this.walkManySep(n,r,s);else if(n instanceof G)this.walkMany(n,r,s);else if(n instanceof J)this.walkOr(n,r,s);else throw Error("non exhaustive match")})}walkTerminal(t,s,n){}walkProdRef(t,s,n){}walkFlat(t,s,n){let i=s.concat(n);this.walk(t,i)}walkOption(t,s,n){let i=s.concat(n);this.walk(t,i)}walkAtLeastOne(t,s,n){let i=[new K({definition:t.definition})].concat(s,n);this.walk(t,i)}walkAtLeastOneSep(t,s,n){let i=Nn(t,s,n);this.walk(t,i)}walkMany(t,s,n){let i=[new K({definition:t.definition})].concat(s,n);this.walk(t,i)}walkManySep(t,s,n){let i=Nn(t,s,n);this.walk(t,i)}walkOr(t,s,n){let i=s.concat(n);t.definition.forEach((r)=>{let o=new j({definition:[r]});this.walk(o,i)})}}function Nn(t,s,n){return[new K({definition:[new F({terminalType:t.separator})].concat(t.definition)})].concat(s,n)}function Ke(t){if(t instanceof W)return Ke(t.referencedRule);else if(t instanceof F)return Vr(t);else if(vs(t))return jr(t);else if(Ms(t))return Kr(t);else throw Error("non exhaustive match")}function jr(t){let s=[],n=t.definition,i=0,r=n.length>i,o,h=!0;while(r&&h)o=n[i],h=je(o),s=s.concat(Ke(o)),i=i+1,r=n.length>i;return[...new Set(s)]}function Kr(t){let s=t.definition.map((n)=>Ke(n));return[...new Set(s.flat())]}function Vr(t){return[t.terminalType]}var jt="_~IN~_";class In extends $e{constructor(t){super();this.topProd=t,this.follows={}}startWalking(){return this.walk(this.topProd),this.follows}walkTerminal(t,s,n){}walkProdRef(t,s,n){let i=zr(t.referencedRule,t.idx)+this.topProd.name,r=s.concat(n),o=new j({definition:r}),h=Ke(o);this.follows[i]=h}}function kn(t){let s={};return t.forEach((n)=>{let i=new In(n).startWalking();Object.assign(s,i)}),s}function zr(t,s){return t.name+s+jt}function x(t){return t.charCodeAt(0)}function Kt(t,s){if(Array.isArray(t))t.forEach(function(n){s.push(n)});else s.push(t)}function nt(t,s){if(t[s]===!0)throw"duplicate flag "+s;let n=t[s];t[s]=!0}function Ve(t){if(t===void 0)throw Error("Internal Error - Should never get here!");return!0}function Rt(){throw Error("Internal Error - Should never get here!")}function ws(t){return t.type==="Character"}var yt=[];for(let t=x("0");t<=x("9");t++)yt.push(t);var Ot=[x("_")].concat(yt);for(let t=x("a");t<=x("z");t++)Ot.push(t);for(let t=x("A");t<=x("Z");t++)Ot.push(t);var Us=[x(" "),x("\f"),x(`
1
+ import{e,a,D,b,O,C,S,E,T,A,R,L,l,p,M,ni,ue,oe,se,gt,ge,ye}from"./chunk-1s53190z.js";import{he}from"./chunk-r7frwjqx.js";import{le}from"./chunk-989jq2h8.js";function tt(t){if(console&&console.error)console.error(`Error: ${t}`)}function Tt(t){if(console&&console.warn)console.warn(`Warning: ${t}`)}function At(t){let s=new Date().getTime(),n=t();return{time:new Date().getTime()-s,value:n}}function St(t){function s(){}s.prototype=t;let n=new s;function i(){return typeof n.bar}return i(),i(),t;(0,eval)(t)}function Gr(t){if(Wr(t))return t.LABEL;else return t.name}function Wr(t){return typeof t.LABEL==="string"&&t.LABEL!==""}class Ne{get definition(){return this._definition}set definition(t){this._definition=t}constructor(t){this._definition=t}accept(t){t.visit(this),this.definition.forEach((s)=>{s.accept(t)})}}class W extends Ne{constructor(t){super([]);this.idx=1,Object.assign(this,xe(t))}set definition(t){}get definition(){if(this.referencedRule!==void 0)return this.referencedRule.definition;return[]}accept(t){t.visit(this)}}class Te extends Ne{constructor(t){super(t.definition);this.orgText="",Object.assign(this,xe(t))}}class j extends Ne{constructor(t){super(t.definition);this.ignoreAmbiguities=!1,Object.assign(this,xe(t))}}class K extends Ne{constructor(t){super(t.definition);this.idx=1,Object.assign(this,xe(t))}}class Z extends Ne{constructor(t){super(t.definition);this.idx=1,Object.assign(this,xe(t))}}class Q extends Ne{constructor(t){super(t.definition);this.idx=1,Object.assign(this,xe(t))}}class G extends Ne{constructor(t){super(t.definition);this.idx=1,Object.assign(this,xe(t))}}class q extends Ne{constructor(t){super(t.definition);this.idx=1,Object.assign(this,xe(t))}}class J extends Ne{get definition(){return this._definition}set definition(t){this._definition=t}constructor(t){super(t.definition);this.idx=1,this.ignoreAmbiguities=!1,this.hasPredicates=!1,Object.assign(this,xe(t))}}class F{constructor(t){this.idx=1,Object.assign(this,xe(t))}accept(t){t.visit(this)}}function Wt(t){return t.map(st)}function st(t){function s(n){return n.map(st)}if(t instanceof W){let n={type:"NonTerminal",name:t.nonTerminalName,idx:t.idx};if(typeof t.label==="string")n.label=t.label;return n}else if(t instanceof j)return{type:"Alternative",definition:s(t.definition)};else if(t instanceof K)return{type:"Option",idx:t.idx,definition:s(t.definition)};else if(t instanceof Z)return{type:"RepetitionMandatory",idx:t.idx,definition:s(t.definition)};else if(t instanceof Q)return{type:"RepetitionMandatoryWithSeparator",idx:t.idx,separator:st(new F({terminalType:t.separator})),definition:s(t.definition)};else if(t instanceof q)return{type:"RepetitionWithSeparator",idx:t.idx,separator:st(new F({terminalType:t.separator})),definition:s(t.definition)};else if(t instanceof G)return{type:"Repetition",idx:t.idx,definition:s(t.definition)};else if(t instanceof J)return{type:"Alternation",idx:t.idx,definition:s(t.definition)};else if(t instanceof F){let n={type:"Terminal",name:t.terminalType.name,label:Gr(t.terminalType),idx:t.idx};if(typeof t.label==="string")n.terminalLabel=t.label;let i=t.terminalType.PATTERN;if(t.terminalType.PATTERN)n.pattern=i instanceof RegExp?i.source:i;return n}else if(t instanceof Te)return{type:"Rule",name:t.name,orgText:t.orgText,definition:s(t.definition)};else throw Error("non exhaustive match")}function xe(t){return Object.fromEntries(Object.entries(t).filter(([,s])=>s!==void 0))}class Ae{visit(t){let s=t;switch(s.constructor){case W:return this.visitNonTerminal(s);case j:return this.visitAlternative(s);case K:return this.visitOption(s);case Z:return this.visitRepetitionMandatory(s);case Q:return this.visitRepetitionMandatoryWithSeparator(s);case q:return this.visitRepetitionWithSeparator(s);case G:return this.visitRepetition(s);case J:return this.visitAlternation(s);case F:return this.visitTerminal(s);case Te:return this.visitRule(s);default:throw Error("non exhaustive match")}}visitNonTerminal(t){}visitAlternative(t){}visitOption(t){}visitRepetition(t){}visitRepetitionMandatory(t){}visitRepetitionMandatoryWithSeparator(t){}visitRepetitionWithSeparator(t){}visitAlternation(t){}visitTerminal(t){}visitRule(t){}}function vs(t){return t instanceof j||t instanceof K||t instanceof G||t instanceof Z||t instanceof Q||t instanceof q||t instanceof F||t instanceof Te}function je(t,s=[]){if(t instanceof K||t instanceof G||t instanceof q)return!0;if(t instanceof J)return t.definition.some((i)=>je(i,s));else if(t instanceof W&&s.includes(t))return!1;else if(t instanceof Ne){if(t instanceof W)s.push(t);return t.definition.every((i)=>je(i,s))}else return!1}function Ms(t){return t instanceof J}function Se(t){if(t instanceof W)return"SUBRULE";else if(t instanceof K)return"OPTION";else if(t instanceof J)return"OR";else if(t instanceof Z)return"AT_LEAST_ONE";else if(t instanceof Q)return"AT_LEAST_ONE_SEP";else if(t instanceof q)return"MANY_SEP";else if(t instanceof G)return"MANY";else if(t instanceof F)return"CONSUME";else throw Error("non exhaustive match")}class $e{walk(t,s=[]){t.definition.forEach((n,i)=>{let r=t.definition.slice(i+1);if(n instanceof W)this.walkProdRef(n,r,s);else if(n instanceof F)this.walkTerminal(n,r,s);else if(n instanceof j)this.walkFlat(n,r,s);else if(n instanceof K)this.walkOption(n,r,s);else if(n instanceof Z)this.walkAtLeastOne(n,r,s);else if(n instanceof Q)this.walkAtLeastOneSep(n,r,s);else if(n instanceof q)this.walkManySep(n,r,s);else if(n instanceof G)this.walkMany(n,r,s);else if(n instanceof J)this.walkOr(n,r,s);else throw Error("non exhaustive match")})}walkTerminal(t,s,n){}walkProdRef(t,s,n){}walkFlat(t,s,n){let i=s.concat(n);this.walk(t,i)}walkOption(t,s,n){let i=s.concat(n);this.walk(t,i)}walkAtLeastOne(t,s,n){let i=[new K({definition:t.definition})].concat(s,n);this.walk(t,i)}walkAtLeastOneSep(t,s,n){let i=Nn(t,s,n);this.walk(t,i)}walkMany(t,s,n){let i=[new K({definition:t.definition})].concat(s,n);this.walk(t,i)}walkManySep(t,s,n){let i=Nn(t,s,n);this.walk(t,i)}walkOr(t,s,n){let i=s.concat(n);t.definition.forEach((r)=>{let o=new j({definition:[r]});this.walk(o,i)})}}function Nn(t,s,n){return[new K({definition:[new F({terminalType:t.separator})].concat(t.definition)})].concat(s,n)}function Ke(t){if(t instanceof W)return Ke(t.referencedRule);else if(t instanceof F)return Vr(t);else if(vs(t))return jr(t);else if(Ms(t))return Kr(t);else throw Error("non exhaustive match")}function jr(t){let s=[],n=t.definition,i=0,r=n.length>i,o,h=!0;while(r&&h)o=n[i],h=je(o),s=s.concat(Ke(o)),i=i+1,r=n.length>i;return[...new Set(s)]}function Kr(t){let s=t.definition.map((n)=>Ke(n));return[...new Set(s.flat())]}function Vr(t){return[t.terminalType]}var jt="_~IN~_";class In extends $e{constructor(t){super();this.topProd=t,this.follows={}}startWalking(){return this.walk(this.topProd),this.follows}walkTerminal(t,s,n){}walkProdRef(t,s,n){let i=zr(t.referencedRule,t.idx)+this.topProd.name,r=s.concat(n),o=new j({definition:r}),h=Ke(o);this.follows[i]=h}}function kn(t){let s={};return t.forEach((n)=>{let i=new In(n).startWalking();Object.assign(s,i)}),s}function zr(t,s){return t.name+s+jt}function x(t){return t.charCodeAt(0)}function Kt(t,s){if(Array.isArray(t))t.forEach(function(n){s.push(n)});else s.push(t)}function nt(t,s){if(t[s]===!0)throw"duplicate flag "+s;let n=t[s];t[s]=!0}function Ve(t){if(t===void 0)throw Error("Internal Error - Should never get here!");return!0}function Rt(){throw Error("Internal Error - Should never get here!")}function ws(t){return t.type==="Character"}var yt=[];for(let t=x("0");t<=x("9");t++)yt.push(t);var Ot=[x("_")].concat(yt);for(let t=x("a");t<=x("z");t++)Ot.push(t);for(let t=x("A");t<=x("Z");t++)Ot.push(t);var Us=[x(" "),x("\f"),x(`
2
2
  `),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")];var Hr=/[0-9a-fA-F]/,Vt=/[0-9]/,Xr=/[1-9]/;class zt{constructor(){this.idx=0,this.input="",this.groupIdx=0}saveState(){return{idx:this.idx,input:this.input,groupIdx:this.groupIdx}}restoreState(t){this.idx=t.idx,this.input=t.input,this.groupIdx=t.groupIdx}pattern(t){this.idx=0,this.input=t,this.groupIdx=0,this.consumeChar("/");let s=this.disjunction();this.consumeChar("/");let n={type:"Flags",loc:{begin:this.idx,end:t.length},global:!1,ignoreCase:!1,multiLine:!1,unicode:!1,sticky:!1};while(this.isRegExpFlag())switch(this.popChar()){case"g":nt(n,"global");break;case"i":nt(n,"ignoreCase");break;case"m":nt(n,"multiLine");break;case"u":nt(n,"unicode");break;case"y":nt(n,"sticky");break}if(this.idx!==this.input.length)throw Error("Redundant input: "+this.input.substring(this.idx));return{type:"Pattern",flags:n,value:s,loc:this.loc(0)}}disjunction(){let t=[],s=this.idx;t.push(this.alternative());while(this.peekChar()==="|")this.consumeChar("|"),t.push(this.alternative());return{type:"Disjunction",value:t,loc:this.loc(s)}}alternative(){let t=[],s=this.idx;while(this.isTerm())t.push(this.term());return{type:"Alternative",value:t,loc:this.loc(s)}}term(){if(this.isAssertion())return this.assertion();else return this.atom()}assertion(){let t=this.idx;switch(this.popChar()){case"^":return{type:"StartAnchor",loc:this.loc(t)};case"$":return{type:"EndAnchor",loc:this.loc(t)};case"\\":switch(this.popChar()){case"b":return{type:"WordBoundary",loc:this.loc(t)};case"B":return{type:"NonWordBoundary",loc:this.loc(t)}}throw Error("Invalid Assertion Escape");case"(":this.consumeChar("?");let s;switch(this.popChar()){case"=":s="Lookahead";break;case"!":s="NegativeLookahead";break;case"<":{switch(this.popChar()){case"=":s="Lookbehind";break;case"!":s="NegativeLookbehind"}break}}Ve(s);let n=this.disjunction();return this.consumeChar(")"),{type:s,value:n,loc:this.loc(t)}}return Rt()}quantifier(t=!1){let s=void 0,n=this.idx;switch(this.popChar()){case"*":s={atLeast:0,atMost:1/0};break;case"+":s={atLeast:1,atMost:1/0};break;case"?":s={atLeast:0,atMost:1};break;case"{":let i=this.integerIncludingZero();switch(this.popChar()){case"}":s={atLeast:i,atMost:i};break;case",":let r;if(this.isDigit())r=this.integerIncludingZero(),s={atLeast:i,atMost:r};else s={atLeast:i,atMost:1/0};this.consumeChar("}");break}if(t===!0&&s===void 0)return;Ve(s);break}if(t===!0&&s===void 0)return;if(Ve(s)){if(this.peekChar(0)==="?")this.consumeChar("?"),s.greedy=!1;else s.greedy=!0;return s.type="Quantifier",s.loc=this.loc(n),s}}atom(){let t,s=this.idx;switch(this.peekChar()){case".":t=this.dotAll();break;case"\\":t=this.atomEscape();break;case"[":t=this.characterClass();break;case"(":t=this.group();break}if(t===void 0&&this.isPatternCharacter())t=this.patternCharacter();if(Ve(t)){if(t.loc=this.loc(s),this.isQuantifier())t.quantifier=this.quantifier();return t}return Rt()}dotAll(){return this.consumeChar("."),{type:"Set",complement:!0,value:[x(`
3
3
  `),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 t,s=!1;switch(this.popChar()){case"d":t=yt;break;case"D":t=yt,s=!0;break;case"s":t=Us;break;case"S":t=Us,s=!0;break;case"w":t=Ot;break;case"W":t=Ot,s=!0;break}if(Ve(t))return{type:"Set",value:t,complement:s};return Rt()}controlEscapeAtom(){let t;switch(this.popChar()){case"f":t=x("\f");break;case"n":t=x(`
4
4
  `);break;case"r":t=x("\r");break;case"t":t=x("\t");break;case"v":t=x("\v");break}if(Ve(t))return{type:"Character",value:t};return Rt()}controlLetterEscapeAtom(){this.consumeChar("c");let t=this.popChar();if(/[a-zA-Z]/.test(t)===!1)throw Error("Invalid ");return{type:"Character",value:t.toUpperCase().charCodeAt(0)-64}}nulCharacterAtom(){return this.consumeChar("0"),{type:"Character",value:x("\x00")}}hexEscapeSequenceAtom(){return this.consumeChar("x"),this.parseHexDigits(2)}regExpUnicodeEscapeSequenceAtom(){return this.consumeChar("u"),this.parseHexDigits(4)}identityEscapeAtom(){let t=this.popChar();return{type:"Character",value:x(t)}}classPatternCharacterAtom(){switch(this.peekChar()){case`
@@ -7,7 +7,7 @@ import{e,a,D,b,O,C,S,E,T,A,R,L,l,p,M,ni,ue,oe,se,ht,ye,ve}from"./chunk-pyg1mr80.
7
7
  `:case"\r":case"\u2028":case"\u2029":case"^":case"$":case"\\":case".":case"*":case"+":case"?":case"(":case")":case"[":case"|":throw Error("TBD");default:return{type:"Character",value:x(t)}}}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 Vt.test(this.peekChar(0))}isClassAtom(t=0){switch(this.peekChar(t)){case"]":case`
8
8
  `:case"\r":case"\u2028":case"\u2029":return!1;default:return!0}}isTerm(){return this.isAtom()||this.isAssertion()}isAtom(){if(this.isPatternCharacter())return!0;switch(this.peekChar(0)){case".":case"\\":case"[":case"(":return!0;default:return!1}}isAssertion(){switch(this.peekChar(0)){case"^":case"$":return!0;case"\\":switch(this.peekChar(1)){case"b":case"B":return!0;default:return!1}case"(":return this.peekChar(1)==="?"&&(this.peekChar(2)==="="||this.peekChar(2)==="!"||this.peekChar(2)==="<"&&(this.peekChar(3)==="="||this.peekChar(3)==="!"));default:return!1}}isQuantifier(){let t=this.saveState();try{return this.quantifier(!0)!==void 0}catch(s){return!1}finally{this.restoreState(t)}}isPatternCharacter(){switch(this.peekChar()){case"^":case"$":case"\\":case".":case"*":case"+":case"?":case"(":case")":case"[":case"|":case"/":case`
9
9
  `:case"\r":case"\u2028":case"\u2029":return!1;default:return!0}}parseHexDigits(t){let s="";for(let i=0;i<t;i++){let r=this.popChar();if(Hr.test(r)===!1)throw Error("Expecting a HexDecimal digits");s+=r}return{type:"Character",value:parseInt(s,16)}}peekChar(t=0){return this.input[this.idx+t]}popChar(){let t=this.peekChar(0);return this.consumeChar(void 0),t}consumeChar(t){if(t!==void 0&&this.input[this.idx]!==t)throw Error("Expected: '"+t+"' 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(t){return{begin:t,end:this.idx}}}class ze{visitChildren(t){for(let s in t){let n=t[s];if(t.hasOwnProperty(s)){if(n.type!==void 0)this.visit(n);else if(Array.isArray(n))n.forEach((i)=>{this.visit(i)},this)}}}visit(t){switch(t.type){case"Pattern":this.visitPattern(t);break;case"Flags":this.visitFlags(t);break;case"Disjunction":this.visitDisjunction(t);break;case"Alternative":this.visitAlternative(t);break;case"StartAnchor":this.visitStartAnchor(t);break;case"EndAnchor":this.visitEndAnchor(t);break;case"WordBoundary":this.visitWordBoundary(t);break;case"NonWordBoundary":this.visitNonWordBoundary(t);break;case"Lookahead":this.visitLookahead(t);break;case"NegativeLookahead":this.visitNegativeLookahead(t);break;case"Lookbehind":this.visitLookbehind(t);break;case"NegativeLookbehind":this.visitNegativeLookbehind(t);break;case"Character":this.visitCharacter(t);break;case"Set":this.visitSet(t);break;case"Group":this.visitGroup(t);break;case"GroupBackReference":this.visitGroupBackReference(t);break;case"Quantifier":this.visitQuantifier(t);break}this.visitChildren(t)}visitPattern(t){}visitFlags(t){}visitDisjunction(t){}visitAlternative(t){}visitStartAnchor(t){}visitEndAnchor(t){}visitWordBoundary(t){}visitNonWordBoundary(t){}visitLookahead(t){}visitNegativeLookahead(t){}visitLookbehind(t){}visitNegativeLookbehind(t){}visitCharacter(t){}visitSet(t){}visitGroup(t){}visitGroupBackReference(t){}visitQuantifier(t){}}var Ht={},Yr=new zt;function He(t){let s=t.toString();if(Ht.hasOwnProperty(s))return Ht[s];else{let n=Yr.pattern(s);return Ht[s]=n,n}}function Cn(){Ht={}}var _n="Complement Sets are not supported for first char optimization",Lt=`Unable to use "first char" lexer optimizations:
10
- `;function xn(t,s=!1){try{let n=He(t);return Ps(n.value,{},n.flags.ignoreCase)}catch(n){if(n.message===_n){if(s)gt(`${Lt} Unable to optimize: < ${t.toString()} >
10
+ `;function xn(t,s=!1){try{let n=He(t);return Ps(n.value,{},n.flags.ignoreCase)}catch(n){if(n.message===_n){if(s)Tt(`${Lt} Unable to optimize: < ${t.toString()} >
11
11
  Complement Sets cannot be automatically optimized.
12
12
  This will disable the lexer's first char optimizations.
13
13
  See: https://chevrotain.io/docs/guide/resolving_lexer_errors.html#COMPLEMENT for details.`)}else{let i="";if(s)i=`
@@ -15,11 +15,11 @@ import{e,a,D,b,O,C,S,E,T,A,R,L,l,p,M,ni,ue,oe,se,ht,ye,ve}from"./chunk-pyg1mr80.
15
15
  See: https://chevrotain.io/docs/guide/resolving_lexer_errors.html#REGEXP_PARSING for details.`;tt(`${Lt}
16
16
  Failed parsing: < ${t.toString()} >
17
17
  Using the @chevrotain/regexp-to-ast library
18
- Please open an issue at: https://github.com/chevrotain/chevrotain/issues`+i)}}return[]}function Ps(t,s,n){switch(t.type){case"Disjunction":for(let r=0;r<t.value.length;r++)Ps(t.value[r],s,n);break;case"Alternative":let i=t.value;for(let r=0;r<i.length;r++){let o=i[r];switch(o.type){case"EndAnchor":case"GroupBackReference":case"Lookahead":case"NegativeLookahead":case"Lookbehind":case"NegativeLookbehind":case"StartAnchor":case"WordBoundary":case"NonWordBoundary":continue}let h=o;switch(h.type){case"Character":Xt(h.value,s,n);break;case"Set":if(h.complement===!0)throw Error(_n);h.value.forEach((c)=>{if(typeof c==="number")Xt(c,s,n);else{let d=c;if(n===!0)for(let f=d.from;f<=d.to;f++)Xt(f,s,n);else{for(let f=d.from;f<=d.to&&f<it;f++)Xt(f,s,n);if(d.to>=it){let f=d.from>=it?d.from:it,m=d.to,y=xe(f),N=xe(m);for(let U=y;U<=N;U++)s[U]=U}}}});break;case"Group":Ps(h.value,s,n);break;default:throw Error("Non Exhaustive Match")}let u=h.quantifier!==void 0&&h.quantifier.atLeast===0;if(h.type==="Group"&&Ds(h)===!1||h.type!=="Group"&&u===!1)break}break;default:throw Error("non exhaustive match!")}return Object.values(s)}function Xt(t,s,n){let i=xe(t);if(s[i]=i,n===!0)qr(t,s)}function qr(t,s){let n=String.fromCharCode(t),i=n.toUpperCase();if(i!==n){let r=xe(i.charCodeAt(0));s[r]=r}else{let r=n.toLowerCase();if(r!==n){let o=xe(r.charCodeAt(0));s[o]=o}}}function bn(t,s){return t.value.find((n)=>{if(typeof n==="number")return s.includes(n);else{let i=n;return s.find((r)=>i.from<=r&&r<=i.to)!==void 0}})}function Ds(t){let s=t.quantifier;if(s&&s.atLeast===0)return!0;if(!t.value)return!1;return Array.isArray(t.value)?t.value.every(Ds):Ds(t.value)}class vn extends ze{constructor(t){super();this.targetCharCodes=t,this.found=!1}visitChildren(t){if(this.found===!0)return;switch(t.type){case"Lookahead":this.visitLookahead(t);return;case"NegativeLookahead":this.visitNegativeLookahead(t);return;case"Lookbehind":this.visitLookbehind(t);return;case"NegativeLookbehind":this.visitNegativeLookbehind(t);return}super.visitChildren(t)}visitCharacter(t){if(this.targetCharCodes.includes(t.value))this.found=!0}visitSet(t){if(t.complement){if(bn(t,this.targetCharCodes)===void 0)this.found=!0}else if(bn(t,this.targetCharCodes)!==void 0)this.found=!0}}function Yt(t,s){if(s instanceof RegExp){let n=He(s),i=new vn(t);return i.visit(n),i.found}else{for(let n of s){let i=n.charCodeAt(0);if(t.includes(i))return!0}return!1}}var Xe="PATTERN",rt="defaultMode",qt="modes",Zt=0,Nt=1,Qt=2,es=3;function wn(t,s){s=Object.assign({safeMode:!1,positionTracking:"full",lineTerminatorCharacters:["\r",`
19
- `],tracer:(k,g)=>g()},s);let n=s.tracer;n("initCharCodeToOptimizedIndexMap",()=>{Ea()});let i;n("Reject Lexer.NA",()=>{i=t.filter((k)=>k[Xe]!==z.NA)});let r=!1,o;n("Transform Patterns",()=>{r=!1,o=i.map((k)=>{let g=k[Xe];if(g instanceof RegExp){let w=g.source;if(w.length===1&&w!=="^"&&w!=="$"&&w!=="."&&!g.ignoreCase)return w;else if(w.length===2&&w[0]==="\\"&&!["d","D","s","S","t","r","n","t","0","c","b","B","f","v","w","W"].includes(w[1]))return w[1];else return Mn(g)}else if(typeof g==="function")return r=!0,{exec:g};else if(typeof g==="object")return r=!0,g;else if(typeof g==="string")if(g.length===1)return g;else{let w=g.replace(/[\\^$.*+?()[\]{}|]/g,"\\$&"),te=new RegExp(w);return Mn(te)}else throw Error("non exhaustive match")})});let h,u,c,d,f;n("misc mapping",()=>{h=i.map((k)=>k.tokenTypeIdx),u=i.map((k)=>{let g=k.GROUP;if(g===z.SKIPPED)return;else if(typeof g==="string")return g;else if(g===void 0)return!1;else throw Error("non exhaustive match")}),c=i.map((k)=>{let g=k.LONGER_ALT;if(g)return Array.isArray(g)?g.map((te)=>i.indexOf(te)):[i.indexOf(g)]}),d=i.map((k)=>k.PUSH_MODE),f=i.map((k)=>Object.hasOwn(k,"POP_MODE"))});let m;n("Line Terminator Handling",()=>{let k=Gn(s.lineTerminatorCharacters);if(m=i.map((g)=>!1),s.positionTracking!=="onlyOffset")m=i.map((g)=>{if(Object.hasOwn(g,"LINE_BREAKS"))return!!g.LINE_BREAKS;else return $n(g,k)===!1&&Yt(k,g.PATTERN)})});let y,N,U,P;n("Misc Mapping #2",()=>{y=i.map(Fn),N=o.map(fa),U=i.reduce((k,g)=>{let w=g.GROUP;if(typeof w==="string"&&w!==z.SKIPPED)k[w]=[];return k},{}),P=o.map((k,g)=>{let w=u[g]===void 0&&c[g]===void 0?Jr(i[g].PATTERN):void 0;return{pattern:o[g],asciiClass:w,longerAlt:c[g],canLineTerminator:m[g],matchType:w!==void 0?es:N[g]!==!1?Zt:y[g]?Nt:Qt,short:N[g],group:u[g],push:d[g],pop:f[g],tokenTypeIdx:h[g],tokenType:i[g]}})});let v=!0,_=[];if(!s.safeMode)n("First Char Optimization",()=>{_=i.reduce((k,g,w)=>{if(typeof g.PATTERN==="string"){let te=g.PATTERN.charCodeAt(0),he=xe(te);Fs(k,he,P[w])}else if(Array.isArray(g.START_CHARS_HINT)){let te;g.START_CHARS_HINT.forEach((he)=>{let ft=typeof he==="string"?he.charCodeAt(0):he,Me=xe(ft);if(te!==Me)te=Me,Fs(k,Me,P[w])})}else if(g.PATTERN instanceof RegExp)if(g.PATTERN.unicode){if(v=!1,s.ensureOptimizations)tt(`${Lt} Unable to analyze < ${g.PATTERN.toString()} > pattern.
18
+ Please open an issue at: https://github.com/chevrotain/chevrotain/issues`+i)}}return[]}function Ps(t,s,n){switch(t.type){case"Disjunction":for(let r=0;r<t.value.length;r++)Ps(t.value[r],s,n);break;case"Alternative":let i=t.value;for(let r=0;r<i.length;r++){let o=i[r];switch(o.type){case"EndAnchor":case"GroupBackReference":case"Lookahead":case"NegativeLookahead":case"Lookbehind":case"NegativeLookbehind":case"StartAnchor":case"WordBoundary":case"NonWordBoundary":continue}let h=o;switch(h.type){case"Character":Xt(h.value,s,n);break;case"Set":if(h.complement===!0)throw Error(_n);h.value.forEach((c)=>{if(typeof c==="number")Xt(c,s,n);else{let d=c;if(n===!0)for(let f=d.from;f<=d.to;f++)Xt(f,s,n);else{for(let f=d.from;f<=d.to&&f<it;f++)Xt(f,s,n);if(d.to>=it){let f=d.from>=it?d.from:it,m=d.to,y=ve(f),N=ve(m);for(let U=y;U<=N;U++)s[U]=U}}}});break;case"Group":Ps(h.value,s,n);break;default:throw Error("Non Exhaustive Match")}let u=h.quantifier!==void 0&&h.quantifier.atLeast===0;if(h.type==="Group"&&Ds(h)===!1||h.type!=="Group"&&u===!1)break}break;default:throw Error("non exhaustive match!")}return Object.values(s)}function Xt(t,s,n){let i=ve(t);if(s[i]=i,n===!0)qr(t,s)}function qr(t,s){let n=String.fromCharCode(t),i=n.toUpperCase();if(i!==n){let r=ve(i.charCodeAt(0));s[r]=r}else{let r=n.toLowerCase();if(r!==n){let o=ve(r.charCodeAt(0));s[o]=o}}}function bn(t,s){return t.value.find((n)=>{if(typeof n==="number")return s.includes(n);else{let i=n;return s.find((r)=>i.from<=r&&r<=i.to)!==void 0}})}function Ds(t){let s=t.quantifier;if(s&&s.atLeast===0)return!0;if(!t.value)return!1;return Array.isArray(t.value)?t.value.every(Ds):Ds(t.value)}class vn extends ze{constructor(t){super();this.targetCharCodes=t,this.found=!1}visitChildren(t){if(this.found===!0)return;switch(t.type){case"Lookahead":this.visitLookahead(t);return;case"NegativeLookahead":this.visitNegativeLookahead(t);return;case"Lookbehind":this.visitLookbehind(t);return;case"NegativeLookbehind":this.visitNegativeLookbehind(t);return}super.visitChildren(t)}visitCharacter(t){if(this.targetCharCodes.includes(t.value))this.found=!0}visitSet(t){if(t.complement){if(bn(t,this.targetCharCodes)===void 0)this.found=!0}else if(bn(t,this.targetCharCodes)!==void 0)this.found=!0}}function Yt(t,s){if(s instanceof RegExp){let n=He(s),i=new vn(t);return i.visit(n),i.found}else{for(let n of s){let i=n.charCodeAt(0);if(t.includes(i))return!0}return!1}}var Xe="PATTERN",rt="defaultMode",qt="modes",Zt=0,Nt=1,Qt=2,es=3;function wn(t,s){s=Object.assign({safeMode:!1,positionTracking:"full",lineTerminatorCharacters:["\r",`
19
+ `],tracer:(k,g)=>g()},s);let n=s.tracer;n("initCharCodeToOptimizedIndexMap",()=>{Ea()});let i;n("Reject Lexer.NA",()=>{i=t.filter((k)=>k[Xe]!==z.NA)});let r=!1,o;n("Transform Patterns",()=>{r=!1,o=i.map((k)=>{let g=k[Xe];if(g instanceof RegExp){let w=g.source;if(w.length===1&&w!=="^"&&w!=="$"&&w!=="."&&!g.ignoreCase)return w;else if(w.length===2&&w[0]==="\\"&&!["d","D","s","S","t","r","n","t","0","c","b","B","f","v","w","W"].includes(w[1]))return w[1];else return Mn(g)}else if(typeof g==="function")return r=!0,{exec:g};else if(typeof g==="object")return r=!0,g;else if(typeof g==="string")if(g.length===1)return g;else{let w=g.replace(/[\\^$.*+?()[\]{}|]/g,"\\$&"),te=new RegExp(w);return Mn(te)}else throw Error("non exhaustive match")})});let h,u,c,d,f;n("misc mapping",()=>{h=i.map((k)=>k.tokenTypeIdx),u=i.map((k)=>{let g=k.GROUP;if(g===z.SKIPPED)return;else if(typeof g==="string")return g;else if(g===void 0)return!1;else throw Error("non exhaustive match")}),c=i.map((k)=>{let g=k.LONGER_ALT;if(g)return Array.isArray(g)?g.map((te)=>i.indexOf(te)):[i.indexOf(g)]}),d=i.map((k)=>k.PUSH_MODE),f=i.map((k)=>Object.hasOwn(k,"POP_MODE"))});let m;n("Line Terminator Handling",()=>{let k=Gn(s.lineTerminatorCharacters);if(m=i.map((g)=>!1),s.positionTracking!=="onlyOffset")m=i.map((g)=>{if(Object.hasOwn(g,"LINE_BREAKS"))return!!g.LINE_BREAKS;else return $n(g,k)===!1&&Yt(k,g.PATTERN)})});let y,N,U,P;n("Misc Mapping #2",()=>{y=i.map(Fn),N=o.map(fa),U=i.reduce((k,g)=>{let w=g.GROUP;if(typeof w==="string"&&w!==z.SKIPPED)k[w]=[];return k},{}),P=o.map((k,g)=>{let w=u[g]===void 0&&c[g]===void 0?Jr(i[g].PATTERN):void 0;return{pattern:o[g],asciiClass:w,longerAlt:c[g],canLineTerminator:m[g],matchType:w!==void 0?es:N[g]!==!1?Zt:y[g]?Nt:Qt,short:N[g],group:u[g],push:d[g],pop:f[g],tokenTypeIdx:h[g],tokenType:i[g]}})});let v=!0,_=[];if(!s.safeMode)n("First Char Optimization",()=>{_=i.reduce((k,g,w)=>{if(typeof g.PATTERN==="string"){let te=g.PATTERN.charCodeAt(0),de=ve(te);Fs(k,de,P[w])}else if(Array.isArray(g.START_CHARS_HINT)){let te;g.START_CHARS_HINT.forEach((de)=>{let pt=typeof de==="string"?de.charCodeAt(0):de,Me=ve(pt);if(te!==Me)te=Me,Fs(k,Me,P[w])})}else if(g.PATTERN instanceof RegExp)if(g.PATTERN.unicode){if(v=!1,s.ensureOptimizations)tt(`${Lt} Unable to analyze < ${g.PATTERN.toString()} > pattern.
20
20
  The regexp unicode flag is not currently supported by the regexp-to-ast library.
21
21
  This will disable the lexer's first char optimizations.
22
- For details See: https://chevrotain.io/docs/guide/resolving_lexer_errors.html#UNICODE_OPTIMIZE`)}else{let te=xn(g.PATTERN,s.ensureOptimizations);if(te.length===0)v=!1;te.forEach((he)=>{Fs(k,he,P[w])})}else{if(s.ensureOptimizations)tt(`${Lt} TokenType: <${g.name}> is using a custom token pattern without providing <start_chars_hint> parameter.
22
+ For details See: https://chevrotain.io/docs/guide/resolving_lexer_errors.html#UNICODE_OPTIMIZE`)}else{let te=xn(g.PATTERN,s.ensureOptimizations);if(te.length===0)v=!1;te.forEach((de)=>{Fs(k,de,P[w])})}else{if(s.ensureOptimizations)tt(`${Lt} TokenType: <${g.name}> is using a custom token pattern without providing <start_chars_hint> parameter.
23
23
  This will disable the lexer's first char optimizations.
24
24
  For details See: https://chevrotain.io/docs/guide/resolving_lexer_errors.html#CUSTOM_OPTIMIZE`);v=!1}return k},[])});return{emptyGroups:U,patternIdxToConfig:P,charCodeToPatternIdxToConfig:_,hasCustom:r,canBeOptimized:v}}function Jr(t){var s,n;if(!(t instanceof RegExp)||t.flags!=="")return;let i;try{i=He(t)}catch(u){return}if(i.value.value.length!==1||i.value.value[0].value.length!==1)return;let r=i.value.value[0].value[0],o;while(r.type==="Group"){if(r.capturing||r.quantifier!==void 0&&o!==void 0||r.value.value.length!==1||r.value.value[0].value.length!==1)return;o=(s=r.quantifier)!==null&&s!==void 0?s:o,r=r.value.value[0].value[0]}if(r.type!=="Set"||r.complement||r.quantifier!==void 0&&o!==void 0)return;if(o=(n=r.quantifier)!==null&&n!==void 0?n:o,(o===null||o===void 0?void 0:o.atLeast)!==1||o.atMost!==1/0||!o.greedy)return;let h=new Uint8Array(128);for(let u of r.value){let c=typeof u==="number"?u:u.from,d=typeof u==="number"?u:u.to;if(c<0||d>=h.length)return;h.fill(1,c,d+1)}return h}function Un(t,s){let n=[],i=Qr(t);n=n.concat(i.errors);let r=ea(i.valid),o=r.valid;return n=n.concat(r.errors),n=n.concat(Zr(o)),n=n.concat(la(o)),n=n.concat(ca(o,s)),n=n.concat(ha(o)),n}function Zr(t){let s=[],n=t.filter((i)=>i[Xe]instanceof RegExp);return s=s.concat(sa(n)),s=s.concat(ra(n)),s=s.concat(aa(n)),s=s.concat(oa(n)),s=s.concat(na(n)),s}function Qr(t){let s=t.filter((r)=>!Object.hasOwn(r,Xe)),n=s.map((r)=>({message:"Token Type: ->"+r.name+"<- missing static 'PATTERN' property",type:V.MISSING_PATTERN,tokenTypes:[r]})),i=t.filter((r)=>!s.includes(r));return{errors:n,valid:i}}function ea(t){let s=t.filter((r)=>{let o=r[Xe];return!(o instanceof RegExp)&&typeof o!=="function"&&!Object.hasOwn(o,"exec")&&typeof o!=="string"}),n=s.map((r)=>({message:"Token Type: ->"+r.name+"<- static 'PATTERN' can only be a RegExp, a Function matching the {CustomPatternMatcherFunc} type or an Object matching the {ICustomPattern} interface.",type:V.INVALID_PATTERN,tokenTypes:[r]})),i=t.filter((r)=>!s.includes(r));return{errors:n,valid:i}}var ta=/[^\\][$]/;function sa(t){class s extends ze{constructor(){super(...arguments);this.found=!1}visitEndAnchor(r){this.found=!0}}return t.filter((r)=>{let o=r.PATTERN;try{let h=He(o),u=new s;return u.visit(h),u.found}catch(h){return ta.test(o.source)}}).map((r)=>({message:`Unexpected RegExp Anchor Error:
25
25
  Token Type: ->`+r.name+`<- static 'PATTERN' cannot contain end of input anchor '$'
@@ -41,23 +41,23 @@ See https://chevrotain.io/docs/guide/resolving_lexer_errors.html#UNREACHABLE`;s.
41
41
  Root cause: ${s.errMsg}.
42
42
  For details See: https://chevrotain.io/docs/guide/resolving_lexer_errors.html#IDENTIFY_TERMINATOR`;else if(s.issue===V.CUSTOM_LINE_BREAK)return`Warning: A Custom Token Pattern should specify the <line_breaks> option.
43
43
  The problem is in the <${t.name}> Token Type
44
- For details See: https://chevrotain.io/docs/guide/resolving_lexer_errors.html#CUSTOM_LINE_BREAK`;else throw Error("non exhaustive match")}function Gn(t){return t.map((n)=>{if(typeof n==="string")return n.charCodeAt(0);else return n})}function Fs(t,s,n){if(t[s]===void 0)t[s]=[n];else t[s].push(n)}var it=256,Jt=[];function xe(t){return t<it?t:Jt[t]}function Ea(){if(Jt.length===0){Jt=Array(65536);for(let t=0;t<65536;t++)Jt[t]=t>255?255+~~(t/255):t}}function Ue(t,s){let n=t.tokenTypeIdx;if(n===s.tokenTypeIdx)return!0;else return s.isParent===!0&&s.categoryMatchesMap[n]===!0}function at(t,s){return t.tokenTypeIdx===s.tokenTypeIdx}var Wn=1,Kn={};function Pe(t){let s=Ta(t);ga(s),Sa(s),Aa(s),s.forEach((n)=>{n.isParent=n.categoryMatches.length>0})}function Ta(t){let s=[...t],n=t,i=!0;while(i){n=n.map((o)=>o.CATEGORIES).flat().filter(Boolean);let r=n.filter((o)=>!s.includes(o));if(s=s.concat(r),r.length===0)i=!1;else n=r}return s}function ga(t){t.forEach((s)=>{if(!Bs(s))Kn[Wn]=s,s.tokenTypeIdx=Wn++;if(jn(s)&&!Array.isArray(s.CATEGORIES))s.CATEGORIES=[s.CATEGORIES];if(!jn(s))s.CATEGORIES=[];if(!Ra(s))s.categoryMatches=[];if(!ya(s))s.categoryMatchesMap={}})}function Aa(t){t.forEach((s)=>{s.categoryMatches=[],Object.keys(s.categoryMatchesMap).forEach((n)=>{s.categoryMatches.push(Kn[n].tokenTypeIdx)})})}function Sa(t){t.forEach((s)=>{Vn([],s)})}function Vn(t,s){t.forEach((n)=>{s.categoryMatchesMap[n.tokenTypeIdx]=!0}),s.CATEGORIES.forEach((n)=>{let i=t.concat(s);if(!i.includes(n))Vn(i,n)})}function Bs(t){return Object.hasOwn(t!==null&&t!==void 0?t:{},"tokenTypeIdx")}function jn(t){return Object.hasOwn(t!==null&&t!==void 0?t:{},"CATEGORIES")}function Ra(t){return Object.hasOwn(t!==null&&t!==void 0?t:{},"categoryMatches")}function ya(t){return Object.hasOwn(t!==null&&t!==void 0?t:{},"categoryMatchesMap")}function zn(t){return Object.hasOwn(t!==null&&t!==void 0?t:{},"tokenTypeIdx")}var $s={buildUnableToPopLexerModeMessage(t){return`Unable to pop Lexer Mode after encountering Token ->${t.image}<- The Mode Stack is empty`},buildUnexpectedCharactersMessage(t,s,n,i,r,o){return`unexpected character: ->${t.charAt(s)}<- at offset: ${s}, skipped ${n} characters.`}};var V;(function(t){t[t.MISSING_PATTERN=0]="MISSING_PATTERN",t[t.INVALID_PATTERN=1]="INVALID_PATTERN",t[t.EOI_ANCHOR_FOUND=2]="EOI_ANCHOR_FOUND",t[t.UNSUPPORTED_FLAGS_FOUND=3]="UNSUPPORTED_FLAGS_FOUND",t[t.DUPLICATE_PATTERNS_FOUND=4]="DUPLICATE_PATTERNS_FOUND",t[t.INVALID_GROUP_TYPE_FOUND=5]="INVALID_GROUP_TYPE_FOUND",t[t.PUSH_MODE_DOES_NOT_EXIST=6]="PUSH_MODE_DOES_NOT_EXIST",t[t.MULTI_MODE_LEXER_WITHOUT_DEFAULT_MODE=7]="MULTI_MODE_LEXER_WITHOUT_DEFAULT_MODE",t[t.MULTI_MODE_LEXER_WITHOUT_MODES_PROPERTY=8]="MULTI_MODE_LEXER_WITHOUT_MODES_PROPERTY",t[t.MULTI_MODE_LEXER_DEFAULT_MODE_VALUE_DOES_NOT_EXIST=9]="MULTI_MODE_LEXER_DEFAULT_MODE_VALUE_DOES_NOT_EXIST",t[t.LEXER_DEFINITION_CANNOT_CONTAIN_UNDEFINED=10]="LEXER_DEFINITION_CANNOT_CONTAIN_UNDEFINED",t[t.SOI_ANCHOR_FOUND=11]="SOI_ANCHOR_FOUND",t[t.EMPTY_MATCH_PATTERN=12]="EMPTY_MATCH_PATTERN",t[t.NO_LINE_BREAKS_FLAGS=13]="NO_LINE_BREAKS_FLAGS",t[t.UNREACHABLE_PATTERN=14]="UNREACHABLE_PATTERN",t[t.IDENTIFY_TERMINATOR=15]="IDENTIFY_TERMINATOR",t[t.CUSTOM_LINE_BREAK=16]="CUSTOM_LINE_BREAK",t[t.MULTI_MODE_LEXER_LONGER_ALT_NOT_IN_CURRENT_MODE=17]="MULTI_MODE_LEXER_LONGER_ALT_NOT_IN_CURRENT_MODE"})(V||(V={}));var It={deferDefinitionErrorsHandling:!1,positionTracking:"full",lineTerminatorsPattern:/\n|\r\n?/g,lineTerminatorCharacters:[`
44
+ For details See: https://chevrotain.io/docs/guide/resolving_lexer_errors.html#CUSTOM_LINE_BREAK`;else throw Error("non exhaustive match")}function Gn(t){return t.map((n)=>{if(typeof n==="string")return n.charCodeAt(0);else return n})}function Fs(t,s,n){if(t[s]===void 0)t[s]=[n];else t[s].push(n)}var it=256,Jt=[];function ve(t){return t<it?t:Jt[t]}function Ea(){if(Jt.length===0){Jt=Array(65536);for(let t=0;t<65536;t++)Jt[t]=t>255?255+~~(t/255):t}}function Ue(t,s){let n=t.tokenTypeIdx;if(n===s.tokenTypeIdx)return!0;else return s.isParent===!0&&s.categoryMatchesMap[n]===!0}function at(t,s){return t.tokenTypeIdx===s.tokenTypeIdx}var Wn=1,Kn={};function Pe(t){let s=Ta(t);ga(s),Sa(s),Aa(s),s.forEach((n)=>{n.isParent=n.categoryMatches.length>0})}function Ta(t){let s=[...t],n=t,i=!0;while(i){n=n.map((o)=>o.CATEGORIES).flat().filter(Boolean);let r=n.filter((o)=>!s.includes(o));if(s=s.concat(r),r.length===0)i=!1;else n=r}return s}function ga(t){t.forEach((s)=>{if(!Bs(s))Kn[Wn]=s,s.tokenTypeIdx=Wn++;if(jn(s)&&!Array.isArray(s.CATEGORIES))s.CATEGORIES=[s.CATEGORIES];if(!jn(s))s.CATEGORIES=[];if(!Ra(s))s.categoryMatches=[];if(!ya(s))s.categoryMatchesMap={}})}function Aa(t){t.forEach((s)=>{s.categoryMatches=[],Object.keys(s.categoryMatchesMap).forEach((n)=>{s.categoryMatches.push(Kn[n].tokenTypeIdx)})})}function Sa(t){t.forEach((s)=>{Vn([],s)})}function Vn(t,s){t.forEach((n)=>{s.categoryMatchesMap[n.tokenTypeIdx]=!0}),s.CATEGORIES.forEach((n)=>{let i=t.concat(s);if(!i.includes(n))Vn(i,n)})}function Bs(t){return Object.hasOwn(t!==null&&t!==void 0?t:{},"tokenTypeIdx")}function jn(t){return Object.hasOwn(t!==null&&t!==void 0?t:{},"CATEGORIES")}function Ra(t){return Object.hasOwn(t!==null&&t!==void 0?t:{},"categoryMatches")}function ya(t){return Object.hasOwn(t!==null&&t!==void 0?t:{},"categoryMatchesMap")}function zn(t){return Object.hasOwn(t!==null&&t!==void 0?t:{},"tokenTypeIdx")}var $s={buildUnableToPopLexerModeMessage(t){return`Unable to pop Lexer Mode after encountering Token ->${t.image}<- The Mode Stack is empty`},buildUnexpectedCharactersMessage(t,s,n,i,r,o){return`unexpected character: ->${t.charAt(s)}<- at offset: ${s}, skipped ${n} characters.`}};var V;(function(t){t[t.MISSING_PATTERN=0]="MISSING_PATTERN",t[t.INVALID_PATTERN=1]="INVALID_PATTERN",t[t.EOI_ANCHOR_FOUND=2]="EOI_ANCHOR_FOUND",t[t.UNSUPPORTED_FLAGS_FOUND=3]="UNSUPPORTED_FLAGS_FOUND",t[t.DUPLICATE_PATTERNS_FOUND=4]="DUPLICATE_PATTERNS_FOUND",t[t.INVALID_GROUP_TYPE_FOUND=5]="INVALID_GROUP_TYPE_FOUND",t[t.PUSH_MODE_DOES_NOT_EXIST=6]="PUSH_MODE_DOES_NOT_EXIST",t[t.MULTI_MODE_LEXER_WITHOUT_DEFAULT_MODE=7]="MULTI_MODE_LEXER_WITHOUT_DEFAULT_MODE",t[t.MULTI_MODE_LEXER_WITHOUT_MODES_PROPERTY=8]="MULTI_MODE_LEXER_WITHOUT_MODES_PROPERTY",t[t.MULTI_MODE_LEXER_DEFAULT_MODE_VALUE_DOES_NOT_EXIST=9]="MULTI_MODE_LEXER_DEFAULT_MODE_VALUE_DOES_NOT_EXIST",t[t.LEXER_DEFINITION_CANNOT_CONTAIN_UNDEFINED=10]="LEXER_DEFINITION_CANNOT_CONTAIN_UNDEFINED",t[t.SOI_ANCHOR_FOUND=11]="SOI_ANCHOR_FOUND",t[t.EMPTY_MATCH_PATTERN=12]="EMPTY_MATCH_PATTERN",t[t.NO_LINE_BREAKS_FLAGS=13]="NO_LINE_BREAKS_FLAGS",t[t.UNREACHABLE_PATTERN=14]="UNREACHABLE_PATTERN",t[t.IDENTIFY_TERMINATOR=15]="IDENTIFY_TERMINATOR",t[t.CUSTOM_LINE_BREAK=16]="CUSTOM_LINE_BREAK",t[t.MULTI_MODE_LEXER_LONGER_ALT_NOT_IN_CURRENT_MODE=17]="MULTI_MODE_LEXER_LONGER_ALT_NOT_IN_CURRENT_MODE"})(V||(V={}));var It={deferDefinitionErrorsHandling:!1,positionTracking:"full",lineTerminatorsPattern:/\n|\r\n?/g,lineTerminatorCharacters:[`
45
45
  `,"\r"],ensureOptimizations:!1,safeMode:!1,errorMessageProvider:$s,traceInitPerf:!1,skipValidations:!1,recoveryEnabled:!0};Object.freeze(It);class z{constructor(t,s=It){if(this.lexerDefinition=t,this.lexerDefinitionErrors=[],this.lexerDefinitionWarning=[],this.patternIdxToConfig={},this.charCodeToPatternIdxToConfig={},this.modes=[],this.emptyGroups={},this.cachedGroupKeys=[],this.trackStartLines=!0,this.trackEndLines=!0,this.hasCustom=!1,this.canModeBeOptimized={},this.TRACE_INIT=(i,r)=>{if(this.traceInitPerf===!0){this.traceInitIndent++;let o=Array(this.traceInitIndent+1).join("\t");if(this.traceInitIndent<this.traceInitMaxIdent)console.log(`${o}--> <${i}>`);let{time:h,value:u}=At(r),c=h>10?console.warn:console.log;if(this.traceInitIndent<this.traceInitMaxIdent)c(`${o}<-- <${i}> time: ${h}ms`);return this.traceInitIndent--,u}else return r()},typeof s==="boolean")throw Error(`The second argument to the Lexer constructor is now an ILexerConfig Object.
46
46
  a boolean 2nd argument is no longer supported`);this.config=Object.assign({},It,s);let n=this.config.traceInitPerf;if(n===!0)this.traceInitMaxIdent=1/0,this.traceInitPerf=!0;else if(typeof n==="number")this.traceInitMaxIdent=n,this.traceInitPerf=!0;this.traceInitIndent=-1,this.TRACE_INIT("Lexer Constructor",()=>{let i,r=!0;if(this.TRACE_INIT("Lexer Config handling",()=>{if(this.config.lineTerminatorsPattern===It.lineTerminatorsPattern)this.config.lineTerminatorsPattern=Bn;else if(this.config.lineTerminatorCharacters===It.lineTerminatorCharacters)throw Error(`Error: Missing <lineTerminatorCharacters> property on the Lexer config.
47
47
  For details See: https://chevrotain.io/docs/guide/resolving_lexer_errors.html#MISSING_LINE_TERM_CHARS`);if(s.safeMode&&s.ensureOptimizations)throw Error('"safeMode" and "ensureOptimizations" flags are mutually exclusive.');if(this.trackStartLines=/full|onlyStart/i.test(this.config.positionTracking),this.trackEndLines=/full/i.test(this.config.positionTracking),Array.isArray(t))i={modes:{defaultMode:[...t]},defaultMode:rt};else r=!1,i=Object.assign({},t)}),this.config.skipValidations===!1)this.TRACE_INIT("performRuntimeChecks",()=>{this.lexerDefinitionErrors=this.lexerDefinitionErrors.concat(Pn(i,this.trackStartLines,this.config.lineTerminatorCharacters))}),this.TRACE_INIT("performWarningRuntimeChecks",()=>{this.lexerDefinitionWarning=this.lexerDefinitionWarning.concat(Dn(i,this.trackStartLines,this.config.lineTerminatorCharacters))});i.modes=i.modes?i.modes:{},Object.entries(i.modes).forEach(([h,u])=>{i.modes[h]=u.filter((c)=>c!==void 0)});let o=Object.keys(i.modes);if(Object.entries(i.modes).forEach(([h,u])=>{this.TRACE_INIT(`Mode: <${h}> processing`,()=>{if(this.modes.push(h),this.config.skipValidations===!1)this.TRACE_INIT("validatePatterns",()=>{this.lexerDefinitionErrors=this.lexerDefinitionErrors.concat(Un(u,o))});if(this.lexerDefinitionErrors.length===0){Pe(u);let c;this.TRACE_INIT("analyzeTokenTypes",()=>{c=wn(u,{lineTerminatorCharacters:this.config.lineTerminatorCharacters,positionTracking:s.positionTracking,ensureOptimizations:s.ensureOptimizations,safeMode:s.safeMode,tracer:this.TRACE_INIT})}),this.patternIdxToConfig[h]=c.patternIdxToConfig,this.charCodeToPatternIdxToConfig[h]=c.charCodeToPatternIdxToConfig,this.emptyGroups=Object.assign({},this.emptyGroups,c.emptyGroups),this.hasCustom=c.hasCustom||this.hasCustom,this.canModeBeOptimized[h]=c.canBeOptimized}})}),this.defaultMode=i.defaultMode,this.cachedGroupKeys=Object.keys(this.emptyGroups),this.lexerDefinitionErrors.length>0&&!this.config.deferDefinitionErrorsHandling){let u=this.lexerDefinitionErrors.map((c)=>c.message).join(`-----------------------
48
48
  `);throw Error(`Errors detected in definition of Lexer:
49
- `+u)}this.lexerDefinitionWarning.forEach((h)=>{gt(h.message)}),this.TRACE_INIT("Choosing sub-methods implementations",()=>{if(r)this.handleModes=()=>{};if(this.trackStartLines===!1)this.computeNewColumn=(h)=>h;if(this.trackEndLines===!1)this.updateTokenEndLineColumnLocation=()=>{};if(/full/i.test(this.config.positionTracking))this.createTokenInstance=this.createFullToken;else if(/onlyStart/i.test(this.config.positionTracking))this.createTokenInstance=this.createStartOnlyToken;else if(/onlyOffset/i.test(this.config.positionTracking))this.createTokenInstance=this.createOffsetOnlyToken;else throw Error(`Invalid <positionTracking> config option: "${this.config.positionTracking}"`);if(this.hasCustom)this.addToken=this.addTokenUsingPush,this.handlePayload=this.handlePayloadWithCustom;else this.addToken=this.addTokenUsingMemberAccess,this.handlePayload=this.handlePayloadNoCustom}),this.TRACE_INIT("Failed Optimization Warnings",()=>{let h=Object.entries(this.canModeBeOptimized).reduce((u,[c,d])=>{if(d===!1)u.push(c);return u},[]);if(s.ensureOptimizations&&h.length>0)throw Error(`Lexer Modes: < ${h.join(", ")} > cannot be optimized.
49
+ `+u)}this.lexerDefinitionWarning.forEach((h)=>{Tt(h.message)}),this.TRACE_INIT("Choosing sub-methods implementations",()=>{if(r)this.handleModes=()=>{};if(this.trackStartLines===!1)this.computeNewColumn=(h)=>h;if(this.trackEndLines===!1)this.updateTokenEndLineColumnLocation=()=>{};if(/full/i.test(this.config.positionTracking))this.createTokenInstance=this.createFullToken;else if(/onlyStart/i.test(this.config.positionTracking))this.createTokenInstance=this.createStartOnlyToken;else if(/onlyOffset/i.test(this.config.positionTracking))this.createTokenInstance=this.createOffsetOnlyToken;else throw Error(`Invalid <positionTracking> config option: "${this.config.positionTracking}"`);if(this.hasCustom)this.addToken=this.addTokenUsingPush,this.handlePayload=this.handlePayloadWithCustom;else this.addToken=this.addTokenUsingMemberAccess,this.handlePayload=this.handlePayloadNoCustom}),this.TRACE_INIT("Failed Optimization Warnings",()=>{let h=Object.entries(this.canModeBeOptimized).reduce((u,[c,d])=>{if(d===!1)u.push(c);return u},[]);if(s.ensureOptimizations&&h.length>0)throw Error(`Lexer Modes: < ${h.join(", ")} > cannot be optimized.
50
50
  Disable the "ensureOptimizations" lexer config flag to silently ignore this and run the lexer in an un-optimized mode.
51
51
  Or inspect the console log for details on how to resolve these issues.`)}),this.TRACE_INIT("clearRegExpParserCache",()=>{Cn()}),this.TRACE_INIT("toFastProperties",()=>{St(this)})})}tokenize(t,s=this.defaultMode){if(this.lexerDefinitionErrors.length>0){let i=this.lexerDefinitionErrors.map((r)=>r.message).join(`-----------------------
52
52
  `);throw Error(`Unable to Tokenize because Errors detected in definition of Lexer:
53
- `+i)}return this.tokenizeInternal(t,s)}tokenizeInternal(t,s){let n,i,r,o,h,u,c,d,f,m,y,N,U,P,v,_=t,k=_.length,g=0,w=0,te=this.hasCustom?0:Math.floor(t.length/10),he=Array(te),ft=[],Me=this.trackStartLines?1:void 0,be=this.trackStartLines?1:void 0,et={};for(let ne=0;ne<this.cachedGroupKeys.length;ne++)et[this.cachedGroupKeys[ne]]=[];let Br=this.trackStartLines,ks=this.config.lineTerminatorsPattern,Cs=0,We=[],mt=[],Et=[],yn=[];Object.freeze(yn);let Tt=!1,$r=(ne)=>{if(Et.length===1&&ne.tokenType.PUSH_MODE===void 0){let Oe=this.config.errorMessageProvider.buildUnableToPopLexerModeMessage(ne);ft.push({offset:ne.startOffset,line:ne.startLine,column:ne.startColumn,length:ne.image.length,message:Oe})}else{Et.pop();let Oe=Et.at(-1);We=this.patternIdxToConfig[Oe],mt=this.charCodeToPatternIdxToConfig[Oe],Cs=We.length;let bs=this.canModeBeOptimized[Oe]&&this.config.safeMode===!1;if(mt&&bs)Tt=!0;else Tt=!1}};function On(ne){Et.push(ne),mt=this.charCodeToPatternIdxToConfig[ne],We=this.patternIdxToConfig[ne],Cs=We.length;let Oe=this.canModeBeOptimized[ne]&&this.config.safeMode===!1;if(mt&&Oe)Tt=!0;else Tt=!1}On.call(this,s);let Re,Ln=this.config.recoveryEnabled;while(g<k){u=null,f=-1;let ne=_.charCodeAt(g),Oe;if(Tt){let ae=xe(ne),me=mt[ae];Oe=me!==void 0?me:yn}else Oe=We;let bs=Oe.length;for(n=0;n<bs;n++){Re=Oe[n];let ae=Re.pattern;switch(c=null,Re.matchType){case Zt:if(ne===Re.short)f=1,u=ae;break;case Nt:if(v=ae.exec(_,g,he,et),v!==null){if(u=v[0],f=u.length,v.payload!==void 0)c=v.payload}else u=null;break;case es:{let me=Re.asciiClass;if(me[ne]!==1){ae.lastIndex=0;break}let pe=g+1;while(me[_.charCodeAt(pe)]===1)pe++;f=pe-g,ae.lastIndex=pe;break}case Qt:ae.lastIndex=g,f=this.matchLength(ae,t,g);break}if(f!==-1){if(h=Re.longerAlt,h!==void 0){u=t.substring(g,g+f);let me=h.length;for(r=0;r<me;r++){let pe=We[h[r]],we=pe.pattern;if(d=null,pe.matchType===Nt)if(v=we.exec(_,g,he,et),v!==null){if(o=v[0],v.payload!==void 0)d=v.payload}else o=null;else we.lastIndex=g,o=this.match(we,t,g);if(o&&o.length>u.length){u=o,f=o.length,c=d,Re=pe;break}}}break}}if(f!==-1){if(m=Re.group,m!==void 0)if(u=u!==null?u:t.substring(g,g+f),y=Re.tokenTypeIdx,N=this.createTokenInstance(u,g,y,Re.tokenType,Me,be,f),this.handlePayload(N,c),m===!1)w=this.addToken(he,w,N);else et[m].push(N);if(Br===!0&&Re.canLineTerminator===!0){let ae=0,me,pe;ks.lastIndex=0;do if(u=u!==null?u:t.substring(g,g+f),me=ks.test(u),me===!0)pe=ks.lastIndex-1,ae++;while(me===!0);if(ae!==0)Me=Me+ae,be=f-pe,this.updateTokenEndLineColumnLocation(N,m,pe,ae,Me,be,f);else be=this.computeNewColumn(be,f)}else be=this.computeNewColumn(be,f);g=g+f,this.handleModes(Re,$r,On,N)}else{let ae=g,me=Me,pe=be,we=Ln===!1;while(we===!1&&g<k){g++;for(i=0;i<Cs;i++){let _s=We[i],xs=_s.pattern;switch(_s.matchType){case Zt:if(_.charCodeAt(g)===_s.short)we=!0;break;case Nt:we=xs.exec(_,g,he,et)!==null;break;case es:case Qt:xs.lastIndex=g,we=xs.exec(t)!==null;break}if(we===!0)break}}if(U=g-ae,be=this.computeNewColumn(be,U),P=this.config.errorMessageProvider.buildUnexpectedCharactersMessage(_,ae,U,me,pe,Et.at(-1)),ft.push({offset:ae,line:me,column:pe,length:U,message:P}),Ln===!1)break}}if(!this.hasCustom)he.length=w;return{tokens:he,groups:et,errors:ft}}handleModes(t,s,n,i){if(t.pop===!0){let r=t.push;if(s(i),r!==void 0)n.call(this,r)}else if(t.push!==void 0)n.call(this,t.push)}updateTokenEndLineColumnLocation(t,s,n,i,r,o,h){let u,c;if(s!==void 0){if(u=n===h-1,c=u?-1:0,!(i===1&&u===!0))t.endLine=r+c,t.endColumn=o-1+-c}}computeNewColumn(t,s){return t+s}createOffsetOnlyToken(t,s,n,i){return{image:t,startOffset:s,tokenTypeIdx:n,tokenType:i}}createStartOnlyToken(t,s,n,i,r,o){return{image:t,startOffset:s,startLine:r,startColumn:o,tokenTypeIdx:n,tokenType:i}}createFullToken(t,s,n,i,r,o,h){return{image:t,startOffset:s,endOffset:s+h-1,startLine:r,endLine:r,startColumn:o,endColumn:o+h-1,tokenTypeIdx:n,tokenType:i}}addTokenUsingPush(t,s,n){return t.push(n),s}addTokenUsingMemberAccess(t,s,n){return t[s]=n,s++,s}handlePayloadNoCustom(t,s){}handlePayloadWithCustom(t,s){if(s!==null)t.payload=s}match(t,s,n){if(t.test(s)===!0)return s.substring(n,t.lastIndex);return null}matchLength(t,s,n){if(t.test(s)===!0)return t.lastIndex-n;return-1}}z.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.";z.NA=/NOT_APPLICABLE/;function Ye(t){if(Gs(t))return t.LABEL;else return t.name}function Gs(t){return typeof t.LABEL==="string"&&t.LABEL!==""}var Oa="parent",Hn="categories",Xn="label",Yn="group",qn="push_mode",Jn="pop_mode",Zn="longer_alt",Qn="line_breaks",ei="start_chars_hint";function I(t){return La(t)}function La(t){let s=t.pattern,n={};if(n.name=t.name,s!==void 0)n.PATTERN=s;if(Object.hasOwn(t,Oa))throw`The parent property is no longer supported.
54
- See: https://github.com/chevrotain/chevrotain/issues/564#issuecomment-349062346 for details.`;if(Object.hasOwn(t,Hn))n.CATEGORIES=t[Hn];if(Pe([n]),Object.hasOwn(t,Xn))n.LABEL=t[Xn];if(Object.hasOwn(t,Yn))n.GROUP=t[Yn];if(Object.hasOwn(t,Jn))n.POP_MODE=t[Jn];if(Object.hasOwn(t,qn))n.PUSH_MODE=t[qn];if(Object.hasOwn(t,Zn))n.LONGER_ALT=t[Zn];if(Object.hasOwn(t,Qn))n.LINE_BREAKS=t[Qn];if(Object.hasOwn(t,ei))n.START_CHARS_HINT=t[ei];return n}var Se=I({name:"EOF",pattern:z.NA});Pe([Se]);function qe(t,s,n,i,r,o,h,u){return{image:s,startOffset:n,endOffset:i,startLine:r,endLine:o,startColumn:h,endColumn:u,tokenTypeIdx:t.tokenTypeIdx,tokenType:t}}function kt(t,s){return Ue(t,s)}var ts={buildMismatchTokenMessage({expected:t,actual:s,previous:n,ruleName:i}){return`Expecting ${Gs(t)?`--> ${Ye(t)} <--`:`token of type --> ${t.name} <--`} but found --> '${s.image}' <--`},buildNotAllInputParsedMessage({firstRedundant:t,ruleName:s}){return"Redundant input, expecting EOF but found: "+t.image},buildNoViableAltMessage({expectedPathsPerAlt:t,actual:s,previous:n,customUserDescription:i,ruleName:r}){let u=`
53
+ `+i)}return this.tokenizeInternal(t,s)}tokenizeInternal(t,s){let n,i,r,o,h,u,c,d,f,m,y,N,U,P,v,_=t,k=_.length,g=0,w=0,te=this.hasCustom?0:Math.floor(t.length/10),de=Array(te),pt=[],Me=this.trackStartLines?1:void 0,_e=this.trackStartLines?1:void 0,et={};for(let ne=0;ne<this.cachedGroupKeys.length;ne++)et[this.cachedGroupKeys[ne]]=[];let Br=this.trackStartLines,ks=this.config.lineTerminatorsPattern,Cs=0,We=[],ft=[],mt=[],yn=[];Object.freeze(yn);let Et=!1,$r=(ne)=>{if(mt.length===1&&ne.tokenType.PUSH_MODE===void 0){let Le=this.config.errorMessageProvider.buildUnableToPopLexerModeMessage(ne);pt.push({offset:ne.startOffset,line:ne.startLine,column:ne.startColumn,length:ne.image.length,message:Le})}else{mt.pop();let Le=mt.at(-1);We=this.patternIdxToConfig[Le],ft=this.charCodeToPatternIdxToConfig[Le],Cs=We.length;let bs=this.canModeBeOptimized[Le]&&this.config.safeMode===!1;if(ft&&bs)Et=!0;else Et=!1}};function On(ne){mt.push(ne),ft=this.charCodeToPatternIdxToConfig[ne],We=this.patternIdxToConfig[ne],Cs=We.length;let Le=this.canModeBeOptimized[ne]&&this.config.safeMode===!1;if(ft&&Le)Et=!0;else Et=!1}On.call(this,s);let Oe,Ln=this.config.recoveryEnabled;while(g<k){u=null,f=-1;let ne=_.charCodeAt(g),Le;if(Et){let ae=ve(ne),Ee=ft[ae];Le=Ee!==void 0?Ee:yn}else Le=We;let bs=Le.length;for(n=0;n<bs;n++){Oe=Le[n];let ae=Oe.pattern;switch(c=null,Oe.matchType){case Zt:if(ne===Oe.short)f=1,u=ae;break;case Nt:if(v=ae.exec(_,g,de,et),v!==null){if(u=v[0],f=u.length,v.payload!==void 0)c=v.payload}else u=null;break;case es:{let Ee=Oe.asciiClass;if(Ee[ne]!==1){ae.lastIndex=0;break}let fe=g+1;while(Ee[_.charCodeAt(fe)]===1)fe++;f=fe-g,ae.lastIndex=fe;break}case Qt:ae.lastIndex=g,f=this.matchLength(ae,t,g);break}if(f!==-1){if(h=Oe.longerAlt,h!==void 0){u=t.substring(g,g+f);let Ee=h.length;for(r=0;r<Ee;r++){let fe=We[h[r]],we=fe.pattern;if(d=null,fe.matchType===Nt)if(v=we.exec(_,g,de,et),v!==null){if(o=v[0],v.payload!==void 0)d=v.payload}else o=null;else we.lastIndex=g,o=this.match(we,t,g);if(o&&o.length>u.length){u=o,f=o.length,c=d,Oe=fe;break}}}break}}if(f!==-1){if(m=Oe.group,m!==void 0)if(u=u!==null?u:t.substring(g,g+f),y=Oe.tokenTypeIdx,N=this.createTokenInstance(u,g,y,Oe.tokenType,Me,_e,f),this.handlePayload(N,c),m===!1)w=this.addToken(de,w,N);else et[m].push(N);if(Br===!0&&Oe.canLineTerminator===!0){let ae=0,Ee,fe;ks.lastIndex=0;do if(u=u!==null?u:t.substring(g,g+f),Ee=ks.test(u),Ee===!0)fe=ks.lastIndex-1,ae++;while(Ee===!0);if(ae!==0)Me=Me+ae,_e=f-fe,this.updateTokenEndLineColumnLocation(N,m,fe,ae,Me,_e,f);else _e=this.computeNewColumn(_e,f)}else _e=this.computeNewColumn(_e,f);g=g+f,this.handleModes(Oe,$r,On,N)}else{let ae=g,Ee=Me,fe=_e,we=Ln===!1;while(we===!1&&g<k){g++;for(i=0;i<Cs;i++){let _s=We[i],xs=_s.pattern;switch(_s.matchType){case Zt:if(_.charCodeAt(g)===_s.short)we=!0;break;case Nt:we=xs.exec(_,g,de,et)!==null;break;case es:case Qt:xs.lastIndex=g,we=xs.exec(t)!==null;break}if(we===!0)break}}if(U=g-ae,_e=this.computeNewColumn(_e,U),P=this.config.errorMessageProvider.buildUnexpectedCharactersMessage(_,ae,U,Ee,fe,mt.at(-1)),pt.push({offset:ae,line:Ee,column:fe,length:U,message:P}),Ln===!1)break}}if(!this.hasCustom)de.length=w;return{tokens:de,groups:et,errors:pt}}handleModes(t,s,n,i){if(t.pop===!0){let r=t.push;if(s(i),r!==void 0)n.call(this,r)}else if(t.push!==void 0)n.call(this,t.push)}updateTokenEndLineColumnLocation(t,s,n,i,r,o,h){let u,c;if(s!==void 0){if(u=n===h-1,c=u?-1:0,!(i===1&&u===!0))t.endLine=r+c,t.endColumn=o-1+-c}}computeNewColumn(t,s){return t+s}createOffsetOnlyToken(t,s,n,i){return{image:t,startOffset:s,tokenTypeIdx:n,tokenType:i}}createStartOnlyToken(t,s,n,i,r,o){return{image:t,startOffset:s,startLine:r,startColumn:o,tokenTypeIdx:n,tokenType:i}}createFullToken(t,s,n,i,r,o,h){return{image:t,startOffset:s,endOffset:s+h-1,startLine:r,endLine:r,startColumn:o,endColumn:o+h-1,tokenTypeIdx:n,tokenType:i}}addTokenUsingPush(t,s,n){return t.push(n),s}addTokenUsingMemberAccess(t,s,n){return t[s]=n,s++,s}handlePayloadNoCustom(t,s){}handlePayloadWithCustom(t,s){if(s!==null)t.payload=s}match(t,s,n){if(t.test(s)===!0)return s.substring(n,t.lastIndex);return null}matchLength(t,s,n){if(t.test(s)===!0)return t.lastIndex-n;return-1}}z.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.";z.NA=/NOT_APPLICABLE/;function Ye(t){if(Gs(t))return t.LABEL;else return t.name}function Gs(t){return typeof t.LABEL==="string"&&t.LABEL!==""}var Oa="parent",Hn="categories",Xn="label",Yn="group",qn="push_mode",Jn="pop_mode",Zn="longer_alt",Qn="line_breaks",ei="start_chars_hint";function I(t){return La(t)}function La(t){let s=t.pattern,n={};if(n.name=t.name,s!==void 0)n.PATTERN=s;if(Object.hasOwn(t,Oa))throw`The parent property is no longer supported.
54
+ See: https://github.com/chevrotain/chevrotain/issues/564#issuecomment-349062346 for details.`;if(Object.hasOwn(t,Hn))n.CATEGORIES=t[Hn];if(Pe([n]),Object.hasOwn(t,Xn))n.LABEL=t[Xn];if(Object.hasOwn(t,Yn))n.GROUP=t[Yn];if(Object.hasOwn(t,Jn))n.POP_MODE=t[Jn];if(Object.hasOwn(t,qn))n.PUSH_MODE=t[qn];if(Object.hasOwn(t,Zn))n.LONGER_ALT=t[Zn];if(Object.hasOwn(t,Qn))n.LINE_BREAKS=t[Qn];if(Object.hasOwn(t,ei))n.START_CHARS_HINT=t[ei];return n}var Re=I({name:"EOF",pattern:z.NA});Pe([Re]);function qe(t,s,n,i,r,o,h,u){return{image:s,startOffset:n,endOffset:i,startLine:r,endLine:o,startColumn:h,endColumn:u,tokenTypeIdx:t.tokenTypeIdx,tokenType:t}}function kt(t,s){return Ue(t,s)}var ts={buildMismatchTokenMessage({expected:t,actual:s,previous:n,ruleName:i}){return`Expecting ${Gs(t)?`--> ${Ye(t)} <--`:`token of type --> ${t.name} <--`} but found --> '${s.image}' <--`},buildNotAllInputParsedMessage({firstRedundant:t,ruleName:s}){return"Redundant input, expecting EOF but found: "+t.image},buildNoViableAltMessage({expectedPathsPerAlt:t,actual:s,previous:n,customUserDescription:i,ruleName:r}){let u=`
55
55
  but found: '`+s[0].image+"'";if(i)return"Expecting: "+i+u;else return`Expecting: one of these possible Token sequences:
56
56
  ${t.reduce((y,N)=>y.concat(N),[]).map((y)=>`[${y.map((N)=>Ye(N)).join(", ")}]`).map((y,N)=>` ${N+1}. ${y}`).join(`
57
57
  `)}`+u},buildEarlyExitMessage({expectedIterationPaths:t,actual:s,customUserDescription:n,ruleName:i}){let h=`
58
58
  but found: '`+s[0].image+"'";if(n)return"Expecting: "+n+h;else return`Expecting: expecting at least one iteration which starts with one of these possible Token sequences::
59
59
  <${t.map((d)=>`[${d.map((f)=>Ye(f)).join(",")}]`).join(" ,")}>`+h}};Object.freeze(ts);var ti={buildRuleNotFoundError(t,s){return"Invalid grammar, reference to a rule which is not defined: ->"+s.nonTerminalName+`<-
60
- inside top level rule: ->`+t.name+"<-"}},ke={buildDuplicateFoundError(t,s){function n(f){if(f instanceof F)return f.terminalType.name;else if(f instanceof W)return f.nonTerminalName;else return""}let i=t.name,r=s[0],o=r.idx,h=Ae(r),u=n(r),c=o>0,d=`->${h}${c?o:""}<- ${u?`with argument: ->${u}<-`:""}
60
+ inside top level rule: ->`+t.name+"<-"}},Ce={buildDuplicateFoundError(t,s){function n(f){if(f instanceof F)return f.terminalType.name;else if(f instanceof W)return f.nonTerminalName;else return""}let i=t.name,r=s[0],o=r.idx,h=Se(r),u=n(r),c=o>0,d=`->${h}${c?o:""}<- ${u?`with argument: ->${u}<-`:""}
61
61
  appears more than once (${s.length} times) in the top level rule: ->${i}<-.
62
62
  For further details see: https://chevrotain.io/docs/FAQ.html#NUMERICAL_SUFFIXES
63
63
  `;return d=d.replace(/[ \t]+/g," "),d=d.replace(/\s\s+/g,`
@@ -74,7 +74,7 @@ For Further details.`},buildAlternationAmbiguityError(t){let s=t.alternation.idx
74
74
  Only the last alternative may be empty.
75
75
  `;else{let r=t.prefixPath.map((o)=>Ye(o)).join(", ");i+=`<${r}> may appears as a prefix path in all these alternatives.
76
76
  `}return i+=`See: https://chevrotain.io/docs/guide/resolving_grammar_errors.html#AMBIGUOUS_ALTERNATIVES
77
- For Further details.`,i},buildEmptyRepetitionError(t){let s=Ae(t.repetition);if(t.repetition.idx!==0)s+=t.repetition.idx;return`The repetition <${s}> within Rule <${t.topLevelRule.name}> can never consume any tokens.
77
+ For Further details.`,i},buildEmptyRepetitionError(t){let s=Se(t.repetition);if(t.repetition.idx!==0)s+=t.repetition.idx;return`The repetition <${s}> within Rule <${t.topLevelRule.name}> can never consume any tokens.
78
78
  This could lead to an infinite loop.`},buildTokenNameError(t){return"deprecated"},buildEmptyAlternationError(t){return`Ambiguous empty alternative: <${t.emptyChoiceIdx+1}> in <OR${t.alternation.idx}> inside <${t.topLevelRule.name}> Rule.
79
79
  Only the last alternative may be an empty alternative.`},buildTooManyAlternativesError(t){return`An Alternation cannot have more than 256 alternatives:
80
80
  <OR${t.alternation.idx}> inside <${t.topLevelRule.name}> Rule.
@@ -83,39 +83,39 @@ rule: <${s}> can be invoked from itself (directly or indirectly)
83
83
  without consuming any Tokens. The grammar path that causes this is:
84
84
  ${i}
85
85
  To fix this refactor your grammar to remove the left recursion.
86
- see: https://en.wikipedia.org/wiki/LL_parser#Left_factoring.`},buildInvalidRuleNameError(t){return"deprecated"},buildDuplicateRuleNameError(t){let s;if(t.topLevelRule instanceof Ee)s=t.topLevelRule.name;else s=t.topLevelRule;return`Duplicate definition, rule: ->${s}<- is already defined in the grammar: ->${t.grammarName}<-`}};function si(t,s){let n=new ii(t,s);return n.resolveRefs(),n.errors}class ii extends Te{constructor(t,s){super();this.nameToTopRule=t,this.errMsgProvider=s,this.errors=[]}resolveRefs(){Object.values(this.nameToTopRule).forEach((t)=>{this.currTopLevel=t,t.accept(this)})}visitNonTerminal(t){let s=this.nameToTopRule[t.nonTerminalName];if(!s){let n=this.errMsgProvider.buildRuleNotFoundError(this.currTopLevel,t);this.errors.push({message:n,type:ie.UNRESOLVED_SUBRULE_REF,ruleName:this.currTopLevel.name,unresolvedRefName:t.nonTerminalName})}else t.referencedRule=s}}class ri extends $e{constructor(t,s){super();this.topProd=t,this.path=s,this.possibleTokTypes=[],this.nextProductionName="",this.nextProductionOccurrence=0,this.found=!1,this.isAtEndOfPath=!1}startWalking(){if(this.found=!1,this.path.ruleStack[0]!==this.topProd.name)throw Error("The path does not start with the walker's top Rule!");return this.ruleStack=[...this.path.ruleStack].reverse(),this.occurrenceStack=[...this.path.occurrenceStack].reverse(),this.ruleStack.pop(),this.occurrenceStack.pop(),this.updateExpectedNext(),this.walk(this.topProd),this.possibleTokTypes}walk(t,s=[]){if(!this.found)super.walk(t,s)}walkProdRef(t,s,n){if(t.referencedRule.name===this.nextProductionName&&t.idx===this.nextProductionOccurrence){let i=s.concat(n);this.updateExpectedNext(),this.walk(t.referencedRule,i)}}updateExpectedNext(){if(this.ruleStack.length===0)this.nextProductionName="",this.nextProductionOccurrence=0,this.isAtEndOfPath=!0;else this.nextProductionName=this.ruleStack.pop(),this.nextProductionOccurrence=this.occurrenceStack.pop()}}class Ws extends ri{constructor(t,s){super(t,s);this.path=s,this.nextTerminalName="",this.nextTerminalOccurrence=0,this.nextTerminalName=this.path.lastTok.name,this.nextTerminalOccurrence=this.path.lastTokOccurrence}walkTerminal(t,s,n){if(this.isAtEndOfPath&&t.terminalType.name===this.nextTerminalName&&t.idx===this.nextTerminalOccurrence&&!this.found){let i=s.concat(n),r=new j({definition:i});this.possibleTokTypes=Ke(r),this.found=!0}}}class Ct extends $e{constructor(t,s){super();this.topRule=t,this.occurrence=s,this.result={token:void 0,occurrence:void 0,isEndOfRule:void 0}}startWalking(){return this.walk(this.topRule),this.result}}class js extends Ct{walkMany(t,s,n){if(t.idx===this.occurrence){let i=s.concat(n)[0];if(this.result.isEndOfRule=i===void 0,i instanceof F)this.result.token=i.terminalType,this.result.occurrence=i.idx}else super.walkMany(t,s,n)}}class ss extends Ct{walkManySep(t,s,n){if(t.idx===this.occurrence){let i=s.concat(n)[0];if(this.result.isEndOfRule=i===void 0,i instanceof F)this.result.token=i.terminalType,this.result.occurrence=i.idx}else super.walkManySep(t,s,n)}}class Ks extends Ct{walkAtLeastOne(t,s,n){if(t.idx===this.occurrence){let i=s.concat(n)[0];if(this.result.isEndOfRule=i===void 0,i instanceof F)this.result.token=i.terminalType,this.result.occurrence=i.idx}else super.walkAtLeastOne(t,s,n)}}class ns extends Ct{walkAtLeastOneSep(t,s,n){if(t.idx===this.occurrence){let i=s.concat(n)[0];if(this.result.isEndOfRule=i===void 0,i instanceof F)this.result.token=i.terminalType,this.result.occurrence=i.idx}else super.walkAtLeastOneSep(t,s,n)}}function is(t,s,n=[]){n=[...n];let i=[],r=0;function o(u){return u.concat(t.slice(r+1))}function h(u){let c=is(o(u),s,n);return i.concat(c)}while(n.length<s&&r<t.length){let u=t[r];if(u instanceof j)return h(u.definition);else if(u instanceof W)return h(u.definition);else if(u instanceof K)i=h(u.definition);else if(u instanceof Z){let c=u.definition.concat([new G({definition:u.definition})]);return h(c)}else if(u instanceof Q){let c=[new j({definition:u.definition}),new G({definition:[new F({terminalType:u.separator})].concat(u.definition)})];return h(c)}else if(u instanceof q){let c=u.definition.concat([new G({definition:[new F({terminalType:u.separator})].concat(u.definition)})]);i=h(c)}else if(u instanceof G){let c=u.definition.concat([new G({definition:u.definition})]);i=h(c)}else if(u instanceof J)return u.definition.forEach((c)=>{if(c.definition.length!==0)i=h(c.definition)}),i;else if(u instanceof F)n.push(u.terminalType);else throw Error("non exhaustive match");r++}return i.push({partialPath:n,suffixDef:t.slice(r)}),i}function ai(t,s,n,i){let o=["EXIT_NONE_TERMINAL"],h="EXIT_ALTERNATIVE",u=!1,c=s.length,d=c-i-1,f=[],m=[];m.push({idx:-1,def:t,ruleStack:[],occurrenceStack:[]});while(m.length!==0){let y=m.pop();if(y==="EXIT_ALTERNATIVE"){if(u&&m.at(-1).idx<=d)m.pop();continue}let{def:N,idx:U,ruleStack:P,occurrenceStack:v}=y;if(N.length===0)continue;let _=N[0];if(_==="EXIT_NONE_TERMINAL"){let k={idx:U,def:N.slice(1),ruleStack:P.slice(0,-1),occurrenceStack:v.slice(0,-1)};m.push(k)}else if(_ instanceof F)if(U<c-1){let k=U+1,g=s[k];if(n(g,_.terminalType)){let w={idx:k,def:N.slice(1),ruleStack:P,occurrenceStack:v};m.push(w)}}else if(U===c-1)f.push({nextTokenType:_.terminalType,nextTokenOccurrence:_.idx,ruleStack:P,occurrenceStack:v}),u=!0;else throw Error("non exhaustive match");else if(_ instanceof W){let k=[...P];k.push(_.nonTerminalName);let g=[...v];g.push(_.idx);let w={idx:U,def:_.definition.concat(o,N.slice(1)),ruleStack:k,occurrenceStack:g};m.push(w)}else if(_ instanceof K){let k={idx:U,def:N.slice(1),ruleStack:P,occurrenceStack:v};m.push(k),m.push("EXIT_ALTERNATIVE");let g={idx:U,def:_.definition.concat(N.slice(1)),ruleStack:P,occurrenceStack:v};m.push(g)}else if(_ instanceof Z){let k=new G({definition:_.definition,idx:_.idx}),g=_.definition.concat([k],N.slice(1)),w={idx:U,def:g,ruleStack:P,occurrenceStack:v};m.push(w)}else if(_ instanceof Q){let k=new F({terminalType:_.separator}),g=new G({definition:[k].concat(_.definition),idx:_.idx}),w=_.definition.concat([g],N.slice(1)),te={idx:U,def:w,ruleStack:P,occurrenceStack:v};m.push(te)}else if(_ instanceof q){let k={idx:U,def:N.slice(1),ruleStack:P,occurrenceStack:v};m.push(k),m.push("EXIT_ALTERNATIVE");let g=new F({terminalType:_.separator}),w=new G({definition:[g].concat(_.definition),idx:_.idx}),te=_.definition.concat([w],N.slice(1)),he={idx:U,def:te,ruleStack:P,occurrenceStack:v};m.push(he)}else if(_ instanceof G){let k={idx:U,def:N.slice(1),ruleStack:P,occurrenceStack:v};m.push(k),m.push("EXIT_ALTERNATIVE");let g=new G({definition:_.definition,idx:_.idx}),w=_.definition.concat([g],N.slice(1)),te={idx:U,def:w,ruleStack:P,occurrenceStack:v};m.push(te)}else if(_ instanceof J)for(let k=_.definition.length-1;k>=0;k--){let g=_.definition[k],w={idx:U,def:g.definition.concat(N.slice(1)),ruleStack:P,occurrenceStack:v};m.push(w),m.push("EXIT_ALTERNATIVE")}else if(_ instanceof j)m.push({idx:U,def:_.definition.concat(N.slice(1)),ruleStack:P,occurrenceStack:v});else if(_ instanceof Ee)m.push(Na(_,U,P,v));else throw Error("non exhaustive match")}return f}function Na(t,s,n,i){let r=[...n];r.push(t.name);let o=[...i];return o.push(1),{idx:s,def:t.definition,ruleStack:r,occurrenceStack:o}}var H;(function(t){t[t.OPTION=0]="OPTION",t[t.REPETITION=1]="REPETITION",t[t.REPETITION_MANDATORY=2]="REPETITION_MANDATORY",t[t.REPETITION_MANDATORY_WITH_SEPARATOR=3]="REPETITION_MANDATORY_WITH_SEPARATOR",t[t.REPETITION_WITH_SEPARATOR=4]="REPETITION_WITH_SEPARATOR",t[t.ALTERNATION=5]="ALTERNATION"})(H||(H={}));function rs(t){if(t instanceof K||t==="Option")return H.OPTION;else if(t instanceof G||t==="Repetition")return H.REPETITION;else if(t instanceof Z||t==="RepetitionMandatory")return H.REPETITION_MANDATORY;else if(t instanceof Q||t==="RepetitionMandatoryWithSeparator")return H.REPETITION_MANDATORY_WITH_SEPARATOR;else if(t instanceof q||t==="RepetitionWithSeparator")return H.REPETITION_WITH_SEPARATOR;else if(t instanceof J||t==="Alternation")return H.ALTERNATION;else throw Error("non exhaustive match")}function li(t,s,n,i,r,o){let h=bt(t,s,n),u=mi(h)?at:Ue;return o(h,i,u,r)}function ci(t,s,n,i,r,o){let h=_t(t,s,r,n),u=mi(h)?at:Ue;return o(h[0],u,i)}function hi(t,s,n,i){let r=t.length,o=t.every((h)=>h.every((u)=>u.length===1));if(s)return function(h){let u=h.map((c)=>c.GATE);for(let c=0;c<r;c++){let d=t[c],f=d.length,m=u[c];if(m!==void 0&&m.call(this)===!1)continue;e:for(let y=0;y<f;y++){let N=d[y],U=N.length;for(let P=0;P<U;P++){let v=this.LA_FAST(P+1);if(n(v,N[P])===!1)continue e}return c}}return};else if(o&&!i){let u=t.map((c)=>c.flat()).reduce((c,d,f)=>(d.forEach((m)=>{if(!(m.tokenTypeIdx in c))c[m.tokenTypeIdx]=f;m.categoryMatches.forEach((y)=>{if(!Object.hasOwn(c,y))c[y]=f})}),c),{});return function(){let c=this.LA_FAST(1);return u[c.tokenTypeIdx]}}else return function(){for(let h=0;h<r;h++){let u=t[h],c=u.length;e:for(let d=0;d<c;d++){let f=u[d],m=f.length;for(let y=0;y<m;y++){let N=this.LA_FAST(y+1);if(n(N,f[y])===!1)continue e}return h}}return}}function ui(t,s,n){let i=t.every((o)=>o.length===1),r=t.length;if(i&&!n){let o=t.flat();if(o.length===1&&o[0].categoryMatches.length===0){let u=o[0].tokenTypeIdx;return function(){return this.LA_FAST(1).tokenTypeIdx===u}}else{let h=o.reduce((u,c,d)=>(u[c.tokenTypeIdx]=!0,c.categoryMatches.forEach((f)=>{u[f]=!0}),u),[]);return function(){let u=this.LA_FAST(1);return h[u.tokenTypeIdx]===!0}}}else return function(){e:for(let o=0;o<r;o++){let h=t[o],u=h.length;for(let c=0;c<u;c++){let d=this.LA_FAST(c+1);if(s(d,h[c])===!1)continue e}return!0}return!1}}class di extends $e{constructor(t,s,n){super();this.topProd=t,this.targetOccurrence=s,this.targetProdType=n}startWalking(){return this.walk(this.topProd),this.restDef}checkIsTarget(t,s,n,i){if(t.idx===this.targetOccurrence&&this.targetProdType===s)return this.restDef=n.concat(i),!0;return!1}walkOption(t,s,n){if(!this.checkIsTarget(t,H.OPTION,s,n))super.walkOption(t,s,n)}walkAtLeastOne(t,s,n){if(!this.checkIsTarget(t,H.REPETITION_MANDATORY,s,n))super.walkOption(t,s,n)}walkAtLeastOneSep(t,s,n){if(!this.checkIsTarget(t,H.REPETITION_MANDATORY_WITH_SEPARATOR,s,n))super.walkOption(t,s,n)}walkMany(t,s,n){if(!this.checkIsTarget(t,H.REPETITION,s,n))super.walkOption(t,s,n)}walkManySep(t,s,n){if(!this.checkIsTarget(t,H.REPETITION_WITH_SEPARATOR,s,n))super.walkOption(t,s,n)}}class zs extends Te{constructor(t,s,n){super();this.targetOccurrence=t,this.targetProdType=s,this.targetRef=n,this.result=[]}checkIsTarget(t,s){if(t.idx===this.targetOccurrence&&this.targetProdType===s&&(this.targetRef===void 0||t===this.targetRef))this.result=t.definition}visitOption(t){this.checkIsTarget(t,H.OPTION)}visitRepetition(t){this.checkIsTarget(t,H.REPETITION)}visitRepetitionMandatory(t){this.checkIsTarget(t,H.REPETITION_MANDATORY)}visitRepetitionMandatoryWithSeparator(t){this.checkIsTarget(t,H.REPETITION_MANDATORY_WITH_SEPARATOR)}visitRepetitionWithSeparator(t){this.checkIsTarget(t,H.REPETITION_WITH_SEPARATOR)}visitAlternation(t){this.checkIsTarget(t,H.ALTERNATION)}}function oi(t){let s=Array(t);for(let n=0;n<t;n++)s[n]=[];return s}function Vs(t){let s=[""];for(let n=0;n<t.length;n++){let i=t[n],r=[];for(let o=0;o<s.length;o++){let h=s[o];r.push(h+"_"+i.tokenTypeIdx);for(let u=0;u<i.categoryMatches.length;u++){let c="_"+i.categoryMatches[u];r.push(h+c)}}s=r}return s}function Ia(t,s,n){for(let i=0;i<t.length;i++){if(i===n)continue;let r=t[i];for(let o=0;o<s.length;o++){let h=s[o];if(r[h]===!0)return!1}}return!0}function pi(t,s){let n=t.map((h)=>is([h],1)),i=oi(n.length),r=n.map((h)=>{let u={};return h.forEach((c)=>{Vs(c.partialPath).forEach((f)=>{u[f]=!0})}),u}),o=n;for(let h=1;h<=s;h++){let u=o;o=oi(u.length);for(let c=0;c<u.length;c++){let d=u[c];for(let f=0;f<d.length;f++){let m=d[f].partialPath,y=d[f].suffixDef,N=Vs(m);if(Ia(r,N,c)||y.length===0||m.length===s){let P=i[c];if(as(P,m)===!1){P.push(m);for(let v=0;v<N.length;v++){let _=N[v];r[c][_]=!0}}}else{let P=is(y,h+1,m);o[c]=o[c].concat(P),P.forEach((v)=>{Vs(v.partialPath).forEach((k)=>{r[c][k]=!0})})}}}}return i}function bt(t,s,n,i){let r=new zs(t,H.ALTERNATION,i);return s.accept(r),pi(r.result,n)}function _t(t,s,n,i){let r=new zs(t,n);s.accept(r);let o=r.result,u=new di(s,t,n).startWalking(),c=new j({definition:o}),d=new j({definition:u});return pi([c,d],i)}function as(t,s){e:for(let n=0;n<t.length;n++){let i=t[n];if(i.length!==s.length)continue;for(let r=0;r<i.length;r++){let o=s[r],h=i[r];if((o===h||h.categoryMatchesMap[o.tokenTypeIdx]!==void 0)===!1)continue e}return!0}return!1}function fi(t,s){return t.length<s.length&&t.every((n,i)=>{let r=s[i];return n===r||r.categoryMatchesMap[n.tokenTypeIdx]})}function mi(t){return t.every((s)=>s.every((n)=>n.every((i)=>i.categoryMatches.length===0)))}function Ei(t){return t.lookaheadStrategy.validate({rules:t.rules,tokenTypes:t.tokenTypes,grammarName:t.grammarName}).map((n)=>Object.assign({type:ie.CUSTOM_LOOKAHEAD_VALIDATION},n))}function Ti(t,s,n,i){let r=t.flatMap((c)=>ka(c,n)),o=Ma(t,s,n),h=t.flatMap((c)=>_a(c,n)),u=t.flatMap((c)=>ba(c,t,i,n));return r.concat(o,h,u)}function ka(t,s){let n=new Ai;t.accept(n);let i=n.allProductions,r=Object.groupBy(i,Ca),o=Object.fromEntries(Object.entries(r).filter(([u,c])=>c.length>1));return Object.values(o).map((u)=>{let c=u[0],d=s.buildDuplicateFoundError(t,u),f=Ae(c),m={message:d,type:ie.DUPLICATE_PRODUCTIONS,ruleName:t.name,dslName:f,occurrence:c.idx},y=gi(c);if(y)m.parameter=y;return m})}function Ca(t){return`${Ae(t)}_#_${t.idx}_#_${gi(t)}`}function gi(t){if(t instanceof F)return t.terminalType.name;else if(t instanceof W)return t.nonTerminalName;else return""}class Ai extends Te{constructor(){super(...arguments);this.allProductions=[]}visitNonTerminal(t){this.allProductions.push(t)}visitOption(t){this.allProductions.push(t)}visitRepetitionWithSeparator(t){this.allProductions.push(t)}visitRepetitionMandatory(t){this.allProductions.push(t)}visitRepetitionMandatoryWithSeparator(t){this.allProductions.push(t)}visitRepetition(t){this.allProductions.push(t)}visitAlternation(t){this.allProductions.push(t)}visitTerminal(t){this.allProductions.push(t)}}function ba(t,s,n,i){let r=[];if(s.reduce((h,u)=>{if(u.name===t.name)return h+1;return h},0)>1){let h=i.buildDuplicateRuleNameError({topLevelRule:t,grammarName:n});r.push({message:h,type:ie.DUPLICATE_RULE_NAME,ruleName:t.name})}return r}function Si(t,s,n){let i=[],r;if(!s.includes(t))r=`Invalid rule override, rule: ->${t}<- cannot be overridden in the grammar: ->${n}<-as it is not defined in any of the super grammars `,i.push({message:r,type:ie.INVALID_RULE_OVERRIDE,ruleName:t});return i}function Hs(t,s,n,i=[]){let r=[],o=os(s.definition);if(o.length===0)return[];else{let h=t.name;if(o.includes(t))r.push({message:n.buildLeftRecursionError({topLevelRule:t,leftRecursionPath:i}),type:ie.LEFT_RECURSION,ruleName:h});let c=i.concat([t]),f=o.filter((m)=>!c.includes(m)).flatMap((m)=>{let y=[...i];return y.push(m),Hs(t,m,n,y)});return r.concat(f)}}function os(t){let s=[];if(t.length===0)return s;let n=t[0];if(n instanceof W)s.push(n.referencedRule);else if(n instanceof j||n instanceof K||n instanceof Z||n instanceof Q||n instanceof q||n instanceof G)s=s.concat(os(n.definition));else if(n instanceof J)s=n.definition.map((o)=>os(o.definition)).flat();else if(n instanceof F);else throw Error("non exhaustive match");let i=je(n),r=t.length>1;if(i&&r){let o=t.slice(1);return s.concat(os(o))}else return s}class ls extends Te{constructor(){super(...arguments);this.alternations=[]}visitAlternation(t){this.alternations.push(t)}}function Ri(t,s){let n=new ls;return t.accept(n),n.alternations.flatMap((o)=>o.definition.slice(0,-1).flatMap((u,c)=>{if(ai([u],[],Ue,1).length===0)return[{message:s.buildEmptyAlternationError({topLevelRule:t,alternation:o,emptyChoiceIdx:c}),type:ie.NONE_LAST_EMPTY_ALT,ruleName:t.name,occurrence:o.idx,alternative:c+1}];else return[]}))}function yi(t,s,n){let i=new ls;t.accept(i);let r=i.alternations;return r=r.filter((h)=>h.ignoreAmbiguities!==!0),r.flatMap((h)=>{let u=h.idx,c=h.maxLookahead||s,d=bt(u,t,c,h),f=xa(d,h,t,n),m=va(d,h,t,n);return f.concat(m)})}class Oi extends Te{constructor(){super(...arguments);this.allProductions=[]}visitRepetitionWithSeparator(t){this.allProductions.push(t)}visitRepetitionMandatory(t){this.allProductions.push(t)}visitRepetitionMandatoryWithSeparator(t){this.allProductions.push(t)}visitRepetition(t){this.allProductions.push(t)}}function _a(t,s){let n=new ls;return t.accept(n),n.alternations.flatMap((o)=>{if(o.definition.length>255)return[{message:s.buildTooManyAlternativesError({topLevelRule:t,alternation:o}),type:ie.TOO_MANY_ALTS,ruleName:t.name,occurrence:o.idx}];else return[]})}function Li(t,s,n){let i=[];return t.forEach((r)=>{let o=new Oi;r.accept(o),o.allProductions.forEach((u)=>{let c=rs(u),d=u.maxLookahead||s,f=u.idx;if(_t(f,r,c,d)[0].flat().length===0){let N=n.buildEmptyRepetitionError({topLevelRule:r,repetition:u});i.push({message:N,type:ie.NO_NON_EMPTY_LOOKAHEAD,ruleName:r.name})}})}),i}function xa(t,s,n,i){let r=[];return t.reduce((u,c,d)=>{if(s.definition[d].ignoreAmbiguities===!0)return u;return c.forEach((f)=>{let m=[d];if(t.forEach((y,N)=>{if(d!==N&&as(y,f)&&s.definition[N].ignoreAmbiguities!==!0)m.push(N)}),m.length>1&&!as(r,f))r.push(f),u.push({alts:m,path:f})}),u},[]).map((u)=>{let c=u.alts.map((f)=>f+1);return{message:i.buildAlternationAmbiguityError({topLevelRule:n,alternation:s,ambiguityIndices:c,prefixPath:u.path}),type:ie.AMBIGUOUS_ALTS,ruleName:n.name,occurrence:s.idx,alternatives:u.alts}})}function va(t,s,n,i){let r=t.reduce((h,u,c)=>{let d=u.map((f)=>({idx:c,path:f}));return h.concat(d)},[]);return r.flatMap((h)=>{if(s.definition[h.idx].ignoreAmbiguities===!0)return[];let{idx:c,path:d}=h;return r.filter((y)=>s.definition[y.idx].ignoreAmbiguities!==!0&&y.idx<c&&fi(y.path,d)).map((y)=>{let N=[y.idx+1,c+1],U=s.idx===0?"":s.idx;return{message:i.buildAlternationPrefixAmbiguityError({topLevelRule:n,alternation:s,ambiguityIndices:N,prefixPath:y.path}),type:ie.AMBIGUOUS_PREFIX_ALTS,ruleName:n.name,occurrence:U,alternatives:N}})})}function Ma(t,s,n){let i=[],r=s.map((o)=>o.name);return t.forEach((o)=>{let h=o.name;if(r.includes(h)){let u=n.buildNamespaceConflictError(o);i.push({message:u,type:ie.CONFLICT_TOKENS_RULES_NAMESPACE,ruleName:h})}}),i}function Ni(t){let s=Object.assign({errMsgProvider:ti},t),n={};return t.rules.forEach((i)=>{n[i.name]=i}),si(n,s.errMsgProvider)}function Ii(t){var s;let n=(s=t.errMsgProvider)!==null&&s!==void 0?s:ke;return Ti(t.rules,t.tokenTypes,n,t.grammarName)}var ki=["MismatchedTokenException","NoViableAltException","EarlyExitException","NotAllInputParsedException"];Object.freeze(ki);function Ge(t){return ki.includes(t.name)}class xt extends Error{constructor(t,s){super(t);if(this.token=s,this.resyncedTokens=[],Object.setPrototypeOf(this,new.target.prototype),Error.captureStackTrace)Error.captureStackTrace(this,this.constructor)}}class ot extends xt{constructor(t,s,n){super(t,s);this.previousToken=n,this.name="MismatchedTokenException"}}class cs extends xt{constructor(t,s,n){super(t,s);this.previousToken=n,this.name="NoViableAltException"}}class hs extends xt{constructor(t,s){super(t,s);this.name="NotAllInputParsedException"}}class us extends xt{constructor(t,s,n){super(t,s);this.previousToken=n,this.name="EarlyExitException"}}var Xs={},Ys="InRuleRecoveryException";class Ci extends Error{constructor(t){super(t);this.name=Ys}}class qs{initRecoverable(t){if(this.firstAfterRepMap=[],this.resyncFollows={},this.recoveryEnabled=Object.hasOwn(t,"recoveryEnabled")?t.recoveryEnabled:fe.recoveryEnabled,this.recoveryEnabled)this.attemptInRepetitionRecovery=wa}getTokenToInsert(t){let s=qe(t,"",-1,-1,-1,-1,-1,-1);return s.isInsertedInRecovery=!0,s}canTokenTypeBeInsertedInRecovery(t){return!0}canTokenTypeBeDeletedInRecovery(t){return!0}tryInRepetitionRecovery(t,s,n,i){let r=this.findReSyncTokenType(),o=this.exportLexerState(),h=[],u=!1,c=this.LA_FAST(1),d=this.LA_FAST(1),f=()=>{let m=this.LA(0),y=this.errorMessageProvider.buildMismatchTokenMessage({expected:i,actual:c,previous:m,ruleName:this.getCurrRuleFullName()}),N=new ot(y,c,this.LA(0));N.resyncedTokens=h.slice(0,-1),this.SAVE_ERROR(N)};while(!u)if(this.tokenMatcher(d,i)){f();return}else if(n.call(this)){f(),t.apply(this,s);return}else if(this.tokenMatcher(d,r))u=!0;else d=this.SKIP_TOKEN(),this.addToResyncTokens(d,h);this.importLexerState(o)}shouldInRepetitionRecoveryBeTried(t,s,n){if(n===!1)return!1;if(this.tokenMatcher(this.LA_FAST(1),t))return!1;if(this.isBackTracking())return!1;if(this.canPerformInRuleRecovery(t,this.getFollowsForInRuleRecovery(t,s)))return!1;return!0}getNextPossibleTokenTypes(t){let s=t.ruleStack[0],i=this.getGAstProductions()[s];return new Ws(i,t).startWalking()}getFollowsForInRuleRecovery(t,s){let n=this.getCurrentGrammarPath(t,s);return this.getNextPossibleTokenTypes(n)}tryInRuleRecovery(t,s){if(this.canRecoverWithSingleTokenInsertion(t,s))return this.getTokenToInsert(t);if(this.canRecoverWithSingleTokenDeletion(t)){let n=this.SKIP_TOKEN();return this.consumeToken(),n}throw new Ci("sad sad panda")}canPerformInRuleRecovery(t,s){return this.canRecoverWithSingleTokenInsertion(t,s)||this.canRecoverWithSingleTokenDeletion(t)}canRecoverWithSingleTokenInsertion(t,s){if(!this.canTokenTypeBeInsertedInRecovery(t))return!1;if(s.length===0)return!1;let n=this.LA_FAST(1);return s.find((r)=>this.tokenMatcher(n,r))!==void 0}canRecoverWithSingleTokenDeletion(t){if(!this.canTokenTypeBeDeletedInRecovery(t))return!1;return this.tokenMatcher(this.LA(2),t)}isInCurrentRuleReSyncSet(t){let s=this.getCurrFollowKey();return this.getFollowSetFromFollowKey(s).includes(t)}findReSyncTokenType(){let t=this.flattenFollowSet(),s=this.LA_FAST(1),n=2;while(!0){let i=t.find((r)=>kt(s,r));if(i!==void 0)return i;s=this.LA(n),n++}}getCurrFollowKey(){if(this.RULE_STACK_IDX===0)return Xs;let t=this.currRuleShortName,s=this.getLastExplicitRuleOccurrenceIndex(),n=this.getPreviousExplicitRuleShortName();return{ruleName:this.shortRuleNameToFullName(t),idxInCallingRule:s,inRule:this.shortRuleNameToFullName(n)}}buildFullFollowKeyStack(){let t=this.RULE_STACK,s=this.RULE_OCCURRENCE_STACK,n=this.RULE_STACK_IDX+1,i=Array(n);for(let r=0;r<n;r++)if(r===0)i[r]=Xs;else i[r]={ruleName:this.shortRuleNameToFullName(t[r]),idxInCallingRule:s[r],inRule:this.shortRuleNameToFullName(t[r-1])};return i}flattenFollowSet(){return this.buildFullFollowKeyStack().map((s)=>this.getFollowSetFromFollowKey(s)).flat()}getFollowSetFromFollowKey(t){if(t===Xs)return[Se];let s=t.ruleName+t.idxInCallingRule+jt+t.inRule;return this.resyncFollows[s]}addToResyncTokens(t,s){if(!this.tokenMatcher(t,Se))s.push(t);return s}reSyncTo(t){let s=[],n=this.LA_FAST(1);while(this.tokenMatcher(n,t)===!1)n=this.SKIP_TOKEN(),this.addToResyncTokens(n,s);return s.slice(0,-1)}attemptInRepetitionRecovery(t,s,n,i,r,o,h){}getCurrentGrammarPath(t,s){let n=this.getHumanReadableRuleStack(),i=this.RULE_OCCURRENCE_STACK.slice(0,this.RULE_OCCURRENCE_STACK_IDX+1);return{ruleStack:n,occurrenceStack:i,lastTok:t,lastTokOccurrence:s}}getHumanReadableRuleStack(){let t=this.RULE_STACK_IDX+1,s=Array(t);for(let n=0;n<t;n++)s[n]=this.shortRuleNameToFullName(this.RULE_STACK[n]);return s}}function wa(t,s,n,i,r,o,h){var u,c,d;let f=i|r,m=(u=(c=this.firstAfterRepMap)[d=this.currRuleShortName])!==null&&u!==void 0?u:c[d]=[],y=m[f];if(y===void 0){let v=this.getCurrRuleFullName(),_=this.getGAstProductions()[v];y=new o(_,r).startWalking(),m[f]=y}let N=y.token,U=y.occurrence,P=y.isEndOfRule;if(this.RULE_STACK_IDX===0&&P&&N===void 0)N=Se,U=1;if(N===void 0||U===void 0)return;if(this.shouldInRepetitionRecoveryBeTried(N,U,h))this.tryInRepetitionRecovery(t,s,n,N)}var ds=256,ps=512,vt=768,Mt=1024,wt=1280,lt=1536;class fs{constructor(t){var s;this.maxLookahead=(s=t===null||t===void 0?void 0:t.maxLookahead)!==null&&s!==void 0?s:fe.maxLookahead}validate(t){let s=this.validateNoLeftRecursion(t.rules);if(s.length===0){let n=this.validateEmptyOrAlternatives(t.rules),i=this.validateAmbiguousAlternationAlternatives(t.rules,this.maxLookahead),r=this.validateSomeNonEmptyLookaheadPath(t.rules,this.maxLookahead);return[...s,...n,...i,...r]}return s}validateNoLeftRecursion(t){return t.flatMap((s)=>Hs(s,s,ke))}validateEmptyOrAlternatives(t){return t.flatMap((s)=>Ri(s,ke))}validateAmbiguousAlternationAlternatives(t,s){return t.flatMap((n)=>yi(n,s,ke))}validateSomeNonEmptyLookaheadPath(t,s){return Li(t,s,ke)}buildLookaheadForAlternation(t){return li(t.prodOccurrence,t.rule,t.maxLookahead,t.hasPredicates,t.dynamicTokensEnabled,hi)}buildLookaheadForOptional(t){return ci(t.prodOccurrence,t.rule,t.maxLookahead,t.dynamicTokensEnabled,rs(t.prodType),ui)}}class Js{initLooksAhead(t){this.dynamicTokensEnabled=Object.hasOwn(t,"dynamicTokensEnabled")?t.dynamicTokensEnabled:fe.dynamicTokensEnabled,this.maxLookahead=Object.hasOwn(t,"maxLookahead")?t.maxLookahead:fe.maxLookahead,this.lookaheadStrategy=Object.hasOwn(t,"lookaheadStrategy")?t.lookaheadStrategy:new fs({maxLookahead:this.maxLookahead}),this.lookAheadFuncsCache=[],this.currRuleLookaheadFuncs=[]}preComputeLookaheadFunctions(t){t.forEach((s)=>{this.TRACE_INIT(`${s.name} Rule Lookahead`,()=>{let{alternation:n,repetition:i,option:r,repetitionMandatory:o,repetitionMandatoryWithSeparator:h,repetitionWithSeparator:u}=Ua(s);n.forEach((c)=>{let d=c.idx===0?"":c.idx;this.TRACE_INIT(`${Ae(c)}${d}`,()=>{let f=this.lookaheadStrategy.buildLookaheadForAlternation({prodOccurrence:c.idx,rule:s,maxLookahead:c.maxLookahead||this.maxLookahead,hasPredicates:c.hasPredicates,dynamicTokensEnabled:this.dynamicTokensEnabled});this.setLaFuncCache(this.fullRuleNameToShort[s.name],ds|c.idx,f)})}),i.forEach((c)=>{this.computeLookaheadFunc(s,c.idx,vt,"Repetition",c.maxLookahead,Ae(c))}),r.forEach((c)=>{this.computeLookaheadFunc(s,c.idx,ps,"Option",c.maxLookahead,Ae(c))}),o.forEach((c)=>{this.computeLookaheadFunc(s,c.idx,Mt,"RepetitionMandatory",c.maxLookahead,Ae(c))}),h.forEach((c)=>{this.computeLookaheadFunc(s,c.idx,lt,"RepetitionMandatoryWithSeparator",c.maxLookahead,Ae(c))}),u.forEach((c)=>{this.computeLookaheadFunc(s,c.idx,wt,"RepetitionWithSeparator",c.maxLookahead,Ae(c))})})})}computeLookaheadFunc(t,s,n,i,r,o){this.TRACE_INIT(`${o}${s===0?"":s}`,()=>{let h=this.lookaheadStrategy.buildLookaheadForOptional({prodOccurrence:s,rule:t,maxLookahead:r||this.maxLookahead,dynamicTokensEnabled:this.dynamicTokensEnabled,prodType:i});this.setLaFuncCache(this.fullRuleNameToShort[t.name],n|s,h)})}setLaFuncCache(t,s,n){let i=this.lookAheadFuncsCache[t];if(i===void 0)i=[],this.lookAheadFuncsCache[t]=i;i[s]=n}}class bi extends Te{constructor(){super(...arguments);this.dslMethods={option:[],alternation:[],repetition:[],repetitionWithSeparator:[],repetitionMandatory:[],repetitionMandatoryWithSeparator:[]}}reset(){this.dslMethods={option:[],alternation:[],repetition:[],repetitionWithSeparator:[],repetitionMandatory:[],repetitionMandatoryWithSeparator:[]}}visitOption(t){this.dslMethods.option.push(t)}visitRepetitionWithSeparator(t){this.dslMethods.repetitionWithSeparator.push(t)}visitRepetitionMandatory(t){this.dslMethods.repetitionMandatory.push(t)}visitRepetitionMandatoryWithSeparator(t){this.dslMethods.repetitionMandatoryWithSeparator.push(t)}visitRepetition(t){this.dslMethods.repetition.push(t)}visitAlternation(t){this.dslMethods.alternation.push(t)}}var ms=new bi;function Ua(t){ms.reset(),t.accept(ms);let s=ms.dslMethods;return ms.reset(),s}function Zs(t,s){if(t.startOffset===-1)t.startOffset=s.startOffset,t.endOffset=s.endOffset;else if(t.endOffset<s.endOffset===!0)t.endOffset=s.endOffset}function Qs(t,s){if(t.startOffset===-1)t.startOffset=s.startOffset,t.startColumn=s.startColumn,t.startLine=s.startLine,t.endOffset=s.endOffset,t.endColumn=s.endColumn,t.endLine=s.endLine;else if(t.endOffset<s.endOffset===!0)t.endOffset=s.endOffset,t.endColumn=s.endColumn,t.endLine=s.endLine}function _i(t,s,n){if(t.children[n]===void 0)t.children[n]=[s];else t.children[n].push(s)}function xi(t,s,n){if(t.children[s]===void 0)t.children[s]=[n];else t.children[s].push(n)}function en(t,s){Object.defineProperty(t,"name",{enumerable:!1,configurable:!0,writable:!1,value:s})}function Pa(t,s){let n=Object.keys(t),i=n.length;for(let r=0;r<i;r++){let o=n[r],h=t[o],u=h.length;for(let c=0;c<u;c++){let d=h[c];if(d.tokenTypeIdx===void 0)this[d.name](d.children,s)}}}function vi(t,s){let n=function(){};en(n,t+"BaseSemantics");let i={visit:function(r,o){if(Array.isArray(r))r=r[0];if(r===void 0)return;return this[r.name](r.children,o)},validateVisitor:function(){let r=Da(this,s);if(r.length!==0){let o=r.map((h)=>h.msg);throw Error(`Errors Detected in CST Visitor <${this.constructor.name}>:
86
+ see: https://en.wikipedia.org/wiki/LL_parser#Left_factoring.`},buildInvalidRuleNameError(t){return"deprecated"},buildDuplicateRuleNameError(t){let s;if(t.topLevelRule instanceof Te)s=t.topLevelRule.name;else s=t.topLevelRule;return`Duplicate definition, rule: ->${s}<- is already defined in the grammar: ->${t.grammarName}<-`}};function si(t,s){let n=new ii(t,s);return n.resolveRefs(),n.errors}class ii extends Ae{constructor(t,s){super();this.nameToTopRule=t,this.errMsgProvider=s,this.errors=[]}resolveRefs(){Object.values(this.nameToTopRule).forEach((t)=>{this.currTopLevel=t,t.accept(this)})}visitNonTerminal(t){let s=this.nameToTopRule[t.nonTerminalName];if(!s){let n=this.errMsgProvider.buildRuleNotFoundError(this.currTopLevel,t);this.errors.push({message:n,type:ie.UNRESOLVED_SUBRULE_REF,ruleName:this.currTopLevel.name,unresolvedRefName:t.nonTerminalName})}else t.referencedRule=s}}class ri extends $e{constructor(t,s){super();this.topProd=t,this.path=s,this.possibleTokTypes=[],this.nextProductionName="",this.nextProductionOccurrence=0,this.found=!1,this.isAtEndOfPath=!1}startWalking(){if(this.found=!1,this.path.ruleStack[0]!==this.topProd.name)throw Error("The path does not start with the walker's top Rule!");return this.ruleStack=[...this.path.ruleStack].reverse(),this.occurrenceStack=[...this.path.occurrenceStack].reverse(),this.ruleStack.pop(),this.occurrenceStack.pop(),this.updateExpectedNext(),this.walk(this.topProd),this.possibleTokTypes}walk(t,s=[]){if(!this.found)super.walk(t,s)}walkProdRef(t,s,n){if(t.referencedRule.name===this.nextProductionName&&t.idx===this.nextProductionOccurrence){let i=s.concat(n);this.updateExpectedNext(),this.walk(t.referencedRule,i)}}updateExpectedNext(){if(this.ruleStack.length===0)this.nextProductionName="",this.nextProductionOccurrence=0,this.isAtEndOfPath=!0;else this.nextProductionName=this.ruleStack.pop(),this.nextProductionOccurrence=this.occurrenceStack.pop()}}class Ws extends ri{constructor(t,s){super(t,s);this.path=s,this.nextTerminalName="",this.nextTerminalOccurrence=0,this.nextTerminalName=this.path.lastTok.name,this.nextTerminalOccurrence=this.path.lastTokOccurrence}walkTerminal(t,s,n){if(this.isAtEndOfPath&&t.terminalType.name===this.nextTerminalName&&t.idx===this.nextTerminalOccurrence&&!this.found){let i=s.concat(n),r=new j({definition:i});this.possibleTokTypes=Ke(r),this.found=!0}}}class Ct extends $e{constructor(t,s){super();this.topRule=t,this.occurrence=s,this.result={token:void 0,occurrence:void 0,isEndOfRule:void 0}}startWalking(){return this.walk(this.topRule),this.result}}class js extends Ct{walkMany(t,s,n){if(t.idx===this.occurrence){let i=s.concat(n)[0];if(this.result.isEndOfRule=i===void 0,i instanceof F)this.result.token=i.terminalType,this.result.occurrence=i.idx}else super.walkMany(t,s,n)}}class ss extends Ct{walkManySep(t,s,n){if(t.idx===this.occurrence){let i=s.concat(n)[0];if(this.result.isEndOfRule=i===void 0,i instanceof F)this.result.token=i.terminalType,this.result.occurrence=i.idx}else super.walkManySep(t,s,n)}}class Ks extends Ct{walkAtLeastOne(t,s,n){if(t.idx===this.occurrence){let i=s.concat(n)[0];if(this.result.isEndOfRule=i===void 0,i instanceof F)this.result.token=i.terminalType,this.result.occurrence=i.idx}else super.walkAtLeastOne(t,s,n)}}class ns extends Ct{walkAtLeastOneSep(t,s,n){if(t.idx===this.occurrence){let i=s.concat(n)[0];if(this.result.isEndOfRule=i===void 0,i instanceof F)this.result.token=i.terminalType,this.result.occurrence=i.idx}else super.walkAtLeastOneSep(t,s,n)}}function is(t,s,n=[]){n=[...n];let i=[],r=0;function o(u){return u.concat(t.slice(r+1))}function h(u){let c=is(o(u),s,n);return i.concat(c)}while(n.length<s&&r<t.length){let u=t[r];if(u instanceof j)return h(u.definition);else if(u instanceof W)return h(u.definition);else if(u instanceof K)i=h(u.definition);else if(u instanceof Z){let c=u.definition.concat([new G({definition:u.definition})]);return h(c)}else if(u instanceof Q){let c=[new j({definition:u.definition}),new G({definition:[new F({terminalType:u.separator})].concat(u.definition)})];return h(c)}else if(u instanceof q){let c=u.definition.concat([new G({definition:[new F({terminalType:u.separator})].concat(u.definition)})]);i=h(c)}else if(u instanceof G){let c=u.definition.concat([new G({definition:u.definition})]);i=h(c)}else if(u instanceof J)return u.definition.forEach((c)=>{if(c.definition.length!==0)i=h(c.definition)}),i;else if(u instanceof F)n.push(u.terminalType);else throw Error("non exhaustive match");r++}return i.push({partialPath:n,suffixDef:t.slice(r)}),i}function ai(t,s,n,i){let o=["EXIT_NONE_TERMINAL"],h="EXIT_ALTERNATIVE",u=!1,c=s.length,d=c-i-1,f=[],m=[];m.push({idx:-1,def:t,ruleStack:[],occurrenceStack:[]});while(m.length!==0){let y=m.pop();if(y==="EXIT_ALTERNATIVE"){if(u&&m.at(-1).idx<=d)m.pop();continue}let{def:N,idx:U,ruleStack:P,occurrenceStack:v}=y;if(N.length===0)continue;let _=N[0];if(_==="EXIT_NONE_TERMINAL"){let k={idx:U,def:N.slice(1),ruleStack:P.slice(0,-1),occurrenceStack:v.slice(0,-1)};m.push(k)}else if(_ instanceof F)if(U<c-1){let k=U+1,g=s[k];if(n(g,_.terminalType)){let w={idx:k,def:N.slice(1),ruleStack:P,occurrenceStack:v};m.push(w)}}else if(U===c-1)f.push({nextTokenType:_.terminalType,nextTokenOccurrence:_.idx,ruleStack:P,occurrenceStack:v}),u=!0;else throw Error("non exhaustive match");else if(_ instanceof W){let k=[...P];k.push(_.nonTerminalName);let g=[...v];g.push(_.idx);let w={idx:U,def:_.definition.concat(o,N.slice(1)),ruleStack:k,occurrenceStack:g};m.push(w)}else if(_ instanceof K){let k={idx:U,def:N.slice(1),ruleStack:P,occurrenceStack:v};m.push(k),m.push("EXIT_ALTERNATIVE");let g={idx:U,def:_.definition.concat(N.slice(1)),ruleStack:P,occurrenceStack:v};m.push(g)}else if(_ instanceof Z){let k=new G({definition:_.definition,idx:_.idx}),g=_.definition.concat([k],N.slice(1)),w={idx:U,def:g,ruleStack:P,occurrenceStack:v};m.push(w)}else if(_ instanceof Q){let k=new F({terminalType:_.separator}),g=new G({definition:[k].concat(_.definition),idx:_.idx}),w=_.definition.concat([g],N.slice(1)),te={idx:U,def:w,ruleStack:P,occurrenceStack:v};m.push(te)}else if(_ instanceof q){let k={idx:U,def:N.slice(1),ruleStack:P,occurrenceStack:v};m.push(k),m.push("EXIT_ALTERNATIVE");let g=new F({terminalType:_.separator}),w=new G({definition:[g].concat(_.definition),idx:_.idx}),te=_.definition.concat([w],N.slice(1)),de={idx:U,def:te,ruleStack:P,occurrenceStack:v};m.push(de)}else if(_ instanceof G){let k={idx:U,def:N.slice(1),ruleStack:P,occurrenceStack:v};m.push(k),m.push("EXIT_ALTERNATIVE");let g=new G({definition:_.definition,idx:_.idx}),w=_.definition.concat([g],N.slice(1)),te={idx:U,def:w,ruleStack:P,occurrenceStack:v};m.push(te)}else if(_ instanceof J)for(let k=_.definition.length-1;k>=0;k--){let g=_.definition[k],w={idx:U,def:g.definition.concat(N.slice(1)),ruleStack:P,occurrenceStack:v};m.push(w),m.push("EXIT_ALTERNATIVE")}else if(_ instanceof j)m.push({idx:U,def:_.definition.concat(N.slice(1)),ruleStack:P,occurrenceStack:v});else if(_ instanceof Te)m.push(Na(_,U,P,v));else throw Error("non exhaustive match")}return f}function Na(t,s,n,i){let r=[...n];r.push(t.name);let o=[...i];return o.push(1),{idx:s,def:t.definition,ruleStack:r,occurrenceStack:o}}var H;(function(t){t[t.OPTION=0]="OPTION",t[t.REPETITION=1]="REPETITION",t[t.REPETITION_MANDATORY=2]="REPETITION_MANDATORY",t[t.REPETITION_MANDATORY_WITH_SEPARATOR=3]="REPETITION_MANDATORY_WITH_SEPARATOR",t[t.REPETITION_WITH_SEPARATOR=4]="REPETITION_WITH_SEPARATOR",t[t.ALTERNATION=5]="ALTERNATION"})(H||(H={}));function rs(t){if(t instanceof K||t==="Option")return H.OPTION;else if(t instanceof G||t==="Repetition")return H.REPETITION;else if(t instanceof Z||t==="RepetitionMandatory")return H.REPETITION_MANDATORY;else if(t instanceof Q||t==="RepetitionMandatoryWithSeparator")return H.REPETITION_MANDATORY_WITH_SEPARATOR;else if(t instanceof q||t==="RepetitionWithSeparator")return H.REPETITION_WITH_SEPARATOR;else if(t instanceof J||t==="Alternation")return H.ALTERNATION;else throw Error("non exhaustive match")}function li(t,s,n,i,r,o){let h=bt(t,s,n),u=mi(h)?at:Ue;return o(h,i,u,r)}function ci(t,s,n,i,r,o){let h=_t(t,s,r,n),u=mi(h)?at:Ue;return o(h[0],u,i)}function hi(t,s,n,i){let r=t.length,o=t.every((h)=>h.every((u)=>u.length===1));if(s)return function(h){let u=h.map((c)=>c.GATE);for(let c=0;c<r;c++){let d=t[c],f=d.length,m=u[c];if(m!==void 0&&m.call(this)===!1)continue;e:for(let y=0;y<f;y++){let N=d[y],U=N.length;for(let P=0;P<U;P++){let v=this.LA_FAST(P+1);if(n(v,N[P])===!1)continue e}return c}}return};else if(o&&!i){let u=t.map((c)=>c.flat()).reduce((c,d,f)=>(d.forEach((m)=>{if(!(m.tokenTypeIdx in c))c[m.tokenTypeIdx]=f;m.categoryMatches.forEach((y)=>{if(!Object.hasOwn(c,y))c[y]=f})}),c),{});return function(){let c=this.LA_FAST(1);return u[c.tokenTypeIdx]}}else return function(){for(let h=0;h<r;h++){let u=t[h],c=u.length;e:for(let d=0;d<c;d++){let f=u[d],m=f.length;for(let y=0;y<m;y++){let N=this.LA_FAST(y+1);if(n(N,f[y])===!1)continue e}return h}}return}}function ui(t,s,n){let i=t.every((o)=>o.length===1),r=t.length;if(i&&!n){let o=t.flat();if(o.length===1&&o[0].categoryMatches.length===0){let u=o[0].tokenTypeIdx;return function(){return this.LA_FAST(1).tokenTypeIdx===u}}else{let h=o.reduce((u,c,d)=>(u[c.tokenTypeIdx]=!0,c.categoryMatches.forEach((f)=>{u[f]=!0}),u),[]);return function(){let u=this.LA_FAST(1);return h[u.tokenTypeIdx]===!0}}}else return function(){e:for(let o=0;o<r;o++){let h=t[o],u=h.length;for(let c=0;c<u;c++){let d=this.LA_FAST(c+1);if(s(d,h[c])===!1)continue e}return!0}return!1}}class di extends $e{constructor(t,s,n){super();this.topProd=t,this.targetOccurrence=s,this.targetProdType=n}startWalking(){return this.walk(this.topProd),this.restDef}checkIsTarget(t,s,n,i){if(t.idx===this.targetOccurrence&&this.targetProdType===s)return this.restDef=n.concat(i),!0;return!1}walkOption(t,s,n){if(!this.checkIsTarget(t,H.OPTION,s,n))super.walkOption(t,s,n)}walkAtLeastOne(t,s,n){if(!this.checkIsTarget(t,H.REPETITION_MANDATORY,s,n))super.walkOption(t,s,n)}walkAtLeastOneSep(t,s,n){if(!this.checkIsTarget(t,H.REPETITION_MANDATORY_WITH_SEPARATOR,s,n))super.walkOption(t,s,n)}walkMany(t,s,n){if(!this.checkIsTarget(t,H.REPETITION,s,n))super.walkOption(t,s,n)}walkManySep(t,s,n){if(!this.checkIsTarget(t,H.REPETITION_WITH_SEPARATOR,s,n))super.walkOption(t,s,n)}}class zs extends Ae{constructor(t,s,n){super();this.targetOccurrence=t,this.targetProdType=s,this.targetRef=n,this.result=[]}checkIsTarget(t,s){if(t.idx===this.targetOccurrence&&this.targetProdType===s&&(this.targetRef===void 0||t===this.targetRef))this.result=t.definition}visitOption(t){this.checkIsTarget(t,H.OPTION)}visitRepetition(t){this.checkIsTarget(t,H.REPETITION)}visitRepetitionMandatory(t){this.checkIsTarget(t,H.REPETITION_MANDATORY)}visitRepetitionMandatoryWithSeparator(t){this.checkIsTarget(t,H.REPETITION_MANDATORY_WITH_SEPARATOR)}visitRepetitionWithSeparator(t){this.checkIsTarget(t,H.REPETITION_WITH_SEPARATOR)}visitAlternation(t){this.checkIsTarget(t,H.ALTERNATION)}}function oi(t){let s=Array(t);for(let n=0;n<t;n++)s[n]=[];return s}function Vs(t){let s=[""];for(let n=0;n<t.length;n++){let i=t[n],r=[];for(let o=0;o<s.length;o++){let h=s[o];r.push(h+"_"+i.tokenTypeIdx);for(let u=0;u<i.categoryMatches.length;u++){let c="_"+i.categoryMatches[u];r.push(h+c)}}s=r}return s}function Ia(t,s,n){for(let i=0;i<t.length;i++){if(i===n)continue;let r=t[i];for(let o=0;o<s.length;o++){let h=s[o];if(r[h]===!0)return!1}}return!0}function pi(t,s){let n=t.map((h)=>is([h],1)),i=oi(n.length),r=n.map((h)=>{let u={};return h.forEach((c)=>{Vs(c.partialPath).forEach((f)=>{u[f]=!0})}),u}),o=n;for(let h=1;h<=s;h++){let u=o;o=oi(u.length);for(let c=0;c<u.length;c++){let d=u[c];for(let f=0;f<d.length;f++){let m=d[f].partialPath,y=d[f].suffixDef,N=Vs(m);if(Ia(r,N,c)||y.length===0||m.length===s){let P=i[c];if(as(P,m)===!1){P.push(m);for(let v=0;v<N.length;v++){let _=N[v];r[c][_]=!0}}}else{let P=is(y,h+1,m);o[c]=o[c].concat(P),P.forEach((v)=>{Vs(v.partialPath).forEach((k)=>{r[c][k]=!0})})}}}}return i}function bt(t,s,n,i){let r=new zs(t,H.ALTERNATION,i);return s.accept(r),pi(r.result,n)}function _t(t,s,n,i){let r=new zs(t,n);s.accept(r);let o=r.result,u=new di(s,t,n).startWalking(),c=new j({definition:o}),d=new j({definition:u});return pi([c,d],i)}function as(t,s){e:for(let n=0;n<t.length;n++){let i=t[n];if(i.length!==s.length)continue;for(let r=0;r<i.length;r++){let o=s[r],h=i[r];if((o===h||h.categoryMatchesMap[o.tokenTypeIdx]!==void 0)===!1)continue e}return!0}return!1}function fi(t,s){return t.length<s.length&&t.every((n,i)=>{let r=s[i];return n===r||r.categoryMatchesMap[n.tokenTypeIdx]})}function mi(t){return t.every((s)=>s.every((n)=>n.every((i)=>i.categoryMatches.length===0)))}function Ei(t){return t.lookaheadStrategy.validate({rules:t.rules,tokenTypes:t.tokenTypes,grammarName:t.grammarName}).map((n)=>Object.assign({type:ie.CUSTOM_LOOKAHEAD_VALIDATION},n))}function Ti(t,s,n,i){let r=t.flatMap((c)=>ka(c,n)),o=Ma(t,s,n),h=t.flatMap((c)=>_a(c,n)),u=t.flatMap((c)=>ba(c,t,i,n));return r.concat(o,h,u)}function ka(t,s){let n=new Ai;t.accept(n);let i=n.allProductions,r=Object.groupBy(i,Ca),o=Object.fromEntries(Object.entries(r).filter(([u,c])=>c.length>1));return Object.values(o).map((u)=>{let c=u[0],d=s.buildDuplicateFoundError(t,u),f=Se(c),m={message:d,type:ie.DUPLICATE_PRODUCTIONS,ruleName:t.name,dslName:f,occurrence:c.idx},y=gi(c);if(y)m.parameter=y;return m})}function Ca(t){return`${Se(t)}_#_${t.idx}_#_${gi(t)}`}function gi(t){if(t instanceof F)return t.terminalType.name;else if(t instanceof W)return t.nonTerminalName;else return""}class Ai extends Ae{constructor(){super(...arguments);this.allProductions=[]}visitNonTerminal(t){this.allProductions.push(t)}visitOption(t){this.allProductions.push(t)}visitRepetitionWithSeparator(t){this.allProductions.push(t)}visitRepetitionMandatory(t){this.allProductions.push(t)}visitRepetitionMandatoryWithSeparator(t){this.allProductions.push(t)}visitRepetition(t){this.allProductions.push(t)}visitAlternation(t){this.allProductions.push(t)}visitTerminal(t){this.allProductions.push(t)}}function ba(t,s,n,i){let r=[];if(s.reduce((h,u)=>{if(u.name===t.name)return h+1;return h},0)>1){let h=i.buildDuplicateRuleNameError({topLevelRule:t,grammarName:n});r.push({message:h,type:ie.DUPLICATE_RULE_NAME,ruleName:t.name})}return r}function Si(t,s,n){let i=[],r;if(!s.includes(t))r=`Invalid rule override, rule: ->${t}<- cannot be overridden in the grammar: ->${n}<-as it is not defined in any of the super grammars `,i.push({message:r,type:ie.INVALID_RULE_OVERRIDE,ruleName:t});return i}function Hs(t,s,n,i=[]){let r=[],o=os(s.definition);if(o.length===0)return[];else{let h=t.name;if(o.includes(t))r.push({message:n.buildLeftRecursionError({topLevelRule:t,leftRecursionPath:i}),type:ie.LEFT_RECURSION,ruleName:h});let c=i.concat([t]),f=o.filter((m)=>!c.includes(m)).flatMap((m)=>{let y=[...i];return y.push(m),Hs(t,m,n,y)});return r.concat(f)}}function os(t){let s=[];if(t.length===0)return s;let n=t[0];if(n instanceof W)s.push(n.referencedRule);else if(n instanceof j||n instanceof K||n instanceof Z||n instanceof Q||n instanceof q||n instanceof G)s=s.concat(os(n.definition));else if(n instanceof J)s=n.definition.map((o)=>os(o.definition)).flat();else if(n instanceof F);else throw Error("non exhaustive match");let i=je(n),r=t.length>1;if(i&&r){let o=t.slice(1);return s.concat(os(o))}else return s}class ls extends Ae{constructor(){super(...arguments);this.alternations=[]}visitAlternation(t){this.alternations.push(t)}}function Ri(t,s){let n=new ls;return t.accept(n),n.alternations.flatMap((o)=>o.definition.slice(0,-1).flatMap((u,c)=>{if(ai([u],[],Ue,1).length===0)return[{message:s.buildEmptyAlternationError({topLevelRule:t,alternation:o,emptyChoiceIdx:c}),type:ie.NONE_LAST_EMPTY_ALT,ruleName:t.name,occurrence:o.idx,alternative:c+1}];else return[]}))}function yi(t,s,n){let i=new ls;t.accept(i);let r=i.alternations;return r=r.filter((h)=>h.ignoreAmbiguities!==!0),r.flatMap((h)=>{let u=h.idx,c=h.maxLookahead||s,d=bt(u,t,c,h),f=xa(d,h,t,n),m=va(d,h,t,n);return f.concat(m)})}class Oi extends Ae{constructor(){super(...arguments);this.allProductions=[]}visitRepetitionWithSeparator(t){this.allProductions.push(t)}visitRepetitionMandatory(t){this.allProductions.push(t)}visitRepetitionMandatoryWithSeparator(t){this.allProductions.push(t)}visitRepetition(t){this.allProductions.push(t)}}function _a(t,s){let n=new ls;return t.accept(n),n.alternations.flatMap((o)=>{if(o.definition.length>255)return[{message:s.buildTooManyAlternativesError({topLevelRule:t,alternation:o}),type:ie.TOO_MANY_ALTS,ruleName:t.name,occurrence:o.idx}];else return[]})}function Li(t,s,n){let i=[];return t.forEach((r)=>{let o=new Oi;r.accept(o),o.allProductions.forEach((u)=>{let c=rs(u),d=u.maxLookahead||s,f=u.idx;if(_t(f,r,c,d)[0].flat().length===0){let N=n.buildEmptyRepetitionError({topLevelRule:r,repetition:u});i.push({message:N,type:ie.NO_NON_EMPTY_LOOKAHEAD,ruleName:r.name})}})}),i}function xa(t,s,n,i){let r=[];return t.reduce((u,c,d)=>{if(s.definition[d].ignoreAmbiguities===!0)return u;return c.forEach((f)=>{let m=[d];if(t.forEach((y,N)=>{if(d!==N&&as(y,f)&&s.definition[N].ignoreAmbiguities!==!0)m.push(N)}),m.length>1&&!as(r,f))r.push(f),u.push({alts:m,path:f})}),u},[]).map((u)=>{let c=u.alts.map((f)=>f+1);return{message:i.buildAlternationAmbiguityError({topLevelRule:n,alternation:s,ambiguityIndices:c,prefixPath:u.path}),type:ie.AMBIGUOUS_ALTS,ruleName:n.name,occurrence:s.idx,alternatives:u.alts}})}function va(t,s,n,i){let r=t.reduce((h,u,c)=>{let d=u.map((f)=>({idx:c,path:f}));return h.concat(d)},[]);return r.flatMap((h)=>{if(s.definition[h.idx].ignoreAmbiguities===!0)return[];let{idx:c,path:d}=h;return r.filter((y)=>s.definition[y.idx].ignoreAmbiguities!==!0&&y.idx<c&&fi(y.path,d)).map((y)=>{let N=[y.idx+1,c+1],U=s.idx===0?"":s.idx;return{message:i.buildAlternationPrefixAmbiguityError({topLevelRule:n,alternation:s,ambiguityIndices:N,prefixPath:y.path}),type:ie.AMBIGUOUS_PREFIX_ALTS,ruleName:n.name,occurrence:U,alternatives:N}})})}function Ma(t,s,n){let i=[],r=s.map((o)=>o.name);return t.forEach((o)=>{let h=o.name;if(r.includes(h)){let u=n.buildNamespaceConflictError(o);i.push({message:u,type:ie.CONFLICT_TOKENS_RULES_NAMESPACE,ruleName:h})}}),i}function Ni(t){let s=Object.assign({errMsgProvider:ti},t),n={};return t.rules.forEach((i)=>{n[i.name]=i}),si(n,s.errMsgProvider)}function Ii(t){var s;let n=(s=t.errMsgProvider)!==null&&s!==void 0?s:Ce;return Ti(t.rules,t.tokenTypes,n,t.grammarName)}var ki=["MismatchedTokenException","NoViableAltException","EarlyExitException","NotAllInputParsedException"];Object.freeze(ki);function Ge(t){return ki.includes(t.name)}class xt extends Error{constructor(t,s){super(t);if(this.token=s,this.resyncedTokens=[],Object.setPrototypeOf(this,new.target.prototype),Error.captureStackTrace)Error.captureStackTrace(this,this.constructor)}}class ot extends xt{constructor(t,s,n){super(t,s);this.previousToken=n,this.name="MismatchedTokenException"}}class cs extends xt{constructor(t,s,n){super(t,s);this.previousToken=n,this.name="NoViableAltException"}}class hs extends xt{constructor(t,s){super(t,s);this.name="NotAllInputParsedException"}}class us extends xt{constructor(t,s,n){super(t,s);this.previousToken=n,this.name="EarlyExitException"}}var Xs={},Ys="InRuleRecoveryException";class Ci extends Error{constructor(t){super(t);this.name=Ys}}class qs{initRecoverable(t){if(this.firstAfterRepMap=[],this.resyncFollows={},this.recoveryEnabled=Object.hasOwn(t,"recoveryEnabled")?t.recoveryEnabled:me.recoveryEnabled,this.recoveryEnabled)this.attemptInRepetitionRecovery=wa}getTokenToInsert(t){let s=qe(t,"",-1,-1,-1,-1,-1,-1);return s.isInsertedInRecovery=!0,s}canTokenTypeBeInsertedInRecovery(t){return!0}canTokenTypeBeDeletedInRecovery(t){return!0}tryInRepetitionRecovery(t,s,n,i){let r=this.findReSyncTokenType(),o=this.exportLexerState(),h=[],u=!1,c=this.LA_FAST(1),d=this.LA_FAST(1),f=()=>{let m=this.LA(0),y=this.errorMessageProvider.buildMismatchTokenMessage({expected:i,actual:c,previous:m,ruleName:this.getCurrRuleFullName()}),N=new ot(y,c,this.LA(0));N.resyncedTokens=h.slice(0,-1),this.SAVE_ERROR(N)};while(!u)if(this.tokenMatcher(d,i)){f();return}else if(n.call(this)){f(),t.apply(this,s);return}else if(this.tokenMatcher(d,r))u=!0;else d=this.SKIP_TOKEN(),this.addToResyncTokens(d,h);this.importLexerState(o)}shouldInRepetitionRecoveryBeTried(t,s,n){if(n===!1)return!1;if(this.tokenMatcher(this.LA_FAST(1),t))return!1;if(this.isBackTracking())return!1;if(this.canPerformInRuleRecovery(t,this.getFollowsForInRuleRecovery(t,s)))return!1;return!0}getNextPossibleTokenTypes(t){let s=t.ruleStack[0],i=this.getGAstProductions()[s];return new Ws(i,t).startWalking()}getFollowsForInRuleRecovery(t,s){let n=this.getCurrentGrammarPath(t,s);return this.getNextPossibleTokenTypes(n)}tryInRuleRecovery(t,s){if(this.canRecoverWithSingleTokenInsertion(t,s))return this.getTokenToInsert(t);if(this.canRecoverWithSingleTokenDeletion(t)){let n=this.SKIP_TOKEN();return this.consumeToken(),n}throw new Ci("sad sad panda")}canPerformInRuleRecovery(t,s){return this.canRecoverWithSingleTokenInsertion(t,s)||this.canRecoverWithSingleTokenDeletion(t)}canRecoverWithSingleTokenInsertion(t,s){if(!this.canTokenTypeBeInsertedInRecovery(t))return!1;if(s.length===0)return!1;let n=this.LA_FAST(1);return s.find((r)=>this.tokenMatcher(n,r))!==void 0}canRecoverWithSingleTokenDeletion(t){if(!this.canTokenTypeBeDeletedInRecovery(t))return!1;return this.tokenMatcher(this.LA(2),t)}isInCurrentRuleReSyncSet(t){let s=this.getCurrFollowKey();return this.getFollowSetFromFollowKey(s).includes(t)}findReSyncTokenType(){let t=this.flattenFollowSet(),s=this.LA_FAST(1),n=2;while(!0){let i=t.find((r)=>kt(s,r));if(i!==void 0)return i;s=this.LA(n),n++}}getCurrFollowKey(){if(this.RULE_STACK_IDX===0)return Xs;let t=this.currRuleShortName,s=this.getLastExplicitRuleOccurrenceIndex(),n=this.getPreviousExplicitRuleShortName();return{ruleName:this.shortRuleNameToFullName(t),idxInCallingRule:s,inRule:this.shortRuleNameToFullName(n)}}buildFullFollowKeyStack(){let t=this.RULE_STACK,s=this.RULE_OCCURRENCE_STACK,n=this.RULE_STACK_IDX+1,i=Array(n);for(let r=0;r<n;r++)if(r===0)i[r]=Xs;else i[r]={ruleName:this.shortRuleNameToFullName(t[r]),idxInCallingRule:s[r],inRule:this.shortRuleNameToFullName(t[r-1])};return i}flattenFollowSet(){return this.buildFullFollowKeyStack().map((s)=>this.getFollowSetFromFollowKey(s)).flat()}getFollowSetFromFollowKey(t){if(t===Xs)return[Re];let s=t.ruleName+t.idxInCallingRule+jt+t.inRule;return this.resyncFollows[s]}addToResyncTokens(t,s){if(!this.tokenMatcher(t,Re))s.push(t);return s}reSyncTo(t){let s=[],n=this.LA_FAST(1);while(this.tokenMatcher(n,t)===!1)n=this.SKIP_TOKEN(),this.addToResyncTokens(n,s);return s.slice(0,-1)}attemptInRepetitionRecovery(t,s,n,i,r,o,h){}getCurrentGrammarPath(t,s){let n=this.getHumanReadableRuleStack(),i=this.RULE_OCCURRENCE_STACK.slice(0,this.RULE_OCCURRENCE_STACK_IDX+1);return{ruleStack:n,occurrenceStack:i,lastTok:t,lastTokOccurrence:s}}getHumanReadableRuleStack(){let t=this.RULE_STACK_IDX+1,s=Array(t);for(let n=0;n<t;n++)s[n]=this.shortRuleNameToFullName(this.RULE_STACK[n]);return s}}function wa(t,s,n,i,r,o,h){var u,c,d;let f=i|r,m=(u=(c=this.firstAfterRepMap)[d=this.currRuleShortName])!==null&&u!==void 0?u:c[d]=[],y=m[f];if(y===void 0){let v=this.getCurrRuleFullName(),_=this.getGAstProductions()[v];y=new o(_,r).startWalking(),m[f]=y}let N=y.token,U=y.occurrence,P=y.isEndOfRule;if(this.RULE_STACK_IDX===0&&P&&N===void 0)N=Re,U=1;if(N===void 0||U===void 0)return;if(this.shouldInRepetitionRecoveryBeTried(N,U,h))this.tryInRepetitionRecovery(t,s,n,N)}var ds=256,ps=512,vt=768,Mt=1024,wt=1280,lt=1536;class fs{constructor(t){var s;this.maxLookahead=(s=t===null||t===void 0?void 0:t.maxLookahead)!==null&&s!==void 0?s:me.maxLookahead}validate(t){let s=this.validateNoLeftRecursion(t.rules);if(s.length===0){let n=this.validateEmptyOrAlternatives(t.rules),i=this.validateAmbiguousAlternationAlternatives(t.rules,this.maxLookahead),r=this.validateSomeNonEmptyLookaheadPath(t.rules,this.maxLookahead);return[...s,...n,...i,...r]}return s}validateNoLeftRecursion(t){return t.flatMap((s)=>Hs(s,s,Ce))}validateEmptyOrAlternatives(t){return t.flatMap((s)=>Ri(s,Ce))}validateAmbiguousAlternationAlternatives(t,s){return t.flatMap((n)=>yi(n,s,Ce))}validateSomeNonEmptyLookaheadPath(t,s){return Li(t,s,Ce)}buildLookaheadForAlternation(t){return li(t.prodOccurrence,t.rule,t.maxLookahead,t.hasPredicates,t.dynamicTokensEnabled,hi)}buildLookaheadForOptional(t){return ci(t.prodOccurrence,t.rule,t.maxLookahead,t.dynamicTokensEnabled,rs(t.prodType),ui)}}class Js{initLooksAhead(t){this.dynamicTokensEnabled=Object.hasOwn(t,"dynamicTokensEnabled")?t.dynamicTokensEnabled:me.dynamicTokensEnabled,this.maxLookahead=Object.hasOwn(t,"maxLookahead")?t.maxLookahead:me.maxLookahead,this.lookaheadStrategy=Object.hasOwn(t,"lookaheadStrategy")?t.lookaheadStrategy:new fs({maxLookahead:this.maxLookahead}),this.lookAheadFuncsCache=[],this.currRuleLookaheadFuncs=[]}preComputeLookaheadFunctions(t){t.forEach((s)=>{this.TRACE_INIT(`${s.name} Rule Lookahead`,()=>{let{alternation:n,repetition:i,option:r,repetitionMandatory:o,repetitionMandatoryWithSeparator:h,repetitionWithSeparator:u}=Ua(s);n.forEach((c)=>{let d=c.idx===0?"":c.idx;this.TRACE_INIT(`${Se(c)}${d}`,()=>{let f=this.lookaheadStrategy.buildLookaheadForAlternation({prodOccurrence:c.idx,rule:s,maxLookahead:c.maxLookahead||this.maxLookahead,hasPredicates:c.hasPredicates,dynamicTokensEnabled:this.dynamicTokensEnabled});this.setLaFuncCache(this.fullRuleNameToShort[s.name],ds|c.idx,f)})}),i.forEach((c)=>{this.computeLookaheadFunc(s,c.idx,vt,"Repetition",c.maxLookahead,Se(c))}),r.forEach((c)=>{this.computeLookaheadFunc(s,c.idx,ps,"Option",c.maxLookahead,Se(c))}),o.forEach((c)=>{this.computeLookaheadFunc(s,c.idx,Mt,"RepetitionMandatory",c.maxLookahead,Se(c))}),h.forEach((c)=>{this.computeLookaheadFunc(s,c.idx,lt,"RepetitionMandatoryWithSeparator",c.maxLookahead,Se(c))}),u.forEach((c)=>{this.computeLookaheadFunc(s,c.idx,wt,"RepetitionWithSeparator",c.maxLookahead,Se(c))})})})}computeLookaheadFunc(t,s,n,i,r,o){this.TRACE_INIT(`${o}${s===0?"":s}`,()=>{let h=this.lookaheadStrategy.buildLookaheadForOptional({prodOccurrence:s,rule:t,maxLookahead:r||this.maxLookahead,dynamicTokensEnabled:this.dynamicTokensEnabled,prodType:i});this.setLaFuncCache(this.fullRuleNameToShort[t.name],n|s,h)})}setLaFuncCache(t,s,n){let i=this.lookAheadFuncsCache[t];if(i===void 0)i=[],this.lookAheadFuncsCache[t]=i;i[s]=n}}class bi extends Ae{constructor(){super(...arguments);this.dslMethods={option:[],alternation:[],repetition:[],repetitionWithSeparator:[],repetitionMandatory:[],repetitionMandatoryWithSeparator:[]}}reset(){this.dslMethods={option:[],alternation:[],repetition:[],repetitionWithSeparator:[],repetitionMandatory:[],repetitionMandatoryWithSeparator:[]}}visitOption(t){this.dslMethods.option.push(t)}visitRepetitionWithSeparator(t){this.dslMethods.repetitionWithSeparator.push(t)}visitRepetitionMandatory(t){this.dslMethods.repetitionMandatory.push(t)}visitRepetitionMandatoryWithSeparator(t){this.dslMethods.repetitionMandatoryWithSeparator.push(t)}visitRepetition(t){this.dslMethods.repetition.push(t)}visitAlternation(t){this.dslMethods.alternation.push(t)}}var ms=new bi;function Ua(t){ms.reset(),t.accept(ms);let s=ms.dslMethods;return ms.reset(),s}function Zs(t,s){if(t.startOffset===-1)t.startOffset=s.startOffset,t.endOffset=s.endOffset;else if(t.endOffset<s.endOffset===!0)t.endOffset=s.endOffset}function Qs(t,s){if(t.startOffset===-1)t.startOffset=s.startOffset,t.startColumn=s.startColumn,t.startLine=s.startLine,t.endOffset=s.endOffset,t.endColumn=s.endColumn,t.endLine=s.endLine;else if(t.endOffset<s.endOffset===!0)t.endOffset=s.endOffset,t.endColumn=s.endColumn,t.endLine=s.endLine}function _i(t,s,n){if(t.children[n]===void 0)t.children[n]=[s];else t.children[n].push(s)}function xi(t,s,n){if(t.children[s]===void 0)t.children[s]=[n];else t.children[s].push(n)}function en(t,s){Object.defineProperty(t,"name",{enumerable:!1,configurable:!0,writable:!1,value:s})}function Pa(t,s){let n=Object.keys(t),i=n.length;for(let r=0;r<i;r++){let o=n[r],h=t[o],u=h.length;for(let c=0;c<u;c++){let d=h[c];if(d.tokenTypeIdx===void 0)this[d.name](d.children,s)}}}function vi(t,s){let n=function(){};en(n,t+"BaseSemantics");let i={visit:function(r,o){if(Array.isArray(r))r=r[0];if(r===void 0)return;return this[r.name](r.children,o)},validateVisitor:function(){let r=Da(this,s);if(r.length!==0){let o=r.map((h)=>h.msg);throw Error(`Errors Detected in CST Visitor <${this.constructor.name}>:
87
87
  ${o.join(`
88
88
 
89
89
  `).replace(/\n/g,`
90
- `)}`)}}};return n.prototype=i,n.prototype.constructor=n,n._RULE_NAMES=s,n}function Mi(t,s,n){let i=function(){};en(i,t+"BaseSemanticsWithDefaults");let r=Object.create(n.prototype);return s.forEach((o)=>{r[o]=Pa}),i.prototype=r,i.prototype.constructor=i,i}var tn;(function(t){t[t.REDUNDANT_METHOD=0]="REDUNDANT_METHOD",t[t.MISSING_METHOD=1]="MISSING_METHOD"})(tn||(tn={}));function Da(t,s){return Fa(t,s)}function Fa(t,s){return s.filter((r)=>typeof t[r]==="function"===!1).map((r)=>({msg:`Missing visitor method: <${r}> on ${t.constructor.name} CST Visitor.`,type:tn.MISSING_METHOD,methodName:r})).filter(Boolean)}class sn{initTreeBuilder(t){if(this.CST_STACK=[],this.outputCst=t.outputCst,this.nodeLocationTracking=Object.hasOwn(t,"nodeLocationTracking")?t.nodeLocationTracking:fe.nodeLocationTracking,!this.outputCst)this.cstInvocationStateUpdate=()=>{},this.cstFinallyStateUpdate=()=>{},this.cstPostTerminal=()=>{},this.cstPostNonTerminal=()=>{},this.cstPostRule=()=>{};else if(/full/i.test(this.nodeLocationTracking))if(this.recoveryEnabled)this.setNodeLocationFromToken=Qs,this.setNodeLocationFromNode=Qs,this.cstPostRule=()=>{},this.setInitialNodeLocation=this.setInitialNodeLocationFullRecovery;else this.setNodeLocationFromToken=()=>{},this.setNodeLocationFromNode=()=>{},this.cstPostRule=this.cstPostRuleFull,this.setInitialNodeLocation=this.setInitialNodeLocationFullRegular;else if(/onlyOffset/i.test(this.nodeLocationTracking))if(this.recoveryEnabled)this.setNodeLocationFromToken=Zs,this.setNodeLocationFromNode=Zs,this.cstPostRule=()=>{},this.setInitialNodeLocation=this.setInitialNodeLocationOnlyOffsetRecovery;else this.setNodeLocationFromToken=()=>{},this.setNodeLocationFromNode=()=>{},this.cstPostRule=this.cstPostRuleOnlyOffset,this.setInitialNodeLocation=this.setInitialNodeLocationOnlyOffsetRegular;else if(/none/i.test(this.nodeLocationTracking))this.setNodeLocationFromToken=()=>{},this.setNodeLocationFromNode=()=>{},this.cstPostRule=()=>{},this.setInitialNodeLocation=()=>{};else throw Error(`Invalid <nodeLocationTracking> config option: "${t.nodeLocationTracking}"`)}setInitialNodeLocationOnlyOffsetRecovery(t){t.location={startOffset:-1,endOffset:-1}}setInitialNodeLocationOnlyOffsetRegular(t){t.location={startOffset:this.LA_FAST(1).startOffset,endOffset:-1}}setInitialNodeLocationFullRecovery(t){t.location={startOffset:-1,startLine:-1,startColumn:-1,endOffset:-1,endLine:-1,endColumn:-1}}setInitialNodeLocationFullRegular(t){let s=this.LA_FAST(1);t.location={startOffset:s.startOffset,startLine:s.startLine,startColumn:s.startColumn,endOffset:-1,endLine:-1,endColumn:-1}}cstInvocationStateUpdate(t){let s={name:t,children:Object.create(null)};this.setInitialNodeLocation(s),this.CST_STACK.push(s)}cstFinallyStateUpdate(){this.CST_STACK.pop()}cstPostRuleFull(t){let s=this.LA(0),n=t.location;if(n.startOffset!==-1&&n.startOffset<=s.startOffset===!0)n.endOffset=s.endOffset,n.endLine=s.endLine,n.endColumn=s.endColumn;else n.startOffset=-1,n.startLine=-1,n.startColumn=-1}cstPostRuleOnlyOffset(t){let s=this.LA(0),n=t.location;if(n.startOffset!==-1&&n.startOffset<=s.startOffset===!0)n.endOffset=s.endOffset;else n.startOffset=-1}cstPostTerminal(t,s){let n=this.CST_STACK[this.CST_STACK.length-1];_i(n,s,t),this.setNodeLocationFromToken(n.location,s)}cstPostNonTerminal(t,s){let n=this.CST_STACK[this.CST_STACK.length-1];xi(n,s,t),this.setNodeLocationFromNode(n.location,t.location)}get currCSTNode(){let t=this;return t.CST_STACK[t.CST_STACK.length-1]}getBaseCstVisitorConstructor(){if(this.baseCstVisitorConstructor===void 0){let t=vi(this.className,Object.keys(this.gastProductionsCache));return this.baseCstVisitorConstructor=t,t}return this.baseCstVisitorConstructor}getBaseCstVisitorConstructorWithDefaults(){if(this.baseCstVisitorWithDefaultsConstructor===void 0){let t=Mi(this.className,Object.keys(this.gastProductionsCache),this.getBaseCstVisitorConstructor());return this.baseCstVisitorWithDefaultsConstructor=t,t}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 nn{initLexerAdapter(){this.tokVector=[],this.tokVectorLength=0,this.currIdx=-1}set input(t){if(this.selfAnalysisDone!==!0)throw Error("Missing <performSelfAnalysis> invocation at the end of the Parser's constructor.");this.reset(),this.tokVector=t,this.tokVectorLength=t.length}get input(){return this.tokVector}SKIP_TOKEN(){if(this.currIdx<=this.tokVectorLength-2)return this.consumeToken(),this.LA_FAST(1);else return De}LA_FAST(t){let s=this.currIdx+t;return this.tokVector[s]}LA(t){let s=this.currIdx+t;if(s<0||this.tokVectorLength<=s)return De;else return this.tokVector[s]}consumeToken(){this.currIdx++}exportLexerState(){return this.currIdx}importLexerState(t){this.currIdx=t}resetLexerState(){this.currIdx=-1}moveToTerminatedState(){this.currIdx=this.tokVectorLength-1}getLexerPosition(){return this.exportLexerState()}}class rn{ACTION(t){return t.call(this)}consume(t,s,n){return this.consumeInternal(s,t,n)}subrule(t,s,n){return this.subruleInternal(s,t,n)}option(t,s){return this.optionInternal(s,t)}or(t,s){return this.orInternal(s,t)}many(t,s){return this.manyInternal(t,s)}atLeastOne(t,s){return this.atLeastOneInternal(t,s)}CONSUME(t,s){return this.consumeInternal(t,0,s)}CONSUME1(t,s){return this.consumeInternal(t,1,s)}CONSUME2(t,s){return this.consumeInternal(t,2,s)}CONSUME3(t,s){return this.consumeInternal(t,3,s)}CONSUME4(t,s){return this.consumeInternal(t,4,s)}CONSUME5(t,s){return this.consumeInternal(t,5,s)}CONSUME6(t,s){return this.consumeInternal(t,6,s)}CONSUME7(t,s){return this.consumeInternal(t,7,s)}CONSUME8(t,s){return this.consumeInternal(t,8,s)}CONSUME9(t,s){return this.consumeInternal(t,9,s)}SUBRULE(t,s){return this.subruleInternal(t,0,s)}SUBRULE1(t,s){return this.subruleInternal(t,1,s)}SUBRULE2(t,s){return this.subruleInternal(t,2,s)}SUBRULE3(t,s){return this.subruleInternal(t,3,s)}SUBRULE4(t,s){return this.subruleInternal(t,4,s)}SUBRULE5(t,s){return this.subruleInternal(t,5,s)}SUBRULE6(t,s){return this.subruleInternal(t,6,s)}SUBRULE7(t,s){return this.subruleInternal(t,7,s)}SUBRULE8(t,s){return this.subruleInternal(t,8,s)}SUBRULE9(t,s){return this.subruleInternal(t,9,s)}OPTION(t){return this.optionInternal(t,0)}OPTION1(t){return this.optionInternal(t,1)}OPTION2(t){return this.optionInternal(t,2)}OPTION3(t){return this.optionInternal(t,3)}OPTION4(t){return this.optionInternal(t,4)}OPTION5(t){return this.optionInternal(t,5)}OPTION6(t){return this.optionInternal(t,6)}OPTION7(t){return this.optionInternal(t,7)}OPTION8(t){return this.optionInternal(t,8)}OPTION9(t){return this.optionInternal(t,9)}OR(t){return this.orInternal(t,0)}OR1(t){return this.orInternal(t,1)}OR2(t){return this.orInternal(t,2)}OR3(t){return this.orInternal(t,3)}OR4(t){return this.orInternal(t,4)}OR5(t){return this.orInternal(t,5)}OR6(t){return this.orInternal(t,6)}OR7(t){return this.orInternal(t,7)}OR8(t){return this.orInternal(t,8)}OR9(t){return this.orInternal(t,9)}MANY(t){this.manyInternal(0,t)}MANY1(t){this.manyInternal(1,t)}MANY2(t){this.manyInternal(2,t)}MANY3(t){this.manyInternal(3,t)}MANY4(t){this.manyInternal(4,t)}MANY5(t){this.manyInternal(5,t)}MANY6(t){this.manyInternal(6,t)}MANY7(t){this.manyInternal(7,t)}MANY8(t){this.manyInternal(8,t)}MANY9(t){this.manyInternal(9,t)}MANY_SEP(t){this.manySepFirstInternal(0,t)}MANY_SEP1(t){this.manySepFirstInternal(1,t)}MANY_SEP2(t){this.manySepFirstInternal(2,t)}MANY_SEP3(t){this.manySepFirstInternal(3,t)}MANY_SEP4(t){this.manySepFirstInternal(4,t)}MANY_SEP5(t){this.manySepFirstInternal(5,t)}MANY_SEP6(t){this.manySepFirstInternal(6,t)}MANY_SEP7(t){this.manySepFirstInternal(7,t)}MANY_SEP8(t){this.manySepFirstInternal(8,t)}MANY_SEP9(t){this.manySepFirstInternal(9,t)}AT_LEAST_ONE(t){this.atLeastOneInternal(0,t)}AT_LEAST_ONE1(t){return this.atLeastOneInternal(1,t)}AT_LEAST_ONE2(t){this.atLeastOneInternal(2,t)}AT_LEAST_ONE3(t){this.atLeastOneInternal(3,t)}AT_LEAST_ONE4(t){this.atLeastOneInternal(4,t)}AT_LEAST_ONE5(t){this.atLeastOneInternal(5,t)}AT_LEAST_ONE6(t){this.atLeastOneInternal(6,t)}AT_LEAST_ONE7(t){this.atLeastOneInternal(7,t)}AT_LEAST_ONE8(t){this.atLeastOneInternal(8,t)}AT_LEAST_ONE9(t){this.atLeastOneInternal(9,t)}AT_LEAST_ONE_SEP(t){this.atLeastOneSepFirstInternal(0,t)}AT_LEAST_ONE_SEP1(t){this.atLeastOneSepFirstInternal(1,t)}AT_LEAST_ONE_SEP2(t){this.atLeastOneSepFirstInternal(2,t)}AT_LEAST_ONE_SEP3(t){this.atLeastOneSepFirstInternal(3,t)}AT_LEAST_ONE_SEP4(t){this.atLeastOneSepFirstInternal(4,t)}AT_LEAST_ONE_SEP5(t){this.atLeastOneSepFirstInternal(5,t)}AT_LEAST_ONE_SEP6(t){this.atLeastOneSepFirstInternal(6,t)}AT_LEAST_ONE_SEP7(t){this.atLeastOneSepFirstInternal(7,t)}AT_LEAST_ONE_SEP8(t){this.atLeastOneSepFirstInternal(8,t)}AT_LEAST_ONE_SEP9(t){this.atLeastOneSepFirstInternal(9,t)}RULE(t,s,n=ct){if(this.definedRulesNames.includes(t)){let o={message:ke.buildDuplicateRuleNameError({topLevelRule:t,grammarName:this.className}),type:ie.DUPLICATE_RULE_NAME,ruleName:t};this.definitionErrors.push(o)}this.definedRulesNames.push(t);let i=this.defineRule(t,s,n);return this[t]=i,i}OVERRIDE_RULE(t,s,n=ct){let i=Si(t,this.definedRulesNames,this.className);this.definitionErrors=this.definitionErrors.concat(i);let r=this.defineRule(t,s,n);return this[t]=r,r}BACKTRACK(t,s){var n;let i=(n=t.coreRule)!==null&&n!==void 0?n:t;return function(){this.isBackTrackingStack.push(1);let r=this.saveRecogState();try{return i.apply(this,s),!0}catch(o){if(Ge(o))return!1;else throw o}finally{this.reloadRecogState(r),this.isBackTrackingStack.pop()}}}getGAstProductions(){return this.gastProductionsCache}getSerializedGastProductions(){return Wt(Object.values(this.gastProductionsCache))}}class an{initRecognizerEngine(t,s){if(this.className=this.constructor.name,this.shortRuleNameToFull=[],this.fullRuleNameToShort={},this.ruleShortNameIdx=0,this.tokenMatcher=at,this.subruleIdx=0,this.currRuleShortName=-1,this.definedRulesNames=[],this.tokensMap={},this.isBackTrackingStack=[],this.RULE_STACK=[],this.RULE_STACK_IDX=-1,this.RULE_OCCURRENCE_STACK=[],this.RULE_OCCURRENCE_STACK_IDX=-1,this.gastProductionsCache={},Object.hasOwn(s,"serializedGrammar"))throw Error(`The Parser's configuration can no longer contain a <serializedGrammar> property.
90
+ `)}`)}}};return n.prototype=i,n.prototype.constructor=n,n._RULE_NAMES=s,n}function Mi(t,s,n){let i=function(){};en(i,t+"BaseSemanticsWithDefaults");let r=Object.create(n.prototype);return s.forEach((o)=>{r[o]=Pa}),i.prototype=r,i.prototype.constructor=i,i}var tn;(function(t){t[t.REDUNDANT_METHOD=0]="REDUNDANT_METHOD",t[t.MISSING_METHOD=1]="MISSING_METHOD"})(tn||(tn={}));function Da(t,s){return Fa(t,s)}function Fa(t,s){return s.filter((r)=>typeof t[r]==="function"===!1).map((r)=>({msg:`Missing visitor method: <${r}> on ${t.constructor.name} CST Visitor.`,type:tn.MISSING_METHOD,methodName:r})).filter(Boolean)}class sn{initTreeBuilder(t){if(this.CST_STACK=[],this.outputCst=t.outputCst,this.nodeLocationTracking=Object.hasOwn(t,"nodeLocationTracking")?t.nodeLocationTracking:me.nodeLocationTracking,!this.outputCst)this.cstInvocationStateUpdate=()=>{},this.cstFinallyStateUpdate=()=>{},this.cstPostTerminal=()=>{},this.cstPostNonTerminal=()=>{},this.cstPostRule=()=>{};else if(/full/i.test(this.nodeLocationTracking))if(this.recoveryEnabled)this.setNodeLocationFromToken=Qs,this.setNodeLocationFromNode=Qs,this.cstPostRule=()=>{},this.setInitialNodeLocation=this.setInitialNodeLocationFullRecovery;else this.setNodeLocationFromToken=()=>{},this.setNodeLocationFromNode=()=>{},this.cstPostRule=this.cstPostRuleFull,this.setInitialNodeLocation=this.setInitialNodeLocationFullRegular;else if(/onlyOffset/i.test(this.nodeLocationTracking))if(this.recoveryEnabled)this.setNodeLocationFromToken=Zs,this.setNodeLocationFromNode=Zs,this.cstPostRule=()=>{},this.setInitialNodeLocation=this.setInitialNodeLocationOnlyOffsetRecovery;else this.setNodeLocationFromToken=()=>{},this.setNodeLocationFromNode=()=>{},this.cstPostRule=this.cstPostRuleOnlyOffset,this.setInitialNodeLocation=this.setInitialNodeLocationOnlyOffsetRegular;else if(/none/i.test(this.nodeLocationTracking))this.setNodeLocationFromToken=()=>{},this.setNodeLocationFromNode=()=>{},this.cstPostRule=()=>{},this.setInitialNodeLocation=()=>{};else throw Error(`Invalid <nodeLocationTracking> config option: "${t.nodeLocationTracking}"`)}setInitialNodeLocationOnlyOffsetRecovery(t){t.location={startOffset:-1,endOffset:-1}}setInitialNodeLocationOnlyOffsetRegular(t){t.location={startOffset:this.LA_FAST(1).startOffset,endOffset:-1}}setInitialNodeLocationFullRecovery(t){t.location={startOffset:-1,startLine:-1,startColumn:-1,endOffset:-1,endLine:-1,endColumn:-1}}setInitialNodeLocationFullRegular(t){let s=this.LA_FAST(1);t.location={startOffset:s.startOffset,startLine:s.startLine,startColumn:s.startColumn,endOffset:-1,endLine:-1,endColumn:-1}}cstInvocationStateUpdate(t){let s={name:t,children:Object.create(null)};this.setInitialNodeLocation(s),this.CST_STACK.push(s)}cstFinallyStateUpdate(){this.CST_STACK.pop()}cstPostRuleFull(t){let s=this.LA(0),n=t.location;if(n.startOffset!==-1&&n.startOffset<=s.startOffset===!0)n.endOffset=s.endOffset,n.endLine=s.endLine,n.endColumn=s.endColumn;else n.startOffset=-1,n.startLine=-1,n.startColumn=-1}cstPostRuleOnlyOffset(t){let s=this.LA(0),n=t.location;if(n.startOffset!==-1&&n.startOffset<=s.startOffset===!0)n.endOffset=s.endOffset;else n.startOffset=-1}cstPostTerminal(t,s){let n=this.CST_STACK[this.CST_STACK.length-1];_i(n,s,t),this.setNodeLocationFromToken(n.location,s)}cstPostNonTerminal(t,s){let n=this.CST_STACK[this.CST_STACK.length-1];xi(n,s,t),this.setNodeLocationFromNode(n.location,t.location)}get currCSTNode(){let t=this;return t.CST_STACK[t.CST_STACK.length-1]}getBaseCstVisitorConstructor(){if(this.baseCstVisitorConstructor===void 0){let t=vi(this.className,Object.keys(this.gastProductionsCache));return this.baseCstVisitorConstructor=t,t}return this.baseCstVisitorConstructor}getBaseCstVisitorConstructorWithDefaults(){if(this.baseCstVisitorWithDefaultsConstructor===void 0){let t=Mi(this.className,Object.keys(this.gastProductionsCache),this.getBaseCstVisitorConstructor());return this.baseCstVisitorWithDefaultsConstructor=t,t}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 nn{initLexerAdapter(){this.tokVector=[],this.tokVectorLength=0,this.currIdx=-1}set input(t){if(this.selfAnalysisDone!==!0)throw Error("Missing <performSelfAnalysis> invocation at the end of the Parser's constructor.");this.reset(),this.tokVector=t,this.tokVectorLength=t.length}get input(){return this.tokVector}SKIP_TOKEN(){if(this.currIdx<=this.tokVectorLength-2)return this.consumeToken(),this.LA_FAST(1);else return De}LA_FAST(t){let s=this.currIdx+t;return this.tokVector[s]}LA(t){let s=this.currIdx+t;if(s<0||this.tokVectorLength<=s)return De;else return this.tokVector[s]}consumeToken(){this.currIdx++}exportLexerState(){return this.currIdx}importLexerState(t){this.currIdx=t}resetLexerState(){this.currIdx=-1}moveToTerminatedState(){this.currIdx=this.tokVectorLength-1}getLexerPosition(){return this.exportLexerState()}}class rn{ACTION(t){return t.call(this)}consume(t,s,n){return this.consumeInternal(s,t,n)}subrule(t,s,n){return this.subruleInternal(s,t,n)}option(t,s){return this.optionInternal(s,t)}or(t,s){return this.orInternal(s,t)}many(t,s){return this.manyInternal(t,s)}atLeastOne(t,s){return this.atLeastOneInternal(t,s)}CONSUME(t,s){return this.consumeInternal(t,0,s)}CONSUME1(t,s){return this.consumeInternal(t,1,s)}CONSUME2(t,s){return this.consumeInternal(t,2,s)}CONSUME3(t,s){return this.consumeInternal(t,3,s)}CONSUME4(t,s){return this.consumeInternal(t,4,s)}CONSUME5(t,s){return this.consumeInternal(t,5,s)}CONSUME6(t,s){return this.consumeInternal(t,6,s)}CONSUME7(t,s){return this.consumeInternal(t,7,s)}CONSUME8(t,s){return this.consumeInternal(t,8,s)}CONSUME9(t,s){return this.consumeInternal(t,9,s)}SUBRULE(t,s){return this.subruleInternal(t,0,s)}SUBRULE1(t,s){return this.subruleInternal(t,1,s)}SUBRULE2(t,s){return this.subruleInternal(t,2,s)}SUBRULE3(t,s){return this.subruleInternal(t,3,s)}SUBRULE4(t,s){return this.subruleInternal(t,4,s)}SUBRULE5(t,s){return this.subruleInternal(t,5,s)}SUBRULE6(t,s){return this.subruleInternal(t,6,s)}SUBRULE7(t,s){return this.subruleInternal(t,7,s)}SUBRULE8(t,s){return this.subruleInternal(t,8,s)}SUBRULE9(t,s){return this.subruleInternal(t,9,s)}OPTION(t){return this.optionInternal(t,0)}OPTION1(t){return this.optionInternal(t,1)}OPTION2(t){return this.optionInternal(t,2)}OPTION3(t){return this.optionInternal(t,3)}OPTION4(t){return this.optionInternal(t,4)}OPTION5(t){return this.optionInternal(t,5)}OPTION6(t){return this.optionInternal(t,6)}OPTION7(t){return this.optionInternal(t,7)}OPTION8(t){return this.optionInternal(t,8)}OPTION9(t){return this.optionInternal(t,9)}OR(t){return this.orInternal(t,0)}OR1(t){return this.orInternal(t,1)}OR2(t){return this.orInternal(t,2)}OR3(t){return this.orInternal(t,3)}OR4(t){return this.orInternal(t,4)}OR5(t){return this.orInternal(t,5)}OR6(t){return this.orInternal(t,6)}OR7(t){return this.orInternal(t,7)}OR8(t){return this.orInternal(t,8)}OR9(t){return this.orInternal(t,9)}MANY(t){this.manyInternal(0,t)}MANY1(t){this.manyInternal(1,t)}MANY2(t){this.manyInternal(2,t)}MANY3(t){this.manyInternal(3,t)}MANY4(t){this.manyInternal(4,t)}MANY5(t){this.manyInternal(5,t)}MANY6(t){this.manyInternal(6,t)}MANY7(t){this.manyInternal(7,t)}MANY8(t){this.manyInternal(8,t)}MANY9(t){this.manyInternal(9,t)}MANY_SEP(t){this.manySepFirstInternal(0,t)}MANY_SEP1(t){this.manySepFirstInternal(1,t)}MANY_SEP2(t){this.manySepFirstInternal(2,t)}MANY_SEP3(t){this.manySepFirstInternal(3,t)}MANY_SEP4(t){this.manySepFirstInternal(4,t)}MANY_SEP5(t){this.manySepFirstInternal(5,t)}MANY_SEP6(t){this.manySepFirstInternal(6,t)}MANY_SEP7(t){this.manySepFirstInternal(7,t)}MANY_SEP8(t){this.manySepFirstInternal(8,t)}MANY_SEP9(t){this.manySepFirstInternal(9,t)}AT_LEAST_ONE(t){this.atLeastOneInternal(0,t)}AT_LEAST_ONE1(t){return this.atLeastOneInternal(1,t)}AT_LEAST_ONE2(t){this.atLeastOneInternal(2,t)}AT_LEAST_ONE3(t){this.atLeastOneInternal(3,t)}AT_LEAST_ONE4(t){this.atLeastOneInternal(4,t)}AT_LEAST_ONE5(t){this.atLeastOneInternal(5,t)}AT_LEAST_ONE6(t){this.atLeastOneInternal(6,t)}AT_LEAST_ONE7(t){this.atLeastOneInternal(7,t)}AT_LEAST_ONE8(t){this.atLeastOneInternal(8,t)}AT_LEAST_ONE9(t){this.atLeastOneInternal(9,t)}AT_LEAST_ONE_SEP(t){this.atLeastOneSepFirstInternal(0,t)}AT_LEAST_ONE_SEP1(t){this.atLeastOneSepFirstInternal(1,t)}AT_LEAST_ONE_SEP2(t){this.atLeastOneSepFirstInternal(2,t)}AT_LEAST_ONE_SEP3(t){this.atLeastOneSepFirstInternal(3,t)}AT_LEAST_ONE_SEP4(t){this.atLeastOneSepFirstInternal(4,t)}AT_LEAST_ONE_SEP5(t){this.atLeastOneSepFirstInternal(5,t)}AT_LEAST_ONE_SEP6(t){this.atLeastOneSepFirstInternal(6,t)}AT_LEAST_ONE_SEP7(t){this.atLeastOneSepFirstInternal(7,t)}AT_LEAST_ONE_SEP8(t){this.atLeastOneSepFirstInternal(8,t)}AT_LEAST_ONE_SEP9(t){this.atLeastOneSepFirstInternal(9,t)}RULE(t,s,n=ct){if(this.definedRulesNames.includes(t)){let o={message:Ce.buildDuplicateRuleNameError({topLevelRule:t,grammarName:this.className}),type:ie.DUPLICATE_RULE_NAME,ruleName:t};this.definitionErrors.push(o)}this.definedRulesNames.push(t);let i=this.defineRule(t,s,n);return this[t]=i,i}OVERRIDE_RULE(t,s,n=ct){let i=Si(t,this.definedRulesNames,this.className);this.definitionErrors=this.definitionErrors.concat(i);let r=this.defineRule(t,s,n);return this[t]=r,r}BACKTRACK(t,s){var n;let i=(n=t.coreRule)!==null&&n!==void 0?n:t;return function(){this.isBackTrackingStack.push(1);let r=this.saveRecogState();try{return i.apply(this,s),!0}catch(o){if(Ge(o))return!1;else throw o}finally{this.reloadRecogState(r),this.isBackTrackingStack.pop()}}}getGAstProductions(){return this.gastProductionsCache}getSerializedGastProductions(){return Wt(Object.values(this.gastProductionsCache))}}class an{initRecognizerEngine(t,s){if(this.className=this.constructor.name,this.shortRuleNameToFull=[],this.fullRuleNameToShort={},this.ruleShortNameIdx=0,this.tokenMatcher=at,this.subruleIdx=0,this.currRuleShortName=-1,this.definedRulesNames=[],this.tokensMap={},this.isBackTrackingStack=[],this.RULE_STACK=[],this.RULE_STACK_IDX=-1,this.RULE_OCCURRENCE_STACK=[],this.RULE_OCCURRENCE_STACK_IDX=-1,this.gastProductionsCache={},Object.hasOwn(s,"serializedGrammar"))throw Error(`The Parser's configuration can no longer contain a <serializedGrammar> property.
91
91
  See: https://chevrotain.io/docs/changes/BREAKING_CHANGES.html#_6-0-0
92
92
  For Further details.`);if(Array.isArray(t)){if(t.length===0)throw Error(`A Token Vocabulary cannot be empty.
93
93
  Note that the first argument for the parser constructor
94
94
  is no longer a Token vector (since v4.0).`);if(typeof t[0].startOffset==="number")throw Error(`The Parser constructor no longer accepts a token vector as the first argument.
95
95
  See: https://chevrotain.io/docs/changes/BREAKING_CHANGES.html#_4-0-0
96
- For Further details.`)}if(Array.isArray(t))this.tokensMap=t.reduce((r,o)=>(r[o.name]=o,r),{});else if(Object.hasOwn(t,"modes")&&Object.values(t.modes).flat().every(zn)){let r=Object.values(t.modes).flat(),o=[...new Set(r)];this.tokensMap=o.reduce((h,u)=>(h[u.name]=u,h),{})}else if(typeof t==="object"&&t!==null)this.tokensMap=Object.assign({},t);else throw Error("<tokensDictionary> argument must be An Array of Token constructors, A dictionary of Token constructors or an IMultiModeLexerDefinition");this.tokensMap.EOF=Se;let i=(Object.hasOwn(t,"modes")?Object.values(t.modes).flat():Object.values(t)).every((r)=>{var o;return((o=r.categoryMatches)===null||o===void 0?void 0:o.length)==0});this.tokenMatcher=i?at:Ue,Pe(Object.values(this.tokensMap))}defineRule(t,s,n){if(this.selfAnalysisDone)throw Error(`Grammar rule <${t}> may not be defined after the 'performSelfAnalysis' method has been called'
97
- Make sure that all grammar rule definitions are done before 'performSelfAnalysis' is called.`);let i=Object.hasOwn(n,"resyncEnabled")?n.resyncEnabled:ct.resyncEnabled,r=Object.hasOwn(n,"recoveryValueFunc")?n.recoveryValueFunc:ct.recoveryValueFunc,o=this.ruleShortNameIdx++;this.shortRuleNameToFull[o]=t,this.fullRuleNameToShort[t]=o;let h;if(this.outputCst===!0)h=function(...f){try{this.ruleInvocationStateUpdate(o,t,this.subruleIdx),s.apply(this,f);let m=this.CST_STACK[this.CST_STACK.length-1];return this.cstPostRule(m),m}catch(m){return this.invokeRuleCatch(m,i,r)}finally{this.ruleFinallyStateUpdate()}};else h=function(...f){try{return this.ruleInvocationStateUpdate(o,t,this.subruleIdx),s.apply(this,f)}catch(m){return this.invokeRuleCatch(m,i,r)}finally{this.ruleFinallyStateUpdate()}};return Object.assign(function(...f){this.onBeforeParse(t);try{return h.apply(this,f)}finally{this.onAfterParse(t)}},{ruleName:t,originalGrammarAction:s,coreRule:h})}invokeRuleCatch(t,s,n){let i=this.RULE_STACK_IDX===0,r=s&&!this.isBackTracking()&&this.recoveryEnabled;if(Ge(t)){let o=t;if(r){let h=this.findReSyncTokenType();if(this.isInCurrentRuleReSyncSet(h))if(o.resyncedTokens=this.reSyncTo(h),this.outputCst){let u=this.CST_STACK[this.CST_STACK.length-1];return u.recoveredNode=!0,u}else return n(t);else{if(this.outputCst){let u=this.CST_STACK[this.CST_STACK.length-1];u.recoveredNode=!0,o.partialCstResult=u}throw o}}else if(i)return this.moveToTerminatedState(),n(t);else throw o}else throw t}optionInternal(t,s){let n=ps|s;return this.optionInternalLogic(t,s,n)}optionInternalLogic(t,s,n){let i=this.currRuleLookaheadFuncs[n],r;if(typeof t!=="function"){r=t.DEF;let o=t.GATE;if(o!==void 0){let h=i;i=()=>o.call(this)&&h.call(this)}}else r=t;if(i.call(this)===!0)return r.call(this);return}atLeastOneInternal(t,s){let n=Mt|t;return this.atLeastOneInternalLogic(t,s,n)}atLeastOneInternalLogic(t,s,n){let i=this.currRuleLookaheadFuncs[n],r;if(typeof s!=="function"){r=s.DEF;let o=s.GATE;if(o!==void 0){let h=i;i=()=>o.call(this)&&h.call(this)}}else r=s;if(i.call(this)===!0){let o=this.doSingleRepetition(r);while(i.call(this)===!0&&o===!0)o=this.doSingleRepetition(r)}else throw this.raiseEarlyExitException(t,H.REPETITION_MANDATORY,s.ERR_MSG);this.attemptInRepetitionRecovery(this.atLeastOneInternal,[t,s],i,Mt,t,Ks)}atLeastOneSepFirstInternal(t,s){let n=lt|t;this.atLeastOneSepFirstInternalLogic(t,s,n)}atLeastOneSepFirstInternalLogic(t,s,n){let{DEF:i,SEP:r}=s;if(this.currRuleLookaheadFuncs[n].call(this)===!0){i.call(this);let h=()=>this.tokenMatcher(this.LA_FAST(1),r);while(this.tokenMatcher(this.LA_FAST(1),r)===!0)this.CONSUME(r),i.call(this);this.attemptInRepetitionRecovery(this.repetitionSepSecondInternal,[t,r,h,i,ns],h,lt,t,ns)}else throw this.raiseEarlyExitException(t,H.REPETITION_MANDATORY_WITH_SEPARATOR,s.ERR_MSG)}manyInternal(t,s){let n=vt|t;return this.manyInternalLogic(t,s,n)}manyInternalLogic(t,s,n){let i=this.currRuleLookaheadFuncs[n],r;if(typeof s!=="function"){r=s.DEF;let h=s.GATE;if(h!==void 0){let u=i;i=()=>h.call(this)&&u.call(this)}}else r=s;let o=!0;while(i.call(this)===!0&&o===!0)o=this.doSingleRepetition(r);this.attemptInRepetitionRecovery(this.manyInternal,[t,s],i,vt,t,js,o)}manySepFirstInternal(t,s){let n=wt|t;this.manySepFirstInternalLogic(t,s,n)}manySepFirstInternalLogic(t,s,n){let{DEF:i,SEP:r}=s;if(this.currRuleLookaheadFuncs[n].call(this)===!0){i.call(this);let h=()=>this.tokenMatcher(this.LA_FAST(1),r);while(this.tokenMatcher(this.LA_FAST(1),r)===!0)this.CONSUME(r),i.call(this);this.attemptInRepetitionRecovery(this.repetitionSepSecondInternal,[t,r,h,i,ss],h,wt,t,ss)}}repetitionSepSecondInternal(t,s,n,i,r){while(n())this.CONSUME(s),i.call(this);this.attemptInRepetitionRecovery(this.repetitionSepSecondInternal,[t,s,n,i,r],n,lt,t,r)}doSingleRepetition(t){let s=this.getLexerPosition();return t.call(this),this.getLexerPosition()>s}orInternal(t,s){let n=ds|s,i=Array.isArray(t)?t:t.DEF,o=this.currRuleLookaheadFuncs[n].call(this,i);if(o!==void 0)return i[o].ALT.call(this);this.raiseNoAltException(s,t.ERR_MSG)}ruleFinallyStateUpdate(){if(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(t,s,n){let i;try{let r=n!==void 0?n.ARGS:void 0;return this.subruleIdx=s,i=t.coreRule.apply(this,r),this.cstPostNonTerminal(i,n!==void 0&&n.LABEL!==void 0?n.LABEL:t.ruleName),i}catch(r){throw this.subruleInternalError(r,n,t.ruleName)}}subruleInternalError(t,s,n){if(Ge(t)&&t.partialCstResult!==void 0)this.cstPostNonTerminal(t.partialCstResult,s!==void 0&&s.LABEL!==void 0?s.LABEL:n),delete t.partialCstResult;throw t}consumeInternal(t,s,n){let i;try{let r=this.LA_FAST(1);if(this.tokenMatcher(r,t)===!0)this.consumeToken(),i=r;else this.consumeInternalError(t,r,n)}catch(r){i=this.consumeInternalRecovery(t,s,r)}return this.cstPostTerminal(n!==void 0&&n.LABEL!==void 0?n.LABEL:t.name,i),i}consumeInternalError(t,s,n){let i,r=this.LA(0);if(n!==void 0&&n.ERR_MSG)i=n.ERR_MSG;else i=this.errorMessageProvider.buildMismatchTokenMessage({expected:t,actual:s,previous:r,ruleName:this.getCurrRuleFullName()});throw this.SAVE_ERROR(new ot(i,s,r))}consumeInternalRecovery(t,s,n){if(this.recoveryEnabled&&n.name==="MismatchedTokenException"&&!this.isBackTracking()){let i=this.getFollowsForInRuleRecovery(t,s);try{return this.tryInRuleRecovery(t,i)}catch(r){if(r.name===Ys)throw n;else throw r}}else throw n}saveRecogState(){let t=this.errors,s=this.RULE_STACK.slice(0,this.RULE_STACK_IDX+1);return{errors:t,lexerState:this.exportLexerState(),RULE_STACK:s,CST_STACK:this.CST_STACK}}reloadRecogState(t){this.errors=t.errors,this.importLexerState(t.lexerState);let s=t.RULE_STACK;for(let n=0;n<s.length;n++)this.RULE_STACK[n]=s[n];if(this.RULE_STACK_IDX=s.length-1,this.RULE_STACK_IDX>=0)this.currRuleShortName=this.RULE_STACK[this.RULE_STACK_IDX],this.currRuleLookaheadFuncs=this.lookAheadFuncsCache[this.currRuleShortName]}ruleInvocationStateUpdate(t,s,n){this.RULE_OCCURRENCE_STACK[++this.RULE_OCCURRENCE_STACK_IDX]=n,this.RULE_STACK[++this.RULE_STACK_IDX]=t,this.currRuleShortName=t,this.currRuleLookaheadFuncs=this.lookAheadFuncsCache[t],this.cstInvocationStateUpdate(s)}isBackTracking(){return this.isBackTrackingStack.length!==0}getCurrRuleFullName(){let t=this.currRuleShortName;return this.shortRuleNameToFull[t]}shortRuleNameToFullName(t){return this.shortRuleNameToFull[t]}isAtEndOfInput(){return this.tokenMatcher(this.LA(1),Se)}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(t){for(let s=0;s<this.maxLookahead+1;s++)this.tokVector.push(De)}onAfterParse(t){if(this.isAtEndOfInput()===!1){let s=this.LA(1),n=this.errorMessageProvider.buildNotAllInputParsedMessage({firstRedundant:s,ruleName:this.getCurrRuleFullName()});this.SAVE_ERROR(new hs(n,s))}while(this.tokVector.at(-1)===De)this.tokVector.pop()}}class on{initErrorHandler(t){this._errors=[],this.errorMessageProvider=Object.hasOwn(t,"errorMessageProvider")?t.errorMessageProvider:fe.errorMessageProvider}SAVE_ERROR(t){if(Ge(t))return t.context={ruleStack:this.getHumanReadableRuleStack(),ruleOccurrenceStack:this.RULE_OCCURRENCE_STACK.slice(0,this.RULE_OCCURRENCE_STACK_IDX+1)},this._errors.push(t),t;else throw Error("Trying to save an Error which is not a RecognitionException")}get errors(){return[...this._errors]}set errors(t){this._errors=t}raiseEarlyExitException(t,s,n){let i=this.getCurrRuleFullName(),r=this.getGAstProductions()[i],h=_t(t,r,s,this.maxLookahead)[0],u=[];for(let d=1;d<=this.maxLookahead;d++)u.push(this.LA(d));let c=this.errorMessageProvider.buildEarlyExitMessage({expectedIterationPaths:h,actual:u,previous:this.LA(0),customUserDescription:n,ruleName:i});throw this.SAVE_ERROR(new us(c,this.LA(1),this.LA(0)))}raiseNoAltException(t,s){let n=this.getCurrRuleFullName(),i=this.getGAstProductions()[n],r=bt(t,i,this.maxLookahead),o=[];for(let c=1;c<=this.maxLookahead;c++)o.push(this.LA(c));let h=this.LA(0),u=this.errorMessageProvider.buildNoViableAltMessage({expectedPathsPerAlt:r,actual:o,previous:h,customUserDescription:s,ruleName:this.getCurrRuleFullName()});throw this.SAVE_ERROR(new cs(u,this.LA(1),h))}}var Ts={description:"This Object indicates the Parser is during Recording Phase"};Object.freeze(Ts);var wi=!0,Ui=255,Di=I({name:"RECORDING_PHASE_TOKEN",pattern:z.NA});Pe([Di]);var Fi=qe(Di,`This IToken indicates the Parser is in Recording Phase
96
+ For Further details.`)}if(Array.isArray(t))this.tokensMap=t.reduce((r,o)=>(r[o.name]=o,r),{});else if(Object.hasOwn(t,"modes")&&Object.values(t.modes).flat().every(zn)){let r=Object.values(t.modes).flat(),o=[...new Set(r)];this.tokensMap=o.reduce((h,u)=>(h[u.name]=u,h),{})}else if(typeof t==="object"&&t!==null)this.tokensMap=Object.assign({},t);else throw Error("<tokensDictionary> argument must be An Array of Token constructors, A dictionary of Token constructors or an IMultiModeLexerDefinition");this.tokensMap.EOF=Re;let i=(Object.hasOwn(t,"modes")?Object.values(t.modes).flat():Object.values(t)).every((r)=>{var o;return((o=r.categoryMatches)===null||o===void 0?void 0:o.length)==0});this.tokenMatcher=i?at:Ue,Pe(Object.values(this.tokensMap))}defineRule(t,s,n){if(this.selfAnalysisDone)throw Error(`Grammar rule <${t}> may not be defined after the 'performSelfAnalysis' method has been called'
97
+ Make sure that all grammar rule definitions are done before 'performSelfAnalysis' is called.`);let i=Object.hasOwn(n,"resyncEnabled")?n.resyncEnabled:ct.resyncEnabled,r=Object.hasOwn(n,"recoveryValueFunc")?n.recoveryValueFunc:ct.recoveryValueFunc,o=this.ruleShortNameIdx++;this.shortRuleNameToFull[o]=t,this.fullRuleNameToShort[t]=o;let h;if(this.outputCst===!0)h=function(...f){try{this.ruleInvocationStateUpdate(o,t,this.subruleIdx),s.apply(this,f);let m=this.CST_STACK[this.CST_STACK.length-1];return this.cstPostRule(m),m}catch(m){return this.invokeRuleCatch(m,i,r)}finally{this.ruleFinallyStateUpdate()}};else h=function(...f){try{return this.ruleInvocationStateUpdate(o,t,this.subruleIdx),s.apply(this,f)}catch(m){return this.invokeRuleCatch(m,i,r)}finally{this.ruleFinallyStateUpdate()}};return Object.assign(function(...f){this.onBeforeParse(t);try{return h.apply(this,f)}finally{this.onAfterParse(t)}},{ruleName:t,originalGrammarAction:s,coreRule:h})}invokeRuleCatch(t,s,n){let i=this.RULE_STACK_IDX===0,r=s&&!this.isBackTracking()&&this.recoveryEnabled;if(Ge(t)){let o=t;if(r){let h=this.findReSyncTokenType();if(this.isInCurrentRuleReSyncSet(h))if(o.resyncedTokens=this.reSyncTo(h),this.outputCst){let u=this.CST_STACK[this.CST_STACK.length-1];return u.recoveredNode=!0,u}else return n(t);else{if(this.outputCst){let u=this.CST_STACK[this.CST_STACK.length-1];u.recoveredNode=!0,o.partialCstResult=u}throw o}}else if(i)return this.moveToTerminatedState(),n(t);else throw o}else throw t}optionInternal(t,s){let n=ps|s;return this.optionInternalLogic(t,s,n)}optionInternalLogic(t,s,n){let i=this.currRuleLookaheadFuncs[n],r;if(typeof t!=="function"){r=t.DEF;let o=t.GATE;if(o!==void 0){let h=i;i=()=>o.call(this)&&h.call(this)}}else r=t;if(i.call(this)===!0)return r.call(this);return}atLeastOneInternal(t,s){let n=Mt|t;return this.atLeastOneInternalLogic(t,s,n)}atLeastOneInternalLogic(t,s,n){let i=this.currRuleLookaheadFuncs[n],r;if(typeof s!=="function"){r=s.DEF;let o=s.GATE;if(o!==void 0){let h=i;i=()=>o.call(this)&&h.call(this)}}else r=s;if(i.call(this)===!0){let o=this.doSingleRepetition(r);while(i.call(this)===!0&&o===!0)o=this.doSingleRepetition(r)}else throw this.raiseEarlyExitException(t,H.REPETITION_MANDATORY,s.ERR_MSG);this.attemptInRepetitionRecovery(this.atLeastOneInternal,[t,s],i,Mt,t,Ks)}atLeastOneSepFirstInternal(t,s){let n=lt|t;this.atLeastOneSepFirstInternalLogic(t,s,n)}atLeastOneSepFirstInternalLogic(t,s,n){let{DEF:i,SEP:r}=s;if(this.currRuleLookaheadFuncs[n].call(this)===!0){i.call(this);let h=()=>this.tokenMatcher(this.LA_FAST(1),r);while(this.tokenMatcher(this.LA_FAST(1),r)===!0)this.CONSUME(r),i.call(this);this.attemptInRepetitionRecovery(this.repetitionSepSecondInternal,[t,r,h,i,ns],h,lt,t,ns)}else throw this.raiseEarlyExitException(t,H.REPETITION_MANDATORY_WITH_SEPARATOR,s.ERR_MSG)}manyInternal(t,s){let n=vt|t;return this.manyInternalLogic(t,s,n)}manyInternalLogic(t,s,n){let i=this.currRuleLookaheadFuncs[n],r;if(typeof s!=="function"){r=s.DEF;let h=s.GATE;if(h!==void 0){let u=i;i=()=>h.call(this)&&u.call(this)}}else r=s;let o=!0;while(i.call(this)===!0&&o===!0)o=this.doSingleRepetition(r);this.attemptInRepetitionRecovery(this.manyInternal,[t,s],i,vt,t,js,o)}manySepFirstInternal(t,s){let n=wt|t;this.manySepFirstInternalLogic(t,s,n)}manySepFirstInternalLogic(t,s,n){let{DEF:i,SEP:r}=s;if(this.currRuleLookaheadFuncs[n].call(this)===!0){i.call(this);let h=()=>this.tokenMatcher(this.LA_FAST(1),r);while(this.tokenMatcher(this.LA_FAST(1),r)===!0)this.CONSUME(r),i.call(this);this.attemptInRepetitionRecovery(this.repetitionSepSecondInternal,[t,r,h,i,ss],h,wt,t,ss)}}repetitionSepSecondInternal(t,s,n,i,r){while(n())this.CONSUME(s),i.call(this);this.attemptInRepetitionRecovery(this.repetitionSepSecondInternal,[t,s,n,i,r],n,lt,t,r)}doSingleRepetition(t){let s=this.getLexerPosition();return t.call(this),this.getLexerPosition()>s}orInternal(t,s){let n=ds|s,i=Array.isArray(t)?t:t.DEF,o=this.currRuleLookaheadFuncs[n].call(this,i);if(o!==void 0)return i[o].ALT.call(this);this.raiseNoAltException(s,t.ERR_MSG)}ruleFinallyStateUpdate(){if(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(t,s,n){let i;try{let r=n!==void 0?n.ARGS:void 0;return this.subruleIdx=s,i=t.coreRule.apply(this,r),this.cstPostNonTerminal(i,n!==void 0&&n.LABEL!==void 0?n.LABEL:t.ruleName),i}catch(r){throw this.subruleInternalError(r,n,t.ruleName)}}subruleInternalError(t,s,n){if(Ge(t)&&t.partialCstResult!==void 0)this.cstPostNonTerminal(t.partialCstResult,s!==void 0&&s.LABEL!==void 0?s.LABEL:n),delete t.partialCstResult;throw t}consumeInternal(t,s,n){let i;try{let r=this.LA_FAST(1);if(this.tokenMatcher(r,t)===!0)this.consumeToken(),i=r;else this.consumeInternalError(t,r,n)}catch(r){i=this.consumeInternalRecovery(t,s,r)}return this.cstPostTerminal(n!==void 0&&n.LABEL!==void 0?n.LABEL:t.name,i),i}consumeInternalError(t,s,n){let i,r=this.LA(0);if(n!==void 0&&n.ERR_MSG)i=n.ERR_MSG;else i=this.errorMessageProvider.buildMismatchTokenMessage({expected:t,actual:s,previous:r,ruleName:this.getCurrRuleFullName()});throw this.SAVE_ERROR(new ot(i,s,r))}consumeInternalRecovery(t,s,n){if(this.recoveryEnabled&&n.name==="MismatchedTokenException"&&!this.isBackTracking()){let i=this.getFollowsForInRuleRecovery(t,s);try{return this.tryInRuleRecovery(t,i)}catch(r){if(r.name===Ys)throw n;else throw r}}else throw n}saveRecogState(){let t=this.errors,s=this.RULE_STACK.slice(0,this.RULE_STACK_IDX+1);return{errors:t,lexerState:this.exportLexerState(),RULE_STACK:s,CST_STACK:this.CST_STACK}}reloadRecogState(t){this.errors=t.errors,this.importLexerState(t.lexerState);let s=t.RULE_STACK;for(let n=0;n<s.length;n++)this.RULE_STACK[n]=s[n];if(this.RULE_STACK_IDX=s.length-1,this.RULE_STACK_IDX>=0)this.currRuleShortName=this.RULE_STACK[this.RULE_STACK_IDX],this.currRuleLookaheadFuncs=this.lookAheadFuncsCache[this.currRuleShortName]}ruleInvocationStateUpdate(t,s,n){this.RULE_OCCURRENCE_STACK[++this.RULE_OCCURRENCE_STACK_IDX]=n,this.RULE_STACK[++this.RULE_STACK_IDX]=t,this.currRuleShortName=t,this.currRuleLookaheadFuncs=this.lookAheadFuncsCache[t],this.cstInvocationStateUpdate(s)}isBackTracking(){return this.isBackTrackingStack.length!==0}getCurrRuleFullName(){let t=this.currRuleShortName;return this.shortRuleNameToFull[t]}shortRuleNameToFullName(t){return this.shortRuleNameToFull[t]}isAtEndOfInput(){return this.tokenMatcher(this.LA(1),Re)}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(t){for(let s=0;s<this.maxLookahead+1;s++)this.tokVector.push(De)}onAfterParse(t){if(this.isAtEndOfInput()===!1){let s=this.LA(1),n=this.errorMessageProvider.buildNotAllInputParsedMessage({firstRedundant:s,ruleName:this.getCurrRuleFullName()});this.SAVE_ERROR(new hs(n,s))}while(this.tokVector.at(-1)===De)this.tokVector.pop()}}class on{initErrorHandler(t){this._errors=[],this.errorMessageProvider=Object.hasOwn(t,"errorMessageProvider")?t.errorMessageProvider:me.errorMessageProvider}SAVE_ERROR(t){if(Ge(t))return t.context={ruleStack:this.getHumanReadableRuleStack(),ruleOccurrenceStack:this.RULE_OCCURRENCE_STACK.slice(0,this.RULE_OCCURRENCE_STACK_IDX+1)},this._errors.push(t),t;else throw Error("Trying to save an Error which is not a RecognitionException")}get errors(){return[...this._errors]}set errors(t){this._errors=t}raiseEarlyExitException(t,s,n){let i=this.getCurrRuleFullName(),r=this.getGAstProductions()[i],h=_t(t,r,s,this.maxLookahead)[0],u=[];for(let d=1;d<=this.maxLookahead;d++)u.push(this.LA(d));let c=this.errorMessageProvider.buildEarlyExitMessage({expectedIterationPaths:h,actual:u,previous:this.LA(0),customUserDescription:n,ruleName:i});throw this.SAVE_ERROR(new us(c,this.LA(1),this.LA(0)))}raiseNoAltException(t,s){let n=this.getCurrRuleFullName(),i=this.getGAstProductions()[n],r=bt(t,i,this.maxLookahead),o=[];for(let c=1;c<=this.maxLookahead;c++)o.push(this.LA(c));let h=this.LA(0),u=this.errorMessageProvider.buildNoViableAltMessage({expectedPathsPerAlt:r,actual:o,previous:h,customUserDescription:s,ruleName:this.getCurrRuleFullName()});throw this.SAVE_ERROR(new cs(u,this.LA(1),h))}}var Ts={description:"This Object indicates the Parser is during Recording Phase"};Object.freeze(Ts);var wi=!0,Ui=255,Di=I({name:"RECORDING_PHASE_TOKEN",pattern:z.NA});Pe([Di]);var Fi=qe(Di,`This IToken indicates the Parser is in Recording Phase
98
98
  See: https://chevrotain.io/docs/guide/internals.html#grammar-recording for details`,-1,-1,-1,-1,-1,-1);Object.freeze(Fi);var Ba={name:`This CSTNode indicates the Parser is in Recording Phase
99
- See: https://chevrotain.io/docs/guide/internals.html#grammar-recording for details`,children:{}};class ln{initGastRecorder(t){this.recordingProdStack=[],this.RECORDING_PHASE=!1}enableRecording(){this.RECORDING_PHASE=!0,this.TRACE_INIT("Enable Recording",()=>{for(let t=0;t<10;t++){let s=t>0?t:"";this[`CONSUME${s}`]=function(n,i){return this.consumeInternalRecord(n,t,i)},this[`SUBRULE${s}`]=function(n,i){return this.subruleInternalRecord(n,t,i)},this[`OPTION${s}`]=function(n){return this.optionInternalRecord(n,t)},this[`OR${s}`]=function(n){return this.orInternalRecord(n,t)},this[`MANY${s}`]=function(n){this.manyInternalRecord(t,n)},this[`MANY_SEP${s}`]=function(n){this.manySepFirstInternalRecord(t,n)},this[`AT_LEAST_ONE${s}`]=function(n){this.atLeastOneInternalRecord(t,n)},this[`AT_LEAST_ONE_SEP${s}`]=function(n){this.atLeastOneSepFirstInternalRecord(t,n)}}this.consume=function(t,s,n){return this.consumeInternalRecord(s,t,n)},this.subrule=function(t,s,n){return this.subruleInternalRecord(s,t,n)},this.option=function(t,s){return this.optionInternalRecord(s,t)},this.or=function(t,s){return this.orInternalRecord(s,t)},this.many=function(t,s){this.manyInternalRecord(t,s)},this.atLeastOne=function(t,s){this.atLeastOneInternalRecord(t,s)},this.ACTION=this.ACTION_RECORD,this.BACKTRACK=this.BACKTRACK_RECORD,this.LA=this.LA_RECORD})}disableRecording(){this.RECORDING_PHASE=!1,this.TRACE_INIT("Deleting Recording methods",()=>{let t=this;for(let s=0;s<10;s++){let n=s>0?s:"";delete t[`CONSUME${n}`],delete t[`SUBRULE${n}`],delete t[`OPTION${n}`],delete t[`OR${n}`],delete t[`MANY${n}`],delete t[`MANY_SEP${n}`],delete t[`AT_LEAST_ONE${n}`],delete t[`AT_LEAST_ONE_SEP${n}`]}delete t.consume,delete t.subrule,delete t.option,delete t.or,delete t.many,delete t.atLeastOne,delete t.ACTION,delete t.BACKTRACK,delete t.LA})}ACTION_RECORD(t){}BACKTRACK_RECORD(t,s){return()=>!0}LA_RECORD(t){return De}topLevelRuleRecord(t,s){try{let n=new Ee({definition:[],name:t});return n.name=t,this.recordingProdStack.push(n),s.call(this),this.recordingProdStack.pop(),n}catch(n){if(n.KNOWN_RECORDER_ERROR!==!0)try{n.message=n.message+`
99
+ See: https://chevrotain.io/docs/guide/internals.html#grammar-recording for details`,children:{}};class ln{initGastRecorder(t){this.recordingProdStack=[],this.RECORDING_PHASE=!1}enableRecording(){this.RECORDING_PHASE=!0,this.TRACE_INIT("Enable Recording",()=>{for(let t=0;t<10;t++){let s=t>0?t:"";this[`CONSUME${s}`]=function(n,i){return this.consumeInternalRecord(n,t,i)},this[`SUBRULE${s}`]=function(n,i){return this.subruleInternalRecord(n,t,i)},this[`OPTION${s}`]=function(n){return this.optionInternalRecord(n,t)},this[`OR${s}`]=function(n){return this.orInternalRecord(n,t)},this[`MANY${s}`]=function(n){this.manyInternalRecord(t,n)},this[`MANY_SEP${s}`]=function(n){this.manySepFirstInternalRecord(t,n)},this[`AT_LEAST_ONE${s}`]=function(n){this.atLeastOneInternalRecord(t,n)},this[`AT_LEAST_ONE_SEP${s}`]=function(n){this.atLeastOneSepFirstInternalRecord(t,n)}}this.consume=function(t,s,n){return this.consumeInternalRecord(s,t,n)},this.subrule=function(t,s,n){return this.subruleInternalRecord(s,t,n)},this.option=function(t,s){return this.optionInternalRecord(s,t)},this.or=function(t,s){return this.orInternalRecord(s,t)},this.many=function(t,s){this.manyInternalRecord(t,s)},this.atLeastOne=function(t,s){this.atLeastOneInternalRecord(t,s)},this.ACTION=this.ACTION_RECORD,this.BACKTRACK=this.BACKTRACK_RECORD,this.LA=this.LA_RECORD})}disableRecording(){this.RECORDING_PHASE=!1,this.TRACE_INIT("Deleting Recording methods",()=>{let t=this;for(let s=0;s<10;s++){let n=s>0?s:"";delete t[`CONSUME${n}`],delete t[`SUBRULE${n}`],delete t[`OPTION${n}`],delete t[`OR${n}`],delete t[`MANY${n}`],delete t[`MANY_SEP${n}`],delete t[`AT_LEAST_ONE${n}`],delete t[`AT_LEAST_ONE_SEP${n}`]}delete t.consume,delete t.subrule,delete t.option,delete t.or,delete t.many,delete t.atLeastOne,delete t.ACTION,delete t.BACKTRACK,delete t.LA})}ACTION_RECORD(t){}BACKTRACK_RECORD(t,s){return()=>!0}LA_RECORD(t){return De}topLevelRuleRecord(t,s){try{let n=new Te({definition:[],name:t});return n.name=t,this.recordingProdStack.push(n),s.call(this),this.recordingProdStack.pop(),n}catch(n){if(n.KNOWN_RECORDER_ERROR!==!0)try{n.message=n.message+`
100
100
  This error was thrown during the "grammar recording phase" For more info see:
101
101
  https://chevrotain.io/docs/guide/internals.html#grammar-recording`}catch(i){throw n}throw n}}optionInternalRecord(t,s){return Ut.call(this,K,t,s)}atLeastOneInternalRecord(t,s){Ut.call(this,Z,s,t)}atLeastOneSepFirstInternalRecord(t,s){Ut.call(this,Q,s,t,wi)}manyInternalRecord(t,s){Ut.call(this,G,s,t)}manySepFirstInternalRecord(t,s){Ut.call(this,q,s,t,wi)}orInternalRecord(t,s){return $a.call(this,t,s)}subruleInternalRecord(t,s,n){if(Es(s),!t||!Object.hasOwn(t,"ruleName")){let h=Error(`<SUBRULE${Pi(s)}> argument is invalid expecting a Parser method reference but got: <${JSON.stringify(t)}>
102
102
  inside top level rule: <${this.recordingProdStack[0].name}>`);throw h.KNOWN_RECORDER_ERROR=!0,h}let i=this.recordingProdStack.at(-1),r=t.ruleName,o=new W({idx:s,nonTerminalName:r,label:n===null||n===void 0?void 0:n.LABEL,referencedRule:void 0});return i.definition.push(o),this.outputCst?Ba:Ts}consumeInternalRecord(t,s,n){if(Es(s),!Bs(t)){let o=Error(`<CONSUME${Pi(s)}> argument is invalid expecting a TokenType reference but got: <${JSON.stringify(t)}>
103
103
  inside top level rule: <${this.recordingProdStack[0].name}>`);throw o.KNOWN_RECORDER_ERROR=!0,o}let i=this.recordingProdStack.at(-1),r=new F({idx:s,terminalType:t,label:n===null||n===void 0?void 0:n.LABEL});return i.definition.push(r),Fi}}function Ut(t,s,n,i=!1){Es(n);let r=this.recordingProdStack.at(-1),o=typeof s==="function"?s:s.DEF,h=new t({definition:[],idx:n});if(i)h.separator=s.SEP;if(Object.hasOwn(s,"MAX_LOOKAHEAD"))h.maxLookahead=s.MAX_LOOKAHEAD;return this.recordingProdStack.push(h),o.call(this),r.definition.push(h),this.recordingProdStack.pop(),Ts}function $a(t,s){Es(s);let n=this.recordingProdStack.at(-1),i=Array.isArray(t)===!1,r=i===!1?t:t.DEF,o=new J({definition:[],idx:s,ignoreAmbiguities:i&&t.IGNORE_AMBIGUITIES===!0});if(Object.hasOwn(t,"MAX_LOOKAHEAD"))o.maxLookahead=t.MAX_LOOKAHEAD;let h=r.some((u)=>typeof u.GATE==="function");return o.hasPredicates=h,n.definition.push(o),r.forEach((u)=>{let c=new j({definition:[]});if(o.definition.push(c),Object.hasOwn(u,"IGNORE_AMBIGUITIES"))c.ignoreAmbiguities=u.IGNORE_AMBIGUITIES;else if(Object.hasOwn(u,"GATE"))c.ignoreAmbiguities=!0;this.recordingProdStack.push(c),u.ALT.call(this),this.recordingProdStack.pop()}),Ts}function Pi(t){return t===0?"":`${t}`}function Es(t){if(t<0||t>Ui){let s=Error(`Invalid DSL Method idx value: <${t}>
104
- Idx value must be a none negative value smaller than ${Ui+1}`);throw s.KNOWN_RECORDER_ERROR=!0,s}}class cn{initPerformanceTracer(t){if(Object.hasOwn(t,"traceInitPerf")){let s=t.traceInitPerf,n=typeof s==="number";this.traceInitMaxIdent=n?s:1/0,this.traceInitPerf=n?s>0:s}else this.traceInitMaxIdent=0,this.traceInitPerf=fe.traceInitPerf;this.traceInitIndent=-1}TRACE_INIT(t,s){if(this.traceInitPerf===!0){this.traceInitIndent++;let n=Array(this.traceInitIndent+1).join("\t");if(this.traceInitIndent<this.traceInitMaxIdent)console.log(`${n}--> <${t}>`);let{time:i,value:r}=At(s),o=i>10?console.warn:console.log;if(this.traceInitIndent<this.traceInitMaxIdent)o(`${n}<-- <${t}> time: ${i}ms`);return this.traceInitIndent--,r}else return s()}}function Bi(t,s){s.forEach((n)=>{let i=n.prototype;Object.getOwnPropertyNames(i).forEach((r)=>{if(r==="constructor")return;let o=Object.getOwnPropertyDescriptor(i,r);if(o&&(o.get||o.set))Object.defineProperty(t.prototype,r,o);else t.prototype[r]=n.prototype[r]})})}var De=qe(Se,"",-1,-1,-1,-1,-1,-1);Object.freeze(De);var fe=Object.freeze({recoveryEnabled:!1,maxLookahead:3,dynamicTokensEnabled:!1,outputCst:!0,errorMessageProvider:ts,nodeLocationTracking:"none",traceInitPerf:!1,skipValidations:!1}),ct=Object.freeze({recoveryValueFunc:()=>{return},resyncEnabled:!0}),ie;(function(t){t[t.INVALID_RULE_NAME=0]="INVALID_RULE_NAME",t[t.DUPLICATE_RULE_NAME=1]="DUPLICATE_RULE_NAME",t[t.INVALID_RULE_OVERRIDE=2]="INVALID_RULE_OVERRIDE",t[t.DUPLICATE_PRODUCTIONS=3]="DUPLICATE_PRODUCTIONS",t[t.UNRESOLVED_SUBRULE_REF=4]="UNRESOLVED_SUBRULE_REF",t[t.LEFT_RECURSION=5]="LEFT_RECURSION",t[t.NONE_LAST_EMPTY_ALT=6]="NONE_LAST_EMPTY_ALT",t[t.AMBIGUOUS_ALTS=7]="AMBIGUOUS_ALTS",t[t.CONFLICT_TOKENS_RULES_NAMESPACE=8]="CONFLICT_TOKENS_RULES_NAMESPACE",t[t.INVALID_TOKEN_NAME=9]="INVALID_TOKEN_NAME",t[t.NO_NON_EMPTY_LOOKAHEAD=10]="NO_NON_EMPTY_LOOKAHEAD",t[t.AMBIGUOUS_PREFIX_ALTS=11]="AMBIGUOUS_PREFIX_ALTS",t[t.TOO_MANY_ALTS=12]="TOO_MANY_ALTS",t[t.CUSTOM_LOOKAHEAD_VALIDATION=13]="CUSTOM_LOOKAHEAD_VALIDATION"})(ie||(ie={}));class Pt{static performSelfAnalysis(t){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 t;this.selfAnalysisDone=!0;let s=this.className;this.TRACE_INIT("toFastProps",()=>{St(this)}),this.TRACE_INIT("Grammar Recording",()=>{try{this.enableRecording(),this.definedRulesNames.forEach((i)=>{let o=this[i].originalGrammarAction,h;this.TRACE_INIT(`${i} Rule`,()=>{h=this.topLevelRuleRecord(i,o)}),this.gastProductionsCache[i]=h})}finally{this.disableRecording()}});let n=[];if(this.TRACE_INIT("Grammar Resolving",()=>{n=Ni({rules:Object.values(this.gastProductionsCache)}),this.definitionErrors=this.definitionErrors.concat(n)}),this.TRACE_INIT("Grammar Validations",()=>{if(n.length===0&&this.skipValidations===!1){let i=Ii({rules:Object.values(this.gastProductionsCache),tokenTypes:Object.values(this.tokensMap),errMsgProvider:ke,grammarName:s}),r=Ei({lookaheadStrategy:this.lookaheadStrategy,rules:Object.values(this.gastProductionsCache),tokenTypes:Object.values(this.tokensMap),grammarName:s});this.definitionErrors=this.definitionErrors.concat(i,r)}}),this.definitionErrors.length===0){if(this.recoveryEnabled)this.TRACE_INIT("computeAllProdsFollows",()=>{let i=kn(Object.values(this.gastProductionsCache));this.resyncFollows=i});this.TRACE_INIT("ComputeLookaheadFunctions",()=>{var i,r;(r=(i=this.lookaheadStrategy).initialize)===null||r===void 0||r.call(i,{rules:Object.values(this.gastProductionsCache)}),this.preComputeLookaheadFunctions(Object.values(this.gastProductionsCache))})}if(!Pt.DEFER_DEFINITION_ERRORS_HANDLING&&this.definitionErrors.length!==0)throw t=this.definitionErrors.map((i)=>i.message),Error(`Parser Definition Errors detected:
104
+ Idx value must be a none negative value smaller than ${Ui+1}`);throw s.KNOWN_RECORDER_ERROR=!0,s}}class cn{initPerformanceTracer(t){if(Object.hasOwn(t,"traceInitPerf")){let s=t.traceInitPerf,n=typeof s==="number";this.traceInitMaxIdent=n?s:1/0,this.traceInitPerf=n?s>0:s}else this.traceInitMaxIdent=0,this.traceInitPerf=me.traceInitPerf;this.traceInitIndent=-1}TRACE_INIT(t,s){if(this.traceInitPerf===!0){this.traceInitIndent++;let n=Array(this.traceInitIndent+1).join("\t");if(this.traceInitIndent<this.traceInitMaxIdent)console.log(`${n}--> <${t}>`);let{time:i,value:r}=At(s),o=i>10?console.warn:console.log;if(this.traceInitIndent<this.traceInitMaxIdent)o(`${n}<-- <${t}> time: ${i}ms`);return this.traceInitIndent--,r}else return s()}}function Bi(t,s){s.forEach((n)=>{let i=n.prototype;Object.getOwnPropertyNames(i).forEach((r)=>{if(r==="constructor")return;let o=Object.getOwnPropertyDescriptor(i,r);if(o&&(o.get||o.set))Object.defineProperty(t.prototype,r,o);else t.prototype[r]=n.prototype[r]})})}var De=qe(Re,"",-1,-1,-1,-1,-1,-1);Object.freeze(De);var me=Object.freeze({recoveryEnabled:!1,maxLookahead:3,dynamicTokensEnabled:!1,outputCst:!0,errorMessageProvider:ts,nodeLocationTracking:"none",traceInitPerf:!1,skipValidations:!1}),ct=Object.freeze({recoveryValueFunc:()=>{return},resyncEnabled:!0}),ie;(function(t){t[t.INVALID_RULE_NAME=0]="INVALID_RULE_NAME",t[t.DUPLICATE_RULE_NAME=1]="DUPLICATE_RULE_NAME",t[t.INVALID_RULE_OVERRIDE=2]="INVALID_RULE_OVERRIDE",t[t.DUPLICATE_PRODUCTIONS=3]="DUPLICATE_PRODUCTIONS",t[t.UNRESOLVED_SUBRULE_REF=4]="UNRESOLVED_SUBRULE_REF",t[t.LEFT_RECURSION=5]="LEFT_RECURSION",t[t.NONE_LAST_EMPTY_ALT=6]="NONE_LAST_EMPTY_ALT",t[t.AMBIGUOUS_ALTS=7]="AMBIGUOUS_ALTS",t[t.CONFLICT_TOKENS_RULES_NAMESPACE=8]="CONFLICT_TOKENS_RULES_NAMESPACE",t[t.INVALID_TOKEN_NAME=9]="INVALID_TOKEN_NAME",t[t.NO_NON_EMPTY_LOOKAHEAD=10]="NO_NON_EMPTY_LOOKAHEAD",t[t.AMBIGUOUS_PREFIX_ALTS=11]="AMBIGUOUS_PREFIX_ALTS",t[t.TOO_MANY_ALTS=12]="TOO_MANY_ALTS",t[t.CUSTOM_LOOKAHEAD_VALIDATION=13]="CUSTOM_LOOKAHEAD_VALIDATION"})(ie||(ie={}));class Pt{static performSelfAnalysis(t){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 t;this.selfAnalysisDone=!0;let s=this.className;this.TRACE_INIT("toFastProps",()=>{St(this)}),this.TRACE_INIT("Grammar Recording",()=>{try{this.enableRecording(),this.definedRulesNames.forEach((i)=>{let o=this[i].originalGrammarAction,h;this.TRACE_INIT(`${i} Rule`,()=>{h=this.topLevelRuleRecord(i,o)}),this.gastProductionsCache[i]=h})}finally{this.disableRecording()}});let n=[];if(this.TRACE_INIT("Grammar Resolving",()=>{n=Ni({rules:Object.values(this.gastProductionsCache)}),this.definitionErrors=this.definitionErrors.concat(n)}),this.TRACE_INIT("Grammar Validations",()=>{if(n.length===0&&this.skipValidations===!1){let i=Ii({rules:Object.values(this.gastProductionsCache),tokenTypes:Object.values(this.tokensMap),errMsgProvider:Ce,grammarName:s}),r=Ei({lookaheadStrategy:this.lookaheadStrategy,rules:Object.values(this.gastProductionsCache),tokenTypes:Object.values(this.tokensMap),grammarName:s});this.definitionErrors=this.definitionErrors.concat(i,r)}}),this.definitionErrors.length===0){if(this.recoveryEnabled)this.TRACE_INIT("computeAllProdsFollows",()=>{let i=kn(Object.values(this.gastProductionsCache));this.resyncFollows=i});this.TRACE_INIT("ComputeLookaheadFunctions",()=>{var i,r;(r=(i=this.lookaheadStrategy).initialize)===null||r===void 0||r.call(i,{rules:Object.values(this.gastProductionsCache)}),this.preComputeLookaheadFunctions(Object.values(this.gastProductionsCache))})}if(!Pt.DEFER_DEFINITION_ERRORS_HANDLING&&this.definitionErrors.length!==0)throw t=this.definitionErrors.map((i)=>i.message),Error(`Parser Definition Errors detected:
105
105
  ${t.join(`
106
106
  -------------------------------
107
107
  `)}`)})}constructor(t,s){this.definitionErrors=[],this.selfAnalysisDone=!1;let n=this;if(n.initErrorHandler(s),n.initLexerAdapter(),n.initLooksAhead(s),n.initRecognizerEngine(t,s),n.initRecoverable(s),n.initTreeBuilder(s),n.initGastRecorder(s),n.initPerformanceTracer(s),Object.hasOwn(s,"ignoredIssues"))throw Error(`The <ignoredIssues> IParserConfig property has been deprecated.
108
108
  Please use the <IGNORE_AMBIGUITIES> flag on the relevant DSL method instead.
109
109
  See: https://chevrotain.io/docs/guide/resolving_grammar_errors.html#IGNORING_AMBIGUITIES
110
- For further details.`);this.skipValidations=Object.hasOwn(s,"skipValidations")?s.skipValidations:fe.skipValidations}}Pt.DEFER_DEFINITION_ERRORS_HANDLING=!1;Bi(Pt,[qs,Js,sn,nn,an,rn,on,ln,cn]);class gs extends Pt{constructor(t,s=fe){let n=Object.assign({},s);n.outputCst=!0;super(t,n)}}var dt=e((t)=>t!==void 0&&t>=0,"isKnownLocation");function Xi(t,s){let n=t.lexer.tokenize(s);if(n.errors.length>0){let r=n.errors[0],o=dt(r.offset)?r.offset:s.length,h=o+(dt(r.length)?r.length:0);throw Error(`Error lexing ${t.diagramType} diagram: ${r.message} at line ${r.line??1}, column ${r.column??1} [${o},${h})`)}t.parser.input=n.tokens;let i=t.entry();if(t.parser.errors.length>0)throw Error(`Error parsing ${t.diagramType} diagram: ${t.parser.errors[0].message}`);t.visit(i)}e(Xi,"runChevrotainParse");var X={SOLID_ARROW:0,BACK_ARROW:1,LINE_SOLID:2,CIRCLE_ARROW:3,CROSS_ARROW:4,CIRCLE_ARROW_REVERSED:5,CROSS_ARROW_REVERSED:6},Wa="LR",ja=D.usecase,Tn=e(()=>({actors:new Map,useCases:new Map,systemBoundaries:new Map,relationships:[],notes:new Map,jsonNodes:new Map,classDefs:new Map,symbols:new Map,direction:Wa,relationshipCounter:0,noteCounter:0,accTitle:"",accDescription:"",ast:void 0,config:structuredClone(ja)}),"createModel"),Ka=e((t)=>{if(!(t.actors instanceof Map)||!(t.useCases instanceof Map)||!(t.systemBoundaries instanceof Map)||!Array.isArray(t.relationships)||!(t.notes instanceof Map)||!(t.jsonNodes instanceof Map)||!(t.classDefs instanceof Map)||!(t.symbols instanceof Map)||!["TB","TD","BT","RL","LR"].includes(t.direction)||!Number.isSafeInteger(t.relationshipCounter)||t.relationshipCounter<0||!Number.isSafeInteger(t.noteCounter)||t.noteCounter<0||typeof t.accTitle!=="string"||typeof t.accDescription!=="string"||!t.config)throw Error("Cannot commit an incomplete usecase model")},"assertCompleteModel"),B=Tn(),Va=e(()=>structuredClone(B.config),"getConfig"),za=e(()=>B.ast,"getAST"),Ha=e((t)=>{let s=structuredClone(t);Ka(s);let n=E(),i=A();try{S(s.accTitle),T(s.accDescription),B=s}catch(r){throw S(n),T(i),r}},"commit"),Xa=e(()=>{B=Tn(),C()},"clear"),Ya=e(()=>B.actors,"getActors"),qa=e((t)=>B.actors.get(t),"getActor"),Ja=e(()=>B.useCases,"getUseCases"),Za=e((t)=>B.useCases.get(t),"getUseCase"),Qa=e(()=>B.systemBoundaries,"getSystemBoundaries"),eo=e((t)=>B.systemBoundaries.get(t),"getSystemBoundary"),to=e(()=>B.relationships,"getRelationships"),so=e(()=>B.notes,"getNotes"),no=e((t)=>B.notes.get(t),"getNote"),io=e(()=>B.jsonNodes,"getJsonNodes"),ro=e((t)=>B.jsonNodes.get(t),"getJsonNode"),ao=e(()=>B.classDefs,"getClassDefs"),oo=e((t)=>B.classDefs.get(t),"getClassDef"),Yi=e(()=>B.direction,"getDirection"),Je=e((t)=>{let s=new Map;for(let n of["default",...t]){let i=B.classDefs.get(n);if(!i)continue;for(let r of i.styles){let o=r.trim(),h=o.indexOf(":"),u=(h===-1?o:o.slice(0,h)).trim();if(u)s.set(u,o)}}return[...s.values()]},"getCompiledStyles"),lo=e((t)=>t.replaceAll("~","~0").replaceAll("/","~1"),"escapeJsonPointerPart"),$i=e((t)=>typeof t==="string"?t:t===null?"null":String(t),"displayJsonScalar"),co=e((t,s,n=(i)=>i)=>{let i=[],r=e((h,u,c)=>{i.push({key:n(h),accessibleKey:n(u),value:n(c)})},"append"),o=e((h,u,c)=>{if(Array.isArray(h)){if(h.length===0){r(u,u,"[]");return}if(h.every((f)=>f===null||["string","number","boolean"].includes(typeof f))){for(let[f,m]of h.entries())r(f===0?u:"",u,$i(m));return}for(let[f,m]of h.entries())o(m,`${u}[${f}]`,`${c}/${f}`);return}if(h!==null&&typeof h==="object"){let d=h,f=s[c]??Object.keys(d);if(f.length===0){r(u,u,"{}");return}for(let m of f){let y=u?`${u}.${m}`:m;o(d[m],y,`${c}/${lo(m)}`)}return}r(u,u,$i(h))},"visit");return o(t,"",""),i},"flattenJsonRows"),ho=e((t)=>{switch(t.type){case"hollow":return"usecaseActorHollow";case"awesome":return"usecaseActorAwesome";case"icon":return"usecaseActorIcon";case"normal":return"usecaseActor"}},"actorShape"),uo=e((t)=>{if(t.shape==="ellipse")return t.business?"usecaseBusiness":"usecaseEllipse";return t.shape},"useCaseShape"),po=e((t)=>{switch(t){case X.SOLID_ARROW:return{arrowTypeStart:"none",arrowTypeEnd:"arrow_point"};case X.BACK_ARROW:return{arrowTypeStart:"arrow_point",arrowTypeEnd:"none"};case X.CIRCLE_ARROW:return{arrowTypeStart:"none",arrowTypeEnd:"arrow_circle"};case X.CROSS_ARROW:return{arrowTypeStart:"none",arrowTypeEnd:"arrow_cross"};case X.CIRCLE_ARROW_REVERSED:return{arrowTypeStart:"arrow_circle",arrowTypeEnd:"none"};case X.CROSS_ARROW_REVERSED:return{arrowTypeStart:"arrow_cross",arrowTypeEnd:"none"};case X.LINE_SOLID:return{arrowTypeStart:"none",arrowTypeEnd:"none"}}},"associationMarkers"),fo=e((t)=>{switch(t.type){case"include":case"extend":return{arrowTypeStart:"none",arrowTypeEnd:"arrow_point",pattern:"dotted",label:t.type,labelType:"text"};case"generalization":return{arrowTypeStart:"none",arrowTypeEnd:"extension",pattern:"solid"};case"association":return{...po(t.arrowType),pattern:"solid",...t.label?{label:t.label}:{},...t.labelType?{labelType:t.labelType}:{}}}},"relationshipVisuals"),mo=e((t)=>t.animate||t.animation?[`edge-animation-${t.animation??"fast"}`]:[],"animationClasses"),Dt=e((...t)=>t.filter((s)=>Boolean(s)).join(" "),"classNames"),Eo=e(()=>{let t=l(),s={...B.config,...t.usecase},n=e((c)=>O(c,t),"sanitize"),i=e((c)=>n(B.actors.get(c)?.label??B.useCases.get(c)?.label??B.jsonNodes.get(c)?.id??B.notes.get(c)?.label??c),"endpointLabel"),r=[],o=[],h=0,u=0;for(let c of B.actors.values())r.push({id:c.id,label:n(c.label),labelType:c.labelType,shape:ho(c),isGroup:!1,padding:10,look:t.look,colorIndex:h++,cssClasses:Dt("default","usecase-actor",`usecase-actor-${c.type}`,c.business&&"usecase-business",...c.classes),cssStyles:[...c.styles],cssCompiledStyles:Je(c.classes),actorType:c.type,business:c.business,...c.icon?{icon:c.icon}:{},...c.stereotype?{stereotype:n(c.stereotype)}:{},...c.parentId?{parentId:c.parentId}:{}});for(let c of B.useCases.values())r.push({id:c.id,label:n(c.label),labelType:c.labelType,shape:uo(c),isGroup:!1,padding:c.shape==="ellipse"?20:10,look:t.look,colorIndex:h++,cssClasses:Dt("default","usecase-element",`usecase-${c.shape}`,c.business&&"usecase-business",...c.classes),cssStyles:[...c.styles],cssCompiledStyles:Je(c.classes),business:c.business,...c.stereotype?{stereotype:n(c.stereotype)}:{},...c.parentId?{parentId:c.parentId}:{}});for(let c of B.notes.values())r.push({id:c.id,label:n(c.label),labelType:c.labelType,shape:"note",isGroup:!1,padding:10,look:t.look,cssClasses:"default usecase-note",cssStyles:[],cssCompiledStyles:Je([]),noteTarget:c.target,noteTargetLabel:n(B.actors.get(c.target)?.label??B.useCases.get(c.target)?.label??B.jsonNodes.get(c.target)?.id??c.target)});for(let c of B.jsonNodes.values())r.push({id:c.id,label:n(c.id),labelType:"text",shape:"usecaseJsonTable",isGroup:!1,padding:10,look:t.look,cssClasses:Dt("default","usecase-json-table",...c.classes),cssStyles:[...c.styles],cssCompiledStyles:Je(c.classes),jsonRows:co(c.value,c.propertyOrder,n)});for(let c of B.systemBoundaries.values())r.push({id:c.id,label:n(c.label),labelType:c.labelType,shape:"usecaseSystemBoundary",isGroup:!0,padding:20,look:t.look,colorIndex:u++,cssClasses:Dt("default","system-boundary",`system-boundary-${c.type}`,...c.classes),cssStyles:[...c.styles],cssCompiledStyles:Je(c.classes),boundaryType:c.type});for(let c of B.relationships){let{label:d,...f}=fo(c);o.push({id:c.id,start:c.source,end:c.target,source:c.source,target:c.target,sourceLabel:i(c.source),targetLabel:i(c.target),type:"edge",relationshipType:c.type,internal:!1,...f,...d!==void 0?{label:n(d)}:{},labelpos:"c",classes:Dt("default","relationship",`relationship-${c.type}`,...c.classes,...mo(c)),style:[...c.styles],cssCompiledStyles:Je(c.classes),animate:c.animate,...c.animation?{animation:c.animation}:{},look:t.look,thickness:"normal",minlen:c.minlen,isUserDefinedId:c.explicitId})}for(let c of B.notes.values())o.push({id:`${c.id}-edge`,start:c.id,end:c.target,source:c.id,target:c.target,type:"edge",relationshipType:"note",sourceLabel:i(c.id),targetLabel:i(c.target),internal:!0,pattern:"dotted",arrowTypeStart:"none",arrowTypeEnd:"none",labelpos:"c",classes:"default relationship relationship-note",style:[],cssCompiledStyles:Je([]),animate:!1,look:t.look,thickness:"normal",minlen:1,isUserDefinedId:!1});for(let c of r){if(c.wrappingWidth??=s.wrappingWidth,!c.isGroup&&!c.shape.startsWith("usecaseActor"))c.minWidth??=s.minNodeWidth;if(c.shape==="usecaseEllipse"||c.shape==="usecaseBusiness")c.spreadPorts=!0}return{nodes:r,edges:o,config:t,type:"usecase",layoutAlgorithm:"dagre",direction:Yi(),nodeSpacing:s.nodeSpacing,rankSpacing:s.rankSpacing,actorFontSize:s.actorFontSize,actorFontFamily:s.actorFontFamily,actorFontWeight:s.actorFontWeight,usecaseFontSize:s.usecaseFontSize,usecaseFontFamily:s.usecaseFontFamily,usecaseFontWeight:s.usecaseFontWeight,diagramPadding:s.diagramPadding,useMaxWidth:s.useMaxWidth,markers:["point","circle","cross","extension"]}},"getData"),Ns={getConfig:Va,createModel:Tn,commit:Ha,getAST:za,clear:Xa,setDiagramTitle:R,getDiagramTitle:L,setAccTitle:S,getAccTitle:E,setAccDescription:T,getAccDescription:A,getActors:Ya,getActor:qa,getUseCases:Ja,getUseCase:Za,getSystemBoundaries:Qa,getSystemBoundary:eo,getRelationships:to,getNotes:so,getNote:no,getJsonNodes:io,getJsonNode:ro,getClassDefs:ao,getClassDef:oo,getDirection:Yi,getData:Eo};function Qe(t,s,n){let i=[n];return i.index=s,i.input=t,i}e(Qe,"customMatch");var To=e((t,s)=>{if(t[s]!=='"'||t[s+1]!=="`")return null;for(let n=s+2;n<t.length-1;n++)if(t[n]==="`"&&t[n+1]==='"')return Qe(t,s,t.slice(s,n+2));return null},"matchMarkdownString"),go=e((t,s)=>{if(t[s]!=="%"||t[s+1]!=="%")return null;for(let i=s-1;i>=0;i--){let r=t[i];if(r===`
110
+ For further details.`);this.skipValidations=Object.hasOwn(s,"skipValidations")?s.skipValidations:me.skipValidations}}Pt.DEFER_DEFINITION_ERRORS_HANDLING=!1;Bi(Pt,[qs,Js,sn,nn,an,rn,on,ln,cn]);class gs extends Pt{constructor(t,s=me){let n=Object.assign({},s);n.outputCst=!0;super(t,n)}}var ut=e((t)=>t!==void 0&&t>=0,"isKnownLocation");function Xi(t,s){let n=t.lexer.tokenize(s);if(n.errors.length>0){let r=n.errors[0],o=ut(r.offset)?r.offset:s.length,h=o+(ut(r.length)?r.length:0);throw Error(`Error lexing ${t.diagramType} diagram: ${r.message} at line ${r.line??1}, column ${r.column??1} [${o},${h})`)}t.parser.input=n.tokens;let i=t.entry();if(t.parser.errors.length>0)throw Error(`Error parsing ${t.diagramType} diagram: ${t.parser.errors[0].message}`);t.visit(i)}e(Xi,"runChevrotainParse");var X={SOLID_ARROW:0,BACK_ARROW:1,LINE_SOLID:2,CIRCLE_ARROW:3,CROSS_ARROW:4,CIRCLE_ARROW_REVERSED:5,CROSS_ARROW_REVERSED:6},Wa="LR",ja=D.usecase,Tn=e(()=>({actors:new Map,useCases:new Map,systemBoundaries:new Map,relationships:[],notes:new Map,jsonNodes:new Map,classDefs:new Map,symbols:new Map,direction:Wa,relationshipCounter:0,noteCounter:0,accTitle:"",accDescription:"",ast:void 0,config:structuredClone(ja)}),"createModel"),Ka=e((t)=>{if(!(t.actors instanceof Map)||!(t.useCases instanceof Map)||!(t.systemBoundaries instanceof Map)||!Array.isArray(t.relationships)||!(t.notes instanceof Map)||!(t.jsonNodes instanceof Map)||!(t.classDefs instanceof Map)||!(t.symbols instanceof Map)||!["TB","TD","BT","RL","LR"].includes(t.direction)||!Number.isSafeInteger(t.relationshipCounter)||t.relationshipCounter<0||!Number.isSafeInteger(t.noteCounter)||t.noteCounter<0||typeof t.accTitle!=="string"||typeof t.accDescription!=="string"||!t.config)throw Error("Cannot commit an incomplete usecase model")},"assertCompleteModel"),B=Tn(),Va=e(()=>structuredClone(B.config),"getConfig"),za=e(()=>B.ast,"getAST"),Ha=e((t)=>{let s=structuredClone(t);Ka(s);let n=E(),i=A();try{S(s.accTitle),T(s.accDescription),B=s}catch(r){throw S(n),T(i),r}},"commit"),Xa=e(()=>{B=Tn(),C()},"clear"),Ya=e(()=>B.actors,"getActors"),qa=e((t)=>B.actors.get(t),"getActor"),Ja=e(()=>B.useCases,"getUseCases"),Za=e((t)=>B.useCases.get(t),"getUseCase"),Qa=e(()=>B.systemBoundaries,"getSystemBoundaries"),eo=e((t)=>B.systemBoundaries.get(t),"getSystemBoundary"),to=e(()=>B.relationships,"getRelationships"),so=e(()=>B.notes,"getNotes"),no=e((t)=>B.notes.get(t),"getNote"),io=e(()=>B.jsonNodes,"getJsonNodes"),ro=e((t)=>B.jsonNodes.get(t),"getJsonNode"),ao=e(()=>B.classDefs,"getClassDefs"),oo=e((t)=>B.classDefs.get(t),"getClassDef"),Yi=e(()=>B.direction,"getDirection"),Je=e((t)=>{let s=new Map;for(let n of["default",...t]){let i=B.classDefs.get(n);if(!i)continue;for(let r of i.styles){let o=r.trim(),h=o.indexOf(":"),u=(h===-1?o:o.slice(0,h)).trim();if(u)s.set(u,o)}}return[...s.values()]},"getCompiledStyles"),lo=e((t)=>t.replaceAll("~","~0").replaceAll("/","~1"),"escapeJsonPointerPart"),$i=e((t)=>typeof t==="string"?t:t===null?"null":String(t),"displayJsonScalar"),co=e((t,s,n=(i)=>i)=>{let i=[],r=e((h,u,c)=>{i.push({key:n(h),accessibleKey:n(u),value:n(c)})},"append"),o=e((h,u,c)=>{if(Array.isArray(h)){if(h.length===0){r(u,u,"[]");return}if(h.every((f)=>f===null||["string","number","boolean"].includes(typeof f))){for(let[f,m]of h.entries())r(f===0?u:"",u,$i(m));return}for(let[f,m]of h.entries())o(m,`${u}[${f}]`,`${c}/${f}`);return}if(h!==null&&typeof h==="object"){let d=h,f=s[c]??Object.keys(d);if(f.length===0){r(u,u,"{}");return}for(let m of f){let y=u?`${u}.${m}`:m;o(d[m],y,`${c}/${lo(m)}`)}return}r(u,u,$i(h))},"visit");return o(t,"",""),i},"flattenJsonRows"),ho=e((t)=>{switch(t.type){case"hollow":return"usecaseActorHollow";case"awesome":return"usecaseActorAwesome";case"icon":return"usecaseActorIcon";case"normal":return"usecaseActor"}},"actorShape"),uo=e((t)=>{if(t.shape==="ellipse")return t.business?"usecaseBusiness":"usecaseEllipse";return t.shape},"useCaseShape"),po=e((t)=>{switch(t){case X.SOLID_ARROW:return{arrowTypeStart:"none",arrowTypeEnd:"arrow_point"};case X.BACK_ARROW:return{arrowTypeStart:"arrow_point",arrowTypeEnd:"none"};case X.CIRCLE_ARROW:return{arrowTypeStart:"none",arrowTypeEnd:"arrow_circle"};case X.CROSS_ARROW:return{arrowTypeStart:"none",arrowTypeEnd:"arrow_cross"};case X.CIRCLE_ARROW_REVERSED:return{arrowTypeStart:"arrow_circle",arrowTypeEnd:"none"};case X.CROSS_ARROW_REVERSED:return{arrowTypeStart:"arrow_cross",arrowTypeEnd:"none"};case X.LINE_SOLID:return{arrowTypeStart:"none",arrowTypeEnd:"none"}}},"associationMarkers"),fo=e((t)=>{switch(t.type){case"include":case"extend":return{arrowTypeStart:"none",arrowTypeEnd:"arrow_point",pattern:"dotted",label:t.type,labelType:"text"};case"generalization":return{arrowTypeStart:"none",arrowTypeEnd:"extension",pattern:"solid"};case"association":return{...po(t.arrowType),pattern:"solid",...t.label?{label:t.label}:{},...t.labelType?{labelType:t.labelType}:{}}}},"relationshipVisuals"),mo=e((t)=>t.animate||t.animation?[`edge-animation-${t.animation??"fast"}`]:[],"animationClasses"),Dt=e((...t)=>t.filter((s)=>Boolean(s)).join(" "),"classNames"),Eo=e(()=>{let t=l(),s={...B.config,...t.usecase},n=e((c)=>O(c,t),"sanitize"),i=e((c)=>n(B.actors.get(c)?.label??B.useCases.get(c)?.label??B.jsonNodes.get(c)?.id??B.notes.get(c)?.label??c),"endpointLabel"),r=[],o=[],h=0,u=0;for(let c of B.actors.values())r.push({id:c.id,label:n(c.label),labelType:c.labelType,shape:ho(c),isGroup:!1,padding:10,look:t.look,colorIndex:h++,cssClasses:Dt("default","usecase-actor",`usecase-actor-${c.type}`,c.business&&"usecase-business",...c.classes),cssStyles:[...c.styles],cssCompiledStyles:Je(c.classes),actorType:c.type,business:c.business,...c.icon?{icon:c.icon}:{},...c.stereotype?{stereotype:n(c.stereotype)}:{},...c.parentId?{parentId:c.parentId}:{}});for(let c of B.useCases.values())r.push({id:c.id,label:n(c.label),labelType:c.labelType,shape:uo(c),isGroup:!1,padding:c.shape==="ellipse"?20:10,look:t.look,colorIndex:h++,cssClasses:Dt("default","usecase-element",`usecase-${c.shape}`,c.business&&"usecase-business",...c.classes),cssStyles:[...c.styles],cssCompiledStyles:Je(c.classes),business:c.business,...c.stereotype?{stereotype:n(c.stereotype)}:{},...c.parentId?{parentId:c.parentId}:{}});for(let c of B.notes.values())r.push({id:c.id,label:n(c.label),labelType:c.labelType,shape:"note",isGroup:!1,padding:10,look:t.look,cssClasses:"default usecase-note",cssStyles:[],cssCompiledStyles:Je([]),noteTarget:c.target,noteTargetLabel:n(B.actors.get(c.target)?.label??B.useCases.get(c.target)?.label??B.jsonNodes.get(c.target)?.id??c.target)});for(let c of B.jsonNodes.values())r.push({id:c.id,label:n(c.id),labelType:"text",shape:"usecaseJsonTable",isGroup:!1,padding:10,look:t.look,cssClasses:Dt("default","usecase-json-table",...c.classes),cssStyles:[...c.styles],cssCompiledStyles:Je(c.classes),jsonRows:co(c.value,c.propertyOrder,n)});for(let c of B.systemBoundaries.values())r.push({id:c.id,label:n(c.label),labelType:c.labelType,shape:"usecaseSystemBoundary",isGroup:!0,padding:20,look:t.look,colorIndex:u++,cssClasses:Dt("default","system-boundary",`system-boundary-${c.type}`,...c.classes),cssStyles:[...c.styles],cssCompiledStyles:Je(c.classes),boundaryType:c.type});for(let c of B.relationships){let{label:d,...f}=fo(c);o.push({id:c.id,start:c.source,end:c.target,source:c.source,target:c.target,sourceLabel:i(c.source),targetLabel:i(c.target),type:"edge",relationshipType:c.type,internal:!1,...f,...d!==void 0?{label:n(d)}:{},labelpos:"c",classes:Dt("default","relationship",`relationship-${c.type}`,...c.classes,...mo(c)),style:[...c.styles],cssCompiledStyles:Je(c.classes),animate:c.animate,...c.animation?{animation:c.animation}:{},look:t.look,thickness:"normal",minlen:c.minlen,isUserDefinedId:c.explicitId})}for(let c of B.notes.values())o.push({id:`${c.id}-edge`,start:c.id,end:c.target,source:c.id,target:c.target,type:"edge",relationshipType:"note",sourceLabel:i(c.id),targetLabel:i(c.target),internal:!0,pattern:"dotted",arrowTypeStart:"none",arrowTypeEnd:"none",labelpos:"c",classes:"default relationship relationship-note",style:[],cssCompiledStyles:Je([]),animate:!1,look:t.look,thickness:"normal",minlen:1,isUserDefinedId:!1});for(let c of r){if(c.wrappingWidth??=s.wrappingWidth,!c.isGroup&&!c.shape.startsWith("usecaseActor"))c.minWidth??=s.minNodeWidth;if(c.shape==="usecaseEllipse"||c.shape==="usecaseBusiness")c.spreadPorts=!0}return{nodes:r,edges:o,config:t,type:"usecase",layoutAlgorithm:"dagre",direction:Yi(),nodeSpacing:s.nodeSpacing,rankSpacing:s.rankSpacing,actorFontSize:s.actorFontSize,actorFontFamily:s.actorFontFamily,actorFontWeight:s.actorFontWeight,usecaseFontSize:s.usecaseFontSize,usecaseFontFamily:s.usecaseFontFamily,usecaseFontWeight:s.usecaseFontWeight,diagramPadding:s.diagramPadding,useMaxWidth:s.useMaxWidth,markers:["point","circle","cross","extension"]}},"getData"),Ns={getConfig:Va,createModel:Tn,commit:Ha,getAST:za,clear:Xa,setDiagramTitle:R,getDiagramTitle:L,setAccTitle:S,getAccTitle:E,setAccDescription:T,getAccDescription:A,getActors:Ya,getActor:qa,getUseCases:Ja,getUseCase:Za,getSystemBoundaries:Qa,getSystemBoundary:eo,getRelationships:to,getNotes:so,getNote:no,getJsonNodes:io,getJsonNode:ro,getClassDefs:ao,getClassDef:oo,getDirection:Yi,getData:Eo};function Qe(t,s,n){let i=[n];return i.index=s,i.input=t,i}e(Qe,"customMatch");var To=e((t,s)=>{if(t[s]!=='"'||t[s+1]!=="`")return null;for(let n=s+2;n<t.length-1;n++)if(t[n]==="`"&&t[n+1]==='"')return Qe(t,s,t.slice(s,n+2));return null},"matchMarkdownString"),go=e((t,s)=>{if(t[s]!=="%"||t[s+1]!=="%")return null;for(let i=s-1;i>=0;i--){let r=t[i];if(r===`
111
111
  `||r==="\r")break;if(r!==" "&&r!=="\t")return null}let n=s+2;while(n<t.length&&t[n]!==`
112
112
  `&&t[n]!=="\r")n++;return Qe(t,s,t.slice(s,n))},"matchComment"),qi=e((t,s)=>{for(let n=s-1;n>=0;n--){let i=t[n];if(i===`
113
- `||i==="\r")return!0;if(i!==" "&&i!=="\t")return!1}return!0},"isIndentedLineStart"),Ji=e((t,s,n)=>{if(!qi(t,s))return null;let i=n.exec(t.slice(s));return i?Qe(t,s,i[0]):null},"matchAccessibilityLine"),Ao=e((t,s)=>{if(!qi(t,s))return null;let n=/^accDescr[\t ]*{/.exec(t.slice(s));if(!n)return null;let i=t.indexOf("}",s+n[0].length);return i===-1?null:Qe(t,s,t.slice(s,i+1))},"matchAccDescrBlock"),So=e((t,s)=>{if(t[s]!=="{")return null;let n=0,i=!1,r=!1;for(let o=s;o<t.length;o++){let h=t[o];if(i){if(r)r=!1;else if(h==="\\")r=!0;else if(h==='"')i=!1;continue}if(h==='"')i=!0;else if(h==="{")n++;else if(h==="}"&&--n===0)return Qe(t,s,t.slice(s,o+1))}return null},"matchJsonObject"),Ro=e((t,s)=>{let n=t.indexOf(">>",s);if(n===-1||/[\n\r]/.test(t.slice(s,n)))return null;let i=t.slice(s,n);return i.trim()?Qe(t,s,i):null},"matchStereotypeText"),re=I({name:"LABEL_TEXT",pattern:z.NA}),pt=I({name:"WORD",pattern:z.NA,categories:re}),gn=I({name:"NUMBER",pattern:/(?:\d+\.\d+|\d+|\.\d+)(?:[A-Za-z]+)?/,categories:re}),Y=I({name:"IDENTIFIER",pattern:/\w+/,longer_alt:gn,categories:pt}),yo=I({name:"HWS",pattern:/[\t ]+/,group:z.SKIPPED}),Be=I({name:"MARKDOWN_STRING",pattern:To,start_chars_hint:['"'],line_breaks:!0}),Oo=I({name:"UNCLOSED_MARKDOWN_STRING",pattern:/"`[^]*/,line_breaks:!0}),un=I({name:"COMMENT",pattern:go,start_chars_hint:["%"],line_breaks:!1}),Fe=I({name:"NEWLINE",pattern:/\r\n|\n|\r/,line_breaks:!0}),Zi=I({name:"ACC_DESCR_BLOCK",pattern:Ao,start_chars_hint:["a"],line_breaks:!0}),Lo=/^accTitle[\t ]*:[^\n\r]*/,No=/^accDescr[\t ]*:[^\n\r]*/,Qi=I({name:"ACC_TITLE_LINE",pattern:e((t,s)=>Ji(t,s,Lo),"pattern"),start_chars_hint:["a"],line_breaks:!1}),er=I({name:"ACC_DESCR_LINE",pattern:e((t,s)=>Ji(t,s,No),"pattern"),start_chars_hint:["a"],line_breaks:!1}),tr=I({name:"JSON_DECLARATION_START",pattern:/json[\t ]+\w+[\t ]*@[\t ]*(?={)/,push_mode:"jsonBody"}),An=I({name:"JSON_OBJECT_LITERAL",pattern:So,start_chars_hint:["{"],line_breaks:!0,pop_mode:!0}),sr=I({name:"UNCLOSED_JSON_OBJECT_LITERAL",pattern:/{[^]*/,line_breaks:!0,pop_mode:!0}),ee=e((t,s)=>I({name:t,pattern:s,longer_alt:Y,categories:pt}),"keyword"),nr=ee("USECASE",/usecase-beta/),dn=ee("ACTOR",/actor/),ir=ee("SYSTEM_BOUNDARY",/systemBoundary/),rr=ee("END",/end/),ar=ee("DIRECTION",/direction/),or=ee("TD",/TD/),lr=ee("TB",/TB/),cr=ee("BT",/BT/),hr=ee("LR",/LR/),ur=ee("RL",/RL/),dr=ee("NOTE",/note/),pr=ee("FOR",/for/),Io=ee("JSON",/json/),fr=ee("CLASS_DEF",/classDef/),mr=ee("CLASS",/class/),Er=ee("STYLE",/style/),Tr=ee("INCLUDE",/include/i),gr=ee("EXTEND",/extend/i),Ar=ee("TRUE",/true/),Sr=ee("FALSE",/false/),Rr=I({name:"GENERALIZATION",pattern:/--\|>/}),yr=I({name:"DEPENDENCY_ARROW",pattern:/\.\.>/}),Or=I({name:"STEREOTYPE_START",pattern:/<</,push_mode:"stereotype"}),Sn=I({name:"STEREOTYPE_END",pattern:/>>/,pop_mode:!0}),Rn=I({name:"STEREOTYPE_TEXT",pattern:Ro,line_breaks:!1}),Lr=I({name:"UNCLOSED_STEREOTYPE_TEXT",pattern:/[^\n\r]+/,line_breaks:!1,pop_mode:!0}),Nr=I({name:"CLASS_SEPARATOR",pattern:/:::/}),As=I({name:"FORWARD_SOLID",pattern:/--+>/}),Ir=I({name:"BACKWARD_SOLID",pattern:/<--+/}),Ss=I({name:"FORWARD_CIRCLE",pattern:/--o/}),kr=I({name:"BACKWARD_CIRCLE",pattern:/o--/}),Rs=I({name:"FORWARD_CROSS",pattern:/--x/}),Cr=I({name:"BACKWARD_CROSS",pattern:/x--/}),Ne=I({name:"MARKERLESS_SOLID",pattern:/--+/}),pn=I({name:"METADATA_START",pattern:/@{/}),ys=I({name:"AT",pattern:/@/,categories:re}),br=I({name:"LBRACE",pattern:/{/}),fn=I({name:"RBRACE",pattern:/}/}),Os=I({name:"LBRACKET",pattern:/\[/}),Ls=I({name:"RBRACKET",pattern:/]/}),Ft=I({name:"LPAREN",pattern:/\(/}),Bt=I({name:"RPAREN",pattern:/\)/}),Ce=I({name:"COMMA",pattern:/,/,categories:re}),$t=I({name:"COLON",pattern:/:/,categories:re}),_r=I({name:"HASH_COLOR",pattern:/#[\dA-Fa-f]+/,categories:re}),Ie=I({name:"PLAIN_STRING",pattern:/"[^\n\r"]*"|'[^\n\r']*'/}),mn=I({name:"CSS_IDENTIFIER",pattern:/--[A-Z_a-z][\w-]*|[A-Z_a-z]\w*(?:-\w+)+/,categories:re}),xr=I({name:"CSS_ESCAPED_COMMA",pattern:/\\,/,categories:re}),vr=I({name:"DASH",pattern:/-/,categories:re}),Mr=I({name:"DOT",pattern:/\./,categories:re}),wr=I({name:"PERCENT",pattern:/%/,categories:re}),Ur=I({name:"CSS_PUNCTUATION",pattern:/[!#$&*+/=?^_|~]/,categories:re}),ko=I({name:"LABEL_PUNCTUATION",pattern:/[;<>\\`]/,categories:re}),Co=I({name:"LABEL_SYMBOL",pattern:/[^\t\n\r !-~]+/,categories:re}),Pr=[re,pt,yo,Be,Oo,un,Fe,Zi,Qi,er,tr,nr,dn,ir,rr,ar,or,lr,cr,hr,ur,dr,pr,Io,fr,mr,Er,Tr,gr,Ar,Sr,Rr,yr,Or,Nr,As,Ir,Ss,kr,Rs,Cr,Ne,pn,ys,br,fn,Os,Ls,Ft,Bt,Ce,$t,_r,Ie,mn,Y,gn,xr,vr,Mr,wr,Ur,ko,Co],bo={defaultMode:"defaultMode",modes:{defaultMode:[...Pr],jsonBody:[An,sr],stereotype:[Sn,Rn,Lr]}},_o=[...Pr,An,sr,Sn,Rn,Lr],xo=new z(bo),Gi=e((t)=>kt(t,re)||t.tokenType===Ie||t.tokenType===Be,"isLabelToken"),vo={allowmixing:!0,newpage:!0,package:!0,rectangle:!0,skinparam:!0},Mo=class extends gs{static{e(this,"UsecaseParser")}constructor(){super(_o,{nodeLocationTracking:"full"});this.RULE("start",()=>{this.CONSUME(nr),this.SUBRULE(this.lineEnd),this.MANY(()=>this.SUBRULE(this.line))}),this.RULE("line",()=>{this.OR([{ALT:e(()=>this.SUBRULE(this.blankLine),"ALT")},{ALT:e(()=>this.SUBRULE(this.commentLine),"ALT")},{GATE:e(()=>this.isStatementStart(),"GATE"),ALT:e(()=>this.SUBRULE(this.statement),"ALT")}])}),this.RULE("statement",()=>{this.OR([{ALT:e(()=>this.SUBRULE(this.accTitleStatement),"ALT")},{ALT:e(()=>this.SUBRULE(this.accDescrStatement),"ALT")},{ALT:e(()=>this.SUBRULE(this.directionStatement),"ALT")},{ALT:e(()=>this.SUBRULE(this.actorStatement),"ALT")},{ALT:e(()=>this.SUBRULE(this.systemBoundaryStatement),"ALT")},{ALT:e(()=>this.SUBRULE(this.noteStatement),"ALT")},{ALT:e(()=>this.SUBRULE(this.jsonStatement),"ALT")},{ALT:e(()=>this.SUBRULE(this.classDefStatement),"ALT")},{ALT:e(()=>this.SUBRULE(this.classStatement),"ALT")},{ALT:e(()=>this.SUBRULE(this.styleStatement),"ALT")},{GATE:e(()=>this.isMetadataAssignment(),"GATE"),ALT:e(()=>this.SUBRULE(this.metadataAssignmentStatement),"ALT")},{GATE:e(()=>!this.isForbiddenPlantUmlStatement(),"GATE"),ALT:e(()=>this.SUBRULE(this.entityStatement),"ALT")}])}),this.RULE("lineEnd",()=>{this.OR([{ALT:e(()=>this.CONSUME(Fe),"ALT")},{ALT:e(()=>this.CONSUME(Se),"ALT")}])}),this.RULE("blankLine",()=>{this.CONSUME(Fe)}),this.RULE("commentLine",()=>{this.CONSUME(un),this.SUBRULE(this.lineEnd)}),this.RULE("accTitleStatement",()=>{this.CONSUME(Qi),this.SUBRULE(this.lineEnd)}),this.RULE("accDescrStatement",()=>{this.OR([{ALT:e(()=>this.CONSUME(er),"ALT")},{ALT:e(()=>this.CONSUME(Zi),"ALT")}]),this.SUBRULE(this.lineEnd)}),this.RULE("actorStatement",()=>{this.CONSUME(dn),this.SUBRULE(this.actorItem),this.OPTION(()=>{this.OR([{ALT:e(()=>this.AT_LEAST_ONE(()=>{this.CONSUME(Ce),this.SUBRULE2(this.actorItem)}),"ALT")},{ALT:e(()=>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:e(()=>{this.CONSUME(Y),this.OPTION(()=>{this.CONSUME(Ft),this.SUBRULE(this.nodeLabel),this.CONSUME(Bt)})},"ALT")},{ALT:e(()=>this.CONSUME(Ie),"ALT")},{ALT:e(()=>this.CONSUME(Be),"ALT")}])}),this.RULE("actorDeclarationOnly",()=>{this.CONSUME(dn),this.SUBRULE(this.actorItem),this.MANY(()=>{this.CONSUME(Ce),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:e(()=>{this.CONSUME(Y),this.OPTION(()=>{this.OR2([{ALT:e(()=>{this.CONSUME(Ft),this.SUBRULE(this.nodeLabel),this.CONSUME(Bt)},"ALT")},{ALT:e(()=>{this.CONSUME(Os),this.SUBRULE2(this.nodeLabel),this.CONSUME(Ls)},"ALT")}])})},"ALT")},{ALT:e(()=>this.CONSUME(Ie),"ALT")},{ALT:e(()=>this.CONSUME(Be),"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:e(()=>this.CONSUME(Ie),"ALT")},{ALT:e(()=>this.CONSUME(Be),"ALT")},{ALT:e(()=>this.AT_LEAST_ONE(()=>this.CONSUME(re)),"ALT")}])}),this.RULE("useCaseMetadata",()=>{this.SUBRULE(this.metadata)}),this.RULE("relationTail",()=>{this.OPTION({GATE:e(()=>this.LA(1).tokenType===Y&&this.LA(2).tokenType===ys,"GATE"),DEF:e(()=>{this.CONSUME(Y),this.CONSUME(ys)},"DEF")}),this.SUBRULE(this.arrow),this.SUBRULE(this.entityName)}),this.RULE("arrow",()=>{this.OR([{ALT:e(()=>this.SUBRULE(this.semanticRelation),"ALT")},{ALT:e(()=>this.SUBRULE(this.forwardSolidOperator),"ALT")},{ALT:e(()=>this.SUBRULE(this.backwardSolidOperator),"ALT")},{ALT:e(()=>this.SUBRULE(this.markerlessSolidOperator),"ALT")},{ALT:e(()=>this.SUBRULE(this.forwardCircleOperator),"ALT")},{ALT:e(()=>this.SUBRULE(this.backwardCircleOperator),"ALT")},{ALT:e(()=>this.SUBRULE(this.forwardCrossOperator),"ALT")},{ALT:e(()=>this.SUBRULE(this.backwardCrossOperator),"ALT")}])}),this.RULE("forwardSolidOperator",()=>{this.CONSUME(As)}),this.RULE("backwardSolidOperator",()=>{this.CONSUME(Ir),this.OPTION({GATE:e(()=>this.LA(0).image==="<--"&&this.hasLabeledRight([Ne]),"GATE"),DEF:e(()=>{this.SUBRULE(this.edgeLabel),this.CONSUME(Ne)},"DEF")})}),this.RULE("markerlessSolidOperator",()=>{this.CONSUME(Ne),this.OPTION({GATE:e(()=>this.LA(0).image==="--"&&this.hasLabeledRight([As,Ne,Ss,Rs]),"GATE"),DEF:e(()=>{this.SUBRULE(this.edgeLabel),this.OR([{ALT:e(()=>this.CONSUME(As),"ALT")},{ALT:e(()=>this.CONSUME2(Ne),"ALT")},{ALT:e(()=>this.CONSUME(Ss),"ALT")},{ALT:e(()=>this.CONSUME(Rs),"ALT")}])},"DEF")})}),this.RULE("forwardCircleOperator",()=>{this.CONSUME(Ss)}),this.RULE("backwardCircleOperator",()=>{this.CONSUME(kr),this.OPTION({GATE:e(()=>this.hasLabeledRight([Ne]),"GATE"),DEF:e(()=>{this.SUBRULE(this.edgeLabel),this.CONSUME(Ne)},"DEF")})}),this.RULE("forwardCrossOperator",()=>{this.CONSUME(Rs)}),this.RULE("backwardCrossOperator",()=>{this.CONSUME(Cr),this.OPTION({GATE:e(()=>this.hasLabeledRight([Ne]),"GATE"),DEF:e(()=>{this.SUBRULE(this.edgeLabel),this.CONSUME(Ne)},"DEF")})}),this.RULE("edgeLabel",()=>{this.OR([{ALT:e(()=>this.CONSUME(Ie),"ALT")},{ALT:e(()=>this.CONSUME(Be),"ALT")},{ALT:e(()=>this.AT_LEAST_ONE(()=>this.CONSUME(re)),"ALT")}])}),this.RULE("semanticRelation",()=>{this.OR([{ALT:e(()=>{this.CONSUME(yr),this.CONSUME($t),this.OR2([{ALT:e(()=>this.CONSUME(Tr),"ALT")},{ALT:e(()=>this.CONSUME(gr),"ALT")}])},"ALT")},{ALT:e(()=>this.CONSUME(Rr),"ALT")}])}),this.RULE("metadata",()=>{this.CONSUME(pn),this.MANY(()=>this.CONSUME(Fe)),this.OPTION(()=>{this.SUBRULE(this.metadataProperty),this.MANY2(()=>{this.SUBRULE(this.metadataSeparator),this.SUBRULE2(this.metadataProperty)}),this.OPTION2(()=>this.CONSUME(Ce)),this.MANY3(()=>this.CONSUME2(Fe))}),this.CONSUME(fn)}),this.RULE("metadataProperty",()=>{this.OR([{ALT:e(()=>this.CONSUME(Y),"ALT")},{ALT:e(()=>this.CONSUME(Ie),"ALT")}]),this.CONSUME($t),this.OR2([{ALT:e(()=>this.CONSUME2(Y),"ALT")},{ALT:e(()=>this.CONSUME2(Ie),"ALT")},{ALT:e(()=>this.CONSUME(Ar),"ALT")},{ALT:e(()=>this.CONSUME(Sr),"ALT")}])}),this.RULE("metadataSeparator",()=>{this.OR([{ALT:e(()=>{this.CONSUME(Ce),this.MANY(()=>this.CONSUME(Fe))},"ALT")},{ALT:e(()=>{this.AT_LEAST_ONE(()=>this.CONSUME2(Fe)),this.OPTION(()=>this.CONSUME2(Ce)),this.MANY2(()=>this.CONSUME3(Fe))},"ALT")}])}),this.RULE("systemBoundaryStatement",()=>{this.CONSUME(ir),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(rr),this.SUBRULE2(this.lineEnd)}),this.RULE("systemBoundaryName",()=>{this.OR([{ALT:e(()=>{this.CONSUME(Y),this.OPTION(()=>{this.OR2([{ALT:e(()=>{this.CONSUME(Ft),this.SUBRULE(this.nodeLabel),this.CONSUME(Bt)},"ALT")},{ALT:e(()=>{this.CONSUME(Os),this.SUBRULE2(this.nodeLabel),this.CONSUME(Ls)},"ALT")}])})},"ALT")},{ALT:e(()=>this.CONSUME(Ie),"ALT")},{ALT:e(()=>this.CONSUME(Be),"ALT")}])}),this.RULE("systemBoundaryContent",()=>{this.MANY(()=>{this.OR([{ALT:e(()=>this.SUBRULE(this.blankLine),"ALT")},{ALT:e(()=>this.SUBRULE(this.commentLine),"ALT")},{ALT:e(()=>this.SUBRULE(this.boundaryElement),"ALT")}])})}),this.RULE("boundaryElement",()=>{this.OR([{ALT:e(()=>this.SUBRULE(this.actorDeclarationOnly),"ALT")},{ALT:e(()=>{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:e(()=>this.CONSUME(Y),"ALT")},{ALT:e(()=>this.CONSUME(Ie),"ALT")},{ALT:e(()=>this.CONSUME(Be),"ALT")}])}),this.RULE("noteStatement",()=>{this.CONSUME(dr),this.CONSUME(pr),this.CONSUME(Y),this.SUBRULE(this.nodeLabel),this.SUBRULE(this.lineEnd)}),this.RULE("stereotype",()=>{this.CONSUME(Or),this.CONSUME(Rn),this.CONSUME(Sn)}),this.RULE("classSuffix",()=>{this.CONSUME(Nr),this.CONSUME(Y),this.MANY(()=>{this.CONSUME(Ce),this.CONSUME2(Y)})}),this.RULE("jsonStatement",()=>{this.CONSUME(tr),this.CONSUME(An),this.OPTION(()=>this.SUBRULE(this.classSuffix)),this.SUBRULE(this.lineEnd)}),this.RULE("directionStatement",()=>{this.CONSUME(ar),this.OR([{ALT:e(()=>this.CONSUME(or),"ALT")},{ALT:e(()=>this.CONSUME(lr),"ALT")},{ALT:e(()=>this.CONSUME(cr),"ALT")},{ALT:e(()=>this.CONSUME(hr),"ALT")},{ALT:e(()=>this.CONSUME(ur),"ALT")}]),this.SUBRULE(this.lineEnd)}),this.RULE("classDefStatement",()=>{this.CONSUME(fr),this.CONSUME(Y),this.MANY(()=>{this.CONSUME(Ce),this.CONSUME2(Y)}),this.SUBRULE(this.styles),this.SUBRULE(this.lineEnd)}),this.RULE("classStatement",()=>{this.CONSUME(mr),this.CONSUME(Y),this.MANY(()=>{this.CONSUME(Ce),this.CONSUME2(Y)}),this.CONSUME3(Y),this.MANY2(()=>{this.CONSUME2(Ce),this.CONSUME4(Y)}),this.SUBRULE(this.lineEnd)}),this.RULE("styleStatement",()=>{this.CONSUME(Er),this.CONSUME(Y),this.SUBRULE(this.styles),this.SUBRULE(this.lineEnd)}),this.RULE("styles",()=>{this.SUBRULE(this.styleValue),this.MANY(()=>{this.CONSUME(Ce),this.SUBRULE2(this.styleValue)})}),this.RULE("styleValue",()=>{this.OR([{ALT:e(()=>this.CONSUME(pt),"ALT")},{ALT:e(()=>this.CONSUME(mn),"ALT")},{ALT:e(()=>{this.CONSUME(Ne),this.CONSUME2(pt)},"ALT")}]),this.CONSUME($t),this.AT_LEAST_ONE(()=>this.SUBRULE(this.styleComponent))}),this.RULE("styleComponent",()=>{this.OR([{ALT:e(()=>this.CONSUME(pt),"ALT")},{ALT:e(()=>this.CONSUME(Ie),"ALT")},{ALT:e(()=>this.CONSUME(gn),"ALT")},{ALT:e(()=>this.CONSUME(_r),"ALT")},{ALT:e(()=>this.CONSUME(mn),"ALT")},{ALT:e(()=>this.CONSUME(xr),"ALT")},{ALT:e(()=>this.CONSUME(vr),"ALT")},{ALT:e(()=>this.CONSUME(Mr),"ALT")},{ALT:e(()=>this.CONSUME(wr),"ALT")},{ALT:e(()=>this.CONSUME(Ur),"ALT")},{ALT:e(()=>this.CONSUME($t),"ALT")},{ALT:e(()=>this.CONSUME(Ft),"ALT")},{ALT:e(()=>this.CONSUME(Bt),"ALT")},{ALT:e(()=>this.CONSUME(Os),"ALT")},{ALT:e(()=>this.CONSUME(Ls),"ALT")},{ALT:e(()=>this.CONSUME(br),"ALT")},{ALT:e(()=>this.CONSUME(fn),"ALT")},{ALT:e(()=>this.CONSUME(ys),"ALT")},{ALT:e(()=>this.CONSUME(Ne),"ALT")}])}),this.performSelfAnalysis()}isMetadataAssignment(){let t=this.LA(1).tokenType;return(t===Y||t===Ie||t===Be)&&this.LA(2).tokenType===pn}isStatementStart(){let t=this.LA(1).tokenType;return t!==Se&&t!==Fe&&t!==un}isForbiddenPlantUmlStatement(){return this.LA(1).tokenType===Y&&vo[this.LA(1).image.toLowerCase()]===!0}hasLabeledRight(t){if(!Gi(this.LA(1)))return!1;for(let s=2;;s++){let n=this.LA(s);if(t.includes(n.tokenType))return!0;if(!Gi(n))return!1}}},Gt=new Mo,Wi=class extends Error{constructor(t,s,n){super(`${t} (line ${s}, column ${n})`);this.line=s,this.column=n,this.name="UsecaseJsonError"}static{e(this,"UsecaseJsonError")}},En=e((t,s,n,i)=>{let r=n,o=i,h=Math.min(Math.max(s,0),t.length);for(let u=0;u<h;u++){let c=t[u];if(c==="\r")r++,o=1;else if(c===`
113
+ `||i==="\r")return!0;if(i!==" "&&i!=="\t")return!1}return!0},"isIndentedLineStart"),Ji=e((t,s,n)=>{if(!qi(t,s))return null;let i=n.exec(t.slice(s));return i?Qe(t,s,i[0]):null},"matchAccessibilityLine"),Ao=e((t,s)=>{if(!qi(t,s))return null;let n=/^accDescr[\t ]*{/.exec(t.slice(s));if(!n)return null;let i=t.indexOf("}",s+n[0].length);return i===-1?null:Qe(t,s,t.slice(s,i+1))},"matchAccDescrBlock"),So=e((t,s)=>{if(t[s]!=="{")return null;let n=0,i=!1,r=!1;for(let o=s;o<t.length;o++){let h=t[o];if(i){if(r)r=!1;else if(h==="\\")r=!0;else if(h==='"')i=!1;continue}if(h==='"')i=!0;else if(h==="{")n++;else if(h==="}"&&--n===0)return Qe(t,s,t.slice(s,o+1))}return null},"matchJsonObject"),Ro=e((t,s)=>{let n=t.indexOf(">>",s);if(n===-1||/[\n\r]/.test(t.slice(s,n)))return null;let i=t.slice(s,n);return i.trim()?Qe(t,s,i):null},"matchStereotypeText"),re=I({name:"LABEL_TEXT",pattern:z.NA}),dt=I({name:"WORD",pattern:z.NA,categories:re}),gn=I({name:"NUMBER",pattern:/(?:\d+\.\d+|\d+|\.\d+)(?:[A-Za-z]+)?/,categories:re}),Y=I({name:"IDENTIFIER",pattern:/\w+/,longer_alt:gn,categories:dt}),yo=I({name:"HWS",pattern:/[\t ]+/,group:z.SKIPPED}),Be=I({name:"MARKDOWN_STRING",pattern:To,start_chars_hint:['"'],line_breaks:!0}),Oo=I({name:"UNCLOSED_MARKDOWN_STRING",pattern:/"`[^]*/,line_breaks:!0}),un=I({name:"COMMENT",pattern:go,start_chars_hint:["%"],line_breaks:!1}),Fe=I({name:"NEWLINE",pattern:/\r\n|\n|\r/,line_breaks:!0}),Zi=I({name:"ACC_DESCR_BLOCK",pattern:Ao,start_chars_hint:["a"],line_breaks:!0}),Lo=/^accTitle[\t ]*:[^\n\r]*/,No=/^accDescr[\t ]*:[^\n\r]*/,Qi=I({name:"ACC_TITLE_LINE",pattern:e((t,s)=>Ji(t,s,Lo),"pattern"),start_chars_hint:["a"],line_breaks:!1}),er=I({name:"ACC_DESCR_LINE",pattern:e((t,s)=>Ji(t,s,No),"pattern"),start_chars_hint:["a"],line_breaks:!1}),tr=I({name:"JSON_DECLARATION_START",pattern:/json[\t ]+\w+[\t ]*@[\t ]*(?={)/,push_mode:"jsonBody"}),An=I({name:"JSON_OBJECT_LITERAL",pattern:So,start_chars_hint:["{"],line_breaks:!0,pop_mode:!0}),sr=I({name:"UNCLOSED_JSON_OBJECT_LITERAL",pattern:/{[^]*/,line_breaks:!0,pop_mode:!0}),ee=e((t,s)=>I({name:t,pattern:s,longer_alt:Y,categories:dt}),"keyword"),nr=ee("USECASE",/usecase-beta/),dn=ee("ACTOR",/actor/),ir=ee("SYSTEM_BOUNDARY",/systemBoundary/),rr=ee("END",/end/),ar=ee("DIRECTION",/direction/),or=ee("TD",/TD/),lr=ee("TB",/TB/),cr=ee("BT",/BT/),hr=ee("LR",/LR/),ur=ee("RL",/RL/),dr=ee("NOTE",/note/),pr=ee("FOR",/for/),Io=ee("JSON",/json/),fr=ee("CLASS_DEF",/classDef/),mr=ee("CLASS",/class/),Er=ee("STYLE",/style/),Tr=ee("INCLUDE",/include/i),gr=ee("EXTEND",/extend/i),Ar=ee("TRUE",/true/),Sr=ee("FALSE",/false/),Rr=I({name:"GENERALIZATION",pattern:/--\|>/}),yr=I({name:"DEPENDENCY_ARROW",pattern:/\.\.>/}),Or=I({name:"STEREOTYPE_START",pattern:/<</,push_mode:"stereotype"}),Sn=I({name:"STEREOTYPE_END",pattern:/>>/,pop_mode:!0}),Rn=I({name:"STEREOTYPE_TEXT",pattern:Ro,line_breaks:!1}),Lr=I({name:"UNCLOSED_STEREOTYPE_TEXT",pattern:/[^\n\r]+/,line_breaks:!1,pop_mode:!0}),Nr=I({name:"CLASS_SEPARATOR",pattern:/:::/}),As=I({name:"FORWARD_SOLID",pattern:/--+>/}),Ir=I({name:"BACKWARD_SOLID",pattern:/<--+/}),Ss=I({name:"FORWARD_CIRCLE",pattern:/--o/}),kr=I({name:"BACKWARD_CIRCLE",pattern:/o--/}),Rs=I({name:"FORWARD_CROSS",pattern:/--x/}),Cr=I({name:"BACKWARD_CROSS",pattern:/x--/}),Ie=I({name:"MARKERLESS_SOLID",pattern:/--+/}),pn=I({name:"METADATA_START",pattern:/@{/}),ys=I({name:"AT",pattern:/@/,categories:re}),br=I({name:"LBRACE",pattern:/{/}),fn=I({name:"RBRACE",pattern:/}/}),Os=I({name:"LBRACKET",pattern:/\[/}),Ls=I({name:"RBRACKET",pattern:/]/}),Ft=I({name:"LPAREN",pattern:/\(/}),Bt=I({name:"RPAREN",pattern:/\)/}),be=I({name:"COMMA",pattern:/,/,categories:re}),$t=I({name:"COLON",pattern:/:/,categories:re}),_r=I({name:"HASH_COLOR",pattern:/#[\dA-Fa-f]+/,categories:re}),ke=I({name:"PLAIN_STRING",pattern:/"[^\n\r"]*"|'[^\n\r']*'/}),mn=I({name:"CSS_IDENTIFIER",pattern:/--[A-Z_a-z][\w-]*|[A-Z_a-z]\w*(?:-\w+)+/,categories:re}),xr=I({name:"CSS_ESCAPED_COMMA",pattern:/\\,/,categories:re}),vr=I({name:"DASH",pattern:/-/,categories:re}),Mr=I({name:"DOT",pattern:/\./,categories:re}),wr=I({name:"PERCENT",pattern:/%/,categories:re}),Ur=I({name:"CSS_PUNCTUATION",pattern:/[!#$&*+/=?^_|~]/,categories:re}),ko=I({name:"LABEL_PUNCTUATION",pattern:/[;<>\\`]/,categories:re}),Co=I({name:"LABEL_SYMBOL",pattern:/[^\t\n\r !-~]+/,categories:re}),Pr=[re,dt,yo,Be,Oo,un,Fe,Zi,Qi,er,tr,nr,dn,ir,rr,ar,or,lr,cr,hr,ur,dr,pr,Io,fr,mr,Er,Tr,gr,Ar,Sr,Rr,yr,Or,Nr,As,Ir,Ss,kr,Rs,Cr,Ie,pn,ys,br,fn,Os,Ls,Ft,Bt,be,$t,_r,ke,mn,Y,gn,xr,vr,Mr,wr,Ur,ko,Co],bo={defaultMode:"defaultMode",modes:{defaultMode:[...Pr],jsonBody:[An,sr],stereotype:[Sn,Rn,Lr]}},_o=[...Pr,An,sr,Sn,Rn,Lr],xo=new z(bo),Gi=e((t)=>kt(t,re)||t.tokenType===ke||t.tokenType===Be,"isLabelToken"),vo={allowmixing:!0,newpage:!0,package:!0,rectangle:!0,skinparam:!0},Mo=class extends gs{static{e(this,"UsecaseParser")}constructor(){super(_o,{nodeLocationTracking:"full"});this.RULE("start",()=>{this.CONSUME(nr),this.SUBRULE(this.lineEnd),this.MANY(()=>this.SUBRULE(this.line))}),this.RULE("line",()=>{this.OR([{ALT:e(()=>this.SUBRULE(this.blankLine),"ALT")},{ALT:e(()=>this.SUBRULE(this.commentLine),"ALT")},{GATE:e(()=>this.isStatementStart(),"GATE"),ALT:e(()=>this.SUBRULE(this.statement),"ALT")}])}),this.RULE("statement",()=>{this.OR([{ALT:e(()=>this.SUBRULE(this.accTitleStatement),"ALT")},{ALT:e(()=>this.SUBRULE(this.accDescrStatement),"ALT")},{ALT:e(()=>this.SUBRULE(this.directionStatement),"ALT")},{ALT:e(()=>this.SUBRULE(this.actorStatement),"ALT")},{ALT:e(()=>this.SUBRULE(this.systemBoundaryStatement),"ALT")},{ALT:e(()=>this.SUBRULE(this.noteStatement),"ALT")},{ALT:e(()=>this.SUBRULE(this.jsonStatement),"ALT")},{ALT:e(()=>this.SUBRULE(this.classDefStatement),"ALT")},{ALT:e(()=>this.SUBRULE(this.classStatement),"ALT")},{ALT:e(()=>this.SUBRULE(this.styleStatement),"ALT")},{GATE:e(()=>this.isMetadataAssignment(),"GATE"),ALT:e(()=>this.SUBRULE(this.metadataAssignmentStatement),"ALT")},{GATE:e(()=>!this.isForbiddenPlantUmlStatement(),"GATE"),ALT:e(()=>this.SUBRULE(this.entityStatement),"ALT")}])}),this.RULE("lineEnd",()=>{this.OR([{ALT:e(()=>this.CONSUME(Fe),"ALT")},{ALT:e(()=>this.CONSUME(Re),"ALT")}])}),this.RULE("blankLine",()=>{this.CONSUME(Fe)}),this.RULE("commentLine",()=>{this.CONSUME(un),this.SUBRULE(this.lineEnd)}),this.RULE("accTitleStatement",()=>{this.CONSUME(Qi),this.SUBRULE(this.lineEnd)}),this.RULE("accDescrStatement",()=>{this.OR([{ALT:e(()=>this.CONSUME(er),"ALT")},{ALT:e(()=>this.CONSUME(Zi),"ALT")}]),this.SUBRULE(this.lineEnd)}),this.RULE("actorStatement",()=>{this.CONSUME(dn),this.SUBRULE(this.actorItem),this.OPTION(()=>{this.OR([{ALT:e(()=>this.AT_LEAST_ONE(()=>{this.CONSUME(be),this.SUBRULE2(this.actorItem)}),"ALT")},{ALT:e(()=>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:e(()=>{this.CONSUME(Y),this.OPTION(()=>{this.CONSUME(Ft),this.SUBRULE(this.nodeLabel),this.CONSUME(Bt)})},"ALT")},{ALT:e(()=>this.CONSUME(ke),"ALT")},{ALT:e(()=>this.CONSUME(Be),"ALT")}])}),this.RULE("actorDeclarationOnly",()=>{this.CONSUME(dn),this.SUBRULE(this.actorItem),this.MANY(()=>{this.CONSUME(be),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:e(()=>{this.CONSUME(Y),this.OPTION(()=>{this.OR2([{ALT:e(()=>{this.CONSUME(Ft),this.SUBRULE(this.nodeLabel),this.CONSUME(Bt)},"ALT")},{ALT:e(()=>{this.CONSUME(Os),this.SUBRULE2(this.nodeLabel),this.CONSUME(Ls)},"ALT")}])})},"ALT")},{ALT:e(()=>this.CONSUME(ke),"ALT")},{ALT:e(()=>this.CONSUME(Be),"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:e(()=>this.CONSUME(ke),"ALT")},{ALT:e(()=>this.CONSUME(Be),"ALT")},{ALT:e(()=>this.AT_LEAST_ONE(()=>this.CONSUME(re)),"ALT")}])}),this.RULE("useCaseMetadata",()=>{this.SUBRULE(this.metadata)}),this.RULE("relationTail",()=>{this.OPTION({GATE:e(()=>this.LA(1).tokenType===Y&&this.LA(2).tokenType===ys,"GATE"),DEF:e(()=>{this.CONSUME(Y),this.CONSUME(ys)},"DEF")}),this.SUBRULE(this.arrow),this.SUBRULE(this.entityName)}),this.RULE("arrow",()=>{this.OR([{ALT:e(()=>this.SUBRULE(this.semanticRelation),"ALT")},{ALT:e(()=>this.SUBRULE(this.forwardSolidOperator),"ALT")},{ALT:e(()=>this.SUBRULE(this.backwardSolidOperator),"ALT")},{ALT:e(()=>this.SUBRULE(this.markerlessSolidOperator),"ALT")},{ALT:e(()=>this.SUBRULE(this.forwardCircleOperator),"ALT")},{ALT:e(()=>this.SUBRULE(this.backwardCircleOperator),"ALT")},{ALT:e(()=>this.SUBRULE(this.forwardCrossOperator),"ALT")},{ALT:e(()=>this.SUBRULE(this.backwardCrossOperator),"ALT")}])}),this.RULE("forwardSolidOperator",()=>{this.CONSUME(As)}),this.RULE("backwardSolidOperator",()=>{this.CONSUME(Ir),this.OPTION({GATE:e(()=>this.LA(0).image==="<--"&&this.hasLabeledRight([Ie]),"GATE"),DEF:e(()=>{this.SUBRULE(this.edgeLabel),this.CONSUME(Ie)},"DEF")})}),this.RULE("markerlessSolidOperator",()=>{this.CONSUME(Ie),this.OPTION({GATE:e(()=>this.LA(0).image==="--"&&this.hasLabeledRight([As,Ie,Ss,Rs]),"GATE"),DEF:e(()=>{this.SUBRULE(this.edgeLabel),this.OR([{ALT:e(()=>this.CONSUME(As),"ALT")},{ALT:e(()=>this.CONSUME2(Ie),"ALT")},{ALT:e(()=>this.CONSUME(Ss),"ALT")},{ALT:e(()=>this.CONSUME(Rs),"ALT")}])},"DEF")})}),this.RULE("forwardCircleOperator",()=>{this.CONSUME(Ss)}),this.RULE("backwardCircleOperator",()=>{this.CONSUME(kr),this.OPTION({GATE:e(()=>this.hasLabeledRight([Ie]),"GATE"),DEF:e(()=>{this.SUBRULE(this.edgeLabel),this.CONSUME(Ie)},"DEF")})}),this.RULE("forwardCrossOperator",()=>{this.CONSUME(Rs)}),this.RULE("backwardCrossOperator",()=>{this.CONSUME(Cr),this.OPTION({GATE:e(()=>this.hasLabeledRight([Ie]),"GATE"),DEF:e(()=>{this.SUBRULE(this.edgeLabel),this.CONSUME(Ie)},"DEF")})}),this.RULE("edgeLabel",()=>{this.OR([{ALT:e(()=>this.CONSUME(ke),"ALT")},{ALT:e(()=>this.CONSUME(Be),"ALT")},{ALT:e(()=>this.AT_LEAST_ONE(()=>this.CONSUME(re)),"ALT")}])}),this.RULE("semanticRelation",()=>{this.OR([{ALT:e(()=>{this.CONSUME(yr),this.CONSUME($t),this.OR2([{ALT:e(()=>this.CONSUME(Tr),"ALT")},{ALT:e(()=>this.CONSUME(gr),"ALT")}])},"ALT")},{ALT:e(()=>this.CONSUME(Rr),"ALT")}])}),this.RULE("metadata",()=>{this.CONSUME(pn),this.MANY(()=>this.CONSUME(Fe)),this.OPTION(()=>{this.SUBRULE(this.metadataProperty),this.MANY2(()=>{this.SUBRULE(this.metadataSeparator),this.SUBRULE2(this.metadataProperty)}),this.OPTION2(()=>this.CONSUME(be)),this.MANY3(()=>this.CONSUME2(Fe))}),this.CONSUME(fn)}),this.RULE("metadataProperty",()=>{this.OR([{ALT:e(()=>this.CONSUME(Y),"ALT")},{ALT:e(()=>this.CONSUME(ke),"ALT")}]),this.CONSUME($t),this.OR2([{ALT:e(()=>this.CONSUME2(Y),"ALT")},{ALT:e(()=>this.CONSUME2(ke),"ALT")},{ALT:e(()=>this.CONSUME(Ar),"ALT")},{ALT:e(()=>this.CONSUME(Sr),"ALT")}])}),this.RULE("metadataSeparator",()=>{this.OR([{ALT:e(()=>{this.CONSUME(be),this.MANY(()=>this.CONSUME(Fe))},"ALT")},{ALT:e(()=>{this.AT_LEAST_ONE(()=>this.CONSUME2(Fe)),this.OPTION(()=>this.CONSUME2(be)),this.MANY2(()=>this.CONSUME3(Fe))},"ALT")}])}),this.RULE("systemBoundaryStatement",()=>{this.CONSUME(ir),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(rr),this.SUBRULE2(this.lineEnd)}),this.RULE("systemBoundaryName",()=>{this.OR([{ALT:e(()=>{this.CONSUME(Y),this.OPTION(()=>{this.OR2([{ALT:e(()=>{this.CONSUME(Ft),this.SUBRULE(this.nodeLabel),this.CONSUME(Bt)},"ALT")},{ALT:e(()=>{this.CONSUME(Os),this.SUBRULE2(this.nodeLabel),this.CONSUME(Ls)},"ALT")}])})},"ALT")},{ALT:e(()=>this.CONSUME(ke),"ALT")},{ALT:e(()=>this.CONSUME(Be),"ALT")}])}),this.RULE("systemBoundaryContent",()=>{this.MANY(()=>{this.OR([{ALT:e(()=>this.SUBRULE(this.blankLine),"ALT")},{ALT:e(()=>this.SUBRULE(this.commentLine),"ALT")},{ALT:e(()=>this.SUBRULE(this.boundaryElement),"ALT")}])})}),this.RULE("boundaryElement",()=>{this.OR([{ALT:e(()=>this.SUBRULE(this.actorDeclarationOnly),"ALT")},{ALT:e(()=>{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:e(()=>this.CONSUME(Y),"ALT")},{ALT:e(()=>this.CONSUME(ke),"ALT")},{ALT:e(()=>this.CONSUME(Be),"ALT")}])}),this.RULE("noteStatement",()=>{this.CONSUME(dr),this.CONSUME(pr),this.CONSUME(Y),this.SUBRULE(this.nodeLabel),this.SUBRULE(this.lineEnd)}),this.RULE("stereotype",()=>{this.CONSUME(Or),this.CONSUME(Rn),this.CONSUME(Sn)}),this.RULE("classSuffix",()=>{this.CONSUME(Nr),this.CONSUME(Y),this.MANY(()=>{this.CONSUME(be),this.CONSUME2(Y)})}),this.RULE("jsonStatement",()=>{this.CONSUME(tr),this.CONSUME(An),this.OPTION(()=>this.SUBRULE(this.classSuffix)),this.SUBRULE(this.lineEnd)}),this.RULE("directionStatement",()=>{this.CONSUME(ar),this.OR([{ALT:e(()=>this.CONSUME(or),"ALT")},{ALT:e(()=>this.CONSUME(lr),"ALT")},{ALT:e(()=>this.CONSUME(cr),"ALT")},{ALT:e(()=>this.CONSUME(hr),"ALT")},{ALT:e(()=>this.CONSUME(ur),"ALT")}]),this.SUBRULE(this.lineEnd)}),this.RULE("classDefStatement",()=>{this.CONSUME(fr),this.CONSUME(Y),this.MANY(()=>{this.CONSUME(be),this.CONSUME2(Y)}),this.SUBRULE(this.styles),this.SUBRULE(this.lineEnd)}),this.RULE("classStatement",()=>{this.CONSUME(mr),this.CONSUME(Y),this.MANY(()=>{this.CONSUME(be),this.CONSUME2(Y)}),this.CONSUME3(Y),this.MANY2(()=>{this.CONSUME2(be),this.CONSUME4(Y)}),this.SUBRULE(this.lineEnd)}),this.RULE("styleStatement",()=>{this.CONSUME(Er),this.CONSUME(Y),this.SUBRULE(this.styles),this.SUBRULE(this.lineEnd)}),this.RULE("styles",()=>{this.SUBRULE(this.styleValue),this.MANY(()=>{this.CONSUME(be),this.SUBRULE2(this.styleValue)})}),this.RULE("styleValue",()=>{this.OR([{ALT:e(()=>this.CONSUME(dt),"ALT")},{ALT:e(()=>this.CONSUME(mn),"ALT")},{ALT:e(()=>{this.CONSUME(Ie),this.CONSUME2(dt)},"ALT")}]),this.CONSUME($t),this.AT_LEAST_ONE(()=>this.SUBRULE(this.styleComponent))}),this.RULE("styleComponent",()=>{this.OR([{ALT:e(()=>this.CONSUME(dt),"ALT")},{ALT:e(()=>this.CONSUME(ke),"ALT")},{ALT:e(()=>this.CONSUME(gn),"ALT")},{ALT:e(()=>this.CONSUME(_r),"ALT")},{ALT:e(()=>this.CONSUME(mn),"ALT")},{ALT:e(()=>this.CONSUME(xr),"ALT")},{ALT:e(()=>this.CONSUME(vr),"ALT")},{ALT:e(()=>this.CONSUME(Mr),"ALT")},{ALT:e(()=>this.CONSUME(wr),"ALT")},{ALT:e(()=>this.CONSUME(Ur),"ALT")},{ALT:e(()=>this.CONSUME($t),"ALT")},{ALT:e(()=>this.CONSUME(Ft),"ALT")},{ALT:e(()=>this.CONSUME(Bt),"ALT")},{ALT:e(()=>this.CONSUME(Os),"ALT")},{ALT:e(()=>this.CONSUME(Ls),"ALT")},{ALT:e(()=>this.CONSUME(br),"ALT")},{ALT:e(()=>this.CONSUME(fn),"ALT")},{ALT:e(()=>this.CONSUME(ys),"ALT")},{ALT:e(()=>this.CONSUME(Ie),"ALT")}])}),this.performSelfAnalysis()}isMetadataAssignment(){let t=this.LA(1).tokenType;return(t===Y||t===ke||t===Be)&&this.LA(2).tokenType===pn}isStatementStart(){let t=this.LA(1).tokenType;return t!==Re&&t!==Fe&&t!==un}isForbiddenPlantUmlStatement(){return this.LA(1).tokenType===Y&&vo[this.LA(1).image.toLowerCase()]===!0}hasLabeledRight(t){if(!Gi(this.LA(1)))return!1;for(let s=2;;s++){let n=this.LA(s);if(t.includes(n.tokenType))return!0;if(!Gi(n))return!1}}},Gt=new Mo,Wi=class extends Error{constructor(t,s,n){super(`${t} (line ${s}, column ${n})`);this.line=s,this.column=n,this.name="UsecaseJsonError"}static{e(this,"UsecaseJsonError")}},En=e((t,s,n,i)=>{let r=n,o=i,h=Math.min(Math.max(s,0),t.length);for(let u=0;u<h;u++){let c=t[u];if(c==="\r")r++,o=1;else if(c===`
114
114
  `){if(u===0||t[u-1]!=="\r")r++,o=1}else o++}return{line:r,column:o}},"locationAtOffset"),wo=e((t,s,n,i)=>{let r=/\bposition (\d+)\b/u.exec(t);if(r)return En(s,Number.parseInt(r[1],10),n,i);let o=/\bline (\d+) column (\d+)\b/u.exec(t);if(o){let h=Number.parseInt(o[1],10),u=Number.parseInt(o[2],10);return{line:n+h-1,column:h===1?i+u-1:u}}if(/unexpected end|end of json input/iu.test(t))return En(s,s.length,n,i);return},"locationFromErrorMessage"),ce=class extends Error{constructor(t){super("Invalid JSON token");this.offset=t}static{e(this,"JsonWalkError")}},ji=class{constructor(t){this.text=t,this.offset=0,this.propertyOrder={}}static{e(this,"PropertyOrderCollector")}collect(){if(this.skipWhitespace(),this.collectValue(""),this.skipWhitespace(),this.offset!==this.text.length)throw new ce(this.offset);return this.propertyOrder}collectValue(t){this.skipWhitespace();let s=this.text[this.offset];if(s==="{")this.collectObject(t);else if(s==="[")this.collectArray(t);else if(s==='"')this.readString(!1);else if(s==="t")this.consumeLiteral("true");else if(s==="f")this.consumeLiteral("false");else if(s==="n")this.consumeLiteral("null");else if(s==="-"||s>="0"&&s<="9")this.consumeNumber();else throw new ce(this.offset)}collectObject(t){this.offset++;let s=[],n=new Set;if(this.propertyOrder[t]=s,this.skipWhitespace(),this.text[this.offset]==="}"){this.offset++;return}while(this.offset<this.text.length){if(this.text[this.offset]!=='"')throw new ce(this.offset);let i=this.readString(!0),r=`${t}/${i.replaceAll("~","~0").replaceAll("/","~1")}`;if(n.has(i))this.deletePointerSubtree(r);else n.add(i),s.push(i);if(this.skipWhitespace(),this.text[this.offset]!==":")throw new ce(this.offset);if(this.offset++,this.collectValue(r),this.skipWhitespace(),this.text[this.offset]==="}"){this.offset++;return}if(this.text[this.offset]!==",")throw new ce(this.offset);this.offset++,this.skipWhitespace()}throw new ce(this.offset)}collectArray(t){if(this.offset++,this.skipWhitespace(),this.text[this.offset]==="]"){this.offset++;return}let s=0;while(this.offset<this.text.length){if(this.collectValue(`${t}/${s}`),s++,this.skipWhitespace(),this.text[this.offset]==="]"){this.offset++;return}if(this.text[this.offset]!==",")throw new ce(this.offset);this.offset++,this.skipWhitespace()}throw new ce(this.offset)}readString(t){this.offset++;let s="";while(this.offset<this.text.length){let n=this.offset,i=this.text[this.offset++];if(i==='"')return s;if(i.charCodeAt(0)<32)throw new ce(n);if(i!=="\\"){if(t)s+=i;continue}let r=this.offset,o=this.text[this.offset++];switch(o){case'"':case"\\":case"/":if(t)s+=o;break;case"b":if(t)s+="\b";break;case"f":if(t)s+="\f";break;case"n":if(t)s+=`
115
115
  `;break;case"r":if(t)s+="\r";break;case"t":if(t)s+="\t";break;case"u":{let h=this.text.slice(this.offset,this.offset+4);if(!/^[\dA-Fa-f]{4}$/u.test(h))throw new ce(this.offset);if(t)s+=String.fromCharCode(Number.parseInt(h,16));this.offset+=4;break}default:throw new ce(r)}}throw new ce(this.offset)}consumeLiteral(t){let s=0;for(let n of t){if(this.text[this.offset+s]!==n)throw new ce(this.offset+s);s++}this.offset+=t.length}consumeNumber(){if(this.text[this.offset]==="-")this.offset++;if(this.text[this.offset]==="0")this.offset++;else if(this.text[this.offset]>="1"&&this.text[this.offset]<="9")while(this.text[this.offset]>="0"&&this.text[this.offset]<="9")this.offset++;else throw new ce(this.offset);if(this.text[this.offset]==="."){if(this.offset++,this.text[this.offset]<"0"||this.text[this.offset]>"9")throw new ce(this.offset);while(this.text[this.offset]>="0"&&this.text[this.offset]<="9")this.offset++}if(this.text[this.offset]==="e"||this.text[this.offset]==="E"){if(this.offset++,this.text[this.offset]==="+"||this.text[this.offset]==="-")this.offset++;if(this.text[this.offset]<"0"||this.text[this.offset]>"9")throw new ce(this.offset);while(this.text[this.offset]>="0"&&this.text[this.offset]<="9")this.offset++}}skipWhitespace(){while(this.offset<this.text.length){let t=this.text[this.offset];if(t!==" "&&t!=="\t"&&t!==`
116
- `&&t!=="\r")return;this.offset++}}deletePointerSubtree(t){let s=`${t}/`;for(let n of Object.keys(this.propertyOrder))if(n===t||n.startsWith(s))delete this.propertyOrder[n]}};function Dr(t,s,n){let i;try{i=JSON.parse(t)}catch(r){let o=r instanceof Error?r.message:String(r),h=wo(o,t,s,n);if(!h){let u=0;try{new ji(t).collect()}catch(c){if(c instanceof ce)u=c.offset}h=En(t,u,s,n)}throw new Wi(`Invalid JSON: ${o}`,h.line,h.column)}if(typeof i!=="object"||i===null||Array.isArray(i))throw new Wi("JSON value must have an object root",s,n);return{value:i,propertyOrder:new ji(t).collect()}}e(Dr,"parseOrderedJsonObject");var Uo=e((t)=>({shape:t.type==="normal"?"actor":t.type==="hollow"?"actor-hollow":t.type==="awesome"?"actor-awesome":"actor-icon",...t.label===t.id?{}:{label:t.label},...t.classes.length?{classes:[...t.classes]}:{},...t.styles.length?{styles:[...t.styles]}:{},attrs:{kind:"actor",actorType:t.type,business:t.business,labelType:t.labelType,...t.icon?{icon:t.icon}:{},...t.stereotype?{stereotype:t.stereotype}:{},...t.parentId?{parentId:t.parentId}:{}}}),"actorNode"),Po=e((t)=>({shape:t.shape,...t.label===t.id?{}:{label:t.label},...t.classes.length?{classes:[...t.classes]}:{},...t.styles.length?{styles:[...t.styles]}:{},attrs:{kind:"usecase",useCaseShape:t.shape,business:t.business,labelType:t.labelType,...t.stereotype?{stereotype:t.stereotype}:{},...t.parentId?{parentId:t.parentId}:{}}}),"useCaseNode"),Do=e((t)=>({label:t.label,shape:"note",attrs:{kind:"note",target:t.target,labelType:t.labelType}}),"noteNode"),Fo=e((t)=>({label:t.id,shape:"json-table",...t.classes.length?{classes:[...t.classes]}:{},...t.styles.length?{styles:[...t.styles]}:{},attrs:{kind:"json",value:t.value,propertyOrder:t.propertyOrder,labelType:"text"}}),"jsonNode"),Bo=e((t)=>({id:t.id,source:t.source,target:t.target,...t.label?{label:t.label}:{},...t.classes.length?{classes:[...t.classes]}:{},...t.styles.length?{styles:[...t.styles]}:{},attrs:{relationshipType:t.type,arrowType:t.arrowType,minlen:t.minlen,explicitId:t.explicitId,animate:t.animate,...t.animation?{animation:t.animation}:{},...t.labelType?{labelType:t.labelType}:{}}}),"relationshipEdge"),$o=e((t)=>({id:`${t.id}-edge`,source:t.id,target:t.target,attrs:{relationshipType:"note",arrowType:X.LINE_SOLID,pattern:"dotted",minlen:1,explicitId:!1,animate:!1,internal:!0}}),"noteEdge"),Go=e((t,s,n,i)=>{let r={};for(let c of t.getActors().values())r[c.id]=Uo(c);for(let c of t.getUseCases().values())r[c.id]=Po(c);for(let c of t.getNotes().values())r[c.id]=Do(c);for(let c of t.getJsonNodes().values())r[c.id]=Fo(c);let o={};for(let c of t.getSystemBoundaries().values())o[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}};let h={};for(let c of t.getClassDefs().values())h[c.id]={styles:[...c.styles]};let u=t.getDirection();return{version:1,diagramType:"usecase",source:s,header:{keyword:"usecase",direction:u==="TD"?"TB":u,span:n},...t.getAccTitle()?{accTitle:t.getAccTitle()}:{},...t.getAccDescription()?{accDescr:t.getAccDescription()}:{},nodes:r,edges:[...t.getRelationships().map(Bo),...[...t.getNotes().values()].map($o)],groups:o,classDefs:h,statements:i}},"buildUsecaseGraphAST"),de=e((t)=>`line ${t.line}, column ${t.column} [${t.span[0]},${t.span[1]})`,"locationText"),Ki=e((t)=>t===void 0?"":` (label "${t}")`,"labelSuffix"),Ze=e((t)=>t.generated?t.label:void 0,"generatedFrom"),hn=e((t,s)=>{for(let n of s)if(!t.includes(n))t.push(n)},"pushUnique"),Wo=class{constructor(t){this.db=t,this.source="",this.statements=[],this.elements=[],this.boundaries=[],this.jsonDrafts=[],this.relationshipDrafts=[],this.noteDrafts=[],this.metadataAssignments=[],this.classAssignments=[],this.styleAssignments=[],this.classDefinitions=[],this.directions=[],this.model=t.createModel()}static{e(this,"UsecaseModelBuilder")}reset(t){this.model=this.db.createModel(),this.source=t,this.statements=[],this.elements.length=0,this.boundaries.length=0,this.jsonDrafts.length=0,this.relationshipDrafts.length=0,this.noteDrafts.length=0,this.metadataAssignments.length=0,this.classAssignments.length=0,this.styleAssignments.length=0,this.classDefinitions.length=0,this.directions.length=0}addElement(t){this.elements.push(t)}addBoundary(t){this.boundaries.push(t)}addJson(t){this.jsonDrafts.push(t)}addRelationship(t){this.relationshipDrafts.push(t)}addNote(t){this.noteDrafts.push(t)}addMetadataAssignment(t,s,n,i){this.metadataAssignments.push({target:t,targetLocation:s,metadata:n,statement:i})}addClassDef(t,s){this.classDefinitions.push({ids:t,styles:s})}addClassAssignment(t,s){this.classAssignments.push({targets:t,classes:s})}addStyleAssignment(t,s,n){this.styleAssignments.push({target:t,location:s,styles:n})}setDirection(t){this.directions.push(t==="TD"?"TB":t)}setAccTitle(t){this.model.accTitle=t}setAccDescription(t){this.model.accDescription=t}setStatements(t){this.statements=t}getActors(){return this.model.actors}getUseCases(){return this.model.useCases}getSystemBoundaries(){return this.model.systemBoundaries}getRelationships(){return this.model.relationships}getNotes(){return this.model.notes}getJsonNodes(){return this.model.jsonNodes}getClassDefs(){return this.model.classDefs}getDirection(){return this.model.direction}getAccTitle(){return this.model.accTitle}getAccDescription(){return this.model.accDescription}finalize(t){let s=new Map,n=new Map,i=new Map,r=new Map;for(let c of this.relationshipDrafts)this.recordFirst(r,c.source.id,c.source.location.span[0]),this.recordFirst(r,c.target.id,c.target.location.span[0]);for(let c of this.elements)this.recordFirst(r,c.id,c.location.span[0]);for(let c of this.boundaries)this.recordFirst(r,c.id,c.location.span[0]);for(let c of this.jsonDrafts)this.recordFirst(r,c.id,c.location.span[0]);let o=[...this.elements.map((c)=>({offset:c.location.span[0],type:"element",value:c})),...this.boundaries.map((c)=>({offset:c.location.span[0],type:"boundary",value:c})),...this.jsonDrafts.map((c)=>({offset:c.location.span[0],type:"json",value:c})),...this.relationshipDrafts.filter((c)=>c.explicitId).map((c)=>({offset:c.explicitIdLocation.span[0],type:"edge",value:c}))].sort((c,d)=>c.offset-d.offset);for(let c of o)if(c.type==="element")this.collectElement(c.value,s,n);else if(c.type==="boundary")this.collectBoundary(c.value,s,i);else if(c.type==="json")this.registerUnique(s,c.value.id,"json",c.value.location,!1);else this.registerUnique(s,c.value.explicitId,"edge",c.value.explicitIdLocation,!1);this.materializeElements(n,r),this.materializeBoundaries(i,r),this.materializeJson(r);let h=this.materializeRelationships(s,n,r);this.reorderElements(n,r),this.applyMetadataAssignments(s,n,i,h),this.validateAndRefreshElements(n),this.refreshBoundaries(i,n),this.materializeNotes(s),this.applyClassDefinitions(),this.applyClassesAndStyles(s,h),this.model.direction=this.directions.at(-1)??this.model.direction,this.model.symbols=new Map([...s].map(([c,d])=>[c,d.kind]));let u=Go(this,this.source,t,this.statements);return this.model.ast=u,this.db.commit(this.model),u}collectElement(t,s,n){let i=s.get(t.id),r=Ze({generated:t.generated,label:t.label.text});if(i&&i.kind!==t.kind)this.conflict(`ID '${t.id}' is declared as both ${i.kind} and ${t.kind}`,t.location,i.location,r,Ze(i));if(i&&(i.generated||t.generated))this.conflict(`Generated ID '${t.id}' collides with another declaration`,t.location,i.location,r,Ze(i));let o=n.get(t.id);if(!o){let h={kind:t.kind,id:t.id,label:t.label,location:t.location,generated:t.generated,classes:[...t.classes],...t.parentId?{parentId:t.parentId,parentLocation:t.parentLocation}:{},...t.shape?{shape:t.shape}:{},...t.stereotype?{stereotype:t.stereotype,stereotypeLocation:t.location}:{}};this.applyDeclarationMetadata(h,t.metadata),n.set(t.id,h),s.set(t.id,{kind:t.kind,location:t.location,generated:t.generated,label:t.label.text});return}if(o.label.text!==t.label.text||o.label.type!==t.label.type)this.conflict(`ID '${t.id}' has conflicting labels`,t.location,o.location);if(t.shape&&o.shape&&t.shape!==o.shape)this.conflict(`Use case '${t.id}' has conflicting shapes`,t.location,o.location);if(t.parentId&&o.parentId&&t.parentId!==o.parentId)this.conflict(`Element '${t.id}' belongs to more than one system boundary`,t.parentLocation??t.location,o.parentLocation??o.location);if(t.stereotype&&o.stereotype&&t.stereotype!==o.stereotype)this.conflict(`Element '${t.id}' has conflicting stereotypes`,t.location,o.stereotypeLocation??o.location);o.shape??=t.shape,o.parentId??=t.parentId,o.parentLocation??=t.parentLocation,o.stereotype??=t.stereotype,o.stereotypeLocation??=t.stereotype?t.location:void 0,hn(o.classes,t.classes),this.applyDeclarationMetadata(o,t.metadata)}collectBoundary(t,s,n){let i=s.get(t.id),r=Ze({generated:t.generated,label:t.label.text});if(i&&i.kind!=="boundary")this.conflict(`ID '${t.id}' is declared as both ${i.kind} and boundary`,t.location,i.location,r,Ze(i));if(i&&(i.generated||t.generated))this.conflict(`Generated ID '${t.id}' collides with another declaration`,t.location,i.location,r,Ze(i));let o=n.get(t.id);if(o){if(o.label.text!==t.label.text||o.label.type!==t.label.type)this.conflict(`Boundary '${t.id}' has conflicting titles`,t.location,o.location);hn(o.classes,t.classes);return}n.set(t.id,{id:t.id,label:t.label,location:t.location,generated:t.generated,classes:[...t.classes],styles:[],members:[]}),s.set(t.id,{kind:"boundary",location:t.location,generated:t.generated,label:t.label.text})}materializeElements(t,s){for(let n of[...t.values()].sort((i,r)=>(s.get(i.id)??0)-(s.get(r.id)??0)))this.setElementModel(n)}materializeBoundaries(t,s){for(let n of[...t.values()].sort((i,r)=>(s.get(i.id)??0)-(s.get(r.id)??0)))this.model.systemBoundaries.set(n.id,{id:n.id,label:n.label.text,labelType:n.label.type,type:n.type??"rect",members:[],classes:[...n.classes],styles:[...n.styles]})}materializeJson(t){for(let s of[...this.jsonDrafts].sort((n,i)=>(t.get(n.id)??0)-(t.get(i.id)??0)))this.model.jsonNodes.set(s.id,{id:s.id,value:s.value,propertyOrder:s.propertyOrder,classes:[...s.classes],styles:[]})}materializeRelationships(t,s,n){let i=new Map,r=0;for(let o of this.relationshipDrafts){let h=this.resolveEndpoint(o.source,t,s,n),u=this.resolveEndpoint(o.target,t,s,n);this.validateRelationship(o,h,u,t);let c=o.explicitId??`edge-${r++}`,d={id:c,explicitId:Boolean(o.explicitId),source:o.source.id,target:o.target.id,type:o.type,arrowType:o.arrowType,...o.label?{label:o.label.text,labelType:o.label.type}:{},minlen:o.minlen,classes:[],styles:[],animate:!1};this.model.relationships.push(d),i.set(c,{draft:o,relationship:d})}return this.model.relationshipCounter=r,i}resolveEndpoint(t,s,n,i){if(t.classesOnReference&&!t.declaration)throw Error(`Relationship endpoint '${t.id}' uses ::: without declaring the node at ${de(t.location)}`);let r=s.get(t.id);if(r)return r.kind;return n.set(t.id,{kind:"usecase",id:t.id,label:t.label,location:t.location,generated:t.generated,shape:"ellipse",classes:[]}),s.set(t.id,{kind:"usecase",location:t.location,generated:t.generated,label:t.label.text}),this.recordFirst(i,t.id,t.location.span[0]),"usecase"}reorderElements(t,s){let n=new Map(this.model.actors),i=new Map(this.model.useCases);this.model.actors.clear(),this.model.useCases.clear();for(let r of[...t.values()].sort((o,h)=>(s.get(o.id)??0)-(s.get(h.id)??0))){if(!n.has(r.id)&&!i.has(r.id))this.setElementModel(r);let o=n.get(r.id)??this.model.actors.get(r.id),h=i.get(r.id)??this.model.useCases.get(r.id);if(o)this.model.actors.set(r.id,o);else if(h)this.model.useCases.set(r.id,h)}}applyMetadataAssignments(t,s,n,i){for(let r of this.metadataAssignments){let o=t.get(r.target);if(!o){let h=this.inferMetadataKind(r.metadata);throw Error(`Metadata target '${r.target}' is unresolved${h?` (metadata implies ${h})`:""} at ${de(r.targetLocation)}`)}if(o.kind==="actor"||o.kind==="usecase")this.applyStandaloneElementMetadata(s.get(r.target),r.metadata);else if(o.kind==="boundary"){let h=n.get(r.target);for(let u of r.metadata.properties){if(u.key!=="type"||u.value!=="rect"&&u.value!=="package")this.invalidMetadata(r.target,o.kind,u);h.type=u.value}}else if(o.kind==="edge"){let h=i.get(r.target);if(!h)throw Error(`Metadata target '${r.target}' is not an explicit edge at ${de(r.targetLocation)}`);r.statement.kind="edgeMetadata",r.statement.edges=[{id:r.target,span:r.statement.span,idSpan:r.targetLocation.span,...r.statement.metadata?{metadata:r.statement.metadata}:{}}],delete r.statement.nodes;for(let u of r.metadata.properties)if(u.key==="animate"&&typeof u.value==="boolean")h.relationship.animate=u.value;else if(u.key==="animation"&&(u.value==="fast"||u.value==="slow"))h.relationship.animation=u.value,h.relationship.animate=!0;else this.invalidMetadata(r.target,o.kind,u)}else for(let h of r.metadata.properties)this.invalidMetadata(r.target,o.kind,h)}for(let{relationship:r}of i.values())if(r.animation)r.animate=!0}applyStandaloneElementMetadata(t,s){for(let n of s.properties)if(t.kind==="actor")this.applyActorProperty(t,n,!0);else if(n.key==="business"&&typeof n.value==="boolean")t.business=n.value;else this.invalidMetadata(t.id,t.kind,n)}applyDeclarationMetadata(t,s){if(!s)return;for(let n of s.properties)if(t.kind==="actor")this.applyActorProperty(t,n,!1);else if(n.key==="business"&&typeof n.value==="boolean"){if(t.business!==void 0&&t.business!==n.value)this.conflict(`Use case '${t.id}' has conflicting business metadata`,n.location,t.location);t.business=n.value}else this.invalidMetadata(t.id,t.kind,n)}applyActorProperty(t,s,n){if(s.key==="type"&&(s.value==="normal"||s.value==="hollow"||s.value==="awesome")){if(!n&&t.actorType!==void 0&&t.actorType!==s.value)this.conflict(`Actor '${t.id}' has conflicting type metadata`,s.location,t.location);t.actorType=s.value}else if(s.key==="icon"&&typeof s.value==="string"){if(!n&&t.icon!==void 0&&t.icon!==s.value)this.conflict(`Actor '${t.id}' has conflicting icon metadata`,s.location,t.location);t.icon=s.value}else if(s.key==="business"&&typeof s.value==="boolean"){if(!n&&t.business!==void 0&&t.business!==s.value)this.conflict(`Actor '${t.id}' has conflicting business metadata`,s.location,t.location);t.business=s.value}else this.invalidMetadata(t.id,t.kind,s)}validateAndRefreshElements(t){for(let s of t.values()){let n=s.icon?"icon":s.actorType??"normal";if(s.kind==="actor"){if(s.icon&&s.actorType&&s.actorType!=="normal")throw Error(`Actor '${s.id}' cannot combine icon with type '${s.actorType}' at ${de(s.location)}`);if(s.business&&(n==="icon"||n==="awesome"))throw Error(`Business actor '${s.id}' must use normal or hollow geometry at ${de(s.location)}`)}else if((s.shape??"ellipse")==="rect"&&s.business)throw Error(`Rectangular use case '${s.id}' cannot be a business use case at ${de(s.location)}`);this.setElementModel(s)}}refreshBoundaries(t,s){for(let n of t.values())n.members.length=0;for(let n of[...this.elements].sort((i,r)=>i.location.span[0]-r.location.span[0])){if(!n.parentId)continue;let i=t.get(n.parentId);if(!i)throw Error(`Parent boundary '${n.parentId}' for '${n.id}' is unresolved at ${de(n.parentLocation??n.location)}`);if(!i.members.includes(n.id))i.members.push(n.id)}for(let n of s.values())if(n.parentId&&!t.has(n.parentId))throw Error(`Parent boundary '${n.parentId}' for '${n.id}' is unresolved at ${de(n.parentLocation??n.location)}`);for(let n of t.values()){let i=this.model.systemBoundaries.get(n.id);i.type=n.type??"rect",i.members=[...n.members],i.classes=[...n.classes],i.styles=[...n.styles]}}materializeNotes(t){let s=0;for(let n of this.noteDrafts){let i=t.get(n.target);if(!i)throw Error(`Note target '${n.target}' is unresolved at ${de(n.targetLocation)}`);if(i.kind!=="actor"&&i.kind!=="usecase")this.conflict(`Note target '${n.target}' must be an actor or use case, not ${i.kind}`,n.targetLocation,i.location);let r=`note-${s++}`;this.model.notes.set(r,{id:r,target:n.target,label:n.label.text,labelType:n.label.type})}this.model.noteCounter=s}applyClassDefinitions(){for(let t of this.classDefinitions)for(let s of t.ids)this.model.classDefs.set(s,{id:s,styles:[...t.styles]})}applyClassesAndStyles(t,s){for(let n of this.classAssignments)for(let i of n.targets)hn(this.getStylable(i.id,t,s,i.location).classes,n.classes);for(let n of this.styleAssignments)this.getStylable(n.target,t,s,n.location).styles.push(...n.styles)}getStylable(t,s,n,i){let r=s.get(t)?.kind,o=r==="actor"?this.model.actors.get(t):r==="usecase"?this.model.useCases.get(t):r==="boundary"?this.model.systemBoundaries.get(t):r==="json"?this.model.jsonNodes.get(t):r==="edge"?n.get(t)?.relationship:void 0;if(!o)throw Error(`Class/style target '${t}' is unresolved or anonymous at ${de(i)}`);return o}validateRelationship(t,s,n,i){let r=e((o)=>o==="actor"||o==="usecase"||o==="json","allowed");if(!r(s))this.conflict(`Relationship source '${t.source.id}' cannot be ${s}`,t.source.location,i.get(t.source.id).location);if(!r(n))this.conflict(`Relationship target '${t.target.id}' cannot be ${n}`,t.target.location,i.get(t.target.id).location);if((t.type==="include"||t.type==="extend")&&(s!=="usecase"||n!=="usecase"))throw Error(`${t.type} relationship requires use-case endpoints at ${de(t.location)}`);if(t.type==="generalization"&&(s!=="actor"&&s!=="usecase"||s!==n))throw Error(`Generalization requires actor-to-actor or use-case-to-use-case endpoints at ${de(t.location)}`);if(t.type==="association"&&(s==="json"||n==="json")&&![0,1,2].includes(t.arrowType))throw Error(`JSON relationship '${t.source.id}' to '${t.target.id}' permits only point, reversed-point, or markerless solid association at ${de(t.location)}`)}setElementModel(t){if(t.kind==="actor"){let s=t.icon?"icon":t.actorType??"normal";this.model.useCases.delete(t.id),this.model.actors.set(t.id,{id:t.id,label:t.label.text,labelType:t.label.type,type:s,...t.icon?{icon:t.icon}:{},business:t.business??!1,...t.stereotype?{stereotype:t.stereotype}:{},...t.parentId?{parentId:t.parentId}:{},classes:[...t.classes],styles:this.model.actors.get(t.id)?.styles??[]})}else this.model.actors.delete(t.id),this.model.useCases.set(t.id,{id:t.id,label:t.label.text,labelType:t.label.type,shape:t.shape??"ellipse",business:t.business??!1,...t.stereotype?{stereotype:t.stereotype}:{},...t.parentId?{parentId:t.parentId}:{},classes:[...t.classes],styles:this.model.useCases.get(t.id)?.styles??[]})}inferMetadataKind(t){let s=new Set(["actor","usecase","boundary","edge"]);for(let n of t.properties)if(n.key==="icon")s.clear(),s.add("actor");else if(n.key==="animate"||n.key==="animation")s.clear(),s.add("edge");else if(n.key==="type"){if(s.clear(),n.value==="rect"||n.value==="package")s.add("boundary");else if(n.value==="normal"||n.value==="hollow"||n.value==="awesome")s.add("actor")}else if(n.key==="business")s.delete("boundary"),s.delete("edge");else return;return s.size===1?[...s][0]:void 0}invalidMetadata(t,s,n){throw Error(`Metadata property '${n.key}' is invalid for ${s} '${t}' at ${de(n.location)}`)}registerUnique(t,s,n,i,r){let o=t.get(s);if(o)this.conflict(`ID '${s}' is declared more than once (${o.kind} and ${n})`,i,o.location,void 0,Ze(o));t.set(s,{kind:n,location:i,generated:r})}recordFirst(t,s,n){let i=t.get(s);if(i===void 0||n<i)t.set(s,n)}conflict(t,s,n,i,r){throw Error(`${t} at ${de(s)}${Ki(i)}; previous declaration at ${de(n)}${Ki(r)}`)}},jo=Gt.getBaseCstVisitorConstructor(),Ko=class extends jo{constructor(){super();this.builder=new Wo(Ns),this.source="",this.anonymousEdge=0,this.anonymousNote=0,this.validateVisitor()}static{e(this,"UsecaseVisitor")}build(t,s){this.source=s,this.parentBoundary=void 0,this.anonymousEdge=0,this.anonymousNote=0,this.builder.reset(s),this.visit(t)}start(t){let s=this.tokens(t,"USECASE")[0],n=[];for(let i of this.nodes(t,"line"))n.push(this.visit(i));this.builder.setStatements(n),this.builder.finalize(this.tokenSpan(s))}line(t){let s=this.firstNode(t,"blankLine","commentLine","statement");return this.wrap(s,this.visit(s))}statement(t){return this.visit(this.firstNode(t,"accTitleStatement","accDescrStatement","directionStatement","actorStatement","systemBoundaryStatement","noteStatement","jsonStatement","classDefStatement","classStatement","styleStatement","metadataAssignmentStatement","entityStatement"))}lineEnd(t){return}blankLine(t){return{kind:"blank",span:this.tokenSpan(this.tokens(t,"NEWLINE")[0])}}commentLine(t){return{kind:"comment",span:this.tokenSpan(this.tokens(t,"COMMENT")[0])}}accTitleStatement(t){let s=this.tokens(t,"ACC_TITLE_LINE")[0].image;return this.builder.setAccTitle(s.slice(s.indexOf(":")+1).trim()),{kind:"accTitle",span:[0,0]}}accDescrStatement(t){let s=this.tokens(t,"ACC_DESCR_LINE")[0],n=this.tokens(t,"ACC_DESCR_BLOCK")[0],i=s?s.image.slice(s.image.indexOf(":")+1).trim():n.image.slice(n.image.indexOf("{")+1,n.image.lastIndexOf("}")).trim();return this.builder.setAccDescription(i),{kind:"accDescr",span:[0,0]}}actorStatement(t){let s=this.nodes(t,"actorItem"),n=s.map((c)=>this.visit(c)),i=this.nodes(t,"relationTail")[0],r=n.map((c,d)=>this.actorOccurrence(s[d],c,!0));for(let c of n)this.builder.addElement(this.actorDraft(c));if(!i)return{kind:"node",span:[0,0],nodes:r};let o=this.visit(i);if(o.target.explicitDeclaration)this.builder.addElement(this.entityDraft(o.target));let h=this.relationshipDraft(n[0],o,this.nodeLocation(i));this.builder.addRelationship(h);let u=h.explicitId??`edge-${this.anonymousEdge++}`;return r.push(this.entityOccurrence(this.nodes(i.children,"entityName")[0],o.target,o.target.explicitDeclaration)),{kind:"edge",span:[0,0],nodes:r,edges:[{id:u,span:[0,0],...h.explicitIdLocation?{idSpan:h.explicitIdLocation.span}:{},...h.label?{labelSpan:h.label.span}:{}}]}}actorItem(t){let s=this.visit(this.nodes(t,"actorName")[0]),n=this.nodes(t,"metadata")[0],i=this.nodes(t,"stereotype")[0],r=this.nodes(t,"classSuffix")[0],o=r?this.visit(r):{classes:[],spans:[]};return{...s,...n?{metadata:this.visit(n)}:{},...i?{stereotype:this.visit(i)}:{},classes:o.classes,classSpans:o.spans}}actorName(t){let s=this.tokens(t,"IDENTIFIER")[0],n=this.tokens(t,"PLAIN_STRING")[0]??this.tokens(t,"MARKDOWN_STRING")[0];if(s){let r=this.nodes(t,"nodeLabel")[0],o=r?this.visit(r):this.tokenLabel(s);return{id:s.image,label:o,location:this.tokenLocation(s),generated:!1,classes:[],classSpans:[]}}let i=this.tokenLabel(n);return{id:this.generateId(i.text),label:i,location:this.tokenLocation(n),generated:!0,classes:[],classSpans:[]}}actorDeclarationOnly(t){let s=this.nodes(t,"actorItem"),n=s.map((i)=>this.visit(i));for(let i of n)this.builder.addElement(this.actorDraft(i));return{kind:"node",span:[0,0],nodes:n.map((i,r)=>this.actorOccurrence(s[r],i,!0))}}entityStatement(t){let s=this.nodes(t,"entityName"),n=this.visit(s[0]),i=this.nodes(t,"relationTail")[0];if(!i)return n.explicitDeclaration=!0,n.shape??="ellipse",this.builder.addElement(this.entityDraft(n)),{kind:"node",span:[0,0],nodes:[this.entityOccurrence(s[0],n,!0)]};if(n.explicitDeclaration)this.builder.addElement(this.entityDraft(n));let r=this.visit(i);if(r.target.explicitDeclaration)this.builder.addElement(this.entityDraft(r.target));let o={source:this.endpoint(n),target:this.endpoint(r.target),location:this.nodeLocation(i),...r.explicitId?{explicitId:r.explicitId,explicitIdLocation:r.explicitIdLocation}:{},...r.arrow};this.builder.addRelationship(o);let h=o.explicitId??`edge-${this.anonymousEdge++}`;return{kind:"edge",span:[0,0],nodes:[this.entityOccurrence(s[0],n,n.explicitDeclaration),this.entityOccurrence(this.nodes(i.children,"entityName")[0],r.target,r.target.explicitDeclaration)],edges:[{id:h,span:[0,0],...o.explicitIdLocation?{idSpan:o.explicitIdLocation.span}:{},...o.label?{labelSpan:o.label.span}:{}}]}}entityName(t){let s=this.tokens(t,"IDENTIFIER")[0],n=this.tokens(t,"PLAIN_STRING")[0]??this.tokens(t,"MARKDOWN_STRING")[0],i=this.nodes(t,"nodeLabel")[0],r=this.nodes(t,"useCaseMetadata")[0],o=this.nodes(t,"stereotype")[0],h=this.nodes(t,"classSuffix")[0],u=h?this.visit(h):{classes:[],spans:[]};if(s){let d=i?this.visit(i):this.tokenLabel(s),f=i?this.tokens(t,"LBRACKET").length?"rect":"ellipse":void 0;return{id:s.image,label:d,location:this.tokenLocation(s),generated:!1,...f?{shape:f}:{},...r?{metadata:this.visit(r)}:{},...o?{stereotype:this.visit(o)}:{},classes:u.classes,classSpans:u.spans,explicitDeclaration:Boolean(f||r||o)}}let c=this.tokenLabel(n);return{id:this.generateId(c.text),label:c,location:this.tokenLocation(n),generated:!0,...r?{metadata:this.visit(r)}:{},...o?{stereotype:this.visit(o)}:{},classes:u.classes,classSpans:u.spans,explicitDeclaration:Boolean(r||o)}}nodeLabel(t){let s=this.allTokens(t);if(s.length===1&&(s[0].tokenType.name==="PLAIN_STRING"||s[0].tokenType.name==="MARKDOWN_STRING"))return this.tokenLabel(s[0]);let n=[s[0].startOffset,(s.at(-1).endOffset??s.at(-1).startOffset)+1];return{text:this.source.slice(n[0],n[1]),type:"text",span:n}}useCaseMetadata(t){return this.visit(this.nodes(t,"metadata")[0])}relationTail(t){let s=this.tokens(t,"IDENTIFIER")[0];return{...s?{explicitId:s.image,explicitIdLocation:this.tokenLocation(s)}:{},arrow:this.visit(this.nodes(t,"arrow")[0]),target:this.visit(this.nodes(t,"entityName")[0])}}arrow(t){return this.visit(this.firstNode(t,"semanticRelation","forwardSolidOperator","backwardSolidOperator","markerlessSolidOperator","forwardCircleOperator","backwardCircleOperator","forwardCrossOperator","backwardCrossOperator"))}edgeLabel(t){return this.nodeLabel(t)}semanticRelation(t){if(this.tokens(t,"GENERALIZATION").length)return{type:"generalization",arrowType:X.SOLID_ARROW,minlen:1};let s=this.tokens(t,"INCLUDE").length?"include":"extend",n=this.tokens(t,s==="include"?"INCLUDE":"EXTEND")[0];return{type:s,arrowType:X.SOLID_ARROW,label:{text:s,type:"text",span:this.tokenSpan(n)},minlen:1}}metadata(t){return{properties:this.nodes(t,"metadataProperty").map((s)=>this.visit(s)),location:this.ctxLocation(t)}}metadataProperty(t){let s=this.allTokens(t).filter((h)=>h.tokenType.name!=="COLON"),n=s[0],i=s[1],r=i.tokenType.name==="TRUE"?!0:i.tokenType.name==="FALSE"?!1:this.decodePlain(i),o=[n.startOffset,(i.endOffset??i.startOffset)+1];return{key:this.decodePlain(n),value:r,span:o,keySpan:this.contentSpan(n),valueSpan:this.contentSpan(i),location:this.tokenLocation(n)}}metadataSeparator(t){return}systemBoundaryStatement(t){let s=this.visit(this.nodes(t,"systemBoundaryName")[0]),n=this.nodes(t,"classSuffix")[0],i=n?this.visit(n):{classes:[],spans:[]};s.classes=i.classes,this.builder.addBoundary(s);let r=this.parentBoundary;this.parentBoundary={id:s.id,location:s.location};let o=this.nodes(t,"systemBoundaryContent")[0],h=o?this.visit(o):[];this.parentBoundary=r;let u=this.tokens(t,"END")[0],c=this.nodes(t,"metadata")[0],d=c?this.visit(c):void 0,f={kind:"group",span:[0,0],group:s.id,idSpan:s.location.span,titleSpan:s.label.span,endSpan:this.tokenSpan(u),classSpans:i.spans,...d?{metadata:d.properties.map(({key:m,span:y,keySpan:N,valueSpan:U})=>({key:m,span:y,keySpan:N,valueSpan:U}))}:{},...h.length?{children:h}:{}};if(d)this.builder.addMetadataAssignment(s.id,s.location,d,f);return f}systemBoundaryName(t){let s=this.tokens(t,"IDENTIFIER")[0];if(s){let r=this.nodes(t,"nodeLabel")[0];return{id:s.image,label:r?this.visit(r):this.tokenLabel(s),location:this.tokenLocation(s),generated:!1,classes:[]}}let n=this.tokens(t,"PLAIN_STRING")[0]??this.tokens(t,"MARKDOWN_STRING")[0],i=this.tokenLabel(n);return{id:this.generateId(i.text),label:i,location:this.tokenLocation(n),generated:!0,classes:[]}}systemBoundaryContent(t){return[...this.nodes(t,"blankLine"),...this.nodes(t,"commentLine"),...this.nodes(t,"boundaryElement")].sort((n,i)=>(n.location?.startOffset??0)-(i.location?.startOffset??0)).map((n)=>this.wrap(n,this.visit(n)))}boundaryElement(t){let s=this.nodes(t,"actorDeclarationOnly")[0];if(s)return this.visit(s);let n=this.nodes(t,"entityName")[0],i=this.visit(n);return i.explicitDeclaration=!0,i.shape??="ellipse",this.builder.addElement(this.entityDraft(i)),{kind:"node",span:[0,0],nodes:[this.entityOccurrence(n,i,!0)]}}metadataAssignmentStatement(t){let s=this.visit(this.nodes(t,"metadataAssignmentTarget")[0]),n=this.visit(this.nodes(t,"metadata")[0]),i={kind:"metadata",span:[0,0],nodes:[{id:s.id,span:s.location.span,idSpan:s.location.span}],metadata:n.properties.map(({key:r,span:o,keySpan:h,valueSpan:u})=>({key:r,span:o,keySpan:h,valueSpan:u}))};return this.builder.addMetadataAssignment(s.id,s.location,n,i),i}metadataAssignmentTarget(t){let s=this.allTokens(t)[0],n=this.tokenLabel(s);return{id:s.tokenType.name==="IDENTIFIER"?s.image:this.generateId(n.text),location:this.tokenLocation(s)}}noteStatement(t){let s=this.tokens(t,"IDENTIFIER")[0],n=this.visit(this.nodes(t,"nodeLabel")[0]);return this.builder.addNote({target:s.image,targetLocation:this.tokenLocation(s),label:n,location:this.ctxLocation(t)}),{kind:"note",span:[0,0],ref:`note-${this.anonymousNote++}`,refSpan:n.span,nodes:[{id:s.image,span:this.tokenSpan(s),idSpan:this.tokenSpan(s)}]}}stereotype(t){let s=this.tokens(t,"STEREOTYPE_TEXT")[0];return{value:s.image.trim(),span:this.tokenSpan(s)}}classSuffix(t){let s=this.tokens(t,"IDENTIFIER");return{classes:s.map((n)=>n.image),spans:s.map((n)=>this.tokenSpan(n))}}jsonStatement(t){let s=this.tokens(t,"JSON_DECLARATION_START")[0],n=this.tokens(t,"JSON_OBJECT_LITERAL")[0],i=/^json[\t ]+(\w+)/.exec(s.image),r=i[1],o=i[0].length-r.length,h={span:[s.startOffset+o,s.startOffset+o+r.length],line:s.startLine??1,column:(s.startColumn??1)+o},u=Dr(n.image,n.startLine??1,n.startColumn??1),c=this.nodes(t,"classSuffix")[0],d=c?this.visit(c):{classes:[],spans:[]},f={id:r,value:u.value,propertyOrder:u.propertyOrder,location:h,classes:d.classes};return this.builder.addJson(f),{kind:"json",span:[0,0],nodes:[{id:r,span:h.span,idSpan:h.span,defines:!0,classSpans:d.spans}],classSpans:d.spans}}directionStatement(t){let s=this.allTokens(t).find((n)=>["TD","TB","BT","RL","LR"].includes(n.tokenType.name));return this.builder.setDirection(s.image),{kind:"direction",span:[0,0]}}classDefStatement(t){let s=this.tokens(t,"IDENTIFIER"),n=this.visit(this.nodes(t,"styles")[0]);return this.builder.addClassDef(s.map((i)=>i.image),n),{kind:"classDef",span:[0,0],ref:s[0].image,refSpan:this.tokenSpan(s[0])}}classStatement(t){let s=this.tokens(t,"IDENTIFIER"),n=1;for(;n<s.length;n++)if(!this.source.slice((s[n-1].endOffset??s[n-1].startOffset)+1,s[n].startOffset).includes(","))break;let i=s.slice(0,n).map((o)=>({id:o.image,location:this.tokenLocation(o)})),r=s.slice(n).map((o)=>o.image);return this.builder.addClassAssignment(i,r),{kind:"classAssign",span:[0,0],ref:r[0],refSpan:this.tokenSpan(s[n]),nodes:i.map(({id:o,location:h})=>({id:o,span:h.span,idSpan:h.span}))}}styleStatement(t){let s=this.tokens(t,"IDENTIFIER")[0],n=this.visit(this.nodes(t,"styles")[0]);return this.builder.addStyleAssignment(s.image,this.tokenLocation(s),n),{kind:"style",span:[0,0],nodes:[{id:s.image,span:this.tokenSpan(s),idSpan:this.tokenSpan(s)}]}}styles(t){return this.nodes(t,"styleValue").map((s)=>this.visit(s))}styleValue(t){let s=this.allTokens(t),n=[s[0].startOffset,(s.at(-1).endOffset??s.at(-1).startOffset)+1];return this.source.slice(n[0],n[1]).replaceAll("\\,",",")}styleComponent(t){return this.allTokens(t).map((s)=>s.image).join("")}forwardSolidOperator(t){let s=this.tokens(t,"FORWARD_SOLID")[0];return{type:"association",arrowType:X.SOLID_ARROW,minlen:this.solidMinlen(s)}}backwardSolidOperator(t){let s=this.tokens(t,"BACKWARD_SOLID")[0],n=this.nodes(t,"edgeLabel")[0],i=n?this.tokens(t,"MARKERLESS_SOLID").at(-1):s;return{type:"association",arrowType:X.BACK_ARROW,minlen:this.solidMinlen(i),...n?{label:this.visit(n)}:{}}}markerlessSolidOperator(t){let s=this.nodes(t,"edgeLabel")[0],n=this.allTokens(t);if(!s)return{type:"association",arrowType:X.LINE_SOLID,minlen:this.solidMinlen(this.tokens(t,"MARKERLESS_SOLID")[0])};let i=n.at(-1),r=i.tokenType.name==="FORWARD_SOLID"?X.SOLID_ARROW:i.tokenType.name==="FORWARD_CIRCLE"?X.CIRCLE_ARROW:i.tokenType.name==="FORWARD_CROSS"?X.CROSS_ARROW:X.LINE_SOLID;return{type:"association",arrowType:r,label:this.visit(s),minlen:r===X.SOLID_ARROW||r===X.LINE_SOLID?this.solidMinlen(i):1}}forwardCircleOperator(t){return{type:"association",arrowType:X.CIRCLE_ARROW,minlen:1}}backwardCircleOperator(t){let s=this.nodes(t,"edgeLabel")[0];return{type:"association",arrowType:X.CIRCLE_ARROW_REVERSED,minlen:1,...s?{label:this.visit(s)}:{}}}forwardCrossOperator(t){return{type:"association",arrowType:X.CROSS_ARROW,minlen:1}}backwardCrossOperator(t){let s=this.nodes(t,"edgeLabel")[0];return{type:"association",arrowType:X.CROSS_ARROW_REVERSED,minlen:1,...s?{label:this.visit(s)}:{}}}actorDraft(t){return{id:t.id,kind:"actor",label:t.label,location:t.location,generated:t.generated,...this.parentBoundary?{parentId:this.parentBoundary.id,parentLocation:this.parentBoundary.location}:{},...t.metadata?{metadata:t.metadata}:{},...t.stereotype?{stereotype:t.stereotype.value,stereotypeSpan:t.stereotype.span}:{},classes:t.classes}}entityDraft(t){return{id:t.id,kind:"usecase",label:t.label,location:t.location,generated:t.generated,...this.parentBoundary?{parentId:this.parentBoundary.id,parentLocation:this.parentBoundary.location}:{},...t.shape?{shape:t.shape}:{},...t.metadata?{metadata:t.metadata}:{},...t.stereotype?{stereotype:t.stereotype.value,stereotypeSpan:t.stereotype.span}:{},classes:t.classes}}endpoint(t,s=t.explicitDeclaration??!0){return{id:t.id,label:t.label,location:t.location,generated:t.generated,declaration:s,classesOnReference:t.classes.length>0}}relationshipDraft(t,s,n){return{source:this.endpoint(t,!0),target:this.endpoint(s.target),location:n,...s.explicitId?{explicitId:s.explicitId,explicitIdLocation:s.explicitIdLocation}:{},...s.arrow}}actorOccurrence(t,s,n){return{id:s.id,span:this.nodeSpan(t),idSpan:s.location.span,labelSpan:s.label.span,...n?{defines:!0}:{},...s.stereotype?{stereotypeSpan:s.stereotype.span}:{},...s.metadata?{metadata:s.metadata.properties.map(({key:i,span:r,keySpan:o,valueSpan:h})=>({key:i,span:r,keySpan:o,valueSpan:h}))}:{},...s.classSpans.length?{classSpans:s.classSpans}:{}}}entityOccurrence(t,s,n){return this.actorOccurrence(t,s,n)}wrap(t,s){if(s.kind==="blank"||s.kind==="comment")return s;s.span=this.nodeSpan(t);for(let n of s.edges??[])n.span=s.span;return s}tokenLabel(t){let s=t.tokenType.name==="MARKDOWN_STRING"?"markdown":"text",n=s==="markdown"?2:t.tokenType.name==="PLAIN_STRING"?1:0,i=this.tokenSpan(t,n);return{text:this.source.slice(i[0],i[1]),type:s,span:i}}decodePlain(t){return t.tokenType.name==="PLAIN_STRING"?t.image.slice(1,-1):t.image}contentSpan(t){return this.tokenSpan(t,t.tokenType.name==="PLAIN_STRING"?1:t.tokenType.name==="MARKDOWN_STRING"?2:0)}generateId(t){return t.replace(/\W/g,"_")}solidMinlen(t){return Math.max(1,(t.image.match(/-/g)?.length??2)-1)}nodeLocation(t){let s=this.allTokens(t.children)[0];return{span:this.nodeSpan(t),line:s.startLine??1,column:s.startColumn??1}}ctxLocation(t){let s=this.allTokens(t).filter((r)=>r.tokenType.name!=="NEWLINE"&&r.tokenType.name!=="EOF"),n=s[0],i=s.at(-1);return{span:[n.startOffset,Math.min(this.source.length,(i.endOffset??i.startOffset+i.image.length-1)+1)],line:n.startLine??1,column:n.startColumn??1}}tokenLocation(t){let s=t.tokenType.name==="PLAIN_STRING"?1:t.tokenType.name==="MARKDOWN_STRING"?2:0;return{span:this.tokenSpan(t,s),line:t.startLine??1,column:(t.startColumn??1)+s}}nodeSpan(t){let s=this.allTokens(t.children).filter((r)=>r.tokenType.name!=="NEWLINE"&&r.tokenType.name!=="EOF"),n=s[0],i=s.at(-1);if(!n||!i)throw Error("Usecase CST node has no source token");return[n.startOffset,Math.min(this.source.length,(i.endOffset??i.startOffset+i.image.length-1)+1)]}tokenSpan(t,s=0){return[t.startOffset+s,Math.min(this.source.length,(t.endOffset??t.startOffset+t.image.length-1)+1-s)]}nodes(t,s){return(t[s]??[]).filter((n)=>("children"in n))}tokens(t,s){return(t[s]??[]).filter((n)=>("tokenTypeIdx"in n))}firstNode(t,...s){for(let n of s){let i=this.nodes(t,n)[0];if(i)return i}throw Error(`Usecase CST is missing one of: ${s.join(", ")}`)}allTokens(t){let s=[];for(let n of Object.values(t))for(let i of n)if("tokenTypeIdx"in i)s.push(i);else s.push(...this.allTokens(i.children));return s.sort((n,i)=>n.startOffset-i.startOffset)}},Vo=new Ko,zo={parse:e(async(t)=>{Ns.clear(),Gt.input=[];try{Xi({diagramType:"usecase",lexer:xo,parser:Gt,entry:e(()=>Gt.start(),"entry"),visit:e((s)=>Vo.build(s,t),"visit")},t)}catch(s){Ns.clear();let n=Gt.errors[0];if(n){let{token:i}=n,r=dt(i.startOffset)?i.startOffset:t.length,o=dt(i.endOffset)?i.endOffset+1:r,h=dt(i.startLine)?i.startLine:t.slice(0,r).split(/\r\n|\r|\n/).length,u=Math.max(t.lastIndexOf(`
117
- `,r-1),t.lastIndexOf("\r",r-1)),c=dt(i.startColumn)?i.startColumn:r-u,d=s instanceof Error?s.message:String(s);throw Error(`${d} at line ${h}, column ${c} [${r},${o})`)}throw s}},"parse")},Ho=["point","circle","cross","extension"],Fr={usecaseActor:!0,usecaseActorHollow:!0,usecaseActorAwesome:!0,usecaseActorIcon:!0},Vi=e((t,s)=>{let[n,i]=[t,s].map((r)=>r.replace(/[^\w-]+/g,"_").replace(/^_+|_+$/g,"")||"element");return`usecase-${n}-${i}`},"usecaseDomId"),Xo=e((t)=>`usecase-${t.replace(/[^\w-]+/g,"_").replace(/^_+|_+$/g,"")||"element"}`,"usecaseNodeDomId"),Is=e((t,s)=>{if(s!=="markdown")return t;return ni(t).map((n)=>n.map((i)=>i.content).join(" ")).join(`
118
- `)},"getAccessibleLabel"),Yo=e((t)=>{let s=Is(t.label??t.id,t.labelType);if(Fr[t.shape]){let i=t.actorType&&t.actorType!=="normal"?`${t.actorType} `:"",r=t.business?"business ":"",o=t.stereotype?`, stereotype ${t.stereotype}`:"";return`${r}${i}actor ${s}${o}`}if(t.shape==="note")return`Note for ${t.noteTargetLabel??t.noteTarget??""}: ${s}`;if(t.shape==="usecaseJsonTable"){let i=(t.jsonRows??[]).map((r)=>`${r.accessibleKey}: ${r.value}`).join("; ");return i?`${s}: ${i}`:s}let n=t.stereotype?`, stereotype ${t.stereotype}`:"";return`${t.business?"business ":""}use case ${s}${n}`},"getUsecaseNodeAccessibleName"),qo=e((t)=>`${t.boundaryType} system boundary ${Is(t.label??t.id,t.labelType)}`,"getUsecaseBoundaryAccessibleName"),Jo=e((t)=>{if(t.relationshipType==="note")return"";return`${t.relationshipType==="association"&&t.label?`association ${Is(t.label,t.labelType)}`:t.relationshipType} from ${t.sourceLabel} to ${t.targetLabel}`},"getUsecaseEdgeAccessibleName"),ut=e((t)=>t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;"),"escapePlainLabel"),zi=e((t)=>t.replace(/([*[\\\]_`])/g,"\\$1"),"escapeMarkdownMarkers"),Zo=e((t,s)=>{t.diagramId=s,t.markers=[...Ho];for(let n of t.nodes){let i=n;if(i.domId=Xo(n.id),n.label!==void 0&&n.labelType==="text")n.label=ut(n.label);if(n.stereotype)n.stereotype=ut(n.stereotype);if(!n.isGroup&&n.shape==="usecaseJsonTable")n.jsonRows=n.jsonRows?.map((r)=>({...r,key:ut(r.key),value:ut(r.value)}));if(!n.isGroup&&(n.shape==="usecaseEllipse"||n.shape==="rect")&&n.stereotype){let r=n.label??ut(n.id);n.label=`«${zi(n.stereotype)}»<br/>${n.labelType==="text"?zi(r):r}`,n.labelType="markdown",i.hasFoldedStereotype=!0,delete n.stereotype}}for(let n of t.edges)if(n.label!==void 0&&n.labelType==="text")n.label=ut(n.label);return t},"prepareUsecaseLayoutData"),Qo=e((t,s,n)=>{for(let r of s.nodes){let o=typeof r.domId==="string"?r.domId:Vi(s.diagramId,r.id),h=t.select(`#${o}`),u=r.isGroup?"boundary":Fr[r.shape]?"actor":r.shape==="note"?"note":r.shape==="usecaseJsonTable"?"json":"usecase",c=n.nodes.get(r.id)??r.id;if(h.attr("data-usecase-id",r.id).attr("data-usecase-kind",u).attr("role","img").attr("aria-label",c),!r.isGroup&&(r.shape==="usecaseEllipse"||r.shape==="rect")&&"hasFoldedStereotype"in r&&r.hasFoldedStereotype===!0){let d=h.node(),f=d?.querySelector(".nodeLabel"),m=f?.querySelector("p")??f,y=m?.firstChild;if(m&&y?.nodeType===3){let N=m.ownerDocument.createElement("span");N.className="usecase-stereotype",m.insertBefore(N,y),N.appendChild(y)}else d?.querySelector(".label tspan tspan, .label tspan")?.classList.add("usecase-stereotype")}}let i=new Map(s.edges.map((r)=>[r.id,r]));t.selectAll('path[data-et="edge"]').each(function(){let r=i.get(this.getAttribute("data-id")??"");if(!r)return;let o=p(this);if(o.attr("id",Vi(s.diagramId,r.id)).attr("data-usecase-id",r.id).attr("data-usecase-kind",r.internal?"note-connector":"relationship"),r.internal)o.attr("aria-hidden","true");else o.attr("role","img").attr("aria-label",n.edges.get(r.id)??r.id)})},"annotateUsecaseElements"),Hi=e((t,s)=>{t.style("--mermaid-usecase-actor-font-size",`${s.actorFontSize}px`).style("--mermaid-usecase-actor-font-family",s.actorFontFamily).style("--mermaid-usecase-actor-font-weight",s.actorFontWeight).style("--mermaid-usecase-font-size",`${s.usecaseFontSize}px`).style("--mermaid-usecase-font-family",s.usecaseFontFamily).style("--mermaid-usecase-font-weight",s.usecaseFontWeight)},"applyUsecaseFonts"),el=e(async(t,s,n,i)=>{a.info("Drawing usecase diagram (unified)",s);let{layout:r}=l(),o=i.db,h=o.getData(),u=new Map(h.nodes.map((m)=>[m.id,Is(m.label??m.id,m.labelType)])),c={nodes:new Map(h.nodes.map((m)=>[m.id,m.isGroup?qo(m):Yo(m.shape==="note"?{...m,noteTargetLabel:u.get(m.noteTarget??"")}:m)])),edges:new Map(h.edges.map((m)=>[m.id,Jo({...m,sourceLabel:u.get(m.source)??m.sourceLabel,targetLabel:u.get(m.target)??m.targetLabel})]))},d=ge(s,h.config.securityLevel);h.layoutAlgorithm=ve(r),Zo(h,s),Hi(d,h),await ye(h,d),Qo(d,h,c);let f=h.diagramPadding;M.insertTitle(d,"usecaseDiagramTitleText",0,o.getDiagramTitle?.()??""),le(d,f,"usecaseDiagram",h.useMaxWidth),Hi(d,h)},"draw"),tl={draw:el},sl=e((t)=>({actorBkg:t.usecaseActorBkg??t.actorBkg??t.mainBkg,actorBorder:t.usecaseActorBorder??t.actorBorder??t.primaryColor,bkg:t.usecaseBkg??t.mainBkg,border:t.usecaseBorder??t.nodeBorder??t.primaryColor,boundaryBkg:t.usecaseBoundaryBkg??t.clusterBkg,boundaryBorder:t.usecaseBoundaryBorder??t.clusterBorder,includeLine:t.usecaseIncludeLine??t.lineColor,extendLine:t.usecaseExtendLine??t.lineColor}),"roleColors"),nl=e((t)=>{let{theme:s,bkgColorArray:n,borderColorArray:i}=t;if(!oe(s,i))return"";let r=b().usecase?.colorScheme==="rotate",o=se(t.look),h=o==="handDrawn",u=ue(n),c="";for(let d=0;d<ht(i);d++){let f=i[d],m=u?`fill: ${n[d%n.length]};`:"",y=`[data-look="${o}"][data-color-id="color-${d}"]`;if(c+=`
116
+ `&&t!=="\r")return;this.offset++}}deletePointerSubtree(t){let s=`${t}/`;for(let n of Object.keys(this.propertyOrder))if(n===t||n.startsWith(s))delete this.propertyOrder[n]}};function Dr(t,s,n){let i;try{i=JSON.parse(t)}catch(r){let o=r instanceof Error?r.message:String(r),h=wo(o,t,s,n);if(!h){let u=0;try{new ji(t).collect()}catch(c){if(c instanceof ce)u=c.offset}h=En(t,u,s,n)}throw new Wi(`Invalid JSON: ${o}`,h.line,h.column)}if(typeof i!=="object"||i===null||Array.isArray(i))throw new Wi("JSON value must have an object root",s,n);return{value:i,propertyOrder:new ji(t).collect()}}e(Dr,"parseOrderedJsonObject");var Uo=e((t)=>({shape:t.type==="normal"?"actor":t.type==="hollow"?"actor-hollow":t.type==="awesome"?"actor-awesome":"actor-icon",...t.label===t.id?{}:{label:t.label},...t.classes.length?{classes:[...t.classes]}:{},...t.styles.length?{styles:[...t.styles]}:{},attrs:{kind:"actor",actorType:t.type,business:t.business,labelType:t.labelType,...t.icon?{icon:t.icon}:{},...t.stereotype?{stereotype:t.stereotype}:{},...t.parentId?{parentId:t.parentId}:{}}}),"actorNode"),Po=e((t)=>({shape:t.shape,...t.label===t.id?{}:{label:t.label},...t.classes.length?{classes:[...t.classes]}:{},...t.styles.length?{styles:[...t.styles]}:{},attrs:{kind:"usecase",useCaseShape:t.shape,business:t.business,labelType:t.labelType,...t.stereotype?{stereotype:t.stereotype}:{},...t.parentId?{parentId:t.parentId}:{}}}),"useCaseNode"),Do=e((t)=>({label:t.label,shape:"note",attrs:{kind:"note",target:t.target,labelType:t.labelType}}),"noteNode"),Fo=e((t)=>({label:t.id,shape:"json-table",...t.classes.length?{classes:[...t.classes]}:{},...t.styles.length?{styles:[...t.styles]}:{},attrs:{kind:"json",value:t.value,propertyOrder:t.propertyOrder,labelType:"text"}}),"jsonNode"),Bo=e((t)=>({id:t.id,source:t.source,target:t.target,...t.label?{label:t.label}:{},...t.classes.length?{classes:[...t.classes]}:{},...t.styles.length?{styles:[...t.styles]}:{},attrs:{relationshipType:t.type,arrowType:t.arrowType,minlen:t.minlen,explicitId:t.explicitId,animate:t.animate,...t.animation?{animation:t.animation}:{},...t.labelType?{labelType:t.labelType}:{}}}),"relationshipEdge"),$o=e((t)=>({id:`${t.id}-edge`,source:t.id,target:t.target,attrs:{relationshipType:"note",arrowType:X.LINE_SOLID,pattern:"dotted",minlen:1,explicitId:!1,animate:!1,internal:!0}}),"noteEdge"),Go=e((t,s,n,i)=>{let r={};for(let c of t.getActors().values())r[c.id]=Uo(c);for(let c of t.getUseCases().values())r[c.id]=Po(c);for(let c of t.getNotes().values())r[c.id]=Do(c);for(let c of t.getJsonNodes().values())r[c.id]=Fo(c);let o={};for(let c of t.getSystemBoundaries().values())o[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}};let h={};for(let c of t.getClassDefs().values())h[c.id]={styles:[...c.styles]};let u=t.getDirection();return{version:1,diagramType:"usecase",source:s,header:{keyword:"usecase",direction:u==="TD"?"TB":u,span:n},...t.getAccTitle()?{accTitle:t.getAccTitle()}:{},...t.getAccDescription()?{accDescr:t.getAccDescription()}:{},nodes:r,edges:[...t.getRelationships().map(Bo),...[...t.getNotes().values()].map($o)],groups:o,classDefs:h,statements:i}},"buildUsecaseGraphAST"),pe=e((t)=>`line ${t.line}, column ${t.column} [${t.span[0]},${t.span[1]})`,"locationText"),Ki=e((t)=>t===void 0?"":` (label "${t}")`,"labelSuffix"),Ze=e((t)=>t.generated?t.label:void 0,"generatedFrom"),hn=e((t,s)=>{for(let n of s)if(!t.includes(n))t.push(n)},"pushUnique"),Wo=class{constructor(t){this.db=t,this.source="",this.statements=[],this.elements=[],this.boundaries=[],this.jsonDrafts=[],this.relationshipDrafts=[],this.noteDrafts=[],this.metadataAssignments=[],this.classAssignments=[],this.styleAssignments=[],this.classDefinitions=[],this.directions=[],this.model=t.createModel()}static{e(this,"UsecaseModelBuilder")}reset(t){this.model=this.db.createModel(),this.source=t,this.statements=[],this.elements.length=0,this.boundaries.length=0,this.jsonDrafts.length=0,this.relationshipDrafts.length=0,this.noteDrafts.length=0,this.metadataAssignments.length=0,this.classAssignments.length=0,this.styleAssignments.length=0,this.classDefinitions.length=0,this.directions.length=0}addElement(t){this.elements.push(t)}addBoundary(t){this.boundaries.push(t)}addJson(t){this.jsonDrafts.push(t)}addRelationship(t){this.relationshipDrafts.push(t)}addNote(t){this.noteDrafts.push(t)}addMetadataAssignment(t,s,n,i){this.metadataAssignments.push({target:t,targetLocation:s,metadata:n,statement:i})}addClassDef(t,s){this.classDefinitions.push({ids:t,styles:s})}addClassAssignment(t,s){this.classAssignments.push({targets:t,classes:s})}addStyleAssignment(t,s,n){this.styleAssignments.push({target:t,location:s,styles:n})}setDirection(t){this.directions.push(t==="TD"?"TB":t)}setAccTitle(t){this.model.accTitle=t}setAccDescription(t){this.model.accDescription=t}setStatements(t){this.statements=t}getActors(){return this.model.actors}getUseCases(){return this.model.useCases}getSystemBoundaries(){return this.model.systemBoundaries}getRelationships(){return this.model.relationships}getNotes(){return this.model.notes}getJsonNodes(){return this.model.jsonNodes}getClassDefs(){return this.model.classDefs}getDirection(){return this.model.direction}getAccTitle(){return this.model.accTitle}getAccDescription(){return this.model.accDescription}finalize(t){let s=new Map,n=new Map,i=new Map,r=new Map;for(let c of this.relationshipDrafts)this.recordFirst(r,c.source.id,c.source.location.span[0]),this.recordFirst(r,c.target.id,c.target.location.span[0]);for(let c of this.elements)this.recordFirst(r,c.id,c.location.span[0]);for(let c of this.boundaries)this.recordFirst(r,c.id,c.location.span[0]);for(let c of this.jsonDrafts)this.recordFirst(r,c.id,c.location.span[0]);let o=[...this.elements.map((c)=>({offset:c.location.span[0],type:"element",value:c})),...this.boundaries.map((c)=>({offset:c.location.span[0],type:"boundary",value:c})),...this.jsonDrafts.map((c)=>({offset:c.location.span[0],type:"json",value:c})),...this.relationshipDrafts.filter((c)=>c.explicitId).map((c)=>({offset:c.explicitIdLocation.span[0],type:"edge",value:c}))].sort((c,d)=>c.offset-d.offset);for(let c of o)if(c.type==="element")this.collectElement(c.value,s,n);else if(c.type==="boundary")this.collectBoundary(c.value,s,i);else if(c.type==="json")this.registerUnique(s,c.value.id,"json",c.value.location,!1);else this.registerUnique(s,c.value.explicitId,"edge",c.value.explicitIdLocation,!1);this.materializeElements(n,r),this.materializeBoundaries(i,r),this.materializeJson(r);let h=this.materializeRelationships(s,n,r);this.reorderElements(n,r),this.applyMetadataAssignments(s,n,i,h),this.validateAndRefreshElements(n),this.refreshBoundaries(i,n),this.materializeNotes(s),this.applyClassDefinitions(),this.applyClassesAndStyles(s,h),this.model.direction=this.directions.at(-1)??this.model.direction,this.model.symbols=new Map([...s].map(([c,d])=>[c,d.kind]));let u=Go(this,this.source,t,this.statements);return this.model.ast=u,this.db.commit(this.model),u}collectElement(t,s,n){let i=s.get(t.id),r=Ze({generated:t.generated,label:t.label.text});if(i&&i.kind!==t.kind)this.conflict(`ID '${t.id}' is declared as both ${i.kind} and ${t.kind}`,t.location,i.location,r,Ze(i));if(i&&(i.generated||t.generated))this.conflict(`Generated ID '${t.id}' collides with another declaration`,t.location,i.location,r,Ze(i));let o=n.get(t.id);if(!o){let h={kind:t.kind,id:t.id,label:t.label,location:t.location,generated:t.generated,classes:[...t.classes],...t.parentId?{parentId:t.parentId,parentLocation:t.parentLocation}:{},...t.shape?{shape:t.shape}:{},...t.stereotype?{stereotype:t.stereotype,stereotypeLocation:t.location}:{}};this.applyDeclarationMetadata(h,t.metadata),n.set(t.id,h),s.set(t.id,{kind:t.kind,location:t.location,generated:t.generated,label:t.label.text});return}if(o.label.text!==t.label.text||o.label.type!==t.label.type)this.conflict(`ID '${t.id}' has conflicting labels`,t.location,o.location);if(t.shape&&o.shape&&t.shape!==o.shape)this.conflict(`Use case '${t.id}' has conflicting shapes`,t.location,o.location);if(t.parentId&&o.parentId&&t.parentId!==o.parentId)this.conflict(`Element '${t.id}' belongs to more than one system boundary`,t.parentLocation??t.location,o.parentLocation??o.location);if(t.stereotype&&o.stereotype&&t.stereotype!==o.stereotype)this.conflict(`Element '${t.id}' has conflicting stereotypes`,t.location,o.stereotypeLocation??o.location);o.shape??=t.shape,o.parentId??=t.parentId,o.parentLocation??=t.parentLocation,o.stereotype??=t.stereotype,o.stereotypeLocation??=t.stereotype?t.location:void 0,hn(o.classes,t.classes),this.applyDeclarationMetadata(o,t.metadata)}collectBoundary(t,s,n){let i=s.get(t.id),r=Ze({generated:t.generated,label:t.label.text});if(i&&i.kind!=="boundary")this.conflict(`ID '${t.id}' is declared as both ${i.kind} and boundary`,t.location,i.location,r,Ze(i));if(i&&(i.generated||t.generated))this.conflict(`Generated ID '${t.id}' collides with another declaration`,t.location,i.location,r,Ze(i));let o=n.get(t.id);if(o){if(o.label.text!==t.label.text||o.label.type!==t.label.type)this.conflict(`Boundary '${t.id}' has conflicting titles`,t.location,o.location);hn(o.classes,t.classes);return}n.set(t.id,{id:t.id,label:t.label,location:t.location,generated:t.generated,classes:[...t.classes],styles:[],members:[]}),s.set(t.id,{kind:"boundary",location:t.location,generated:t.generated,label:t.label.text})}materializeElements(t,s){for(let n of[...t.values()].sort((i,r)=>(s.get(i.id)??0)-(s.get(r.id)??0)))this.setElementModel(n)}materializeBoundaries(t,s){for(let n of[...t.values()].sort((i,r)=>(s.get(i.id)??0)-(s.get(r.id)??0)))this.model.systemBoundaries.set(n.id,{id:n.id,label:n.label.text,labelType:n.label.type,type:n.type??"rect",members:[],classes:[...n.classes],styles:[...n.styles]})}materializeJson(t){for(let s of[...this.jsonDrafts].sort((n,i)=>(t.get(n.id)??0)-(t.get(i.id)??0)))this.model.jsonNodes.set(s.id,{id:s.id,value:s.value,propertyOrder:s.propertyOrder,classes:[...s.classes],styles:[]})}materializeRelationships(t,s,n){let i=new Map,r=0;for(let o of this.relationshipDrafts){let h=this.resolveEndpoint(o.source,t,s,n),u=this.resolveEndpoint(o.target,t,s,n);this.validateRelationship(o,h,u,t);let c=o.explicitId??`edge-${r++}`,d={id:c,explicitId:Boolean(o.explicitId),source:o.source.id,target:o.target.id,type:o.type,arrowType:o.arrowType,...o.label?{label:o.label.text,labelType:o.label.type}:{},minlen:o.minlen,classes:[],styles:[],animate:!1};this.model.relationships.push(d),i.set(c,{draft:o,relationship:d})}return this.model.relationshipCounter=r,i}resolveEndpoint(t,s,n,i){if(t.classesOnReference&&!t.declaration)throw Error(`Relationship endpoint '${t.id}' uses ::: without declaring the node at ${pe(t.location)}`);let r=s.get(t.id);if(r)return r.kind;return n.set(t.id,{kind:"usecase",id:t.id,label:t.label,location:t.location,generated:t.generated,shape:"ellipse",classes:[]}),s.set(t.id,{kind:"usecase",location:t.location,generated:t.generated,label:t.label.text}),this.recordFirst(i,t.id,t.location.span[0]),"usecase"}reorderElements(t,s){let n=new Map(this.model.actors),i=new Map(this.model.useCases);this.model.actors.clear(),this.model.useCases.clear();for(let r of[...t.values()].sort((o,h)=>(s.get(o.id)??0)-(s.get(h.id)??0))){if(!n.has(r.id)&&!i.has(r.id))this.setElementModel(r);let o=n.get(r.id)??this.model.actors.get(r.id),h=i.get(r.id)??this.model.useCases.get(r.id);if(o)this.model.actors.set(r.id,o);else if(h)this.model.useCases.set(r.id,h)}}applyMetadataAssignments(t,s,n,i){for(let r of this.metadataAssignments){let o=t.get(r.target);if(!o){let h=this.inferMetadataKind(r.metadata);throw Error(`Metadata target '${r.target}' is unresolved${h?` (metadata implies ${h})`:""} at ${pe(r.targetLocation)}`)}if(o.kind==="actor"||o.kind==="usecase")this.applyStandaloneElementMetadata(s.get(r.target),r.metadata);else if(o.kind==="boundary"){let h=n.get(r.target);for(let u of r.metadata.properties){if(u.key!=="type"||u.value!=="rect"&&u.value!=="package")this.invalidMetadata(r.target,o.kind,u);h.type=u.value}}else if(o.kind==="edge"){let h=i.get(r.target);if(!h)throw Error(`Metadata target '${r.target}' is not an explicit edge at ${pe(r.targetLocation)}`);r.statement.kind="edgeMetadata",r.statement.edges=[{id:r.target,span:r.statement.span,idSpan:r.targetLocation.span,...r.statement.metadata?{metadata:r.statement.metadata}:{}}],delete r.statement.nodes;for(let u of r.metadata.properties)if(u.key==="animate"&&typeof u.value==="boolean")h.relationship.animate=u.value;else if(u.key==="animation"&&(u.value==="fast"||u.value==="slow"))h.relationship.animation=u.value,h.relationship.animate=!0;else this.invalidMetadata(r.target,o.kind,u)}else for(let h of r.metadata.properties)this.invalidMetadata(r.target,o.kind,h)}for(let{relationship:r}of i.values())if(r.animation)r.animate=!0}applyStandaloneElementMetadata(t,s){for(let n of s.properties)if(t.kind==="actor")this.applyActorProperty(t,n,!0);else if(n.key==="business"&&typeof n.value==="boolean")t.business=n.value;else this.invalidMetadata(t.id,t.kind,n)}applyDeclarationMetadata(t,s){if(!s)return;for(let n of s.properties)if(t.kind==="actor")this.applyActorProperty(t,n,!1);else if(n.key==="business"&&typeof n.value==="boolean"){if(t.business!==void 0&&t.business!==n.value)this.conflict(`Use case '${t.id}' has conflicting business metadata`,n.location,t.location);t.business=n.value}else this.invalidMetadata(t.id,t.kind,n)}applyActorProperty(t,s,n){if(s.key==="type"&&(s.value==="normal"||s.value==="hollow"||s.value==="awesome")){if(!n&&t.actorType!==void 0&&t.actorType!==s.value)this.conflict(`Actor '${t.id}' has conflicting type metadata`,s.location,t.location);t.actorType=s.value}else if(s.key==="icon"&&typeof s.value==="string"){if(!n&&t.icon!==void 0&&t.icon!==s.value)this.conflict(`Actor '${t.id}' has conflicting icon metadata`,s.location,t.location);t.icon=s.value}else if(s.key==="business"&&typeof s.value==="boolean"){if(!n&&t.business!==void 0&&t.business!==s.value)this.conflict(`Actor '${t.id}' has conflicting business metadata`,s.location,t.location);t.business=s.value}else this.invalidMetadata(t.id,t.kind,s)}validateAndRefreshElements(t){for(let s of t.values()){let n=s.icon?"icon":s.actorType??"normal";if(s.kind==="actor"){if(s.icon&&s.actorType&&s.actorType!=="normal")throw Error(`Actor '${s.id}' cannot combine icon with type '${s.actorType}' at ${pe(s.location)}`);if(s.business&&(n==="icon"||n==="awesome"))throw Error(`Business actor '${s.id}' must use normal or hollow geometry at ${pe(s.location)}`)}else if((s.shape??"ellipse")==="rect"&&s.business)throw Error(`Rectangular use case '${s.id}' cannot be a business use case at ${pe(s.location)}`);this.setElementModel(s)}}refreshBoundaries(t,s){for(let n of t.values())n.members.length=0;for(let n of[...this.elements].sort((i,r)=>i.location.span[0]-r.location.span[0])){if(!n.parentId)continue;let i=t.get(n.parentId);if(!i)throw Error(`Parent boundary '${n.parentId}' for '${n.id}' is unresolved at ${pe(n.parentLocation??n.location)}`);if(!i.members.includes(n.id))i.members.push(n.id)}for(let n of s.values())if(n.parentId&&!t.has(n.parentId))throw Error(`Parent boundary '${n.parentId}' for '${n.id}' is unresolved at ${pe(n.parentLocation??n.location)}`);for(let n of t.values()){let i=this.model.systemBoundaries.get(n.id);i.type=n.type??"rect",i.members=[...n.members],i.classes=[...n.classes],i.styles=[...n.styles]}}materializeNotes(t){let s=0;for(let n of this.noteDrafts){let i=t.get(n.target);if(!i)throw Error(`Note target '${n.target}' is unresolved at ${pe(n.targetLocation)}`);if(i.kind!=="actor"&&i.kind!=="usecase")this.conflict(`Note target '${n.target}' must be an actor or use case, not ${i.kind}`,n.targetLocation,i.location);let r=`note-${s++}`;this.model.notes.set(r,{id:r,target:n.target,label:n.label.text,labelType:n.label.type})}this.model.noteCounter=s}applyClassDefinitions(){for(let t of this.classDefinitions)for(let s of t.ids)this.model.classDefs.set(s,{id:s,styles:[...t.styles]})}applyClassesAndStyles(t,s){for(let n of this.classAssignments)for(let i of n.targets)hn(this.getStylable(i.id,t,s,i.location).classes,n.classes);for(let n of this.styleAssignments)this.getStylable(n.target,t,s,n.location).styles.push(...n.styles)}getStylable(t,s,n,i){let r=s.get(t)?.kind,o=r==="actor"?this.model.actors.get(t):r==="usecase"?this.model.useCases.get(t):r==="boundary"?this.model.systemBoundaries.get(t):r==="json"?this.model.jsonNodes.get(t):r==="edge"?n.get(t)?.relationship:void 0;if(!o)throw Error(`Class/style target '${t}' is unresolved or anonymous at ${pe(i)}`);return o}validateRelationship(t,s,n,i){let r=e((o)=>o==="actor"||o==="usecase"||o==="json","allowed");if(!r(s))this.conflict(`Relationship source '${t.source.id}' cannot be ${s}`,t.source.location,i.get(t.source.id).location);if(!r(n))this.conflict(`Relationship target '${t.target.id}' cannot be ${n}`,t.target.location,i.get(t.target.id).location);if((t.type==="include"||t.type==="extend")&&(s!=="usecase"||n!=="usecase"))throw Error(`${t.type} relationship requires use-case endpoints at ${pe(t.location)}`);if(t.type==="generalization"&&(s!=="actor"&&s!=="usecase"||s!==n))throw Error(`Generalization requires actor-to-actor or use-case-to-use-case endpoints at ${pe(t.location)}`);if(t.type==="association"&&(s==="json"||n==="json")&&![0,1,2].includes(t.arrowType))throw Error(`JSON relationship '${t.source.id}' to '${t.target.id}' permits only point, reversed-point, or markerless solid association at ${pe(t.location)}`)}setElementModel(t){if(t.kind==="actor"){let s=t.icon?"icon":t.actorType??"normal";this.model.useCases.delete(t.id),this.model.actors.set(t.id,{id:t.id,label:t.label.text,labelType:t.label.type,type:s,...t.icon?{icon:t.icon}:{},business:t.business??!1,...t.stereotype?{stereotype:t.stereotype}:{},...t.parentId?{parentId:t.parentId}:{},classes:[...t.classes],styles:this.model.actors.get(t.id)?.styles??[]})}else this.model.actors.delete(t.id),this.model.useCases.set(t.id,{id:t.id,label:t.label.text,labelType:t.label.type,shape:t.shape??"ellipse",business:t.business??!1,...t.stereotype?{stereotype:t.stereotype}:{},...t.parentId?{parentId:t.parentId}:{},classes:[...t.classes],styles:this.model.useCases.get(t.id)?.styles??[]})}inferMetadataKind(t){let s=new Set(["actor","usecase","boundary","edge"]);for(let n of t.properties)if(n.key==="icon")s.clear(),s.add("actor");else if(n.key==="animate"||n.key==="animation")s.clear(),s.add("edge");else if(n.key==="type"){if(s.clear(),n.value==="rect"||n.value==="package")s.add("boundary");else if(n.value==="normal"||n.value==="hollow"||n.value==="awesome")s.add("actor")}else if(n.key==="business")s.delete("boundary"),s.delete("edge");else return;return s.size===1?[...s][0]:void 0}invalidMetadata(t,s,n){throw Error(`Metadata property '${n.key}' is invalid for ${s} '${t}' at ${pe(n.location)}`)}registerUnique(t,s,n,i,r){let o=t.get(s);if(o)this.conflict(`ID '${s}' is declared more than once (${o.kind} and ${n})`,i,o.location,void 0,Ze(o));t.set(s,{kind:n,location:i,generated:r})}recordFirst(t,s,n){let i=t.get(s);if(i===void 0||n<i)t.set(s,n)}conflict(t,s,n,i,r){throw Error(`${t} at ${pe(s)}${Ki(i)}; previous declaration at ${pe(n)}${Ki(r)}`)}},jo=Gt.getBaseCstVisitorConstructor(),Ko=class extends jo{constructor(){super();this.builder=new Wo(Ns),this.source="",this.anonymousEdge=0,this.anonymousNote=0,this.validateVisitor()}static{e(this,"UsecaseVisitor")}build(t,s){this.source=s,this.parentBoundary=void 0,this.anonymousEdge=0,this.anonymousNote=0,this.builder.reset(s),this.visit(t)}start(t){let s=this.tokens(t,"USECASE")[0],n=[];for(let i of this.nodes(t,"line"))n.push(this.visit(i));this.builder.setStatements(n),this.builder.finalize(this.tokenSpan(s))}line(t){let s=this.firstNode(t,"blankLine","commentLine","statement");return this.wrap(s,this.visit(s))}statement(t){return this.visit(this.firstNode(t,"accTitleStatement","accDescrStatement","directionStatement","actorStatement","systemBoundaryStatement","noteStatement","jsonStatement","classDefStatement","classStatement","styleStatement","metadataAssignmentStatement","entityStatement"))}lineEnd(t){return}blankLine(t){return{kind:"blank",span:this.tokenSpan(this.tokens(t,"NEWLINE")[0])}}commentLine(t){return{kind:"comment",span:this.tokenSpan(this.tokens(t,"COMMENT")[0])}}accTitleStatement(t){let s=this.tokens(t,"ACC_TITLE_LINE")[0].image;return this.builder.setAccTitle(s.slice(s.indexOf(":")+1).trim()),{kind:"accTitle",span:[0,0]}}accDescrStatement(t){let s=this.tokens(t,"ACC_DESCR_LINE")[0],n=this.tokens(t,"ACC_DESCR_BLOCK")[0],i=s?s.image.slice(s.image.indexOf(":")+1).trim():n.image.slice(n.image.indexOf("{")+1,n.image.lastIndexOf("}")).trim();return this.builder.setAccDescription(i),{kind:"accDescr",span:[0,0]}}actorStatement(t){let s=this.nodes(t,"actorItem"),n=s.map((c)=>this.visit(c)),i=this.nodes(t,"relationTail")[0],r=n.map((c,d)=>this.actorOccurrence(s[d],c,!0));for(let c of n)this.builder.addElement(this.actorDraft(c));if(!i)return{kind:"node",span:[0,0],nodes:r};let o=this.visit(i);if(o.target.explicitDeclaration)this.builder.addElement(this.entityDraft(o.target));let h=this.relationshipDraft(n[0],o,this.nodeLocation(i));this.builder.addRelationship(h);let u=h.explicitId??`edge-${this.anonymousEdge++}`;return r.push(this.entityOccurrence(this.nodes(i.children,"entityName")[0],o.target,o.target.explicitDeclaration)),{kind:"edge",span:[0,0],nodes:r,edges:[{id:u,span:[0,0],...h.explicitIdLocation?{idSpan:h.explicitIdLocation.span}:{},...h.label?{labelSpan:h.label.span}:{}}]}}actorItem(t){let s=this.visit(this.nodes(t,"actorName")[0]),n=this.nodes(t,"metadata")[0],i=this.nodes(t,"stereotype")[0],r=this.nodes(t,"classSuffix")[0],o=r?this.visit(r):{classes:[],spans:[]};return{...s,...n?{metadata:this.visit(n)}:{},...i?{stereotype:this.visit(i)}:{},classes:o.classes,classSpans:o.spans}}actorName(t){let s=this.tokens(t,"IDENTIFIER")[0],n=this.tokens(t,"PLAIN_STRING")[0]??this.tokens(t,"MARKDOWN_STRING")[0];if(s){let r=this.nodes(t,"nodeLabel")[0],o=r?this.visit(r):this.tokenLabel(s);return{id:s.image,label:o,location:this.tokenLocation(s),generated:!1,classes:[],classSpans:[]}}let i=this.tokenLabel(n);return{id:this.generateId(i.text),label:i,location:this.tokenLocation(n),generated:!0,classes:[],classSpans:[]}}actorDeclarationOnly(t){let s=this.nodes(t,"actorItem"),n=s.map((i)=>this.visit(i));for(let i of n)this.builder.addElement(this.actorDraft(i));return{kind:"node",span:[0,0],nodes:n.map((i,r)=>this.actorOccurrence(s[r],i,!0))}}entityStatement(t){let s=this.nodes(t,"entityName"),n=this.visit(s[0]),i=this.nodes(t,"relationTail")[0];if(!i)return n.explicitDeclaration=!0,n.shape??="ellipse",this.builder.addElement(this.entityDraft(n)),{kind:"node",span:[0,0],nodes:[this.entityOccurrence(s[0],n,!0)]};if(n.explicitDeclaration)this.builder.addElement(this.entityDraft(n));let r=this.visit(i);if(r.target.explicitDeclaration)this.builder.addElement(this.entityDraft(r.target));let o={source:this.endpoint(n),target:this.endpoint(r.target),location:this.nodeLocation(i),...r.explicitId?{explicitId:r.explicitId,explicitIdLocation:r.explicitIdLocation}:{},...r.arrow};this.builder.addRelationship(o);let h=o.explicitId??`edge-${this.anonymousEdge++}`;return{kind:"edge",span:[0,0],nodes:[this.entityOccurrence(s[0],n,n.explicitDeclaration),this.entityOccurrence(this.nodes(i.children,"entityName")[0],r.target,r.target.explicitDeclaration)],edges:[{id:h,span:[0,0],...o.explicitIdLocation?{idSpan:o.explicitIdLocation.span}:{},...o.label?{labelSpan:o.label.span}:{}}]}}entityName(t){let s=this.tokens(t,"IDENTIFIER")[0],n=this.tokens(t,"PLAIN_STRING")[0]??this.tokens(t,"MARKDOWN_STRING")[0],i=this.nodes(t,"nodeLabel")[0],r=this.nodes(t,"useCaseMetadata")[0],o=this.nodes(t,"stereotype")[0],h=this.nodes(t,"classSuffix")[0],u=h?this.visit(h):{classes:[],spans:[]};if(s){let d=i?this.visit(i):this.tokenLabel(s),f=i?this.tokens(t,"LBRACKET").length?"rect":"ellipse":void 0;return{id:s.image,label:d,location:this.tokenLocation(s),generated:!1,...f?{shape:f}:{},...r?{metadata:this.visit(r)}:{},...o?{stereotype:this.visit(o)}:{},classes:u.classes,classSpans:u.spans,explicitDeclaration:Boolean(f||r||o)}}let c=this.tokenLabel(n);return{id:this.generateId(c.text),label:c,location:this.tokenLocation(n),generated:!0,...r?{metadata:this.visit(r)}:{},...o?{stereotype:this.visit(o)}:{},classes:u.classes,classSpans:u.spans,explicitDeclaration:Boolean(r||o)}}nodeLabel(t){let s=this.allTokens(t);if(s.length===1&&(s[0].tokenType.name==="PLAIN_STRING"||s[0].tokenType.name==="MARKDOWN_STRING"))return this.tokenLabel(s[0]);let n=[s[0].startOffset,(s.at(-1).endOffset??s.at(-1).startOffset)+1];return{text:this.source.slice(n[0],n[1]),type:"text",span:n}}useCaseMetadata(t){return this.visit(this.nodes(t,"metadata")[0])}relationTail(t){let s=this.tokens(t,"IDENTIFIER")[0];return{...s?{explicitId:s.image,explicitIdLocation:this.tokenLocation(s)}:{},arrow:this.visit(this.nodes(t,"arrow")[0]),target:this.visit(this.nodes(t,"entityName")[0])}}arrow(t){return this.visit(this.firstNode(t,"semanticRelation","forwardSolidOperator","backwardSolidOperator","markerlessSolidOperator","forwardCircleOperator","backwardCircleOperator","forwardCrossOperator","backwardCrossOperator"))}edgeLabel(t){return this.nodeLabel(t)}semanticRelation(t){if(this.tokens(t,"GENERALIZATION").length)return{type:"generalization",arrowType:X.SOLID_ARROW,minlen:1};let s=this.tokens(t,"INCLUDE").length?"include":"extend",n=this.tokens(t,s==="include"?"INCLUDE":"EXTEND")[0];return{type:s,arrowType:X.SOLID_ARROW,label:{text:s,type:"text",span:this.tokenSpan(n)},minlen:1}}metadata(t){return{properties:this.nodes(t,"metadataProperty").map((s)=>this.visit(s)),location:this.ctxLocation(t)}}metadataProperty(t){let s=this.allTokens(t).filter((h)=>h.tokenType.name!=="COLON"),n=s[0],i=s[1],r=i.tokenType.name==="TRUE"?!0:i.tokenType.name==="FALSE"?!1:this.decodePlain(i),o=[n.startOffset,(i.endOffset??i.startOffset)+1];return{key:this.decodePlain(n),value:r,span:o,keySpan:this.contentSpan(n),valueSpan:this.contentSpan(i),location:this.tokenLocation(n)}}metadataSeparator(t){return}systemBoundaryStatement(t){let s=this.visit(this.nodes(t,"systemBoundaryName")[0]),n=this.nodes(t,"classSuffix")[0],i=n?this.visit(n):{classes:[],spans:[]};s.classes=i.classes,this.builder.addBoundary(s);let r=this.parentBoundary;this.parentBoundary={id:s.id,location:s.location};let o=this.nodes(t,"systemBoundaryContent")[0],h=o?this.visit(o):[];this.parentBoundary=r;let u=this.tokens(t,"END")[0],c=this.nodes(t,"metadata")[0],d=c?this.visit(c):void 0,f={kind:"group",span:[0,0],group:s.id,idSpan:s.location.span,titleSpan:s.label.span,endSpan:this.tokenSpan(u),classSpans:i.spans,...d?{metadata:d.properties.map(({key:m,span:y,keySpan:N,valueSpan:U})=>({key:m,span:y,keySpan:N,valueSpan:U}))}:{},...h.length?{children:h}:{}};if(d)this.builder.addMetadataAssignment(s.id,s.location,d,f);return f}systemBoundaryName(t){let s=this.tokens(t,"IDENTIFIER")[0];if(s){let r=this.nodes(t,"nodeLabel")[0];return{id:s.image,label:r?this.visit(r):this.tokenLabel(s),location:this.tokenLocation(s),generated:!1,classes:[]}}let n=this.tokens(t,"PLAIN_STRING")[0]??this.tokens(t,"MARKDOWN_STRING")[0],i=this.tokenLabel(n);return{id:this.generateId(i.text),label:i,location:this.tokenLocation(n),generated:!0,classes:[]}}systemBoundaryContent(t){return[...this.nodes(t,"blankLine"),...this.nodes(t,"commentLine"),...this.nodes(t,"boundaryElement")].sort((n,i)=>(n.location?.startOffset??0)-(i.location?.startOffset??0)).map((n)=>this.wrap(n,this.visit(n)))}boundaryElement(t){let s=this.nodes(t,"actorDeclarationOnly")[0];if(s)return this.visit(s);let n=this.nodes(t,"entityName")[0],i=this.visit(n);return i.explicitDeclaration=!0,i.shape??="ellipse",this.builder.addElement(this.entityDraft(i)),{kind:"node",span:[0,0],nodes:[this.entityOccurrence(n,i,!0)]}}metadataAssignmentStatement(t){let s=this.visit(this.nodes(t,"metadataAssignmentTarget")[0]),n=this.visit(this.nodes(t,"metadata")[0]),i={kind:"metadata",span:[0,0],nodes:[{id:s.id,span:s.location.span,idSpan:s.location.span}],metadata:n.properties.map(({key:r,span:o,keySpan:h,valueSpan:u})=>({key:r,span:o,keySpan:h,valueSpan:u}))};return this.builder.addMetadataAssignment(s.id,s.location,n,i),i}metadataAssignmentTarget(t){let s=this.allTokens(t)[0],n=this.tokenLabel(s);return{id:s.tokenType.name==="IDENTIFIER"?s.image:this.generateId(n.text),location:this.tokenLocation(s)}}noteStatement(t){let s=this.tokens(t,"IDENTIFIER")[0],n=this.visit(this.nodes(t,"nodeLabel")[0]);return this.builder.addNote({target:s.image,targetLocation:this.tokenLocation(s),label:n,location:this.ctxLocation(t)}),{kind:"note",span:[0,0],ref:`note-${this.anonymousNote++}`,refSpan:n.span,nodes:[{id:s.image,span:this.tokenSpan(s),idSpan:this.tokenSpan(s)}]}}stereotype(t){let s=this.tokens(t,"STEREOTYPE_TEXT")[0];return{value:s.image.trim(),span:this.tokenSpan(s)}}classSuffix(t){let s=this.tokens(t,"IDENTIFIER");return{classes:s.map((n)=>n.image),spans:s.map((n)=>this.tokenSpan(n))}}jsonStatement(t){let s=this.tokens(t,"JSON_DECLARATION_START")[0],n=this.tokens(t,"JSON_OBJECT_LITERAL")[0],i=/^json[\t ]+(\w+)/.exec(s.image),r=i[1],o=i[0].length-r.length,h={span:[s.startOffset+o,s.startOffset+o+r.length],line:s.startLine??1,column:(s.startColumn??1)+o},u=Dr(n.image,n.startLine??1,n.startColumn??1),c=this.nodes(t,"classSuffix")[0],d=c?this.visit(c):{classes:[],spans:[]},f={id:r,value:u.value,propertyOrder:u.propertyOrder,location:h,classes:d.classes};return this.builder.addJson(f),{kind:"json",span:[0,0],nodes:[{id:r,span:h.span,idSpan:h.span,defines:!0,classSpans:d.spans}],classSpans:d.spans}}directionStatement(t){let s=this.allTokens(t).find((n)=>["TD","TB","BT","RL","LR"].includes(n.tokenType.name));return this.builder.setDirection(s.image),{kind:"direction",span:[0,0]}}classDefStatement(t){let s=this.tokens(t,"IDENTIFIER"),n=this.visit(this.nodes(t,"styles")[0]);return this.builder.addClassDef(s.map((i)=>i.image),n),{kind:"classDef",span:[0,0],ref:s[0].image,refSpan:this.tokenSpan(s[0])}}classStatement(t){let s=this.tokens(t,"IDENTIFIER"),n=1;for(;n<s.length;n++)if(!this.source.slice((s[n-1].endOffset??s[n-1].startOffset)+1,s[n].startOffset).includes(","))break;let i=s.slice(0,n).map((o)=>({id:o.image,location:this.tokenLocation(o)})),r=s.slice(n).map((o)=>o.image);return this.builder.addClassAssignment(i,r),{kind:"classAssign",span:[0,0],ref:r[0],refSpan:this.tokenSpan(s[n]),nodes:i.map(({id:o,location:h})=>({id:o,span:h.span,idSpan:h.span}))}}styleStatement(t){let s=this.tokens(t,"IDENTIFIER")[0],n=this.visit(this.nodes(t,"styles")[0]);return this.builder.addStyleAssignment(s.image,this.tokenLocation(s),n),{kind:"style",span:[0,0],nodes:[{id:s.image,span:this.tokenSpan(s),idSpan:this.tokenSpan(s)}]}}styles(t){return this.nodes(t,"styleValue").map((s)=>this.visit(s))}styleValue(t){let s=this.allTokens(t),n=[s[0].startOffset,(s.at(-1).endOffset??s.at(-1).startOffset)+1];return this.source.slice(n[0],n[1]).replaceAll("\\,",",")}styleComponent(t){return this.allTokens(t).map((s)=>s.image).join("")}forwardSolidOperator(t){let s=this.tokens(t,"FORWARD_SOLID")[0];return{type:"association",arrowType:X.SOLID_ARROW,minlen:this.solidMinlen(s)}}backwardSolidOperator(t){let s=this.tokens(t,"BACKWARD_SOLID")[0],n=this.nodes(t,"edgeLabel")[0],i=n?this.tokens(t,"MARKERLESS_SOLID").at(-1):s;return{type:"association",arrowType:X.BACK_ARROW,minlen:this.solidMinlen(i),...n?{label:this.visit(n)}:{}}}markerlessSolidOperator(t){let s=this.nodes(t,"edgeLabel")[0],n=this.allTokens(t);if(!s)return{type:"association",arrowType:X.LINE_SOLID,minlen:this.solidMinlen(this.tokens(t,"MARKERLESS_SOLID")[0])};let i=n.at(-1),r=i.tokenType.name==="FORWARD_SOLID"?X.SOLID_ARROW:i.tokenType.name==="FORWARD_CIRCLE"?X.CIRCLE_ARROW:i.tokenType.name==="FORWARD_CROSS"?X.CROSS_ARROW:X.LINE_SOLID;return{type:"association",arrowType:r,label:this.visit(s),minlen:r===X.SOLID_ARROW||r===X.LINE_SOLID?this.solidMinlen(i):1}}forwardCircleOperator(t){return{type:"association",arrowType:X.CIRCLE_ARROW,minlen:1}}backwardCircleOperator(t){let s=this.nodes(t,"edgeLabel")[0];return{type:"association",arrowType:X.CIRCLE_ARROW_REVERSED,minlen:1,...s?{label:this.visit(s)}:{}}}forwardCrossOperator(t){return{type:"association",arrowType:X.CROSS_ARROW,minlen:1}}backwardCrossOperator(t){let s=this.nodes(t,"edgeLabel")[0];return{type:"association",arrowType:X.CROSS_ARROW_REVERSED,minlen:1,...s?{label:this.visit(s)}:{}}}actorDraft(t){return{id:t.id,kind:"actor",label:t.label,location:t.location,generated:t.generated,...this.parentBoundary?{parentId:this.parentBoundary.id,parentLocation:this.parentBoundary.location}:{},...t.metadata?{metadata:t.metadata}:{},...t.stereotype?{stereotype:t.stereotype.value,stereotypeSpan:t.stereotype.span}:{},classes:t.classes}}entityDraft(t){return{id:t.id,kind:"usecase",label:t.label,location:t.location,generated:t.generated,...this.parentBoundary?{parentId:this.parentBoundary.id,parentLocation:this.parentBoundary.location}:{},...t.shape?{shape:t.shape}:{},...t.metadata?{metadata:t.metadata}:{},...t.stereotype?{stereotype:t.stereotype.value,stereotypeSpan:t.stereotype.span}:{},classes:t.classes}}endpoint(t,s=t.explicitDeclaration??!0){return{id:t.id,label:t.label,location:t.location,generated:t.generated,declaration:s,classesOnReference:t.classes.length>0}}relationshipDraft(t,s,n){return{source:this.endpoint(t,!0),target:this.endpoint(s.target),location:n,...s.explicitId?{explicitId:s.explicitId,explicitIdLocation:s.explicitIdLocation}:{},...s.arrow}}actorOccurrence(t,s,n){return{id:s.id,span:this.nodeSpan(t),idSpan:s.location.span,labelSpan:s.label.span,...n?{defines:!0}:{},...s.stereotype?{stereotypeSpan:s.stereotype.span}:{},...s.metadata?{metadata:s.metadata.properties.map(({key:i,span:r,keySpan:o,valueSpan:h})=>({key:i,span:r,keySpan:o,valueSpan:h}))}:{},...s.classSpans.length?{classSpans:s.classSpans}:{}}}entityOccurrence(t,s,n){return this.actorOccurrence(t,s,n)}wrap(t,s){if(s.kind==="blank"||s.kind==="comment")return s;s.span=this.nodeSpan(t);for(let n of s.edges??[])n.span=s.span;return s}tokenLabel(t){let s=t.tokenType.name==="MARKDOWN_STRING"?"markdown":"text",n=s==="markdown"?2:t.tokenType.name==="PLAIN_STRING"?1:0,i=this.tokenSpan(t,n);return{text:this.source.slice(i[0],i[1]),type:s,span:i}}decodePlain(t){return t.tokenType.name==="PLAIN_STRING"?t.image.slice(1,-1):t.image}contentSpan(t){return this.tokenSpan(t,t.tokenType.name==="PLAIN_STRING"?1:t.tokenType.name==="MARKDOWN_STRING"?2:0)}generateId(t){return t.replace(/\W/g,"_")}solidMinlen(t){return Math.max(1,(t.image.match(/-/g)?.length??2)-1)}nodeLocation(t){let s=this.allTokens(t.children)[0];return{span:this.nodeSpan(t),line:s.startLine??1,column:s.startColumn??1}}ctxLocation(t){let s=this.allTokens(t).filter((r)=>r.tokenType.name!=="NEWLINE"&&r.tokenType.name!=="EOF"),n=s[0],i=s.at(-1);return{span:[n.startOffset,Math.min(this.source.length,(i.endOffset??i.startOffset+i.image.length-1)+1)],line:n.startLine??1,column:n.startColumn??1}}tokenLocation(t){let s=t.tokenType.name==="PLAIN_STRING"?1:t.tokenType.name==="MARKDOWN_STRING"?2:0;return{span:this.tokenSpan(t,s),line:t.startLine??1,column:(t.startColumn??1)+s}}nodeSpan(t){let s=this.allTokens(t.children).filter((r)=>r.tokenType.name!=="NEWLINE"&&r.tokenType.name!=="EOF"),n=s[0],i=s.at(-1);if(!n||!i)throw Error("Usecase CST node has no source token");return[n.startOffset,Math.min(this.source.length,(i.endOffset??i.startOffset+i.image.length-1)+1)]}tokenSpan(t,s=0){return[t.startOffset+s,Math.min(this.source.length,(t.endOffset??t.startOffset+t.image.length-1)+1-s)]}nodes(t,s){return(t[s]??[]).filter((n)=>("children"in n))}tokens(t,s){return(t[s]??[]).filter((n)=>("tokenTypeIdx"in n))}firstNode(t,...s){for(let n of s){let i=this.nodes(t,n)[0];if(i)return i}throw Error(`Usecase CST is missing one of: ${s.join(", ")}`)}allTokens(t){let s=[];for(let n of Object.values(t))for(let i of n)if("tokenTypeIdx"in i)s.push(i);else s.push(...this.allTokens(i.children));return s.sort((n,i)=>n.startOffset-i.startOffset)}},Vo=new Ko,zo={parse:e(async(t)=>{Ns.clear(),Gt.input=[];try{Xi({diagramType:"usecase",lexer:xo,parser:Gt,entry:e(()=>Gt.start(),"entry"),visit:e((s)=>Vo.build(s,t),"visit")},t)}catch(s){Ns.clear();let n=Gt.errors[0];if(n){let{token:i}=n,r=ut(i.startOffset)?i.startOffset:t.length,o=ut(i.endOffset)?i.endOffset+1:r,h=ut(i.startLine)?i.startLine:t.slice(0,r).split(/\r\n|\r|\n/).length,u=Math.max(t.lastIndexOf(`
117
+ `,r-1),t.lastIndexOf("\r",r-1)),c=ut(i.startColumn)?i.startColumn:r-u,d=s instanceof Error?s.message:String(s);throw Error(`${d} at line ${h}, column ${c} [${r},${o})`)}throw s}},"parse")},Ho=["point","circle","cross","extension"],Fr={usecaseActor:!0,usecaseActorHollow:!0,usecaseActorAwesome:!0,usecaseActorIcon:!0},Vi=e((t,s)=>{let[n,i]=[t,s].map((r)=>r.replace(/[^\w-]+/g,"_").replace(/^_+|_+$/g,"")||"element");return`usecase-${n}-${i}`},"usecaseDomId"),Xo=e((t)=>`usecase-${t.replace(/[^\w-]+/g,"_").replace(/^_+|_+$/g,"")||"element"}`,"usecaseNodeDomId"),Is=e((t,s)=>{if(s!=="markdown")return t;return ni(t).map((n)=>n.map((i)=>i.content).join(" ")).join(`
118
+ `)},"getAccessibleLabel"),Yo=e((t)=>{let s=Is(t.label??t.id,t.labelType);if(Fr[t.shape]){let i=t.actorType&&t.actorType!=="normal"?`${t.actorType} `:"",r=t.business?"business ":"",o=t.stereotype?`, stereotype ${t.stereotype}`:"";return`${r}${i}actor ${s}${o}`}if(t.shape==="note")return`Note for ${t.noteTargetLabel??t.noteTarget??""}: ${s}`;if(t.shape==="usecaseJsonTable"){let i=(t.jsonRows??[]).map((r)=>`${r.accessibleKey}: ${r.value}`).join("; ");return i?`${s}: ${i}`:s}let n=t.stereotype?`, stereotype ${t.stereotype}`:"";return`${t.business?"business ":""}use case ${s}${n}`},"getUsecaseNodeAccessibleName"),qo=e((t)=>`${t.boundaryType} system boundary ${Is(t.label??t.id,t.labelType)}`,"getUsecaseBoundaryAccessibleName"),Jo=e((t)=>{if(t.relationshipType==="note")return"";return`${t.relationshipType==="association"&&t.label?`association ${Is(t.label,t.labelType)}`:t.relationshipType} from ${t.sourceLabel} to ${t.targetLabel}`},"getUsecaseEdgeAccessibleName"),ht=e((t)=>t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;"),"escapePlainLabel"),zi=e((t)=>t.replace(/([*[\\\]_`])/g,"\\$1"),"escapeMarkdownMarkers"),Zo=e((t,s)=>{t.diagramId=s,t.markers=[...Ho];for(let n of t.nodes){let i=n;if(i.domId=Xo(n.id),n.label!==void 0&&n.labelType==="text")n.label=ht(n.label);if(n.stereotype)n.stereotype=ht(n.stereotype);if(!n.isGroup&&n.shape==="usecaseJsonTable")n.jsonRows=n.jsonRows?.map((r)=>({...r,key:ht(r.key),value:ht(r.value)}));if(!n.isGroup&&(n.shape==="usecaseEllipse"||n.shape==="rect")&&n.stereotype){let r=n.label??ht(n.id);n.label=`«${zi(n.stereotype)}»<br/>${n.labelType==="text"?zi(r):r}`,n.labelType="markdown",i.hasFoldedStereotype=!0,delete n.stereotype}}for(let n of t.edges)if(n.label!==void 0&&n.labelType==="text")n.label=ht(n.label);return t},"prepareUsecaseLayoutData"),Qo=e((t,s,n)=>{for(let r of s.nodes){let o=typeof r.domId==="string"?r.domId:Vi(s.diagramId,r.id),h=t.select(`#${o}`),u=r.isGroup?"boundary":Fr[r.shape]?"actor":r.shape==="note"?"note":r.shape==="usecaseJsonTable"?"json":"usecase",c=n.nodes.get(r.id)??r.id;if(h.attr("data-usecase-id",r.id).attr("data-usecase-kind",u).attr("role","img").attr("aria-label",c),!r.isGroup&&(r.shape==="usecaseEllipse"||r.shape==="rect")&&"hasFoldedStereotype"in r&&r.hasFoldedStereotype===!0){let d=h.node(),f=d?.querySelector(".nodeLabel"),m=f?.querySelector("p")??f,y=m?.firstChild;if(m&&y?.nodeType===3){let N=m.ownerDocument.createElement("span");N.className="usecase-stereotype",m.insertBefore(N,y),N.appendChild(y)}else d?.querySelector(".label tspan tspan, .label tspan")?.classList.add("usecase-stereotype")}}let i=new Map(s.edges.map((r)=>[r.id,r]));t.selectAll('path[data-et="edge"]').each(function(){let r=i.get(this.getAttribute("data-id")??"");if(!r)return;let o=p(this);if(o.attr("id",Vi(s.diagramId,r.id)).attr("data-usecase-id",r.id).attr("data-usecase-kind",r.internal?"note-connector":"relationship"),r.internal)o.attr("aria-hidden","true");else o.attr("role","img").attr("aria-label",n.edges.get(r.id)??r.id)})},"annotateUsecaseElements"),Hi=e((t,s)=>{t.style("--mermaid-usecase-actor-font-size",`${s.actorFontSize}px`).style("--mermaid-usecase-actor-font-family",s.actorFontFamily).style("--mermaid-usecase-actor-font-weight",s.actorFontWeight).style("--mermaid-usecase-font-size",`${s.usecaseFontSize}px`).style("--mermaid-usecase-font-family",s.usecaseFontFamily).style("--mermaid-usecase-font-weight",s.usecaseFontWeight)},"applyUsecaseFonts"),el=e(async(t,s,n,i)=>{a.info("Drawing usecase diagram (unified)",s);let{layout:r}=l(),o=i.db,h=o.getData(),u=new Map(h.nodes.map((m)=>[m.id,Is(m.label??m.id,m.labelType)])),c={nodes:new Map(h.nodes.map((m)=>[m.id,m.isGroup?qo(m):Yo(m.shape==="note"?{...m,noteTargetLabel:u.get(m.noteTarget??"")}:m)])),edges:new Map(h.edges.map((m)=>[m.id,Jo({...m,sourceLabel:u.get(m.source)??m.sourceLabel,targetLabel:u.get(m.target)??m.targetLabel})]))},d=he(s,h.config.securityLevel);h.layoutAlgorithm=ye(r),Zo(h,s),Hi(d,h),await ge(h,d),Qo(d,h,c);let f=h.diagramPadding;M.insertTitle(d,"usecaseDiagramTitleText",0,o.getDiagramTitle?.()??""),le(d,f,"usecaseDiagram",h.useMaxWidth),Hi(d,h)},"draw"),tl={draw:el},sl=e((t)=>({actorBkg:t.usecaseActorBkg??t.actorBkg??t.mainBkg,actorBorder:t.usecaseActorBorder??t.actorBorder??t.primaryColor,bkg:t.usecaseBkg??t.mainBkg,border:t.usecaseBorder??t.nodeBorder??t.primaryColor,boundaryBkg:t.usecaseBoundaryBkg??t.clusterBkg,boundaryBorder:t.usecaseBoundaryBorder??t.clusterBorder,includeLine:t.usecaseIncludeLine??t.lineColor,extendLine:t.usecaseExtendLine??t.lineColor}),"roleColors"),nl=e((t)=>{let{theme:s,bkgColorArray:n,borderColorArray:i}=t;if(!oe(s,i))return"";let r=b().usecase?.colorScheme==="rotate",o=se(t.look),h=o==="handDrawn",u=ue(n),c="";for(let d=0;d<gt(i);d++){let f=i[d],m=u?`fill: ${n[d%n.length]};`:"",y=`[data-look="${o}"][data-color-id="color-${d}"]`;if(c+=`
119
119
 
120
120
  & ${y}.system-boundary rect.boundary-body,
121
121
  & ${y}.system-boundary rect.boundary-tab,