openpinescript 0.1.1__py3-none-any.whl

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 (332) hide show
  1. openpinescript/__init__.py +129 -0
  2. openpinescript/__main__.py +5 -0
  3. openpinescript/_cli.py +24 -0
  4. openpinescript/_engine/LICENSE +674 -0
  5. openpinescript/_engine/VERSION +1 -0
  6. openpinescript/_engine/dist/cli.mjs +108691 -0
  7. openpinescript/_engine/node_modules/antlr4ng/LICENSE.txt +29 -0
  8. openpinescript/_engine/node_modules/antlr4ng/dist/atn/ATN.cjs +3159 -0
  9. openpinescript/_engine/node_modules/antlr4ng/dist/atn/ATN.js +3159 -0
  10. openpinescript/_engine/node_modules/antlr4ng/dist/atn/ATN.mjs +3139 -0
  11. openpinescript/_engine/node_modules/antlr4ng/dist/atn/ATNConfig.cjs +911 -0
  12. openpinescript/_engine/node_modules/antlr4ng/dist/atn/ATNConfig.js +911 -0
  13. openpinescript/_engine/node_modules/antlr4ng/dist/atn/ATNConfig.mjs +891 -0
  14. openpinescript/_engine/node_modules/antlr4ng/dist/atn/ATNConfigSet.cjs +3781 -0
  15. openpinescript/_engine/node_modules/antlr4ng/dist/atn/ATNConfigSet.js +3781 -0
  16. openpinescript/_engine/node_modules/antlr4ng/dist/atn/ATNConfigSet.mjs +3761 -0
  17. openpinescript/_engine/node_modules/antlr4ng/dist/atn/ATNDeserializationOptions.cjs +17 -0
  18. openpinescript/_engine/node_modules/antlr4ng/dist/atn/ATNDeserializationOptions.js +17 -0
  19. openpinescript/_engine/node_modules/antlr4ng/dist/atn/ATNDeserializationOptions.mjs +0 -0
  20. openpinescript/_engine/node_modules/antlr4ng/dist/atn/ATNDeserializer.cjs +4300 -0
  21. openpinescript/_engine/node_modules/antlr4ng/dist/atn/ATNDeserializer.js +4300 -0
  22. openpinescript/_engine/node_modules/antlr4ng/dist/atn/ATNDeserializer.mjs +4280 -0
  23. openpinescript/_engine/node_modules/antlr4ng/dist/atn/ATNSerializer.cjs +4798 -0
  24. openpinescript/_engine/node_modules/antlr4ng/dist/atn/ATNSerializer.js +4798 -0
  25. openpinescript/_engine/node_modules/antlr4ng/dist/atn/ATNSerializer.mjs +4778 -0
  26. openpinescript/_engine/node_modules/antlr4ng/dist/atn/ATNSimulator.cjs +982 -0
  27. openpinescript/_engine/node_modules/antlr4ng/dist/atn/ATNSimulator.js +982 -0
  28. openpinescript/_engine/node_modules/antlr4ng/dist/atn/ATNSimulator.mjs +962 -0
  29. openpinescript/_engine/node_modules/antlr4ng/dist/atn/ATNState.cjs +85 -0
  30. openpinescript/_engine/node_modules/antlr4ng/dist/atn/ATNState.js +85 -0
  31. openpinescript/_engine/node_modules/antlr4ng/dist/atn/ATNState.mjs +67 -0
  32. openpinescript/_engine/node_modules/antlr4ng/dist/atn/AbstractPredicateTransition.cjs +78 -0
  33. openpinescript/_engine/node_modules/antlr4ng/dist/atn/AbstractPredicateTransition.js +78 -0
  34. openpinescript/_engine/node_modules/antlr4ng/dist/atn/AbstractPredicateTransition.mjs +58 -0
  35. openpinescript/_engine/node_modules/antlr4ng/dist/atn/ActionTransition.cjs +96 -0
  36. openpinescript/_engine/node_modules/antlr4ng/dist/atn/ActionTransition.js +96 -0
  37. openpinescript/_engine/node_modules/antlr4ng/dist/atn/ActionTransition.mjs +76 -0
  38. openpinescript/_engine/node_modules/antlr4ng/dist/atn/AmbiguityInfo.cjs +17 -0
  39. openpinescript/_engine/node_modules/antlr4ng/dist/atn/AmbiguityInfo.js +17 -0
  40. openpinescript/_engine/node_modules/antlr4ng/dist/atn/AmbiguityInfo.mjs +0 -0
  41. openpinescript/_engine/node_modules/antlr4ng/dist/atn/ArrayPredictionContext.cjs +243 -0
  42. openpinescript/_engine/node_modules/antlr4ng/dist/atn/ArrayPredictionContext.js +243 -0
  43. openpinescript/_engine/node_modules/antlr4ng/dist/atn/ArrayPredictionContext.mjs +223 -0
  44. openpinescript/_engine/node_modules/antlr4ng/dist/atn/AtomTransition.cjs +904 -0
  45. openpinescript/_engine/node_modules/antlr4ng/dist/atn/AtomTransition.js +904 -0
  46. openpinescript/_engine/node_modules/antlr4ng/dist/atn/AtomTransition.mjs +884 -0
  47. openpinescript/_engine/node_modules/antlr4ng/dist/atn/BasicBlockStartState.cjs +112 -0
  48. openpinescript/_engine/node_modules/antlr4ng/dist/atn/BasicBlockStartState.js +112 -0
  49. openpinescript/_engine/node_modules/antlr4ng/dist/atn/BasicBlockStartState.mjs +92 -0
  50. openpinescript/_engine/node_modules/antlr4ng/dist/atn/BasicState.cjs +95 -0
  51. openpinescript/_engine/node_modules/antlr4ng/dist/atn/BasicState.js +95 -0
  52. openpinescript/_engine/node_modules/antlr4ng/dist/atn/BasicState.mjs +75 -0
  53. openpinescript/_engine/node_modules/antlr4ng/dist/atn/BlockEndState.cjs +96 -0
  54. openpinescript/_engine/node_modules/antlr4ng/dist/atn/BlockEndState.js +96 -0
  55. openpinescript/_engine/node_modules/antlr4ng/dist/atn/BlockEndState.mjs +76 -0
  56. openpinescript/_engine/node_modules/antlr4ng/dist/atn/BlockStartState.cjs +104 -0
  57. openpinescript/_engine/node_modules/antlr4ng/dist/atn/BlockStartState.js +104 -0
  58. openpinescript/_engine/node_modules/antlr4ng/dist/atn/BlockStartState.mjs +84 -0
  59. openpinescript/_engine/node_modules/antlr4ng/dist/atn/CodePointTransitions.cjs +947 -0
  60. openpinescript/_engine/node_modules/antlr4ng/dist/atn/CodePointTransitions.js +947 -0
  61. openpinescript/_engine/node_modules/antlr4ng/dist/atn/CodePointTransitions.mjs +927 -0
  62. openpinescript/_engine/node_modules/antlr4ng/dist/atn/ContextSensitivityInfo.cjs +17 -0
  63. openpinescript/_engine/node_modules/antlr4ng/dist/atn/ContextSensitivityInfo.js +17 -0
  64. openpinescript/_engine/node_modules/antlr4ng/dist/atn/ContextSensitivityInfo.mjs +0 -0
  65. openpinescript/_engine/node_modules/antlr4ng/dist/atn/DecisionEventInfo.cjs +17 -0
  66. openpinescript/_engine/node_modules/antlr4ng/dist/atn/DecisionEventInfo.js +17 -0
  67. openpinescript/_engine/node_modules/antlr4ng/dist/atn/DecisionEventInfo.mjs +0 -0
  68. openpinescript/_engine/node_modules/antlr4ng/dist/atn/DecisionInfo.cjs +206 -0
  69. openpinescript/_engine/node_modules/antlr4ng/dist/atn/DecisionInfo.js +206 -0
  70. openpinescript/_engine/node_modules/antlr4ng/dist/atn/DecisionInfo.mjs +188 -0
  71. openpinescript/_engine/node_modules/antlr4ng/dist/atn/DecisionState.cjs +96 -0
  72. openpinescript/_engine/node_modules/antlr4ng/dist/atn/DecisionState.js +96 -0
  73. openpinescript/_engine/node_modules/antlr4ng/dist/atn/DecisionState.mjs +76 -0
  74. openpinescript/_engine/node_modules/antlr4ng/dist/atn/EmptyPredictionContext.cjs +237 -0
  75. openpinescript/_engine/node_modules/antlr4ng/dist/atn/EmptyPredictionContext.js +237 -0
  76. openpinescript/_engine/node_modules/antlr4ng/dist/atn/EmptyPredictionContext.mjs +217 -0
  77. openpinescript/_engine/node_modules/antlr4ng/dist/atn/EpsilonTransition.cjs +103 -0
  78. openpinescript/_engine/node_modules/antlr4ng/dist/atn/EpsilonTransition.js +103 -0
  79. openpinescript/_engine/node_modules/antlr4ng/dist/atn/EpsilonTransition.mjs +83 -0
  80. openpinescript/_engine/node_modules/antlr4ng/dist/atn/LL1Analyzer.cjs +3159 -0
  81. openpinescript/_engine/node_modules/antlr4ng/dist/atn/LL1Analyzer.js +3159 -0
  82. openpinescript/_engine/node_modules/antlr4ng/dist/atn/LL1Analyzer.mjs +3139 -0
  83. openpinescript/_engine/node_modules/antlr4ng/dist/atn/LexerATNConfig.cjs +961 -0
  84. openpinescript/_engine/node_modules/antlr4ng/dist/atn/LexerATNConfig.js +961 -0
  85. openpinescript/_engine/node_modules/antlr4ng/dist/atn/LexerATNConfig.mjs +941 -0
  86. openpinescript/_engine/node_modules/antlr4ng/dist/atn/LexerATNSimulator.cjs +5604 -0
  87. openpinescript/_engine/node_modules/antlr4ng/dist/atn/LexerATNSimulator.js +5604 -0
  88. openpinescript/_engine/node_modules/antlr4ng/dist/atn/LexerATNSimulator.mjs +5584 -0
  89. openpinescript/_engine/node_modules/antlr4ng/dist/atn/LexerAction.cjs +17 -0
  90. openpinescript/_engine/node_modules/antlr4ng/dist/atn/LexerAction.js +17 -0
  91. openpinescript/_engine/node_modules/antlr4ng/dist/atn/LexerAction.mjs +0 -0
  92. openpinescript/_engine/node_modules/antlr4ng/dist/atn/LexerActionExecutor.cjs +305 -0
  93. openpinescript/_engine/node_modules/antlr4ng/dist/atn/LexerActionExecutor.js +305 -0
  94. openpinescript/_engine/node_modules/antlr4ng/dist/atn/LexerActionExecutor.mjs +285 -0
  95. openpinescript/_engine/node_modules/antlr4ng/dist/atn/LexerActionType.cjs +42 -0
  96. openpinescript/_engine/node_modules/antlr4ng/dist/atn/LexerActionType.js +42 -0
  97. openpinescript/_engine/node_modules/antlr4ng/dist/atn/LexerActionType.mjs +22 -0
  98. openpinescript/_engine/node_modules/antlr4ng/dist/atn/LexerChannelAction.cjs +163 -0
  99. openpinescript/_engine/node_modules/antlr4ng/dist/atn/LexerChannelAction.js +163 -0
  100. openpinescript/_engine/node_modules/antlr4ng/dist/atn/LexerChannelAction.mjs +143 -0
  101. openpinescript/_engine/node_modules/antlr4ng/dist/atn/LexerCustomAction.cjs +169 -0
  102. openpinescript/_engine/node_modules/antlr4ng/dist/atn/LexerCustomAction.js +169 -0
  103. openpinescript/_engine/node_modules/antlr4ng/dist/atn/LexerCustomAction.mjs +149 -0
  104. openpinescript/_engine/node_modules/antlr4ng/dist/atn/LexerIndexedCustomAction.cjs +142 -0
  105. openpinescript/_engine/node_modules/antlr4ng/dist/atn/LexerIndexedCustomAction.js +142 -0
  106. openpinescript/_engine/node_modules/antlr4ng/dist/atn/LexerIndexedCustomAction.mjs +122 -0
  107. openpinescript/_engine/node_modules/antlr4ng/dist/atn/LexerModeAction.cjs +163 -0
  108. openpinescript/_engine/node_modules/antlr4ng/dist/atn/LexerModeAction.js +163 -0
  109. openpinescript/_engine/node_modules/antlr4ng/dist/atn/LexerModeAction.mjs +143 -0
  110. openpinescript/_engine/node_modules/antlr4ng/dist/atn/LexerMoreAction.cjs +73 -0
  111. openpinescript/_engine/node_modules/antlr4ng/dist/atn/LexerMoreAction.js +73 -0
  112. openpinescript/_engine/node_modules/antlr4ng/dist/atn/LexerMoreAction.mjs +53 -0
  113. openpinescript/_engine/node_modules/antlr4ng/dist/atn/LexerPopModeAction.cjs +73 -0
  114. openpinescript/_engine/node_modules/antlr4ng/dist/atn/LexerPopModeAction.js +73 -0
  115. openpinescript/_engine/node_modules/antlr4ng/dist/atn/LexerPopModeAction.mjs +53 -0
  116. openpinescript/_engine/node_modules/antlr4ng/dist/atn/LexerPushModeAction.cjs +163 -0
  117. openpinescript/_engine/node_modules/antlr4ng/dist/atn/LexerPushModeAction.js +163 -0
  118. openpinescript/_engine/node_modules/antlr4ng/dist/atn/LexerPushModeAction.mjs +143 -0
  119. openpinescript/_engine/node_modules/antlr4ng/dist/atn/LexerSkipAction.cjs +71 -0
  120. openpinescript/_engine/node_modules/antlr4ng/dist/atn/LexerSkipAction.js +71 -0
  121. openpinescript/_engine/node_modules/antlr4ng/dist/atn/LexerSkipAction.mjs +51 -0
  122. openpinescript/_engine/node_modules/antlr4ng/dist/atn/LexerTypeAction.cjs +159 -0
  123. openpinescript/_engine/node_modules/antlr4ng/dist/atn/LexerTypeAction.js +159 -0
  124. openpinescript/_engine/node_modules/antlr4ng/dist/atn/LexerTypeAction.mjs +139 -0
  125. openpinescript/_engine/node_modules/antlr4ng/dist/atn/LookaheadEventInfo.cjs +17 -0
  126. openpinescript/_engine/node_modules/antlr4ng/dist/atn/LookaheadEventInfo.js +17 -0
  127. openpinescript/_engine/node_modules/antlr4ng/dist/atn/LookaheadEventInfo.mjs +0 -0
  128. openpinescript/_engine/node_modules/antlr4ng/dist/atn/LoopEndState.cjs +96 -0
  129. openpinescript/_engine/node_modules/antlr4ng/dist/atn/LoopEndState.js +96 -0
  130. openpinescript/_engine/node_modules/antlr4ng/dist/atn/LoopEndState.mjs +76 -0
  131. openpinescript/_engine/node_modules/antlr4ng/dist/atn/NotSetTransition.cjs +921 -0
  132. openpinescript/_engine/node_modules/antlr4ng/dist/atn/NotSetTransition.js +921 -0
  133. openpinescript/_engine/node_modules/antlr4ng/dist/atn/NotSetTransition.mjs +901 -0
  134. openpinescript/_engine/node_modules/antlr4ng/dist/atn/OrderedATNConfigSet.cjs +3824 -0
  135. openpinescript/_engine/node_modules/antlr4ng/dist/atn/OrderedATNConfigSet.js +3824 -0
  136. openpinescript/_engine/node_modules/antlr4ng/dist/atn/OrderedATNConfigSet.mjs +3804 -0
  137. openpinescript/_engine/node_modules/antlr4ng/dist/atn/ParseInfo.cjs +156 -0
  138. openpinescript/_engine/node_modules/antlr4ng/dist/atn/ParseInfo.js +156 -0
  139. openpinescript/_engine/node_modules/antlr4ng/dist/atn/ParseInfo.mjs +138 -0
  140. openpinescript/_engine/node_modules/antlr4ng/dist/atn/ParserATNSimulator.cjs +6082 -0
  141. openpinescript/_engine/node_modules/antlr4ng/dist/atn/ParserATNSimulator.js +6082 -0
  142. openpinescript/_engine/node_modules/antlr4ng/dist/atn/ParserATNSimulator.mjs +6062 -0
  143. openpinescript/_engine/node_modules/antlr4ng/dist/atn/PlusBlockStartState.cjs +113 -0
  144. openpinescript/_engine/node_modules/antlr4ng/dist/atn/PlusBlockStartState.js +113 -0
  145. openpinescript/_engine/node_modules/antlr4ng/dist/atn/PlusBlockStartState.mjs +93 -0
  146. openpinescript/_engine/node_modules/antlr4ng/dist/atn/PlusLoopbackState.cjs +104 -0
  147. openpinescript/_engine/node_modules/antlr4ng/dist/atn/PlusLoopbackState.js +104 -0
  148. openpinescript/_engine/node_modules/antlr4ng/dist/atn/PlusLoopbackState.mjs +84 -0
  149. openpinescript/_engine/node_modules/antlr4ng/dist/atn/PrecedencePredicateTransition.cjs +887 -0
  150. openpinescript/_engine/node_modules/antlr4ng/dist/atn/PrecedencePredicateTransition.js +887 -0
  151. openpinescript/_engine/node_modules/antlr4ng/dist/atn/PrecedencePredicateTransition.mjs +867 -0
  152. openpinescript/_engine/node_modules/antlr4ng/dist/atn/PredicateEvalInfo.cjs +17 -0
  153. openpinescript/_engine/node_modules/antlr4ng/dist/atn/PredicateEvalInfo.js +17 -0
  154. openpinescript/_engine/node_modules/antlr4ng/dist/atn/PredicateEvalInfo.mjs +0 -0
  155. openpinescript/_engine/node_modules/antlr4ng/dist/atn/PredicateTransition.cjs +892 -0
  156. openpinescript/_engine/node_modules/antlr4ng/dist/atn/PredicateTransition.js +892 -0
  157. openpinescript/_engine/node_modules/antlr4ng/dist/atn/PredicateTransition.mjs +872 -0
  158. openpinescript/_engine/node_modules/antlr4ng/dist/atn/PredictionContext.cjs +153 -0
  159. openpinescript/_engine/node_modules/antlr4ng/dist/atn/PredictionContext.js +153 -0
  160. openpinescript/_engine/node_modules/antlr4ng/dist/atn/PredictionContext.mjs +133 -0
  161. openpinescript/_engine/node_modules/antlr4ng/dist/atn/PredictionContextCache.cjs +715 -0
  162. openpinescript/_engine/node_modules/antlr4ng/dist/atn/PredictionContextCache.js +715 -0
  163. openpinescript/_engine/node_modules/antlr4ng/dist/atn/PredictionContextCache.mjs +695 -0
  164. openpinescript/_engine/node_modules/antlr4ng/dist/atn/PredictionContextUtils.cjs +3604 -0
  165. openpinescript/_engine/node_modules/antlr4ng/dist/atn/PredictionContextUtils.js +3604 -0
  166. openpinescript/_engine/node_modules/antlr4ng/dist/atn/PredictionContextUtils.mjs +3584 -0
  167. openpinescript/_engine/node_modules/antlr4ng/dist/atn/PredictionMode.cjs +4284 -0
  168. openpinescript/_engine/node_modules/antlr4ng/dist/atn/PredictionMode.js +4284 -0
  169. openpinescript/_engine/node_modules/antlr4ng/dist/atn/PredictionMode.mjs +4264 -0
  170. openpinescript/_engine/node_modules/antlr4ng/dist/atn/ProfilingATNSimulator.cjs +6467 -0
  171. openpinescript/_engine/node_modules/antlr4ng/dist/atn/ProfilingATNSimulator.js +6467 -0
  172. openpinescript/_engine/node_modules/antlr4ng/dist/atn/ProfilingATNSimulator.mjs +6447 -0
  173. openpinescript/_engine/node_modules/antlr4ng/dist/atn/RangeTransition.cjs +905 -0
  174. openpinescript/_engine/node_modules/antlr4ng/dist/atn/RangeTransition.js +905 -0
  175. openpinescript/_engine/node_modules/antlr4ng/dist/atn/RangeTransition.mjs +885 -0
  176. openpinescript/_engine/node_modules/antlr4ng/dist/atn/RuleStartState.cjs +97 -0
  177. openpinescript/_engine/node_modules/antlr4ng/dist/atn/RuleStartState.js +97 -0
  178. openpinescript/_engine/node_modules/antlr4ng/dist/atn/RuleStartState.mjs +77 -0
  179. openpinescript/_engine/node_modules/antlr4ng/dist/atn/RuleStopState.cjs +95 -0
  180. openpinescript/_engine/node_modules/antlr4ng/dist/atn/RuleStopState.js +95 -0
  181. openpinescript/_engine/node_modules/antlr4ng/dist/atn/RuleStopState.mjs +75 -0
  182. openpinescript/_engine/node_modules/antlr4ng/dist/atn/RuleTransition.cjs +93 -0
  183. openpinescript/_engine/node_modules/antlr4ng/dist/atn/RuleTransition.js +93 -0
  184. openpinescript/_engine/node_modules/antlr4ng/dist/atn/RuleTransition.mjs +73 -0
  185. openpinescript/_engine/node_modules/antlr4ng/dist/atn/SemanticContext.cjs +807 -0
  186. openpinescript/_engine/node_modules/antlr4ng/dist/atn/SemanticContext.js +807 -0
  187. openpinescript/_engine/node_modules/antlr4ng/dist/atn/SemanticContext.mjs +787 -0
  188. openpinescript/_engine/node_modules/antlr4ng/dist/atn/SetTransition.cjs +905 -0
  189. openpinescript/_engine/node_modules/antlr4ng/dist/atn/SetTransition.js +905 -0
  190. openpinescript/_engine/node_modules/antlr4ng/dist/atn/SetTransition.mjs +885 -0
  191. openpinescript/_engine/node_modules/antlr4ng/dist/atn/SingletonPredictionContext.cjs +207 -0
  192. openpinescript/_engine/node_modules/antlr4ng/dist/atn/SingletonPredictionContext.js +207 -0
  193. openpinescript/_engine/node_modules/antlr4ng/dist/atn/SingletonPredictionContext.mjs +187 -0
  194. openpinescript/_engine/node_modules/antlr4ng/dist/atn/StarBlockStartState.cjs +112 -0
  195. openpinescript/_engine/node_modules/antlr4ng/dist/atn/StarBlockStartState.js +112 -0
  196. openpinescript/_engine/node_modules/antlr4ng/dist/atn/StarBlockStartState.mjs +92 -0
  197. openpinescript/_engine/node_modules/antlr4ng/dist/atn/StarLoopEntryState.cjs +117 -0
  198. openpinescript/_engine/node_modules/antlr4ng/dist/atn/StarLoopEntryState.js +117 -0
  199. openpinescript/_engine/node_modules/antlr4ng/dist/atn/StarLoopEntryState.mjs +97 -0
  200. openpinescript/_engine/node_modules/antlr4ng/dist/atn/StarLoopbackState.cjs +95 -0
  201. openpinescript/_engine/node_modules/antlr4ng/dist/atn/StarLoopbackState.js +95 -0
  202. openpinescript/_engine/node_modules/antlr4ng/dist/atn/StarLoopbackState.mjs +75 -0
  203. openpinescript/_engine/node_modules/antlr4ng/dist/atn/TokensStartState.cjs +104 -0
  204. openpinescript/_engine/node_modules/antlr4ng/dist/atn/TokensStartState.js +104 -0
  205. openpinescript/_engine/node_modules/antlr4ng/dist/atn/TokensStartState.mjs +84 -0
  206. openpinescript/_engine/node_modules/antlr4ng/dist/atn/Transition.cjs +66 -0
  207. openpinescript/_engine/node_modules/antlr4ng/dist/atn/Transition.js +66 -0
  208. openpinescript/_engine/node_modules/antlr4ng/dist/atn/Transition.mjs +48 -0
  209. openpinescript/_engine/node_modules/antlr4ng/dist/atn/WildcardTransition.cjs +84 -0
  210. openpinescript/_engine/node_modules/antlr4ng/dist/atn/WildcardTransition.js +84 -0
  211. openpinescript/_engine/node_modules/antlr4ng/dist/atn/WildcardTransition.mjs +64 -0
  212. openpinescript/_engine/node_modules/antlr4ng/dist/atn/helpers.cjs +246 -0
  213. openpinescript/_engine/node_modules/antlr4ng/dist/atn/helpers.js +246 -0
  214. openpinescript/_engine/node_modules/antlr4ng/dist/atn/helpers.mjs +226 -0
  215. openpinescript/_engine/node_modules/antlr4ng/dist/atn/index.cjs +9485 -0
  216. openpinescript/_engine/node_modules/antlr4ng/dist/atn/index.js +9485 -0
  217. openpinescript/_engine/node_modules/antlr4ng/dist/atn/index.mjs +9465 -0
  218. openpinescript/_engine/node_modules/antlr4ng/dist/dfa/DFA.cjs +559 -0
  219. openpinescript/_engine/node_modules/antlr4ng/dist/dfa/DFA.js +559 -0
  220. openpinescript/_engine/node_modules/antlr4ng/dist/dfa/DFA.mjs +539 -0
  221. openpinescript/_engine/node_modules/antlr4ng/dist/dfa/DFASerializer.cjs +76 -0
  222. openpinescript/_engine/node_modules/antlr4ng/dist/dfa/DFASerializer.js +76 -0
  223. openpinescript/_engine/node_modules/antlr4ng/dist/dfa/DFASerializer.mjs +58 -0
  224. openpinescript/_engine/node_modules/antlr4ng/dist/dfa/DFAState.cjs +136 -0
  225. openpinescript/_engine/node_modules/antlr4ng/dist/dfa/DFAState.js +136 -0
  226. openpinescript/_engine/node_modules/antlr4ng/dist/dfa/DFAState.mjs +116 -0
  227. openpinescript/_engine/node_modules/antlr4ng/dist/dfa/DFAStateEqualityComparator.cjs +150 -0
  228. openpinescript/_engine/node_modules/antlr4ng/dist/dfa/DFAStateEqualityComparator.js +150 -0
  229. openpinescript/_engine/node_modules/antlr4ng/dist/dfa/DFAStateEqualityComparator.mjs +130 -0
  230. openpinescript/_engine/node_modules/antlr4ng/dist/dfa/LexerDFASerializer.cjs +237 -0
  231. openpinescript/_engine/node_modules/antlr4ng/dist/dfa/LexerDFASerializer.js +237 -0
  232. openpinescript/_engine/node_modules/antlr4ng/dist/dfa/LexerDFASerializer.mjs +217 -0
  233. openpinescript/_engine/node_modules/antlr4ng/dist/dfa/PredPrediction.cjs +31 -0
  234. openpinescript/_engine/node_modules/antlr4ng/dist/dfa/PredPrediction.js +31 -0
  235. openpinescript/_engine/node_modules/antlr4ng/dist/dfa/PredPrediction.mjs +13 -0
  236. openpinescript/_engine/node_modules/antlr4ng/dist/dfa/index.cjs +571 -0
  237. openpinescript/_engine/node_modules/antlr4ng/dist/dfa/index.js +571 -0
  238. openpinescript/_engine/node_modules/antlr4ng/dist/dfa/index.mjs +551 -0
  239. openpinescript/_engine/node_modules/antlr4ng/dist/index.cjs +17501 -0
  240. openpinescript/_engine/node_modules/antlr4ng/dist/index.mjs +17481 -0
  241. openpinescript/_engine/node_modules/antlr4ng/dist/misc/BitSet.cjs +208 -0
  242. openpinescript/_engine/node_modules/antlr4ng/dist/misc/BitSet.js +208 -0
  243. openpinescript/_engine/node_modules/antlr4ng/dist/misc/BitSet.mjs +190 -0
  244. openpinescript/_engine/node_modules/antlr4ng/dist/misc/DefaultEqualityComparator.cjs +68 -0
  245. openpinescript/_engine/node_modules/antlr4ng/dist/misc/DefaultEqualityComparator.js +68 -0
  246. openpinescript/_engine/node_modules/antlr4ng/dist/misc/DefaultEqualityComparator.mjs +48 -0
  247. openpinescript/_engine/node_modules/antlr4ng/dist/misc/EqualityComparator.cjs +17 -0
  248. openpinescript/_engine/node_modules/antlr4ng/dist/misc/EqualityComparator.js +17 -0
  249. openpinescript/_engine/node_modules/antlr4ng/dist/misc/EqualityComparator.mjs +0 -0
  250. openpinescript/_engine/node_modules/antlr4ng/dist/misc/HashMap.cjs +545 -0
  251. openpinescript/_engine/node_modules/antlr4ng/dist/misc/HashMap.js +545 -0
  252. openpinescript/_engine/node_modules/antlr4ng/dist/misc/HashMap.mjs +525 -0
  253. openpinescript/_engine/node_modules/antlr4ng/dist/misc/HashSet.cjs +438 -0
  254. openpinescript/_engine/node_modules/antlr4ng/dist/misc/HashSet.js +438 -0
  255. openpinescript/_engine/node_modules/antlr4ng/dist/misc/HashSet.mjs +418 -0
  256. openpinescript/_engine/node_modules/antlr4ng/dist/misc/InterpreterDataReader.cjs +4420 -0
  257. openpinescript/_engine/node_modules/antlr4ng/dist/misc/InterpreterDataReader.js +4420 -0
  258. openpinescript/_engine/node_modules/antlr4ng/dist/misc/InterpreterDataReader.mjs +4400 -0
  259. openpinescript/_engine/node_modules/antlr4ng/dist/misc/Interval.cjs +133 -0
  260. openpinescript/_engine/node_modules/antlr4ng/dist/misc/Interval.js +133 -0
  261. openpinescript/_engine/node_modules/antlr4ng/dist/misc/Interval.mjs +115 -0
  262. openpinescript/_engine/node_modules/antlr4ng/dist/misc/IntervalSet.cjs +834 -0
  263. openpinescript/_engine/node_modules/antlr4ng/dist/misc/IntervalSet.js +834 -0
  264. openpinescript/_engine/node_modules/antlr4ng/dist/misc/IntervalSet.mjs +814 -0
  265. openpinescript/_engine/node_modules/antlr4ng/dist/misc/MapKeyEqualityOperator.cjs +40 -0
  266. openpinescript/_engine/node_modules/antlr4ng/dist/misc/MapKeyEqualityOperator.js +40 -0
  267. openpinescript/_engine/node_modules/antlr4ng/dist/misc/MapKeyEqualityOperator.mjs +22 -0
  268. openpinescript/_engine/node_modules/antlr4ng/dist/misc/MultiMap.cjs +55 -0
  269. openpinescript/_engine/node_modules/antlr4ng/dist/misc/MultiMap.js +55 -0
  270. openpinescript/_engine/node_modules/antlr4ng/dist/misc/MultiMap.mjs +37 -0
  271. openpinescript/_engine/node_modules/antlr4ng/dist/misc/ObjectEqualityComparator.cjs +43 -0
  272. openpinescript/_engine/node_modules/antlr4ng/dist/misc/ObjectEqualityComparator.js +43 -0
  273. openpinescript/_engine/node_modules/antlr4ng/dist/misc/ObjectEqualityComparator.mjs +25 -0
  274. openpinescript/_engine/node_modules/antlr4ng/dist/misc/OrderedHashMap.cjs +610 -0
  275. openpinescript/_engine/node_modules/antlr4ng/dist/misc/OrderedHashMap.js +610 -0
  276. openpinescript/_engine/node_modules/antlr4ng/dist/misc/OrderedHashMap.mjs +590 -0
  277. openpinescript/_engine/node_modules/antlr4ng/dist/misc/OrderedHashSet.cjs +470 -0
  278. openpinescript/_engine/node_modules/antlr4ng/dist/misc/OrderedHashSet.js +470 -0
  279. openpinescript/_engine/node_modules/antlr4ng/dist/misc/OrderedHashSet.mjs +450 -0
  280. openpinescript/_engine/node_modules/antlr4ng/dist/misc/ParseCancellationException.cjs +34 -0
  281. openpinescript/_engine/node_modules/antlr4ng/dist/misc/ParseCancellationException.js +34 -0
  282. openpinescript/_engine/node_modules/antlr4ng/dist/misc/ParseCancellationException.mjs +16 -0
  283. openpinescript/_engine/node_modules/antlr4ng/dist/misc/index.cjs +4643 -0
  284. openpinescript/_engine/node_modules/antlr4ng/dist/misc/index.js +4643 -0
  285. openpinescript/_engine/node_modules/antlr4ng/dist/misc/index.mjs +4623 -0
  286. openpinescript/_engine/node_modules/antlr4ng/dist/tree/AbstractParseTreeVisitor.cjs +63 -0
  287. openpinescript/_engine/node_modules/antlr4ng/dist/tree/AbstractParseTreeVisitor.js +63 -0
  288. openpinescript/_engine/node_modules/antlr4ng/dist/tree/AbstractParseTreeVisitor.mjs +45 -0
  289. openpinescript/_engine/node_modules/antlr4ng/dist/tree/ErrorNode.cjs +211 -0
  290. openpinescript/_engine/node_modules/antlr4ng/dist/tree/ErrorNode.js +211 -0
  291. openpinescript/_engine/node_modules/antlr4ng/dist/tree/ErrorNode.mjs +191 -0
  292. openpinescript/_engine/node_modules/antlr4ng/dist/tree/ParseTree.cjs +17 -0
  293. openpinescript/_engine/node_modules/antlr4ng/dist/tree/ParseTree.js +17 -0
  294. openpinescript/_engine/node_modules/antlr4ng/dist/tree/ParseTree.mjs +0 -0
  295. openpinescript/_engine/node_modules/antlr4ng/dist/tree/ParseTreeListener.cjs +17 -0
  296. openpinescript/_engine/node_modules/antlr4ng/dist/tree/ParseTreeListener.js +17 -0
  297. openpinescript/_engine/node_modules/antlr4ng/dist/tree/ParseTreeListener.mjs +0 -0
  298. openpinescript/_engine/node_modules/antlr4ng/dist/tree/ParseTreeVisitor.cjs +17 -0
  299. openpinescript/_engine/node_modules/antlr4ng/dist/tree/ParseTreeVisitor.js +17 -0
  300. openpinescript/_engine/node_modules/antlr4ng/dist/tree/ParseTreeVisitor.mjs +0 -0
  301. openpinescript/_engine/node_modules/antlr4ng/dist/tree/ParseTreeWalker.cjs +267 -0
  302. openpinescript/_engine/node_modules/antlr4ng/dist/tree/ParseTreeWalker.js +267 -0
  303. openpinescript/_engine/node_modules/antlr4ng/dist/tree/ParseTreeWalker.mjs +247 -0
  304. openpinescript/_engine/node_modules/antlr4ng/dist/tree/TerminalNode.cjs +201 -0
  305. openpinescript/_engine/node_modules/antlr4ng/dist/tree/TerminalNode.js +201 -0
  306. openpinescript/_engine/node_modules/antlr4ng/dist/tree/TerminalNode.mjs +181 -0
  307. openpinescript/_engine/node_modules/antlr4ng/dist/tree/Trees.cjs +3159 -0
  308. openpinescript/_engine/node_modules/antlr4ng/dist/tree/Trees.js +3159 -0
  309. openpinescript/_engine/node_modules/antlr4ng/dist/tree/Trees.mjs +3139 -0
  310. openpinescript/_engine/node_modules/antlr4ng/dist/tree/index.cjs +16018 -0
  311. openpinescript/_engine/node_modules/antlr4ng/dist/tree/index.js +16018 -0
  312. openpinescript/_engine/node_modules/antlr4ng/dist/tree/index.mjs +15998 -0
  313. openpinescript/_engine/node_modules/antlr4ng/dist/utils/DoubleDict.cjs +568 -0
  314. openpinescript/_engine/node_modules/antlr4ng/dist/utils/DoubleDict.js +568 -0
  315. openpinescript/_engine/node_modules/antlr4ng/dist/utils/DoubleDict.mjs +548 -0
  316. openpinescript/_engine/node_modules/antlr4ng/dist/utils/MurmurHash.cjs +98 -0
  317. openpinescript/_engine/node_modules/antlr4ng/dist/utils/MurmurHash.js +98 -0
  318. openpinescript/_engine/node_modules/antlr4ng/dist/utils/MurmurHash.mjs +80 -0
  319. openpinescript/_engine/node_modules/antlr4ng/dist/utils/helpers.cjs +78 -0
  320. openpinescript/_engine/node_modules/antlr4ng/dist/utils/helpers.js +78 -0
  321. openpinescript/_engine/node_modules/antlr4ng/dist/utils/helpers.mjs +60 -0
  322. openpinescript/_engine/node_modules/antlr4ng/dist/utils/index.cjs +625 -0
  323. openpinescript/_engine/node_modules/antlr4ng/dist/utils/index.js +625 -0
  324. openpinescript/_engine/node_modules/antlr4ng/dist/utils/index.mjs +605 -0
  325. openpinescript/_engine/node_modules/antlr4ng/package.json +72 -0
  326. openpinescript/_engine/package.json +94 -0
  327. openpinescript/_runtime.py +29 -0
  328. openpinescript-0.1.1.dist-info/METADATA +140 -0
  329. openpinescript-0.1.1.dist-info/RECORD +332 -0
  330. openpinescript-0.1.1.dist-info/WHEEL +4 -0
  331. openpinescript-0.1.1.dist-info/entry_points.txt +2 -0
  332. openpinescript-0.1.1.dist-info/licenses/LICENSE +674 -0
@@ -0,0 +1,4264 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+
4
+ // src/IntStream.ts
5
+ var IntStream;
6
+ ((IntStream2) => {
7
+ IntStream2.EOF = -1;
8
+ IntStream2.UNKNOWN_SOURCE_NAME = "<unknown>";
9
+ })(IntStream || (IntStream = {}));
10
+
11
+ // src/Token.ts
12
+ var Token;
13
+ ((Token2) => {
14
+ Token2.INVALID_TYPE = 0;
15
+ Token2.EPSILON = -2;
16
+ Token2.MIN_USER_TOKEN_TYPE = 1;
17
+ Token2.EOF = IntStream.EOF;
18
+ Token2.DEFAULT_CHANNEL = 0;
19
+ Token2.HIDDEN_CHANNEL = 1;
20
+ Token2.MIN_USER_CHANNEL_VALUE = 2;
21
+ })(Token || (Token = {}));
22
+ var isToken = /* @__PURE__ */ __name((candidate) => {
23
+ const token = candidate;
24
+ return token.tokenSource !== void 0 && token.channel !== void 0;
25
+ }, "isToken");
26
+
27
+ // src/misc/BitSet.ts
28
+ var BitSet = class {
29
+ static {
30
+ __name(this, "BitSet");
31
+ }
32
+ data;
33
+ /**
34
+ * Creates a new bit set. All bits are initially `false`.
35
+ *
36
+ * @param data Optional initial data.
37
+ */
38
+ constructor(data) {
39
+ if (data) {
40
+ this.data = new Uint32Array(data.map((value) => {
41
+ return value >>> 0;
42
+ }));
43
+ } else {
44
+ this.data = new Uint32Array(1);
45
+ }
46
+ }
47
+ /**
48
+ * @returns an iterator over all set bits.
49
+ */
50
+ [Symbol.iterator]() {
51
+ const length = this.data.length;
52
+ let currentIndex = 0;
53
+ let currentWord = this.data[currentIndex];
54
+ const words = this.data;
55
+ return {
56
+ [Symbol.iterator]() {
57
+ return this;
58
+ },
59
+ next: /* @__PURE__ */ __name(() => {
60
+ while (currentIndex < length) {
61
+ if (currentWord !== 0) {
62
+ const t = currentWord & -currentWord;
63
+ const value = (currentIndex << 5) + this.bitCount(t - 1);
64
+ currentWord ^= t;
65
+ return { done: false, value };
66
+ } else {
67
+ currentIndex++;
68
+ if (currentIndex < length) {
69
+ currentWord = words[currentIndex];
70
+ }
71
+ }
72
+ }
73
+ return { done: true, value: void 0 };
74
+ }, "next")
75
+ };
76
+ }
77
+ /**
78
+ * Sets a single bit or all of the bits in this `BitSet` to `false`.
79
+ *
80
+ * @param index the index of the bit to be cleared, or undefined to clear all bits.
81
+ */
82
+ clear(index) {
83
+ if (index === void 0) {
84
+ this.data = new Uint32Array();
85
+ } else {
86
+ this.resize(index);
87
+ this.data[index >>> 5] &= ~(1 << index);
88
+ }
89
+ }
90
+ /**
91
+ * Performs a logical **OR** of this bit set with the bit set argument. This bit set is modified so that a bit in it
92
+ * has the value `true` if and only if it either already had the value `true` or the corresponding bit in the bit
93
+ * set argument has the value `true`.
94
+ *
95
+ * @param set the bit set to be ORed with.
96
+ */
97
+ or(set) {
98
+ const minCount = Math.min(this.data.length, set.data.length);
99
+ for (let k = 0; k < minCount; ++k) {
100
+ this.data[k] |= set.data[k];
101
+ }
102
+ if (this.data.length < set.data.length) {
103
+ this.resize((set.data.length << 5) - 1);
104
+ const c = set.data.length;
105
+ for (let k = minCount; k < c; ++k) {
106
+ this.data[k] = set.data[k];
107
+ }
108
+ }
109
+ }
110
+ /**
111
+ * Returns the value of the bit with the specified index. The value is `true` if the bit with the index `bitIndex`
112
+ * is currently set in this `BitSet`; otherwise, the result is `false`.
113
+ *
114
+ * @param index the bit index
115
+ *
116
+ * @returns the value of the bit with the specified index.
117
+ */
118
+ get(index) {
119
+ if (index < 0) {
120
+ throw new RangeError("index cannot be negative");
121
+ }
122
+ const slot = index >>> 5;
123
+ if (slot >= this.data.length) {
124
+ return false;
125
+ }
126
+ return (this.data[slot] & 1 << index % 32) !== 0;
127
+ }
128
+ /**
129
+ * @returns the number of set bits.
130
+ */
131
+ get length() {
132
+ let result = 0;
133
+ const c = this.data.length;
134
+ const w = this.data;
135
+ for (let i = 0; i < c; i++) {
136
+ result += this.bitCount(w[i]);
137
+ }
138
+ return result;
139
+ }
140
+ /**
141
+ * @returns an array with indices of set bits.
142
+ */
143
+ values() {
144
+ const result = new Array(this.length);
145
+ let pos = 0;
146
+ const length = this.data.length;
147
+ for (let k = 0; k < length; ++k) {
148
+ let w = this.data[k];
149
+ while (w !== 0) {
150
+ const t = w & -w;
151
+ result[pos++] = (k << 5) + this.bitCount(t - 1);
152
+ w ^= t;
153
+ }
154
+ }
155
+ return result;
156
+ }
157
+ /**
158
+ * @returns the index of the first bit that is set to `true` that occurs on or after the specified starting index.
159
+ * If no such bit exists then undefined is returned.
160
+ *
161
+ * @param fromIndex the index to start checking from (inclusive)
162
+ */
163
+ nextSetBit(fromIndex) {
164
+ if (fromIndex < 0) {
165
+ throw new RangeError("index cannot be negative");
166
+ }
167
+ for (const index of this) {
168
+ if (index >= fromIndex) {
169
+ return index;
170
+ }
171
+ }
172
+ return void 0;
173
+ }
174
+ /**
175
+ * Sets the bit at the specified index to `true`.
176
+ *
177
+ * @param index a bit index
178
+ */
179
+ set(index) {
180
+ if (index < 0) {
181
+ throw new RangeError("index cannot be negative");
182
+ }
183
+ this.resize(index);
184
+ this.data[index >>> 5] |= 1 << index % 32;
185
+ }
186
+ /**
187
+ * @returns a string representation of this bit set.
188
+ */
189
+ toString() {
190
+ return "{" + this.values().join(", ") + "}";
191
+ }
192
+ resize(index) {
193
+ const count = index + 32 >>> 5;
194
+ if (count <= this.data.length) {
195
+ return;
196
+ }
197
+ const data = new Uint32Array(count);
198
+ data.set(this.data);
199
+ data.fill(0, this.data.length);
200
+ this.data = data;
201
+ }
202
+ bitCount(v) {
203
+ v = v - (v >> 1 & 1431655765);
204
+ v = (v & 858993459) + (v >> 2 & 858993459);
205
+ v = v + (v >> 4) & 252645135;
206
+ v = v + (v >> 8);
207
+ v = v + (v >> 16);
208
+ return v & 63;
209
+ }
210
+ };
211
+
212
+ // src/utils/MurmurHash.ts
213
+ var c1 = 3432918353;
214
+ var c2 = 461845907;
215
+ var r1 = 15;
216
+ var r2 = 13;
217
+ var m = 5;
218
+ var n = 3864292196;
219
+ var MurmurHash = class _MurmurHash {
220
+ static {
221
+ __name(this, "MurmurHash");
222
+ }
223
+ static defaultSeed = 701;
224
+ constructor() {
225
+ }
226
+ /**
227
+ * Initialize the hash using the specified {@code seed}.
228
+ *
229
+ * @param seed the seed
230
+ *
231
+ * @returns the intermediate hash value
232
+ */
233
+ static initialize(seed = _MurmurHash.defaultSeed) {
234
+ return seed;
235
+ }
236
+ static updateFromComparable(hash, value) {
237
+ return this.update(hash, value?.hashCode() ?? 0);
238
+ }
239
+ /**
240
+ * Update the intermediate hash value for the next input {@code value}.
241
+ *
242
+ * @param hash The intermediate hash value.
243
+ * @param value the value to add to the current hash.
244
+ *
245
+ * @returns the updated intermediate hash value
246
+ */
247
+ static update(hash, value) {
248
+ value = Math.imul(value, c1);
249
+ value = value << r1 | value >>> 32 - r1;
250
+ value = Math.imul(value, c2);
251
+ hash = hash ^ value;
252
+ hash = hash << r2 | hash >>> 32 - r2;
253
+ hash = Math.imul(hash, m) + n;
254
+ return hash;
255
+ }
256
+ /**
257
+ * Apply the final computation steps to the intermediate value {@code hash}
258
+ * to form the final result of the MurmurHash 3 hash function.
259
+ *
260
+ * @param hash The intermediate hash value.
261
+ * @param entryCount The number of values added to the hash.
262
+ *
263
+ * @returns the final hash result
264
+ */
265
+ static finish(hash, entryCount) {
266
+ hash ^= entryCount * 4;
267
+ hash ^= hash >>> 16;
268
+ hash = Math.imul(hash, 2246822507);
269
+ hash ^= hash >>> 13;
270
+ hash = Math.imul(hash, 3266489909);
271
+ hash ^= hash >>> 16;
272
+ return hash;
273
+ }
274
+ /**
275
+ * An all-in-one convenience method to compute a hash for a single value.
276
+ *
277
+ * @param value The value to hash.
278
+ * @param seed The seed for the hash value.
279
+ *
280
+ * @returns The computed hash.
281
+ */
282
+ static hashCode(value, seed) {
283
+ return _MurmurHash.finish(_MurmurHash.update(seed ?? _MurmurHash.defaultSeed, value), 1);
284
+ }
285
+ };
286
+
287
+ // src/misc/ObjectEqualityComparator.ts
288
+ var ObjectEqualityComparator = class _ObjectEqualityComparator {
289
+ static {
290
+ __name(this, "ObjectEqualityComparator");
291
+ }
292
+ static instance = new _ObjectEqualityComparator();
293
+ hashCode(obj) {
294
+ if (obj == null) {
295
+ return 0;
296
+ }
297
+ return obj.hashCode();
298
+ }
299
+ equals(a, b) {
300
+ if (a == null) {
301
+ return b == null;
302
+ }
303
+ return a.equals(b);
304
+ }
305
+ };
306
+
307
+ // src/misc/DefaultEqualityComparator.ts
308
+ var DefaultEqualityComparator = class _DefaultEqualityComparator {
309
+ static {
310
+ __name(this, "DefaultEqualityComparator");
311
+ }
312
+ static instance = new _DefaultEqualityComparator();
313
+ hashCode(obj) {
314
+ if (obj == null) {
315
+ return 0;
316
+ }
317
+ return ObjectEqualityComparator.instance.hashCode(obj);
318
+ }
319
+ equals(a, b) {
320
+ if (a == null) {
321
+ return b == null;
322
+ }
323
+ if (typeof a === "string" || typeof a === "number") {
324
+ return a === b;
325
+ }
326
+ return ObjectEqualityComparator.instance.equals(a, b);
327
+ }
328
+ };
329
+
330
+ // src/misc/HashSet.ts
331
+ var HashSet = class _HashSet {
332
+ static {
333
+ __name(this, "HashSet");
334
+ }
335
+ static defaultLoadFactor = 0.75;
336
+ static initialCapacity = 16;
337
+ // must be power of 2
338
+ comparator;
339
+ buckets;
340
+ threshold;
341
+ /** How many elements in set */
342
+ itemCount = 0;
343
+ constructor(comparatorOrSet, initialCapacity = _HashSet.initialCapacity) {
344
+ if (comparatorOrSet instanceof _HashSet) {
345
+ this.comparator = comparatorOrSet.comparator;
346
+ this.buckets = comparatorOrSet.buckets.slice(0);
347
+ for (let i = 0; i < this.buckets.length; i++) {
348
+ const bucket = this.buckets[i];
349
+ if (bucket) {
350
+ this.buckets[i] = bucket.slice(0);
351
+ }
352
+ }
353
+ this.itemCount = comparatorOrSet.itemCount;
354
+ this.threshold = comparatorOrSet.threshold;
355
+ } else {
356
+ this.comparator = comparatorOrSet ?? DefaultEqualityComparator.instance;
357
+ this.buckets = this.createBuckets(initialCapacity);
358
+ this.threshold = Math.floor(_HashSet.initialCapacity * _HashSet.defaultLoadFactor);
359
+ }
360
+ }
361
+ /**
362
+ * Add `o` to set if not there; return existing value if already
363
+ * there. This method performs the same operation as {@link #add} aside from
364
+ * the return value.
365
+ *
366
+ * @param o the object to add to the set.
367
+ *
368
+ * @returns An existing element that equals to `o` if already in set, otherwise `o`.
369
+ */
370
+ getOrAdd(o) {
371
+ if (this.itemCount > this.threshold) {
372
+ this.expand();
373
+ }
374
+ const b = this.getBucket(o);
375
+ let bucket = this.buckets[b];
376
+ if (!bucket) {
377
+ bucket = [o];
378
+ this.buckets[b] = bucket;
379
+ ++this.itemCount;
380
+ return o;
381
+ }
382
+ for (const existing of bucket) {
383
+ if (this.comparator.equals(existing, o)) {
384
+ return existing;
385
+ }
386
+ }
387
+ bucket.push(o);
388
+ ++this.itemCount;
389
+ return o;
390
+ }
391
+ get(o) {
392
+ if (o == null) {
393
+ return o;
394
+ }
395
+ const b = this.getBucket(o);
396
+ const bucket = this.buckets[b];
397
+ if (!bucket) {
398
+ return void 0;
399
+ }
400
+ for (const e of bucket) {
401
+ if (this.comparator.equals(e, o)) {
402
+ return e;
403
+ }
404
+ }
405
+ return void 0;
406
+ }
407
+ /**
408
+ * Removes the specified element from this set if it is present.
409
+ *
410
+ * @param o object to be removed from this set, if present.
411
+ *
412
+ * @returns `true` if the set contained the specified element.
413
+ */
414
+ remove(o) {
415
+ if (o == null) {
416
+ return false;
417
+ }
418
+ const b = this.getBucket(o);
419
+ const bucket = this.buckets[b];
420
+ if (!bucket) {
421
+ return false;
422
+ }
423
+ for (let i = 0; i < bucket.length; i++) {
424
+ const existing = bucket[i];
425
+ if (this.comparator.equals(existing, o)) {
426
+ bucket.splice(i, 1);
427
+ --this.itemCount;
428
+ return true;
429
+ }
430
+ }
431
+ return false;
432
+ }
433
+ hashCode() {
434
+ let hash = MurmurHash.initialize();
435
+ for (const bucket of this.buckets) {
436
+ if (bucket == null) {
437
+ continue;
438
+ }
439
+ for (const o of bucket) {
440
+ if (o == null) {
441
+ break;
442
+ }
443
+ hash = MurmurHash.update(hash, this.comparator.hashCode(o));
444
+ }
445
+ }
446
+ hash = MurmurHash.finish(hash, this.size);
447
+ return hash;
448
+ }
449
+ equals(o) {
450
+ if (o === this) {
451
+ return true;
452
+ }
453
+ if (!(o instanceof _HashSet)) {
454
+ return false;
455
+ }
456
+ if (o.size !== this.size) {
457
+ return false;
458
+ }
459
+ return this.containsAll(o);
460
+ }
461
+ add(t) {
462
+ const existing = this.getOrAdd(t);
463
+ return existing === t;
464
+ }
465
+ contains(o) {
466
+ return this.containsFast(o);
467
+ }
468
+ containsFast(obj) {
469
+ if (obj == null) {
470
+ return false;
471
+ }
472
+ return this.get(obj) !== void 0;
473
+ }
474
+ *[Symbol.iterator]() {
475
+ yield* this.toArray();
476
+ }
477
+ toArray() {
478
+ const a = new Array(this.size);
479
+ let i = 0;
480
+ for (const bucket of this.buckets) {
481
+ if (bucket == null) {
482
+ continue;
483
+ }
484
+ for (const o of bucket) {
485
+ if (o == null) {
486
+ break;
487
+ }
488
+ a[i++] = o;
489
+ }
490
+ }
491
+ return a;
492
+ }
493
+ containsAll(collection) {
494
+ if (collection instanceof _HashSet) {
495
+ for (const bucket of collection.buckets) {
496
+ if (bucket == null) {
497
+ continue;
498
+ }
499
+ for (const o of bucket) {
500
+ if (o == null) {
501
+ break;
502
+ }
503
+ if (!this.containsFast(o)) {
504
+ return false;
505
+ }
506
+ }
507
+ }
508
+ } else {
509
+ for (const o of collection) {
510
+ if (!this.containsFast(o)) {
511
+ return false;
512
+ }
513
+ }
514
+ }
515
+ return true;
516
+ }
517
+ addAll(c) {
518
+ let changed = false;
519
+ for (const o of c) {
520
+ const existing = this.getOrAdd(o);
521
+ if (existing !== o) {
522
+ changed = true;
523
+ }
524
+ }
525
+ return changed;
526
+ }
527
+ clear() {
528
+ this.buckets = this.createBuckets(_HashSet.initialCapacity);
529
+ this.itemCount = 0;
530
+ this.threshold = Math.floor(_HashSet.initialCapacity * _HashSet.defaultLoadFactor);
531
+ }
532
+ toString() {
533
+ if (this.size === 0) {
534
+ return "{}";
535
+ }
536
+ let buf = "{";
537
+ let first = true;
538
+ for (const bucket of this.buckets) {
539
+ if (bucket == null) {
540
+ continue;
541
+ }
542
+ for (const o of bucket) {
543
+ if (o == null) {
544
+ break;
545
+ }
546
+ if (first) {
547
+ first = false;
548
+ } else {
549
+ buf += ", ";
550
+ }
551
+ buf += o.toString();
552
+ }
553
+ }
554
+ buf += "}";
555
+ return buf;
556
+ }
557
+ toTableString() {
558
+ let buf = "";
559
+ for (const bucket of this.buckets) {
560
+ if (bucket == null) {
561
+ buf += "null\n";
562
+ continue;
563
+ }
564
+ buf += "[";
565
+ let first = true;
566
+ for (const o of bucket) {
567
+ if (first) {
568
+ first = false;
569
+ } else {
570
+ buf += " ";
571
+ }
572
+ if (o == null) {
573
+ buf += "_";
574
+ } else {
575
+ buf += o.toString();
576
+ }
577
+ }
578
+ buf += "]\n";
579
+ }
580
+ return buf;
581
+ }
582
+ getBucket(o) {
583
+ const hash = this.comparator.hashCode(o);
584
+ const b = hash & this.buckets.length - 1;
585
+ return b;
586
+ }
587
+ expand() {
588
+ const old = this.buckets;
589
+ const newCapacity = this.buckets.length * 2;
590
+ const newTable = this.createBuckets(newCapacity);
591
+ this.buckets = newTable;
592
+ this.threshold = Math.floor(newCapacity * _HashSet.defaultLoadFactor);
593
+ for (const bucket of old) {
594
+ if (!bucket) {
595
+ continue;
596
+ }
597
+ for (const o of bucket) {
598
+ const b = this.getBucket(o);
599
+ let newBucket = this.buckets[b];
600
+ if (!newBucket) {
601
+ newBucket = [];
602
+ this.buckets[b] = newBucket;
603
+ }
604
+ newBucket.push(o);
605
+ }
606
+ }
607
+ }
608
+ get size() {
609
+ return this.itemCount;
610
+ }
611
+ get isEmpty() {
612
+ return this.itemCount === 0;
613
+ }
614
+ /**
615
+ * Return an array of `T[]` with length `capacity`.
616
+ *
617
+ * @param capacity the length of the array to return
618
+ * @returns the newly constructed array
619
+ */
620
+ createBuckets(capacity) {
621
+ return new Array(capacity);
622
+ }
623
+ };
624
+
625
+ // src/misc/Interval.ts
626
+ var Interval = class _Interval {
627
+ static {
628
+ __name(this, "Interval");
629
+ }
630
+ static INVALID_INTERVAL = new _Interval(-1, -2);
631
+ static INTERVAL_POOL_MAX_VALUE = 1e3;
632
+ static cache = [];
633
+ start;
634
+ stop;
635
+ cachedHashCode;
636
+ constructor(start, stop) {
637
+ this.start = start;
638
+ this.stop = stop;
639
+ this.cachedHashCode = Math.imul(651 + start, 31) + stop;
640
+ }
641
+ /**
642
+ * Creates a new interval from the given values.
643
+ *
644
+ * Interval objects are used readonly so share all with the
645
+ * same single value a==b up to some max size. Use an array as a perfect hash.
646
+ * Return shared object for 0..INTERVAL_POOL_MAX_VALUE or a new
647
+ * Interval object with a..a in it. On Java.g4, 218623 IntervalSets
648
+ * have a..a (set with 1 element).
649
+ *
650
+ * @param a The start of the interval.
651
+ * @param b The end of the interval (inclusive).
652
+ *
653
+ * @returns A cached or new interval.
654
+ */
655
+ static of(a, b) {
656
+ if (a !== b || a < 0 || a > _Interval.INTERVAL_POOL_MAX_VALUE) {
657
+ return new _Interval(a, b);
658
+ }
659
+ if (!_Interval.cache[a]) {
660
+ _Interval.cache[a] = new _Interval(a, a);
661
+ }
662
+ return _Interval.cache[a];
663
+ }
664
+ equals(o) {
665
+ return this.start === o.start && this.stop === o.stop;
666
+ }
667
+ hashCode() {
668
+ return this.cachedHashCode;
669
+ }
670
+ /** Does this start completely before other? Disjoint */
671
+ startsBeforeDisjoint(other) {
672
+ return this.start < other.start && this.stop < other.start;
673
+ }
674
+ /** Does this start at or before other? Nondisjoint */
675
+ startsBeforeNonDisjoint(other) {
676
+ return this.start <= other.start && this.stop >= other.start;
677
+ }
678
+ /** Does this.start start after other.stop? May or may not be disjoint */
679
+ startsAfter(other) {
680
+ return this.start > other.start;
681
+ }
682
+ /** Does this start completely after other? Disjoint */
683
+ startsAfterDisjoint(other) {
684
+ return this.start > other.stop;
685
+ }
686
+ /** Does this start after other? NonDisjoint */
687
+ startsAfterNonDisjoint(other) {
688
+ return this.start > other.start && this.start <= other.stop;
689
+ }
690
+ /** Are both ranges disjoint? I.e., no overlap? */
691
+ disjoint(other) {
692
+ return this.startsBeforeDisjoint(other) || this.startsAfterDisjoint(other);
693
+ }
694
+ /** Are two intervals adjacent such as 0..41 and 42..42? */
695
+ adjacent(other) {
696
+ return this.start === other.stop + 1 || this.stop === other.start - 1;
697
+ }
698
+ properlyContains(other) {
699
+ return other.start >= this.start && other.stop <= this.stop;
700
+ }
701
+ /** Return the interval computed from combining this and other */
702
+ union(other) {
703
+ return _Interval.of(Math.min(this.start, other.start), Math.max(this.stop, other.stop));
704
+ }
705
+ /** Return the interval in common between this and o */
706
+ intersection(other) {
707
+ return _Interval.of(Math.max(this.start, other.start), Math.min(this.stop, other.stop));
708
+ }
709
+ /**
710
+ * Return the interval with elements from this not in other;
711
+ * other must not be totally enclosed (properly contained)
712
+ * within this, which would result in two disjoint intervals
713
+ * instead of the single one returned by this method.
714
+ */
715
+ differenceNotProperlyContained(other) {
716
+ let diff = null;
717
+ if (other.startsBeforeNonDisjoint(this)) {
718
+ diff = _Interval.of(Math.max(this.start, other.stop + 1), this.stop);
719
+ } else if (other.startsAfterNonDisjoint(this)) {
720
+ diff = _Interval.of(this.start, other.start - 1);
721
+ }
722
+ return diff;
723
+ }
724
+ toString() {
725
+ return `${this.start}..${this.stop}`;
726
+ }
727
+ get length() {
728
+ if (this.stop < this.start) {
729
+ return 0;
730
+ }
731
+ return this.stop - this.start + 1;
732
+ }
733
+ };
734
+
735
+ // src/Vocabulary.ts
736
+ var Vocabulary = class _Vocabulary {
737
+ static {
738
+ __name(this, "Vocabulary");
739
+ }
740
+ static EMPTY_NAMES = [];
741
+ /**
742
+ * Gets an empty {@link Vocabulary} instance.
743
+ *
744
+ *
745
+ * No literal or symbol names are assigned to token types, so
746
+ * {@link #getDisplayName(int)} returns the numeric value for all tokens
747
+ * except {@link Token#EOF}.
748
+ */
749
+ static EMPTY_VOCABULARY = new _Vocabulary(_Vocabulary.EMPTY_NAMES, _Vocabulary.EMPTY_NAMES, _Vocabulary.EMPTY_NAMES);
750
+ maxTokenType;
751
+ literalNames;
752
+ symbolicNames;
753
+ displayNames;
754
+ /**
755
+ * Constructs a new instance of {@link Vocabulary} from the specified
756
+ * literal, symbolic, and display token names.
757
+ *
758
+ * @param literalNames The literal names assigned to tokens, or `null`
759
+ * if no literal names are assigned.
760
+ * @param symbolicNames The symbolic names assigned to tokens, or
761
+ * `null` if no symbolic names are assigned.
762
+ * @param displayNames The display names assigned to tokens, or `null`
763
+ * to use the values in `literalNames` and `symbolicNames` as
764
+ * the source of display names, as described in
765
+ * {@link #getDisplayName(int)}.
766
+ */
767
+ constructor(literalNames, symbolicNames, displayNames) {
768
+ this.literalNames = literalNames ?? _Vocabulary.EMPTY_NAMES;
769
+ this.symbolicNames = symbolicNames ?? _Vocabulary.EMPTY_NAMES;
770
+ this.displayNames = displayNames ?? _Vocabulary.EMPTY_NAMES;
771
+ this.maxTokenType = Math.max(this.displayNames.length, Math.max(
772
+ this.literalNames.length,
773
+ this.symbolicNames.length
774
+ )) - 1;
775
+ }
776
+ /**
777
+ * Returns a {@link Vocabulary} instance from the specified set of token
778
+ * names. This method acts as a compatibility layer for the single
779
+ * `tokenNames` array generated by previous releases of ANTLR.
780
+ *
781
+ * The resulting vocabulary instance returns `null` for
782
+ * {@link getLiteralName getLiteralName(int)} and {@link getSymbolicName getSymbolicName(int)}, and the
783
+ * value from `tokenNames` for the display names.
784
+ *
785
+ * @param tokenNames The token names, or `null` if no token names are
786
+ * available.
787
+ * @returns A {@link Vocabulary} instance which uses `tokenNames` for
788
+ * the display names of tokens.
789
+ */
790
+ static fromTokenNames(tokenNames) {
791
+ if (tokenNames == null || tokenNames.length === 0) {
792
+ return _Vocabulary.EMPTY_VOCABULARY;
793
+ }
794
+ const literalNames = [...tokenNames];
795
+ const symbolicNames = [...tokenNames];
796
+ for (let i = 0; i < tokenNames.length; i++) {
797
+ const tokenName = tokenNames[i];
798
+ if (tokenName == null) {
799
+ continue;
800
+ }
801
+ if (tokenName.length > 0) {
802
+ const firstChar = tokenName.codePointAt(0);
803
+ if (firstChar === 39) {
804
+ symbolicNames[i] = null;
805
+ continue;
806
+ } else if (firstChar >= 65 && firstChar <= 90) {
807
+ literalNames[i] = null;
808
+ continue;
809
+ }
810
+ }
811
+ literalNames[i] = null;
812
+ symbolicNames[i] = null;
813
+ }
814
+ return new _Vocabulary(literalNames, symbolicNames, tokenNames);
815
+ }
816
+ getMaxTokenType() {
817
+ return this.maxTokenType;
818
+ }
819
+ getLiteralName(tokenType) {
820
+ if (tokenType >= 0 && tokenType < this.literalNames.length) {
821
+ return this.literalNames[tokenType];
822
+ }
823
+ return null;
824
+ }
825
+ getSymbolicName(tokenType) {
826
+ if (tokenType >= 0 && tokenType < this.symbolicNames.length) {
827
+ return this.symbolicNames[tokenType];
828
+ }
829
+ if (tokenType === Token.EOF) {
830
+ return "EOF";
831
+ }
832
+ return null;
833
+ }
834
+ getDisplayName(tokenType) {
835
+ if (tokenType >= 0 && tokenType < this.displayNames.length) {
836
+ const displayName = this.displayNames[tokenType];
837
+ if (displayName != null) {
838
+ return displayName;
839
+ }
840
+ }
841
+ const literalName = this.getLiteralName(tokenType);
842
+ if (literalName != null) {
843
+ return literalName;
844
+ }
845
+ const symbolicName = this.getSymbolicName(tokenType);
846
+ if (symbolicName != null) {
847
+ return symbolicName;
848
+ }
849
+ return `${tokenType}`;
850
+ }
851
+ getLiteralNames() {
852
+ return this.literalNames;
853
+ }
854
+ getSymbolicNames() {
855
+ return this.symbolicNames;
856
+ }
857
+ getDisplayNames() {
858
+ return this.displayNames;
859
+ }
860
+ };
861
+
862
+ // src/misc/IntervalSet.ts
863
+ var IntervalSet = class _IntervalSet {
864
+ static {
865
+ __name(this, "IntervalSet");
866
+ }
867
+ /** The list of sorted, disjoint intervals. */
868
+ intervals = [];
869
+ cachedHashCode;
870
+ constructor(set) {
871
+ if (set) {
872
+ if (Array.isArray(set)) {
873
+ for (const el of set) {
874
+ this.addOne(el);
875
+ }
876
+ } else {
877
+ this.addSet(set);
878
+ }
879
+ }
880
+ }
881
+ /** Create a set with all ints within range [a..b] (inclusive) */
882
+ static of(a, b) {
883
+ const s = new _IntervalSet();
884
+ s.addRange(a, b);
885
+ return s;
886
+ }
887
+ /** Combine all sets in the array and return the union of them */
888
+ static or(sets) {
889
+ const result = new _IntervalSet();
890
+ for (const set of sets) {
891
+ result.addSet(set);
892
+ }
893
+ return result;
894
+ }
895
+ [Symbol.iterator]() {
896
+ return this.intervals[Symbol.iterator]();
897
+ }
898
+ get(index) {
899
+ return this.intervals[index];
900
+ }
901
+ /**
902
+ * Returns the minimum value contained in the set if not isNil().
903
+ *
904
+ * @returns the minimum value contained in the set.
905
+ */
906
+ get minElement() {
907
+ if (this.intervals.length === 0) {
908
+ return Token.INVALID_TYPE;
909
+ }
910
+ return this.intervals[0].start;
911
+ }
912
+ /**
913
+ * Returns the maximum value contained in the set if not isNil().
914
+ *
915
+ * @returns the maximum value contained in the set.
916
+ */
917
+ get maxElement() {
918
+ if (this.intervals.length === 0) {
919
+ return Token.INVALID_TYPE;
920
+ }
921
+ return this.intervals[this.intervals.length - 1].stop;
922
+ }
923
+ clear() {
924
+ this.cachedHashCode = void 0;
925
+ this.intervals = [];
926
+ }
927
+ /**
928
+ * Add a single element to the set. An isolated element is stored
929
+ * as a range el..el.
930
+ */
931
+ addOne(v) {
932
+ this.addInterval(new Interval(v, v));
933
+ }
934
+ /**
935
+ * Add interval; i.e., add all integers from a to b to set.
936
+ * If b < a, do nothing.
937
+ * Keep list in sorted order (by left range value).
938
+ * If overlap, combine ranges. For example,
939
+ * If this is {1..5, 10..20}, adding 6..7 yields
940
+ * {1..5, 6..7, 10..20}. Adding 4..8 yields {1..8, 10..20}.
941
+ */
942
+ addRange(l, h) {
943
+ this.addInterval(new Interval(l, h));
944
+ }
945
+ addInterval(addition) {
946
+ this.cachedHashCode = void 0;
947
+ if (this.intervals.length === 0) {
948
+ this.intervals.push(addition);
949
+ } else {
950
+ for (let pos = 0; pos < this.intervals.length; pos++) {
951
+ const existing = this.intervals[pos];
952
+ if (addition.equals(existing)) {
953
+ return;
954
+ }
955
+ if (addition.adjacent(existing) || !addition.disjoint(existing)) {
956
+ const bigger = addition.union(existing);
957
+ this.intervals[pos] = bigger;
958
+ for (let sub = pos + 1; sub < this.intervals.length; ) {
959
+ const next = this.intervals[sub];
960
+ if (!bigger.adjacent(next) && bigger.disjoint(next)) {
961
+ break;
962
+ }
963
+ this.intervals.splice(sub, 1);
964
+ this.intervals[pos] = bigger.union(next);
965
+ }
966
+ return;
967
+ }
968
+ if (addition.startsBeforeDisjoint(existing)) {
969
+ this.intervals.splice(pos, 0, addition);
970
+ return;
971
+ }
972
+ }
973
+ this.intervals.push(addition);
974
+ }
975
+ }
976
+ addSet(other) {
977
+ other.intervals.forEach((toAdd) => {
978
+ return this.addInterval(toAdd);
979
+ }, this);
980
+ return this;
981
+ }
982
+ complementWithVocabulary(vocabulary) {
983
+ const result = new _IntervalSet();
984
+ if (!vocabulary) {
985
+ return result;
986
+ }
987
+ if (vocabulary.length === 0) {
988
+ return result;
989
+ }
990
+ result.addSet(vocabulary);
991
+ return result.subtract(this);
992
+ }
993
+ complement(minElement, maxElement) {
994
+ const result = new _IntervalSet();
995
+ result.addInterval(new Interval(minElement, maxElement));
996
+ return result.subtract(this);
997
+ }
998
+ /** combine all sets in the array returned the or'd value */
999
+ or(sets) {
1000
+ const result = new _IntervalSet();
1001
+ result.addSet(this);
1002
+ sets.forEach((set) => {
1003
+ return result.addSet(set);
1004
+ });
1005
+ return result;
1006
+ }
1007
+ and(other) {
1008
+ if (other.length === 0) {
1009
+ return new _IntervalSet();
1010
+ }
1011
+ const myIntervals = this.intervals;
1012
+ const theirIntervals = other.intervals;
1013
+ let intersection;
1014
+ const mySize = myIntervals.length;
1015
+ const theirSize = theirIntervals.length;
1016
+ let i = 0;
1017
+ let j = 0;
1018
+ while (i < mySize && j < theirSize) {
1019
+ const mine = myIntervals[i];
1020
+ const theirs = theirIntervals[j];
1021
+ if (mine.startsBeforeDisjoint(theirs)) {
1022
+ i++;
1023
+ } else if (theirs.startsBeforeDisjoint(mine)) {
1024
+ j++;
1025
+ } else if (mine.properlyContains(theirs)) {
1026
+ if (!intersection) {
1027
+ intersection = new _IntervalSet();
1028
+ }
1029
+ intersection.addInterval(mine.intersection(theirs));
1030
+ j++;
1031
+ } else if (theirs.properlyContains(mine)) {
1032
+ if (!intersection) {
1033
+ intersection = new _IntervalSet();
1034
+ }
1035
+ intersection.addInterval(mine.intersection(theirs));
1036
+ i++;
1037
+ } else if (!mine.disjoint(theirs)) {
1038
+ if (!intersection) {
1039
+ intersection = new _IntervalSet();
1040
+ }
1041
+ intersection.addInterval(mine.intersection(theirs));
1042
+ if (mine.startsAfterNonDisjoint(theirs)) {
1043
+ j++;
1044
+ } else if (theirs.startsAfterNonDisjoint(mine)) {
1045
+ i++;
1046
+ }
1047
+ }
1048
+ }
1049
+ if (!intersection) {
1050
+ return new _IntervalSet();
1051
+ }
1052
+ return intersection;
1053
+ }
1054
+ /**
1055
+ * Compute the set difference between two interval sets. The specific
1056
+ * operation is `left - right`. If either of the input sets is
1057
+ * `null`, it is treated as though it was an empty set.
1058
+ */
1059
+ subtract(other) {
1060
+ if (this.length === 0) {
1061
+ return new _IntervalSet();
1062
+ }
1063
+ const result = new _IntervalSet(this);
1064
+ if (other.length === 0) {
1065
+ return result;
1066
+ }
1067
+ let resultI = 0;
1068
+ let rightI = 0;
1069
+ while (resultI < result.intervals.length && rightI < other.intervals.length) {
1070
+ const resultInterval = result.intervals[resultI];
1071
+ const rightInterval = other.intervals[rightI];
1072
+ if (rightInterval.stop < resultInterval.start) {
1073
+ rightI++;
1074
+ continue;
1075
+ }
1076
+ if (rightInterval.start > resultInterval.stop) {
1077
+ resultI++;
1078
+ continue;
1079
+ }
1080
+ let beforeCurrent;
1081
+ let afterCurrent;
1082
+ if (rightInterval.start > resultInterval.start) {
1083
+ beforeCurrent = new Interval(resultInterval.start, rightInterval.start - 1);
1084
+ }
1085
+ if (rightInterval.stop < resultInterval.stop) {
1086
+ afterCurrent = new Interval(rightInterval.stop + 1, resultInterval.stop);
1087
+ }
1088
+ if (beforeCurrent) {
1089
+ if (afterCurrent) {
1090
+ result.intervals[resultI] = beforeCurrent;
1091
+ result.intervals.splice(resultI + 1, 0, afterCurrent);
1092
+ resultI++;
1093
+ rightI++;
1094
+ } else {
1095
+ result.intervals[resultI] = beforeCurrent;
1096
+ resultI++;
1097
+ }
1098
+ } else {
1099
+ if (afterCurrent) {
1100
+ result.intervals[resultI] = afterCurrent;
1101
+ rightI++;
1102
+ } else {
1103
+ result.intervals.splice(resultI, 1);
1104
+ }
1105
+ }
1106
+ }
1107
+ return result;
1108
+ }
1109
+ contains(el) {
1110
+ const n2 = this.intervals.length;
1111
+ let l = 0;
1112
+ let r = n2 - 1;
1113
+ while (l <= r) {
1114
+ const m2 = Math.floor((l + r) / 2);
1115
+ const interval = this.intervals[m2];
1116
+ if (interval.stop < el) {
1117
+ l = m2 + 1;
1118
+ } else if (interval.start > el) {
1119
+ r = m2 - 1;
1120
+ } else {
1121
+ return true;
1122
+ }
1123
+ }
1124
+ return false;
1125
+ }
1126
+ removeRange(toRemove) {
1127
+ this.cachedHashCode = void 0;
1128
+ if (toRemove.start === toRemove.stop) {
1129
+ this.removeOne(toRemove.start);
1130
+ } else if (this.intervals !== null) {
1131
+ let pos = 0;
1132
+ for (const existing of this.intervals) {
1133
+ if (toRemove.stop <= existing.start) {
1134
+ return;
1135
+ } else if (toRemove.start > existing.start && toRemove.stop < existing.stop) {
1136
+ this.intervals[pos] = new Interval(existing.start, toRemove.start);
1137
+ const x = new Interval(toRemove.stop, existing.stop);
1138
+ this.intervals.splice(pos, 0, x);
1139
+ return;
1140
+ } else if (toRemove.start <= existing.start && toRemove.stop >= existing.stop) {
1141
+ this.intervals.splice(pos, 1);
1142
+ pos = pos - 1;
1143
+ } else if (toRemove.start < existing.stop) {
1144
+ this.intervals[pos] = new Interval(existing.start, toRemove.start);
1145
+ } else if (toRemove.stop < existing.stop) {
1146
+ this.intervals[pos] = new Interval(toRemove.stop, existing.stop);
1147
+ }
1148
+ pos += 1;
1149
+ }
1150
+ }
1151
+ }
1152
+ removeOne(value) {
1153
+ this.cachedHashCode = void 0;
1154
+ for (let i = 0; i < this.intervals.length; i++) {
1155
+ const existing = this.intervals[i];
1156
+ if (value < existing.start) {
1157
+ return;
1158
+ } else if (value === existing.start && value === existing.stop) {
1159
+ this.intervals.splice(i, 1);
1160
+ return;
1161
+ } else if (value === existing.start) {
1162
+ this.intervals[i] = new Interval(existing.start + 1, existing.stop);
1163
+ return;
1164
+ } else if (value === existing.stop) {
1165
+ this.intervals[i] = new Interval(existing.start, existing.stop - 1);
1166
+ return;
1167
+ } else if (value < existing.stop) {
1168
+ const replace = new Interval(existing.start, value - 1);
1169
+ this.intervals[i] = new Interval(value + 1, existing.stop);
1170
+ this.intervals.splice(i, 0, replace);
1171
+ return;
1172
+ }
1173
+ }
1174
+ }
1175
+ hashCode() {
1176
+ if (this.cachedHashCode === void 0) {
1177
+ let hash = MurmurHash.initialize();
1178
+ for (const interval of this.intervals) {
1179
+ hash = MurmurHash.update(hash, interval.start);
1180
+ hash = MurmurHash.update(hash, interval.stop);
1181
+ }
1182
+ this.cachedHashCode = MurmurHash.finish(hash, this.intervals.length * 2);
1183
+ }
1184
+ return this.cachedHashCode;
1185
+ }
1186
+ /**
1187
+ * Are two IntervalSets equal? Because all intervals are sorted and disjoint, equals is a simple linear walk over
1188
+ * both lists to make sure they are the same. Interval.equals() is used by the List.equals() method to check
1189
+ * the ranges.
1190
+ */
1191
+ equals(other) {
1192
+ if (this === other) {
1193
+ return true;
1194
+ }
1195
+ if (this.intervals.length !== other.intervals.length) {
1196
+ return false;
1197
+ }
1198
+ for (let i = 0; i < this.intervals.length; i++) {
1199
+ if (!this.intervals[i].equals(other.intervals[i])) {
1200
+ return false;
1201
+ }
1202
+ }
1203
+ return true;
1204
+ }
1205
+ toString(elementsAreChar) {
1206
+ if (this.intervals.length === 0) {
1207
+ return "{}";
1208
+ }
1209
+ let result = "";
1210
+ if (this.length > 1) {
1211
+ result += "{";
1212
+ }
1213
+ for (let i = 0; i < this.intervals.length; ++i) {
1214
+ const interval = this.intervals[i];
1215
+ const start = interval.start;
1216
+ const stop = interval.stop;
1217
+ if (start === stop) {
1218
+ if (start === Token.EOF) {
1219
+ result += "<EOF>";
1220
+ } else if (elementsAreChar) {
1221
+ result += "'" + String.fromCodePoint(start) + "'";
1222
+ } else {
1223
+ result += start;
1224
+ }
1225
+ } else {
1226
+ if (elementsAreChar) {
1227
+ result += "'" + String.fromCodePoint(start) + "'..'" + String.fromCodePoint(stop) + "'";
1228
+ } else {
1229
+ result += start + ".." + stop;
1230
+ }
1231
+ }
1232
+ if (i < this.intervals.length - 1) {
1233
+ result += ", ";
1234
+ }
1235
+ }
1236
+ if (this.length > 1) {
1237
+ result += "}";
1238
+ }
1239
+ return result;
1240
+ }
1241
+ toStringWithVocabulary(vocabulary) {
1242
+ if (this.intervals.length === 0) {
1243
+ return "{}";
1244
+ }
1245
+ let result = "";
1246
+ if (this.length > 1) {
1247
+ result += "{";
1248
+ }
1249
+ for (let i = 0; i < this.intervals.length; ++i) {
1250
+ const interval = this.intervals[i];
1251
+ const start = interval.start;
1252
+ const stop = interval.stop;
1253
+ if (start === stop) {
1254
+ if (start === Token.EOF) {
1255
+ result += "<EOF>";
1256
+ } else {
1257
+ result += this.elementName(vocabulary, start);
1258
+ }
1259
+ } else {
1260
+ for (let i2 = start; i2 <= stop; ++i2) {
1261
+ if (i2 > start) {
1262
+ result += ", ";
1263
+ }
1264
+ result += this.elementName(vocabulary, i2);
1265
+ }
1266
+ }
1267
+ if (i < this.intervals.length - 1) {
1268
+ result += ", ";
1269
+ }
1270
+ }
1271
+ if (this.length > 1) {
1272
+ result += "}";
1273
+ }
1274
+ return result;
1275
+ }
1276
+ toStringWithRuleNames(ruleNames) {
1277
+ if (this.intervals.length === 0) {
1278
+ return "{}";
1279
+ }
1280
+ let result = "";
1281
+ if (this.length > 1) {
1282
+ result += "{";
1283
+ }
1284
+ const vocabulary = Vocabulary.fromTokenNames(ruleNames);
1285
+ for (let i = 0; i < this.intervals.length; ++i) {
1286
+ const interval = this.intervals[i];
1287
+ const start = interval.start;
1288
+ const stop = interval.stop;
1289
+ if (start === stop) {
1290
+ if (start === Token.EOF) {
1291
+ result += "<EOF>";
1292
+ } else {
1293
+ result += this.elementName(vocabulary, start);
1294
+ }
1295
+ } else {
1296
+ for (let i2 = start; i2 <= stop; ++i2) {
1297
+ if (i2 > start) {
1298
+ result += ", ";
1299
+ }
1300
+ result += this.elementName(vocabulary, i2);
1301
+ }
1302
+ }
1303
+ if (i < this.intervals.length - 1) {
1304
+ result += ", ";
1305
+ }
1306
+ }
1307
+ if (this.length > 1) {
1308
+ result += "}";
1309
+ }
1310
+ return result;
1311
+ }
1312
+ toArray() {
1313
+ const data = [];
1314
+ for (const interval of this.intervals) {
1315
+ for (let j = interval.start; j <= interval.stop; j++) {
1316
+ data.push(j);
1317
+ }
1318
+ }
1319
+ return data;
1320
+ }
1321
+ /** @returns the number of elements in this set. */
1322
+ get length() {
1323
+ let result = 0;
1324
+ for (const interval of this.intervals) {
1325
+ result += interval.length;
1326
+ }
1327
+ return result;
1328
+ }
1329
+ elementName(vocabulary, token) {
1330
+ if (token === Token.EOF) {
1331
+ return "<EOF>";
1332
+ }
1333
+ if (token === Token.EPSILON) {
1334
+ return "<EPSILON>";
1335
+ }
1336
+ return vocabulary.getDisplayName(token);
1337
+ }
1338
+ };
1339
+
1340
+ // src/utils/helpers.ts
1341
+ var valueToString = /* @__PURE__ */ __name((v) => {
1342
+ return v === null ? "null" : v;
1343
+ }, "valueToString");
1344
+ var arrayToString = /* @__PURE__ */ __name((value) => {
1345
+ return Array.isArray(value) ? "[" + value.map(valueToString).join(", ") + "]" : "null";
1346
+ }, "arrayToString");
1347
+ var equalArrays = /* @__PURE__ */ __name((a, b) => {
1348
+ if (a === b) {
1349
+ return true;
1350
+ }
1351
+ if (a.length !== b.length) {
1352
+ return false;
1353
+ }
1354
+ for (let i = 0; i < a.length; i++) {
1355
+ const left = a[i];
1356
+ const right = b[i];
1357
+ if (left === right) {
1358
+ continue;
1359
+ }
1360
+ if (!left || !left.equals(right)) {
1361
+ return false;
1362
+ }
1363
+ }
1364
+ return true;
1365
+ }, "equalArrays");
1366
+ var equalNumberArrays = /* @__PURE__ */ __name((a, b) => {
1367
+ if (a === b) {
1368
+ return true;
1369
+ }
1370
+ if (a.length !== b.length) {
1371
+ return false;
1372
+ }
1373
+ for (let i = 0; i < a.length; i++) {
1374
+ if (a[i] !== b[i]) {
1375
+ return false;
1376
+ }
1377
+ }
1378
+ return true;
1379
+ }, "equalNumberArrays");
1380
+ var escapeWhitespace = /* @__PURE__ */ __name((s, escapeSpaces = false) => {
1381
+ s = s.replace(/\t/g, "\\t").replace(/\n/g, "\\n").replace(/\r/g, "\\r");
1382
+ if (escapeSpaces) {
1383
+ s = s.replace(/ /g, "\xB7");
1384
+ }
1385
+ return s;
1386
+ }, "escapeWhitespace");
1387
+
1388
+ // src/atn/SemanticContext.ts
1389
+ var SemanticContext = class _SemanticContext {
1390
+ static {
1391
+ __name(this, "SemanticContext");
1392
+ }
1393
+ cachedHashCode;
1394
+ static andContext(a, b) {
1395
+ if (a === null || a === _SemanticContext.NONE) {
1396
+ return b;
1397
+ }
1398
+ if (b === null || b === _SemanticContext.NONE) {
1399
+ return a;
1400
+ }
1401
+ const result = new AND(a, b);
1402
+ if (result.operands.length === 1) {
1403
+ return result.operands[0];
1404
+ }
1405
+ return result;
1406
+ }
1407
+ static orContext(a, b) {
1408
+ if (a === null) {
1409
+ return b;
1410
+ }
1411
+ if (b === null) {
1412
+ return a;
1413
+ }
1414
+ if (a === _SemanticContext.NONE || b === _SemanticContext.NONE) {
1415
+ return _SemanticContext.NONE;
1416
+ }
1417
+ const result = new OR(a, b);
1418
+ if (result.operands.length === 1) {
1419
+ return result.operands[0];
1420
+ } else {
1421
+ return result;
1422
+ }
1423
+ }
1424
+ static filterPrecedencePredicates(set) {
1425
+ const result = [];
1426
+ for (const context of set) {
1427
+ if (context instanceof _SemanticContext.PrecedencePredicate) {
1428
+ result.push(context);
1429
+ }
1430
+ }
1431
+ return result;
1432
+ }
1433
+ /**
1434
+ * Evaluate the precedence predicates for the context and reduce the result.
1435
+ *
1436
+ * @param _parser The parser instance.
1437
+ * @param _parserCallStack The current parser context object.
1438
+ * @returns The simplified semantic context after precedence predicates are
1439
+ * evaluated, which will be one of the following values.
1440
+ * - {@link NONE}: if the predicate simplifies to `true` after
1441
+ * precedence predicates are evaluated.
1442
+ * - `null`: if the predicate simplifies to `false` after
1443
+ * precedence predicates are evaluated.
1444
+ * - `this`: if the semantic context is not changed as a result of
1445
+ * precedence predicate evaluation.
1446
+ * - A non-`null` {@link SemanticContext}: the new simplified
1447
+ * semantic context after precedence predicates are evaluated.
1448
+ */
1449
+ evalPrecedence(_parser, _parserCallStack) {
1450
+ return this;
1451
+ }
1452
+ };
1453
+ var AND = class _AND extends SemanticContext {
1454
+ static {
1455
+ __name(this, "AND");
1456
+ }
1457
+ operands;
1458
+ /**
1459
+ * A semantic context which is true whenever none of the contained contexts
1460
+ * is false
1461
+ */
1462
+ constructor(a, b) {
1463
+ super();
1464
+ const operands = new HashSet();
1465
+ if (a instanceof _AND) {
1466
+ a.operands.forEach((o) => {
1467
+ operands.add(o);
1468
+ });
1469
+ } else {
1470
+ operands.add(a);
1471
+ }
1472
+ if (b instanceof _AND) {
1473
+ b.operands.forEach((o) => {
1474
+ operands.add(o);
1475
+ });
1476
+ } else {
1477
+ operands.add(b);
1478
+ }
1479
+ const precedencePredicates = SemanticContext.filterPrecedencePredicates(operands);
1480
+ if (precedencePredicates.length > 0) {
1481
+ let reduced = null;
1482
+ precedencePredicates.forEach((p) => {
1483
+ if (reduced === null || p.precedence < reduced.precedence) {
1484
+ reduced = p;
1485
+ }
1486
+ });
1487
+ if (reduced) {
1488
+ operands.add(reduced);
1489
+ }
1490
+ }
1491
+ this.operands = operands.toArray();
1492
+ }
1493
+ equals(other) {
1494
+ if (this === other) {
1495
+ return true;
1496
+ }
1497
+ if (!(other instanceof _AND)) {
1498
+ return false;
1499
+ }
1500
+ return equalArrays(this.operands, other.operands);
1501
+ }
1502
+ hashCode() {
1503
+ if (this.cachedHashCode === void 0) {
1504
+ let hash = MurmurHash.initialize();
1505
+ for (const operand of this.operands) {
1506
+ hash = MurmurHash.updateFromComparable(hash, operand);
1507
+ }
1508
+ hash = MurmurHash.update(hash, 3813686060);
1509
+ this.cachedHashCode = MurmurHash.finish(hash, this.operands.length + 1);
1510
+ }
1511
+ return this.cachedHashCode;
1512
+ }
1513
+ /**
1514
+ * {@inheritDoc}
1515
+ *
1516
+ *
1517
+ * The evaluation of predicates by this context is short-circuiting, but
1518
+ * unordered.
1519
+ */
1520
+ evaluate(parser, parserCallStack) {
1521
+ for (const operand of this.operands) {
1522
+ if (!operand.evaluate(parser, parserCallStack)) {
1523
+ return false;
1524
+ }
1525
+ }
1526
+ return true;
1527
+ }
1528
+ evalPrecedence(parser, parserCallStack) {
1529
+ let differs = false;
1530
+ const operands = [];
1531
+ for (const context of this.operands) {
1532
+ const evaluated = context.evalPrecedence(parser, parserCallStack);
1533
+ differs ||= evaluated !== context;
1534
+ if (evaluated === null) {
1535
+ return null;
1536
+ } else if (evaluated !== SemanticContext.NONE) {
1537
+ operands.push(evaluated);
1538
+ }
1539
+ }
1540
+ if (!differs) {
1541
+ return this;
1542
+ }
1543
+ if (operands.length === 0) {
1544
+ return SemanticContext.NONE;
1545
+ }
1546
+ let result = null;
1547
+ operands.forEach((o) => {
1548
+ result = result === null ? o : SemanticContext.andContext(result, o);
1549
+ });
1550
+ return result;
1551
+ }
1552
+ toString() {
1553
+ const s = this.operands.map((o) => {
1554
+ return o.toString();
1555
+ });
1556
+ return (s.length > 3 ? s.slice(3) : s).join("&&");
1557
+ }
1558
+ };
1559
+ var OR = class _OR extends SemanticContext {
1560
+ static {
1561
+ __name(this, "OR");
1562
+ }
1563
+ operands;
1564
+ /**
1565
+ * A semantic context which is true whenever at least one of the contained
1566
+ * contexts is true
1567
+ */
1568
+ constructor(a, b) {
1569
+ super();
1570
+ const operands = new HashSet();
1571
+ if (a instanceof _OR) {
1572
+ a.operands.forEach((o) => {
1573
+ operands.add(o);
1574
+ });
1575
+ } else {
1576
+ operands.add(a);
1577
+ }
1578
+ if (b instanceof _OR) {
1579
+ b.operands.forEach((o) => {
1580
+ operands.add(o);
1581
+ });
1582
+ } else {
1583
+ operands.add(b);
1584
+ }
1585
+ const precedencePredicates = SemanticContext.filterPrecedencePredicates(operands);
1586
+ if (precedencePredicates.length > 0) {
1587
+ const s = precedencePredicates.sort((a2, b2) => {
1588
+ return a2.compareTo(b2);
1589
+ });
1590
+ const reduced = s[s.length - 1];
1591
+ operands.add(reduced);
1592
+ }
1593
+ this.operands = operands.toArray();
1594
+ }
1595
+ equals(other) {
1596
+ if (this === other) {
1597
+ return true;
1598
+ } else if (!(other instanceof _OR)) {
1599
+ return false;
1600
+ } else {
1601
+ return equalArrays(this.operands, other.operands);
1602
+ }
1603
+ }
1604
+ hashCode() {
1605
+ if (this.cachedHashCode === void 0) {
1606
+ let hash = MurmurHash.initialize();
1607
+ for (const operand of this.operands) {
1608
+ hash = MurmurHash.updateFromComparable(hash, operand);
1609
+ }
1610
+ hash = MurmurHash.update(hash, 3383313031);
1611
+ this.cachedHashCode = MurmurHash.finish(hash, this.operands.length + 1);
1612
+ }
1613
+ return this.cachedHashCode;
1614
+ }
1615
+ /**
1616
+ * The evaluation of predicates by this context is short-circuiting, but unordered.
1617
+ */
1618
+ evaluate(parser, parserCallStack) {
1619
+ for (const operand of this.operands) {
1620
+ if (operand.evaluate(parser, parserCallStack)) {
1621
+ return true;
1622
+ }
1623
+ }
1624
+ return false;
1625
+ }
1626
+ evalPrecedence(parser, parserCallStack) {
1627
+ let differs = false;
1628
+ const operands = [];
1629
+ for (const context of this.operands) {
1630
+ const evaluated = context.evalPrecedence(parser, parserCallStack);
1631
+ differs ||= evaluated !== context;
1632
+ if (evaluated === SemanticContext.NONE) {
1633
+ return SemanticContext.NONE;
1634
+ } else if (evaluated !== null) {
1635
+ operands.push(evaluated);
1636
+ }
1637
+ }
1638
+ if (!differs) {
1639
+ return this;
1640
+ }
1641
+ if (operands.length === 0) {
1642
+ return null;
1643
+ }
1644
+ let result = null;
1645
+ operands.forEach((o) => {
1646
+ result = result === null ? o : SemanticContext.orContext(result, o);
1647
+ });
1648
+ return result;
1649
+ }
1650
+ toString() {
1651
+ const s = this.operands.map((o) => {
1652
+ return o.toString();
1653
+ });
1654
+ return (s.length > 3 ? s.slice(3) : s).join("||");
1655
+ }
1656
+ };
1657
+ ((SemanticContext2) => {
1658
+ class Predicate extends SemanticContext2 {
1659
+ static {
1660
+ __name(this, "Predicate");
1661
+ }
1662
+ ruleIndex;
1663
+ predIndex;
1664
+ isCtxDependent;
1665
+ // e.g., $i ref in pred
1666
+ constructor(ruleIndex, predIndex, isCtxDependent) {
1667
+ super();
1668
+ this.ruleIndex = ruleIndex ?? -1;
1669
+ this.predIndex = predIndex ?? -1;
1670
+ this.isCtxDependent = isCtxDependent ?? false;
1671
+ }
1672
+ evaluate(parser, outerContext) {
1673
+ const localctx = this.isCtxDependent ? outerContext : null;
1674
+ return parser.sempred(localctx, this.ruleIndex, this.predIndex);
1675
+ }
1676
+ hashCode() {
1677
+ if (this.cachedHashCode === void 0) {
1678
+ let hashCode = MurmurHash.initialize();
1679
+ hashCode = MurmurHash.update(hashCode, this.ruleIndex);
1680
+ hashCode = MurmurHash.update(hashCode, this.predIndex);
1681
+ hashCode = MurmurHash.update(hashCode, this.isCtxDependent ? 1 : 0);
1682
+ hashCode = MurmurHash.finish(hashCode, 3);
1683
+ this.cachedHashCode = hashCode;
1684
+ }
1685
+ return this.cachedHashCode;
1686
+ }
1687
+ equals(other) {
1688
+ if (this === other) {
1689
+ return true;
1690
+ }
1691
+ return this.ruleIndex === other.ruleIndex && this.predIndex === other.predIndex && this.isCtxDependent === other.isCtxDependent;
1692
+ }
1693
+ toString() {
1694
+ return "{" + this.ruleIndex + ":" + this.predIndex + "}?";
1695
+ }
1696
+ }
1697
+ SemanticContext2.Predicate = Predicate;
1698
+ class PrecedencePredicate extends SemanticContext2 {
1699
+ static {
1700
+ __name(this, "PrecedencePredicate");
1701
+ }
1702
+ precedence;
1703
+ constructor(precedence) {
1704
+ super();
1705
+ this.precedence = precedence ?? 0;
1706
+ }
1707
+ evaluate(parser, outerContext) {
1708
+ return parser.precpred(outerContext, this.precedence);
1709
+ }
1710
+ evalPrecedence(parser, outerContext) {
1711
+ if (parser.precpred(outerContext ?? null, this.precedence)) {
1712
+ return SemanticContext2.NONE;
1713
+ }
1714
+ return null;
1715
+ }
1716
+ compareTo(other) {
1717
+ return this.precedence - other.precedence;
1718
+ }
1719
+ hashCode() {
1720
+ return 31 + this.precedence;
1721
+ }
1722
+ equals(other) {
1723
+ if (this === other) {
1724
+ return true;
1725
+ }
1726
+ return this.precedence === other.precedence;
1727
+ }
1728
+ toString() {
1729
+ return "{" + this.precedence + ">=prec}?";
1730
+ }
1731
+ }
1732
+ SemanticContext2.PrecedencePredicate = PrecedencePredicate;
1733
+ SemanticContext2.NONE = new Predicate();
1734
+ })(SemanticContext || (SemanticContext = {}));
1735
+
1736
+ // src/atn/ATNConfig.ts
1737
+ var ATNConfig = class _ATNConfig {
1738
+ static {
1739
+ __name(this, "ATNConfig");
1740
+ }
1741
+ /** The ATN state associated with this configuration */
1742
+ state;
1743
+ /** What alt (or lexer rule) is predicted by this configuration */
1744
+ alt;
1745
+ /**
1746
+ * We cannot execute predicates dependent upon local context unless
1747
+ * we know for sure we are in the correct context. Because there is
1748
+ * no way to do this efficiently, we simply cannot evaluate
1749
+ * dependent predicates unless we are in the rule that initially
1750
+ * invokes the ATN simulator.
1751
+ *
1752
+ * closure() tracks the depth of how far we dip into the outer context:
1753
+ * depth > 0.
1754
+ */
1755
+ reachesIntoOuterContext = false;
1756
+ // Not used in hash code.
1757
+ precedenceFilterSuppressed = false;
1758
+ // Not used in hash code.
1759
+ get semanticContext() {
1760
+ return this.#semanticContext;
1761
+ }
1762
+ cachedHashCode;
1763
+ // Shared with LexerATNConfig.
1764
+ /**
1765
+ * The syntactic context is a graph-structured stack node whose
1766
+ * path(s) to the root is the rule invocation(s)
1767
+ * chain used to arrive at the state. The semantic context is
1768
+ * the tree of semantic predicates encountered before reaching
1769
+ * an ATN state
1770
+ */
1771
+ #context = null;
1772
+ #semanticContext;
1773
+ /** Never create config classes directly. Use the factory methods below. */
1774
+ constructor(c, state, context, semanticContext) {
1775
+ this.state = state;
1776
+ this.alt = c.alt;
1777
+ this.context = context;
1778
+ this.#semanticContext = semanticContext ?? SemanticContext.NONE;
1779
+ this.reachesIntoOuterContext = c.reachesIntoOuterContext;
1780
+ if (c.precedenceFilterSuppressed !== void 0) {
1781
+ this.precedenceFilterSuppressed = c.precedenceFilterSuppressed;
1782
+ }
1783
+ }
1784
+ static duplicate(old, semanticContext) {
1785
+ return new _ATNConfig(old, old.state, old.context, semanticContext ?? old.semanticContext);
1786
+ }
1787
+ static createWithContext(state, alt, context, semanticContext) {
1788
+ return new _ATNConfig({ alt }, state, context, semanticContext);
1789
+ }
1790
+ static createWithConfig(state, config, context) {
1791
+ return new _ATNConfig(config, state, context ?? config.context, config.semanticContext);
1792
+ }
1793
+ static createWithSemanticContext(state, c, semanticContext) {
1794
+ return new _ATNConfig(c, state ?? c.state, c.context, semanticContext);
1795
+ }
1796
+ hashCode() {
1797
+ if (this.cachedHashCode === void 0) {
1798
+ let hashCode = MurmurHash.initialize(7);
1799
+ hashCode = MurmurHash.update(hashCode, this.state.stateNumber);
1800
+ hashCode = MurmurHash.update(hashCode, this.alt);
1801
+ hashCode = MurmurHash.updateFromComparable(hashCode, this.#context);
1802
+ hashCode = MurmurHash.updateFromComparable(hashCode, this.semanticContext);
1803
+ hashCode = MurmurHash.finish(hashCode, 4);
1804
+ this.cachedHashCode = hashCode;
1805
+ }
1806
+ return this.cachedHashCode;
1807
+ }
1808
+ /**
1809
+ * The stack of invoking states leading to the rule/states associated
1810
+ * with this config. We track only those contexts pushed during
1811
+ * execution of the ATN simulator.
1812
+ */
1813
+ get context() {
1814
+ return this.#context;
1815
+ }
1816
+ set context(context) {
1817
+ this.#context = context;
1818
+ this.cachedHashCode = void 0;
1819
+ }
1820
+ /**
1821
+ * An ATN configuration is equal to another if both have
1822
+ * the same state, they predict the same alternative, and
1823
+ * syntactic/semantic contexts are the same.
1824
+ */
1825
+ equals(other) {
1826
+ if (this === other) {
1827
+ return true;
1828
+ }
1829
+ return this.state.stateNumber === other.state.stateNumber && this.alt === other.alt && (this.context === null ? other.context === null : this.context.equals(other.context)) && this.semanticContext.equals(other.semanticContext) && this.precedenceFilterSuppressed === other.precedenceFilterSuppressed;
1830
+ }
1831
+ toString(_recog, showAlt = true) {
1832
+ let alt = "";
1833
+ if (showAlt) {
1834
+ alt = "," + this.alt;
1835
+ }
1836
+ return "(" + this.state + alt + (this.context !== null ? ",[" + this.context.toString() + "]" : "") + (this.semanticContext !== SemanticContext.NONE ? "," + this.semanticContext.toString() : "") + (this.reachesIntoOuterContext ? ",up=" + this.reachesIntoOuterContext : "") + ")";
1837
+ }
1838
+ };
1839
+
1840
+ // src/atn/ATNState.ts
1841
+ var ATNState = class _ATNState {
1842
+ static {
1843
+ __name(this, "ATNState");
1844
+ }
1845
+ static INVALID_STATE_NUMBER = -1;
1846
+ static INVALID_TYPE = 0;
1847
+ static BASIC = 1;
1848
+ static RULE_START = 2;
1849
+ static BLOCK_START = 3;
1850
+ static PLUS_BLOCK_START = 4;
1851
+ static STAR_BLOCK_START = 5;
1852
+ static TOKEN_START = 6;
1853
+ static RULE_STOP = 7;
1854
+ static BLOCK_END = 8;
1855
+ static STAR_LOOP_BACK = 9;
1856
+ static STAR_LOOP_ENTRY = 10;
1857
+ static PLUS_LOOP_BACK = 11;
1858
+ static LOOP_END = 12;
1859
+ static stateType = _ATNState.INVALID_STATE_NUMBER;
1860
+ stateNumber = 0;
1861
+ ruleIndex = 0;
1862
+ // at runtime, we don't have Rule objects
1863
+ epsilonOnlyTransitions = false;
1864
+ /** Used to cache lookahead during parsing, not used during construction */
1865
+ nextTokenWithinRule;
1866
+ /** Track the transitions emanating from this ATN state. */
1867
+ transitions = [];
1868
+ hashCode() {
1869
+ return this.stateNumber;
1870
+ }
1871
+ equals(other) {
1872
+ return this.stateNumber === other.stateNumber;
1873
+ }
1874
+ toString() {
1875
+ return `${this.stateNumber}`;
1876
+ }
1877
+ addTransitionAtIndex(index, transition) {
1878
+ if (this.transitions.length === 0) {
1879
+ this.epsilonOnlyTransitions = transition.isEpsilon;
1880
+ } else if (this.epsilonOnlyTransitions !== transition.isEpsilon) {
1881
+ this.epsilonOnlyTransitions = false;
1882
+ }
1883
+ this.transitions.splice(index, 1, transition);
1884
+ }
1885
+ addTransition(transition) {
1886
+ if (this.transitions.length === 0) {
1887
+ this.epsilonOnlyTransitions = transition.isEpsilon;
1888
+ } else if (this.epsilonOnlyTransitions !== transition.isEpsilon) {
1889
+ this.epsilonOnlyTransitions = false;
1890
+ }
1891
+ this.transitions.push(transition);
1892
+ }
1893
+ setTransition(i, e) {
1894
+ this.transitions.splice(i, 1, e);
1895
+ }
1896
+ removeTransition(index) {
1897
+ const t = this.transitions.splice(index, 1);
1898
+ return t[0];
1899
+ }
1900
+ };
1901
+
1902
+ // src/atn/PredictionContext.ts
1903
+ var PredictionContext = class _PredictionContext {
1904
+ static {
1905
+ __name(this, "PredictionContext");
1906
+ }
1907
+ /**
1908
+ * Represents `$` in an array in full context mode, when `$`
1909
+ * doesn't mean wildcard: `$ + x = [$,x]`. Here,
1910
+ * `$` = {@link EMPTY_RETURN_STATE}.
1911
+ */
1912
+ static EMPTY_RETURN_STATE = 2147483647;
1913
+ static traceATNSimulator = false;
1914
+ cachedHashCode;
1915
+ constructor(cachedHashCode) {
1916
+ this.cachedHashCode = cachedHashCode;
1917
+ }
1918
+ static calculateEmptyHashCode() {
1919
+ let hash = MurmurHash.initialize(31);
1920
+ hash = MurmurHash.finish(hash, 0);
1921
+ return hash;
1922
+ }
1923
+ static calculateHashCodeSingle(parent, returnState) {
1924
+ let hash = MurmurHash.initialize(31);
1925
+ hash = MurmurHash.updateFromComparable(hash, parent);
1926
+ hash = MurmurHash.update(hash, returnState);
1927
+ hash = MurmurHash.finish(hash, 2);
1928
+ return hash;
1929
+ }
1930
+ static calculateHashCodeList(parents, returnStates) {
1931
+ let hash = MurmurHash.initialize(31);
1932
+ for (const parent of parents) {
1933
+ hash = MurmurHash.updateFromComparable(hash, parent);
1934
+ }
1935
+ for (const returnState of returnStates) {
1936
+ hash = MurmurHash.update(hash, returnState);
1937
+ }
1938
+ hash = MurmurHash.finish(hash, 2 * parents.length);
1939
+ return hash;
1940
+ }
1941
+ isEmpty() {
1942
+ return false;
1943
+ }
1944
+ hasEmptyPath() {
1945
+ return this.getReturnState(this.length - 1) === _PredictionContext.EMPTY_RETURN_STATE;
1946
+ }
1947
+ hashCode() {
1948
+ return this.cachedHashCode;
1949
+ }
1950
+ toString(_recog) {
1951
+ return "";
1952
+ }
1953
+ };
1954
+
1955
+ // src/atn/SingletonPredictionContext.ts
1956
+ var SingletonPredictionContext = class _SingletonPredictionContext extends PredictionContext {
1957
+ static {
1958
+ __name(this, "SingletonPredictionContext");
1959
+ }
1960
+ parent;
1961
+ returnState;
1962
+ constructor(parent, returnState) {
1963
+ super(
1964
+ parent ? PredictionContext.calculateHashCodeSingle(parent, returnState) : PredictionContext.calculateEmptyHashCode()
1965
+ );
1966
+ this.parent = parent ?? null;
1967
+ this.returnState = returnState;
1968
+ }
1969
+ getParent(_index) {
1970
+ return this.parent;
1971
+ }
1972
+ getReturnState(_index) {
1973
+ return this.returnState;
1974
+ }
1975
+ equals(other) {
1976
+ if (this === other) {
1977
+ return true;
1978
+ }
1979
+ if (!(other instanceof _SingletonPredictionContext)) {
1980
+ return false;
1981
+ }
1982
+ if (this.hashCode() !== other.hashCode()) {
1983
+ return false;
1984
+ }
1985
+ if (this.returnState !== other.returnState) {
1986
+ return false;
1987
+ }
1988
+ if (this.parent == null) {
1989
+ return other.parent == null;
1990
+ }
1991
+ return this.parent.equals(other.parent);
1992
+ }
1993
+ toString() {
1994
+ const up = this.parent === null ? "" : this.parent.toString();
1995
+ if (up.length === 0) {
1996
+ if (this.returnState === PredictionContext.EMPTY_RETURN_STATE) {
1997
+ return "$";
1998
+ }
1999
+ return "" + this.returnState;
2000
+ } else {
2001
+ return "" + this.returnState + " " + up;
2002
+ }
2003
+ }
2004
+ get length() {
2005
+ return 1;
2006
+ }
2007
+ };
2008
+
2009
+ // src/atn/EmptyPredictionContext.ts
2010
+ var EmptyPredictionContext = class _EmptyPredictionContext extends SingletonPredictionContext {
2011
+ static {
2012
+ __name(this, "EmptyPredictionContext");
2013
+ }
2014
+ /**
2015
+ * Represents `$` in local context prediction, which means wildcard.
2016
+ * `*+x = *`.
2017
+ */
2018
+ static instance = new _EmptyPredictionContext();
2019
+ constructor() {
2020
+ super(void 0, PredictionContext.EMPTY_RETURN_STATE);
2021
+ }
2022
+ isEmpty() {
2023
+ return true;
2024
+ }
2025
+ getParent() {
2026
+ return null;
2027
+ }
2028
+ getReturnState() {
2029
+ return this.returnState;
2030
+ }
2031
+ equals(other) {
2032
+ return this === other;
2033
+ }
2034
+ toString() {
2035
+ return "$";
2036
+ }
2037
+ };
2038
+
2039
+ // src/atn/Transition.ts
2040
+ var Transition = class {
2041
+ static {
2042
+ __name(this, "Transition");
2043
+ }
2044
+ static INVALID = 0;
2045
+ static EPSILON = 1;
2046
+ static RANGE = 2;
2047
+ static RULE = 3;
2048
+ static PREDICATE = 4;
2049
+ // e.g., {isType(input.LT(1))}
2050
+ static ATOM = 5;
2051
+ static ACTION = 6;
2052
+ static SET = 7;
2053
+ // ~(A|B) or ~atom, wildcard, which convert to next
2054
+ static NOT_SET = 8;
2055
+ static WILDCARD = 9;
2056
+ static PRECEDENCE = 10;
2057
+ /** The target of this transition. */
2058
+ target;
2059
+ constructor(target) {
2060
+ this.target = target;
2061
+ }
2062
+ /**
2063
+ * Determines if the transition is an "epsilon" transition.
2064
+ *
2065
+ * The default implementation returns `false`.
2066
+ *
2067
+ * @returns `true` if traversing this transition in the ATN does not
2068
+ * consume an input symbol; otherwise, `false` if traversing this
2069
+ * transition consumes (matches) an input symbol.
2070
+ */
2071
+ get isEpsilon() {
2072
+ return false;
2073
+ }
2074
+ get label() {
2075
+ return null;
2076
+ }
2077
+ toString() {
2078
+ return "";
2079
+ }
2080
+ };
2081
+
2082
+ // src/atn/SetTransition.ts
2083
+ var SetTransition = class extends Transition {
2084
+ static {
2085
+ __name(this, "SetTransition");
2086
+ }
2087
+ set;
2088
+ constructor(target, set) {
2089
+ super(target);
2090
+ if (set) {
2091
+ this.set = set;
2092
+ } else {
2093
+ this.set = IntervalSet.of(Token.INVALID_TYPE, Token.INVALID_TYPE);
2094
+ }
2095
+ }
2096
+ get transitionType() {
2097
+ return Transition.SET;
2098
+ }
2099
+ get label() {
2100
+ return this.set;
2101
+ }
2102
+ matches(symbol, _minVocabSymbol, _maxVocabSymbol) {
2103
+ return this.set.contains(symbol);
2104
+ }
2105
+ toString() {
2106
+ return this.set.toString();
2107
+ }
2108
+ };
2109
+
2110
+ // src/atn/NotSetTransition.ts
2111
+ var NotSetTransition = class extends SetTransition {
2112
+ static {
2113
+ __name(this, "NotSetTransition");
2114
+ }
2115
+ get transitionType() {
2116
+ return Transition.NOT_SET;
2117
+ }
2118
+ matches(symbol, minVocabSymbol, maxVocabSymbol) {
2119
+ return symbol >= minVocabSymbol && symbol <= maxVocabSymbol && !super.matches(symbol, minVocabSymbol, maxVocabSymbol);
2120
+ }
2121
+ toString() {
2122
+ return "~" + super.toString();
2123
+ }
2124
+ };
2125
+
2126
+ // src/misc/MapKeyEqualityOperator.ts
2127
+ var MapKeyEqualityComparator = class {
2128
+ static {
2129
+ __name(this, "MapKeyEqualityComparator");
2130
+ }
2131
+ keyComparator;
2132
+ constructor(keyComparator) {
2133
+ this.keyComparator = keyComparator;
2134
+ }
2135
+ hashCode(obj) {
2136
+ return this.keyComparator.hashCode(obj.key);
2137
+ }
2138
+ equals(a, b) {
2139
+ return this.keyComparator.equals(a.key, b.key);
2140
+ }
2141
+ };
2142
+
2143
+ // src/misc/HashMap.ts
2144
+ var HashMap = class _HashMap {
2145
+ static {
2146
+ __name(this, "HashMap");
2147
+ }
2148
+ backingStore;
2149
+ constructor(keyComparer) {
2150
+ if (keyComparer instanceof _HashMap) {
2151
+ this.backingStore = new HashSet(keyComparer.backingStore);
2152
+ } else {
2153
+ keyComparer = keyComparer ?? DefaultEqualityComparator.instance;
2154
+ this.backingStore = new HashSet(new MapKeyEqualityComparator(keyComparer));
2155
+ }
2156
+ }
2157
+ clear() {
2158
+ this.backingStore.clear();
2159
+ }
2160
+ containsKey(key) {
2161
+ return this.backingStore.contains({ key });
2162
+ }
2163
+ get(key) {
2164
+ const bucket = this.backingStore.get({ key });
2165
+ if (!bucket) {
2166
+ return void 0;
2167
+ }
2168
+ return bucket.value;
2169
+ }
2170
+ get isEmpty() {
2171
+ return this.backingStore.isEmpty;
2172
+ }
2173
+ /**
2174
+ * Sets the value for a key in the map. If the key is not present in the map, it is added.
2175
+ * If the key is present, the value is updated and the old value is returned.
2176
+ *
2177
+ * @param key The key to set.
2178
+ * @param value The value to set.
2179
+ *
2180
+ * @returns The old value for the key, if present.
2181
+ */
2182
+ set(key, value) {
2183
+ const element = this.backingStore.get({ key, value });
2184
+ let result;
2185
+ if (!element) {
2186
+ this.backingStore.add({ key, value });
2187
+ } else {
2188
+ result = element.value;
2189
+ element.value = value;
2190
+ }
2191
+ return result;
2192
+ }
2193
+ /**
2194
+ * Sets the value for a key in the map if the key is not already present. Otherwise the value is not changed and
2195
+ * the old value is returned.
2196
+ *
2197
+ * @param key The key to set.
2198
+ * @param value The value to set.
2199
+ *
2200
+ * @returns The current value for the key, if present.
2201
+ */
2202
+ setIfAbsent(key, value) {
2203
+ const element = this.backingStore.get({ key, value });
2204
+ let result;
2205
+ if (!element) {
2206
+ this.backingStore.add({ key, value });
2207
+ } else {
2208
+ result = element.value;
2209
+ }
2210
+ return result;
2211
+ }
2212
+ keys() {
2213
+ return this.backingStore.toArray().map((bucket) => {
2214
+ return bucket.key;
2215
+ });
2216
+ }
2217
+ values() {
2218
+ return this.backingStore.toArray().map((bucket) => {
2219
+ return bucket.value;
2220
+ });
2221
+ }
2222
+ get size() {
2223
+ return this.backingStore.size;
2224
+ }
2225
+ hashCode() {
2226
+ return this.backingStore.hashCode();
2227
+ }
2228
+ equals(o) {
2229
+ return this.backingStore.equals(o.backingStore);
2230
+ }
2231
+ };
2232
+
2233
+ // src/tree/TerminalNode.ts
2234
+ var TerminalNode = class {
2235
+ static {
2236
+ __name(this, "TerminalNode");
2237
+ }
2238
+ parent = null;
2239
+ symbol;
2240
+ constructor(symbol) {
2241
+ this.symbol = symbol;
2242
+ }
2243
+ getChild(_i) {
2244
+ return null;
2245
+ }
2246
+ getSymbol() {
2247
+ return this.symbol;
2248
+ }
2249
+ getPayload() {
2250
+ return this.symbol;
2251
+ }
2252
+ getSourceInterval() {
2253
+ if (this.symbol === null) {
2254
+ return Interval.INVALID_INTERVAL;
2255
+ }
2256
+ const tokenIndex = this.symbol.tokenIndex;
2257
+ return new Interval(tokenIndex, tokenIndex);
2258
+ }
2259
+ getChildCount() {
2260
+ return 0;
2261
+ }
2262
+ accept(visitor) {
2263
+ return visitor.visitTerminal(this);
2264
+ }
2265
+ getText() {
2266
+ return this.symbol?.text ?? "";
2267
+ }
2268
+ toString() {
2269
+ if (this.symbol?.type === Token.EOF) {
2270
+ return "<EOF>";
2271
+ } else {
2272
+ return this.symbol?.text ?? "";
2273
+ }
2274
+ }
2275
+ toStringTree() {
2276
+ return this.toString();
2277
+ }
2278
+ };
2279
+
2280
+ // src/tree/ErrorNode.ts
2281
+ var ErrorNode = class extends TerminalNode {
2282
+ static {
2283
+ __name(this, "ErrorNode");
2284
+ }
2285
+ accept(visitor) {
2286
+ return visitor.visitErrorNode(this);
2287
+ }
2288
+ };
2289
+
2290
+ // src/CommonToken.ts
2291
+ var CommonToken = class _CommonToken {
2292
+ static {
2293
+ __name(this, "CommonToken");
2294
+ }
2295
+ /**
2296
+ * An empty tuple which is used as the default value of
2297
+ * {@link source} for tokens that do not have a source.
2298
+ */
2299
+ // eslint-disable-next-line @typescript-eslint/naming-convention
2300
+ static EMPTY_SOURCE = [null, null];
2301
+ /**
2302
+ * These properties share a field to reduce the memory footprint of
2303
+ * {@link CommonToken}. Tokens created by a {@link CommonTokenFactory} from
2304
+ * the same source and input stream share a reference to the same
2305
+ * {@link Pair} containing these values.
2306
+ */
2307
+ source;
2308
+ tokenIndex;
2309
+ start;
2310
+ stop;
2311
+ /**
2312
+ * This is the backing field for {@link #getType} and {@link #setType}.
2313
+ */
2314
+ type;
2315
+ /**
2316
+ * The (one-based) line number on which the 1st character of this token was.
2317
+ */
2318
+ line;
2319
+ /**
2320
+ * The zero-based index of the first character position in its line.
2321
+ */
2322
+ column;
2323
+ /**
2324
+ * The token's channel.
2325
+ */
2326
+ channel;
2327
+ /**
2328
+ * This is the backing field for {@link getText} when the token text is
2329
+ * explicitly set in the constructor or via {@link setText}.
2330
+ */
2331
+ #text;
2332
+ constructor(details) {
2333
+ this.type = details.type;
2334
+ this.source = details.source;
2335
+ this.tokenIndex = details.tokenIndex ?? -1;
2336
+ this.line = details.line ?? 0;
2337
+ this.column = details.column ?? -1;
2338
+ this.channel = details.channel ?? Token.DEFAULT_CHANNEL;
2339
+ this.start = details.start ?? 0;
2340
+ this.stop = details.stop ?? 0;
2341
+ this.#text = details.text;
2342
+ if (details.line === void 0 && details.source[0] !== null) {
2343
+ this.line = details.source[0].line;
2344
+ }
2345
+ if (details.column === void 0 && details.source[0] !== null) {
2346
+ this.column = details.source[0].column;
2347
+ }
2348
+ }
2349
+ /**
2350
+ * Constructs a new {@link CommonToken} as a copy of another {@link Token}.
2351
+ *
2352
+ * If `token` is also a {@link CommonToken} instance, the newly
2353
+ * constructed token will share a reference to the {@link #text} field and
2354
+ * the {@link Pair} stored in {@link source}. Otherwise, {@link text} will
2355
+ * be assigned the result of calling {@link getText}, and {@link source}
2356
+ * will be constructed from the result of {@link Token.getTokenSource} and
2357
+ * {@link Token#getInputStream}.
2358
+ *
2359
+ * @param token The token to copy.
2360
+ */
2361
+ static fromToken(token) {
2362
+ const source = [token.tokenSource, token.inputStream];
2363
+ return new _CommonToken({
2364
+ type: token.type,
2365
+ line: token.line,
2366
+ tokenIndex: token.tokenIndex,
2367
+ column: token.column,
2368
+ channel: token.channel,
2369
+ start: token.start,
2370
+ stop: token.stop,
2371
+ text: token.text,
2372
+ source
2373
+ });
2374
+ }
2375
+ /**
2376
+ * Constructs a new {@link CommonToken} with the specified token type and text.
2377
+ *
2378
+ * @param type The token type.
2379
+ * @param text The text of the token.
2380
+ */
2381
+ static fromType(type, text) {
2382
+ return new _CommonToken({ type, text, source: _CommonToken.EMPTY_SOURCE });
2383
+ }
2384
+ static fromSource(source, type, channel, start, stop) {
2385
+ return new _CommonToken({ type, channel, start, stop, source });
2386
+ }
2387
+ get tokenSource() {
2388
+ return this.source[0];
2389
+ }
2390
+ get inputStream() {
2391
+ return this.source[1];
2392
+ }
2393
+ set inputStream(input) {
2394
+ this.source[1] = input;
2395
+ }
2396
+ /**
2397
+ * Constructs a new {@link CommonToken} as a copy of another {@link Token}.
2398
+ *
2399
+ * If `oldToken` is also a {@link CommonToken} instance, the newly
2400
+ * constructed token will share a reference to the {@link text} field and
2401
+ * the {@link Pair} stored in {@link source}. Otherwise, {@link text} will
2402
+ * be assigned the result of calling {@link getText}, and {@link source}
2403
+ * will be constructed from the result of {@link Token.getTokenSource} and
2404
+ * {@link Token.getInputStream}.
2405
+ */
2406
+ clone() {
2407
+ const t = new _CommonToken({
2408
+ source: this.source,
2409
+ type: this.type,
2410
+ channel: this.channel,
2411
+ start: this.start,
2412
+ stop: this.stop,
2413
+ tokenIndex: this.tokenIndex,
2414
+ line: this.line,
2415
+ column: this.column,
2416
+ text: this.#text
2417
+ });
2418
+ return t;
2419
+ }
2420
+ toString(recognizer) {
2421
+ let channelStr = "";
2422
+ if (this.channel > 0) {
2423
+ channelStr = ",channel=" + this.channel;
2424
+ }
2425
+ let text = this.text;
2426
+ if (text) {
2427
+ text = text.replace(/\n/g, "\\n");
2428
+ text = text.replace(/\r/g, "\\r");
2429
+ text = text.replace(/\t/g, "\\t");
2430
+ } else {
2431
+ text = "<no text>";
2432
+ }
2433
+ let typeString = String(this.type);
2434
+ if (recognizer) {
2435
+ typeString = recognizer.vocabulary.getDisplayName(this.type) ?? "<unknown>";
2436
+ }
2437
+ return "[@" + this.tokenIndex + "," + this.start + ":" + this.stop + "='" + text + "',<" + typeString + ">" + channelStr + "," + this.line + ":" + this.column + "]";
2438
+ }
2439
+ get text() {
2440
+ if (this.#text !== void 0) {
2441
+ return this.#text;
2442
+ }
2443
+ const input = this.inputStream;
2444
+ if (!input) {
2445
+ return void 0;
2446
+ }
2447
+ const n2 = input.size;
2448
+ if (this.start < n2 && this.stop < n2) {
2449
+ return input.getTextFromRange(this.start, this.stop);
2450
+ }
2451
+ return "<EOF>";
2452
+ }
2453
+ set text(text) {
2454
+ this.#text = text;
2455
+ }
2456
+ // WritableToken implementation
2457
+ setText(text) {
2458
+ this.#text = text;
2459
+ }
2460
+ setType(ttype) {
2461
+ this.type = ttype;
2462
+ }
2463
+ setLine(line) {
2464
+ this.line = line;
2465
+ }
2466
+ setCharPositionInLine(pos) {
2467
+ this.column = pos;
2468
+ }
2469
+ setChannel(channel) {
2470
+ this.channel = channel;
2471
+ }
2472
+ setTokenIndex(index) {
2473
+ this.tokenIndex = index;
2474
+ }
2475
+ };
2476
+
2477
+ // src/tree/Trees.ts
2478
+ var Trees = class _Trees {
2479
+ static {
2480
+ __name(this, "Trees");
2481
+ }
2482
+ /**
2483
+ * Print out a whole tree in LISP form. {@link getNodeText} is used on the
2484
+ * node payloads to get the text for the nodes. Detect
2485
+ * parse trees and extract data appropriately.
2486
+ */
2487
+ static toStringTree(tree, ruleNames, recog) {
2488
+ ruleNames = ruleNames ?? null;
2489
+ if (recog) {
2490
+ ruleNames = recog.ruleNames;
2491
+ }
2492
+ let s = _Trees.getNodeText(tree, ruleNames);
2493
+ s = escapeWhitespace(s, false);
2494
+ const c = tree.getChildCount();
2495
+ if (c === 0) {
2496
+ return s;
2497
+ }
2498
+ let res = "(" + s + " ";
2499
+ if (c > 0) {
2500
+ s = _Trees.toStringTree(tree.getChild(0), ruleNames);
2501
+ res = res.concat(s);
2502
+ }
2503
+ for (let i = 1; i < c; i++) {
2504
+ s = _Trees.toStringTree(tree.getChild(i), ruleNames);
2505
+ res = res.concat(" " + s);
2506
+ }
2507
+ res = res.concat(")");
2508
+ return res;
2509
+ }
2510
+ static getNodeText(t, ruleNames, recog) {
2511
+ ruleNames = ruleNames ?? null;
2512
+ if (recog) {
2513
+ ruleNames = recog.ruleNames;
2514
+ }
2515
+ if (ruleNames !== null) {
2516
+ if (t instanceof ParserRuleContext) {
2517
+ const context = t.ruleContext;
2518
+ const altNumber = context.getAltNumber();
2519
+ if (altNumber !== 0) {
2520
+ return ruleNames[t.ruleIndex] + ":" + altNumber;
2521
+ }
2522
+ return ruleNames[t.ruleIndex];
2523
+ } else if (t instanceof ErrorNode) {
2524
+ return t.toString();
2525
+ } else if (t instanceof TerminalNode) {
2526
+ return t.symbol.text;
2527
+ }
2528
+ }
2529
+ const payload = t.getPayload();
2530
+ if (isToken(payload)) {
2531
+ return payload.text;
2532
+ }
2533
+ return String(t.getPayload());
2534
+ }
2535
+ /**
2536
+ * Return ordered list of all children of this node
2537
+ */
2538
+ static getChildren(t) {
2539
+ const list = [];
2540
+ for (let i = 0; i < t.getChildCount(); i++) {
2541
+ list.push(t.getChild(i));
2542
+ }
2543
+ return list;
2544
+ }
2545
+ /**
2546
+ * Return a list of all ancestors of this node. The first node of
2547
+ * list is the root and the last is the parent of this node.
2548
+ */
2549
+ static getAncestors(t) {
2550
+ if (t.parent === null) {
2551
+ return [];
2552
+ }
2553
+ let ancestors = [];
2554
+ let p = t.parent;
2555
+ while (p !== null) {
2556
+ ancestors = [p].concat(ancestors);
2557
+ p = p.parent;
2558
+ }
2559
+ return ancestors;
2560
+ }
2561
+ /**
2562
+ * Return true if t is u's parent or a node on path to root from u.
2563
+ */
2564
+ static isAncestorOf(t, u) {
2565
+ if (t === null || u === null || t.parent === null) {
2566
+ return false;
2567
+ }
2568
+ let p = u.parent;
2569
+ while (p !== null) {
2570
+ if (t === p) {
2571
+ return true;
2572
+ }
2573
+ p = p.parent;
2574
+ }
2575
+ return false;
2576
+ }
2577
+ static findAllTokenNodes(t, ttype) {
2578
+ return _Trees.findAllNodes(t, ttype, true);
2579
+ }
2580
+ static findAllRuleNodes(t, ruleIndex) {
2581
+ return _Trees.findAllNodes(t, ruleIndex, false);
2582
+ }
2583
+ static findAllNodes(t, index, findTokens) {
2584
+ const nodes = [];
2585
+ _Trees.doFindAllNodes(t, index, findTokens, nodes);
2586
+ return nodes;
2587
+ }
2588
+ static descendants(t) {
2589
+ let nodes = [t];
2590
+ for (let i = 0; i < t.getChildCount(); i++) {
2591
+ nodes = nodes.concat(_Trees.descendants(t.getChild(i)));
2592
+ }
2593
+ return nodes;
2594
+ }
2595
+ /**
2596
+ * Find smallest subtree of t enclosing range startTokenIndex..stopTokenIndex
2597
+ * inclusively using post order traversal. Recursive depth-first-search.
2598
+ */
2599
+ static getRootOfSubtreeEnclosingRegion(t, startTokenIndex, stopTokenIndex) {
2600
+ const n2 = t.getChildCount();
2601
+ for (let i = 0; i < n2; i++) {
2602
+ const child = t.getChild(i);
2603
+ const r = this.getRootOfSubtreeEnclosingRegion(child, startTokenIndex, stopTokenIndex);
2604
+ if (r !== null) {
2605
+ return r;
2606
+ }
2607
+ }
2608
+ if (t instanceof ParserRuleContext) {
2609
+ if (startTokenIndex >= t.start.tokenIndex && // is range fully contained in t?
2610
+ (t.stop === null || stopTokenIndex <= t.stop.tokenIndex)) {
2611
+ return t;
2612
+ }
2613
+ }
2614
+ return null;
2615
+ }
2616
+ /**
2617
+ * Replace any subtree siblings of root that are completely to left
2618
+ * or right of lookahead range with a CommonToken(Token.INVALID_TYPE,"...")
2619
+ * node. The source interval for t is not altered to suit smaller range!
2620
+ *
2621
+ * WARNING: destructive to t.
2622
+ */
2623
+ static stripChildrenOutOfRange(t, root, startIndex, stopIndex) {
2624
+ if (t === null) {
2625
+ return;
2626
+ }
2627
+ for (let i = 0; i < t.getChildCount(); i++) {
2628
+ const child = t.getChild(i);
2629
+ const range = child.getSourceInterval();
2630
+ if (t instanceof ParserRuleContext && (range.stop < startIndex || range.start > stopIndex)) {
2631
+ if (this.isAncestorOf(child, root)) {
2632
+ const abbrev = CommonToken.fromType(Token.INVALID_TYPE, "...");
2633
+ t.children[i] = new TerminalNode(abbrev);
2634
+ }
2635
+ }
2636
+ }
2637
+ }
2638
+ static doFindAllNodes(t, index, findTokens, nodes) {
2639
+ if (findTokens && t instanceof TerminalNode) {
2640
+ if (t.symbol?.type === index) {
2641
+ nodes.push(t);
2642
+ }
2643
+ } else if (!findTokens && t instanceof ParserRuleContext) {
2644
+ if (t.ruleIndex === index) {
2645
+ nodes.push(t);
2646
+ }
2647
+ }
2648
+ for (let i = 0; i < t.getChildCount(); i++) {
2649
+ _Trees.doFindAllNodes(t.getChild(i), index, findTokens, nodes);
2650
+ }
2651
+ }
2652
+ };
2653
+
2654
+ // src/ParserRuleContext.ts
2655
+ var ParserRuleContext = class _ParserRuleContext {
2656
+ static {
2657
+ __name(this, "ParserRuleContext");
2658
+ }
2659
+ static empty = new _ParserRuleContext(null);
2660
+ start = null;
2661
+ stop = null;
2662
+ children = [];
2663
+ /**
2664
+ * What state invoked the rule associated with this context?
2665
+ * The "return address" is the followState of invokingState
2666
+ * If parent is null, this should be -1 this context object represents
2667
+ * the start rule.
2668
+ */
2669
+ invokingState;
2670
+ parent;
2671
+ /**
2672
+ * A rule context is a record of a single rule invocation. It knows
2673
+ * which context invoked it, if any. If there is no parent context, then
2674
+ * naturally the invoking state is not valid. The parent link
2675
+ * provides a chain upwards from the current rule invocation to the root
2676
+ * of the invocation tree, forming a stack. We actually carry no
2677
+ * information about the rule associated with this context (except
2678
+ * when parsing). We keep only the state number of the invoking state from
2679
+ * the ATN submachine that invoked this. Contrast this with the s
2680
+ * pointer inside ParserRuleContext that tracks the current state
2681
+ * being "executed" for the current rule.
2682
+ *
2683
+ * The parent contexts are useful for computing lookahead sets and
2684
+ * getting error information.
2685
+ *
2686
+ * These objects are used during parsing and prediction.
2687
+ * For the special case of parsers, we use the subclass
2688
+ * ParserRuleContext.
2689
+ */
2690
+ constructor(parent, invokingStateNumber = -1) {
2691
+ this.parent = parent;
2692
+ this.invokingState = invokingStateNumber;
2693
+ }
2694
+ /** Copy a context */
2695
+ copyFrom(ctx) {
2696
+ this.parent = ctx.parent;
2697
+ this.invokingState = ctx.invokingState;
2698
+ this.children.slice(0, this.children.length);
2699
+ this.start = ctx.start;
2700
+ this.stop = ctx.stop;
2701
+ if (ctx.children) {
2702
+ ctx.children.forEach((child) => {
2703
+ if (child instanceof ErrorNode) {
2704
+ this.children.push(child);
2705
+ child.parent = this;
2706
+ }
2707
+ });
2708
+ }
2709
+ }
2710
+ // Double dispatch methods for listeners
2711
+ enterRule(_listener) {
2712
+ }
2713
+ exitRule(_listener) {
2714
+ }
2715
+ addChild(child) {
2716
+ this.children.push(child);
2717
+ return child;
2718
+ }
2719
+ /**
2720
+ * Used by enterOuterAlt to toss out a RuleContext previously added as
2721
+ * we entered a rule. If we have label, we will need to remove
2722
+ * generic ruleContext object.
2723
+ */
2724
+ removeLastChild() {
2725
+ this.children.pop();
2726
+ }
2727
+ addTokenNode(token) {
2728
+ const node = new TerminalNode(token);
2729
+ this.children.push(node);
2730
+ node.parent = this;
2731
+ return node;
2732
+ }
2733
+ addErrorNode(errorNode) {
2734
+ errorNode.parent = this;
2735
+ this.children.push(errorNode);
2736
+ return errorNode;
2737
+ }
2738
+ getChild(i, type) {
2739
+ if (i < 0 || i >= this.children.length) {
2740
+ return null;
2741
+ }
2742
+ if (!type) {
2743
+ return this.children[i];
2744
+ }
2745
+ for (const child of this.children) {
2746
+ if (child instanceof type) {
2747
+ if (i === 0) {
2748
+ return child;
2749
+ } else {
2750
+ i -= 1;
2751
+ }
2752
+ }
2753
+ }
2754
+ return null;
2755
+ }
2756
+ getToken(ttype, i) {
2757
+ if (i < 0 || i >= this.children.length) {
2758
+ return null;
2759
+ }
2760
+ for (const child of this.children) {
2761
+ if ("symbol" in child) {
2762
+ if (child.symbol?.type === ttype) {
2763
+ if (i === 0) {
2764
+ return child;
2765
+ } else {
2766
+ i -= 1;
2767
+ }
2768
+ }
2769
+ }
2770
+ }
2771
+ return null;
2772
+ }
2773
+ getTokens(ttype) {
2774
+ const tokens = [];
2775
+ for (const child of this.children) {
2776
+ if ("symbol" in child) {
2777
+ if (child.symbol?.type === ttype) {
2778
+ tokens.push(child);
2779
+ }
2780
+ }
2781
+ }
2782
+ return tokens;
2783
+ }
2784
+ // XXX: base the child type selection on the rule index, not the class.
2785
+ getRuleContext(index, ctxType) {
2786
+ return this.getChild(index, ctxType);
2787
+ }
2788
+ // XXX: base the child type selection on the rule index, not the class.
2789
+ getRuleContexts(ctxType) {
2790
+ const contexts = [];
2791
+ for (const child of this.children) {
2792
+ if (child instanceof ctxType) {
2793
+ contexts.push(child);
2794
+ }
2795
+ }
2796
+ return contexts;
2797
+ }
2798
+ getChildCount() {
2799
+ return this.children.length;
2800
+ }
2801
+ getSourceInterval() {
2802
+ if (this.start === null) {
2803
+ return Interval.INVALID_INTERVAL;
2804
+ }
2805
+ if (this.stop === null || this.stop.tokenIndex < this.start.tokenIndex) {
2806
+ return new Interval(this.start.tokenIndex, this.start.tokenIndex - 1);
2807
+ }
2808
+ return new Interval(this.start.tokenIndex, this.stop.tokenIndex);
2809
+ }
2810
+ depth() {
2811
+ let n2 = 0;
2812
+ let p = this;
2813
+ while (p !== null) {
2814
+ p = p.parent;
2815
+ n2 += 1;
2816
+ }
2817
+ return n2;
2818
+ }
2819
+ /**
2820
+ * A context is empty if there is no invoking state; meaning nobody call
2821
+ * current context.
2822
+ */
2823
+ isEmpty() {
2824
+ return this.invokingState === -1;
2825
+ }
2826
+ get ruleContext() {
2827
+ return this;
2828
+ }
2829
+ get ruleIndex() {
2830
+ return -1;
2831
+ }
2832
+ getPayload() {
2833
+ return this;
2834
+ }
2835
+ getText() {
2836
+ if (this.children.length === 0) {
2837
+ return "";
2838
+ }
2839
+ return this.children.map((child) => {
2840
+ return child.getText();
2841
+ }).join("");
2842
+ }
2843
+ /**
2844
+ * For rule associated with this parse tree internal node, return
2845
+ * the outer alternative number used to match the input. Default
2846
+ * implementation does not compute nor store this alt num. Create
2847
+ * a subclass of ParserRuleContext with backing field and set
2848
+ * option contextSuperClass.
2849
+ * to set it.
2850
+ */
2851
+ getAltNumber() {
2852
+ return ATN.INVALID_ALT_NUMBER;
2853
+ }
2854
+ /**
2855
+ * Set the outer alternative number for this context node. Default
2856
+ * implementation does nothing to avoid backing field overhead for
2857
+ * trees that don't need it. Create
2858
+ * a subclass of ParserRuleContext with backing field and set
2859
+ * option contextSuperClass.
2860
+ */
2861
+ setAltNumber(_altNumber) {
2862
+ }
2863
+ accept(visitor) {
2864
+ return visitor.visitChildren(this);
2865
+ }
2866
+ toStringTree(...args) {
2867
+ if (args.length < 2) {
2868
+ return Trees.toStringTree(this, null, args[0]);
2869
+ }
2870
+ return Trees.toStringTree(this, args[0], args[1]);
2871
+ }
2872
+ toString(ruleNames, stop) {
2873
+ ruleNames = ruleNames ?? null;
2874
+ stop = stop ?? null;
2875
+ let p = this;
2876
+ let s = "[";
2877
+ while (p !== null && p !== stop) {
2878
+ if (ruleNames === null) {
2879
+ if (!p.isEmpty()) {
2880
+ s += p.invokingState;
2881
+ }
2882
+ } else {
2883
+ const ri = p.ruleIndex;
2884
+ const ruleName = ri >= 0 && ri < ruleNames.length ? ruleNames[ri] : "" + ri;
2885
+ s += ruleName;
2886
+ }
2887
+ if (p.parent !== null && (ruleNames !== null || !p.parent.isEmpty())) {
2888
+ s += " ";
2889
+ }
2890
+ p = p.parent;
2891
+ }
2892
+ s += "]";
2893
+ return s;
2894
+ }
2895
+ };
2896
+
2897
+ // src/atn/ArrayPredictionContext.ts
2898
+ var ArrayPredictionContext = class _ArrayPredictionContext extends PredictionContext {
2899
+ static {
2900
+ __name(this, "ArrayPredictionContext");
2901
+ }
2902
+ parents = [];
2903
+ returnStates = [];
2904
+ constructor(parents, returnStates) {
2905
+ super(PredictionContext.calculateHashCodeList(parents, returnStates));
2906
+ this.parents = parents;
2907
+ this.returnStates = returnStates;
2908
+ return this;
2909
+ }
2910
+ isEmpty() {
2911
+ return this.returnStates[0] === PredictionContext.EMPTY_RETURN_STATE;
2912
+ }
2913
+ get length() {
2914
+ return this.returnStates.length;
2915
+ }
2916
+ getParent(index) {
2917
+ return this.parents[index];
2918
+ }
2919
+ getReturnState(index) {
2920
+ return this.returnStates[index];
2921
+ }
2922
+ equals(other) {
2923
+ if (this === other) {
2924
+ return true;
2925
+ }
2926
+ if (!(other instanceof _ArrayPredictionContext) || this.hashCode() !== other.hashCode()) {
2927
+ return false;
2928
+ }
2929
+ return equalNumberArrays(this.returnStates, other.returnStates) && equalArrays(this.parents, other.parents);
2930
+ }
2931
+ toString() {
2932
+ if (this.isEmpty()) {
2933
+ return "[]";
2934
+ }
2935
+ const entries = [];
2936
+ for (let i = 0; i < this.returnStates.length; i++) {
2937
+ if (this.returnStates[i] === PredictionContext.EMPTY_RETURN_STATE) {
2938
+ entries.push("$");
2939
+ continue;
2940
+ }
2941
+ entries.push(this.returnStates[i].toString());
2942
+ if (this.parents[i]) {
2943
+ entries.push(this.parents[i].toString());
2944
+ } else {
2945
+ entries.push("null");
2946
+ }
2947
+ }
2948
+ return `[${entries.join(", ")}]`;
2949
+ }
2950
+ };
2951
+
2952
+ // src/atn/helpers.ts
2953
+ var createSingletonPredictionContext = /* @__PURE__ */ __name((parent, returnState) => {
2954
+ if (returnState === PredictionContext.EMPTY_RETURN_STATE && parent === null) {
2955
+ return EmptyPredictionContext.instance;
2956
+ } else {
2957
+ return new SingletonPredictionContext(parent, returnState);
2958
+ }
2959
+ }, "createSingletonPredictionContext");
2960
+
2961
+ // src/atn/PredictionContextUtils.ts
2962
+ var predictionContextFromRuleContext = /* @__PURE__ */ __name((atn, outerContext) => {
2963
+ if (!outerContext) {
2964
+ outerContext = ParserRuleContext.empty;
2965
+ }
2966
+ if (!outerContext.parent || outerContext === ParserRuleContext.empty) {
2967
+ return EmptyPredictionContext.instance;
2968
+ }
2969
+ const parent = predictionContextFromRuleContext(atn, outerContext.parent);
2970
+ const state = atn.states[outerContext.invokingState];
2971
+ const transition = state.transitions[0];
2972
+ return createSingletonPredictionContext(parent, transition.followState.stateNumber);
2973
+ }, "predictionContextFromRuleContext");
2974
+ var merge = /* @__PURE__ */ __name((a, b, rootIsWildcard, mergeCache) => {
2975
+ if (a === b || a.equals(b)) {
2976
+ return a;
2977
+ }
2978
+ if (a instanceof SingletonPredictionContext && b instanceof SingletonPredictionContext) {
2979
+ return mergeSingletons(a, b, rootIsWildcard, mergeCache);
2980
+ }
2981
+ if (rootIsWildcard) {
2982
+ if (a instanceof EmptyPredictionContext) {
2983
+ return a;
2984
+ }
2985
+ if (b instanceof EmptyPredictionContext) {
2986
+ return b;
2987
+ }
2988
+ }
2989
+ if (a instanceof SingletonPredictionContext) {
2990
+ a = new ArrayPredictionContext([a.parent], [a.returnState]);
2991
+ }
2992
+ if (b instanceof SingletonPredictionContext) {
2993
+ b = new ArrayPredictionContext([b.parent], [b.returnState]);
2994
+ }
2995
+ return mergeArrays(a, b, rootIsWildcard, mergeCache);
2996
+ }, "merge");
2997
+ var mergeArrays = /* @__PURE__ */ __name((a, b, rootIsWildcard, mergeCache) => {
2998
+ if (mergeCache) {
2999
+ let previous = mergeCache.get(a, b);
3000
+ if (previous) {
3001
+ return previous;
3002
+ }
3003
+ previous = mergeCache.get(b, a);
3004
+ if (previous) {
3005
+ return previous;
3006
+ }
3007
+ }
3008
+ let i = 0;
3009
+ let j = 0;
3010
+ let k = 0;
3011
+ let mergedReturnStates = new Array(a.returnStates.length + b.returnStates.length).fill(0);
3012
+ let mergedParents = new Array(a.returnStates.length + b.returnStates.length).fill(null);
3013
+ while (i < a.returnStates.length && j < b.returnStates.length) {
3014
+ const aParent = a.parents[i];
3015
+ const bParent = b.parents[j];
3016
+ if (a.returnStates[i] === b.returnStates[j]) {
3017
+ const payload = a.returnStates[i];
3018
+ const bothDollars = payload === PredictionContext.EMPTY_RETURN_STATE && aParent === null && bParent === null;
3019
+ const axAx = aParent !== null && bParent !== null && aParent === bParent;
3020
+ if (bothDollars || axAx) {
3021
+ mergedParents[k] = aParent;
3022
+ mergedReturnStates[k] = payload;
3023
+ } else {
3024
+ mergedParents[k] = merge(aParent, bParent, rootIsWildcard, mergeCache);
3025
+ mergedReturnStates[k] = payload;
3026
+ }
3027
+ i += 1;
3028
+ j += 1;
3029
+ } else if (a.returnStates[i] < b.returnStates[j]) {
3030
+ mergedParents[k] = aParent;
3031
+ mergedReturnStates[k] = a.returnStates[i];
3032
+ i += 1;
3033
+ } else {
3034
+ mergedParents[k] = bParent;
3035
+ mergedReturnStates[k] = b.returnStates[j];
3036
+ j += 1;
3037
+ }
3038
+ k += 1;
3039
+ }
3040
+ if (i < a.returnStates.length) {
3041
+ for (let p = i; p < a.returnStates.length; p++) {
3042
+ mergedParents[k] = a.parents[p];
3043
+ mergedReturnStates[k] = a.returnStates[p];
3044
+ k += 1;
3045
+ }
3046
+ } else {
3047
+ for (let p = j; p < b.returnStates.length; p++) {
3048
+ mergedParents[k] = b.parents[p];
3049
+ mergedReturnStates[k] = b.returnStates[p];
3050
+ k += 1;
3051
+ }
3052
+ }
3053
+ if (k < mergedParents.length) {
3054
+ if (k === 1) {
3055
+ const aNew = createSingletonPredictionContext(mergedParents[0] ?? void 0, mergedReturnStates[0]);
3056
+ if (mergeCache !== null) {
3057
+ mergeCache.set(a, b, aNew);
3058
+ }
3059
+ return aNew;
3060
+ }
3061
+ mergedParents = mergedParents.slice(0, k);
3062
+ mergedReturnStates = mergedReturnStates.slice(0, k);
3063
+ }
3064
+ const merged = new ArrayPredictionContext(mergedParents, mergedReturnStates);
3065
+ if (merged.equals(a)) {
3066
+ if (mergeCache !== null) {
3067
+ mergeCache.set(a, b, a);
3068
+ }
3069
+ if (PredictionContext.traceATNSimulator) {
3070
+ console.log("mergeArrays a=" + a + ",b=" + b + " -> a");
3071
+ }
3072
+ return a;
3073
+ }
3074
+ if (merged.equals(b)) {
3075
+ if (mergeCache !== null) {
3076
+ mergeCache.set(a, b, b);
3077
+ }
3078
+ return b;
3079
+ }
3080
+ combineCommonParents(mergedParents);
3081
+ if (mergeCache !== null) {
3082
+ mergeCache.set(a, b, merged);
3083
+ }
3084
+ if (PredictionContext.traceATNSimulator) {
3085
+ console.log("mergeArrays a=" + a + ",b=" + b + " -> " + merged);
3086
+ }
3087
+ return merged;
3088
+ }, "mergeArrays");
3089
+ var combineCommonParents = /* @__PURE__ */ __name((parents) => {
3090
+ const uniqueParents = new HashMap(ObjectEqualityComparator.instance);
3091
+ for (const parent of parents) {
3092
+ if (parent) {
3093
+ if (!uniqueParents.containsKey(parent)) {
3094
+ uniqueParents.set(parent, parent);
3095
+ }
3096
+ }
3097
+ }
3098
+ for (let q = 0; q < parents.length; q++) {
3099
+ if (parents[q]) {
3100
+ parents[q] = uniqueParents.get(parents[q]) ?? null;
3101
+ }
3102
+ }
3103
+ }, "combineCommonParents");
3104
+ var mergeSingletons = /* @__PURE__ */ __name((a, b, rootIsWildcard, mergeCache) => {
3105
+ if (mergeCache !== null) {
3106
+ let previous = mergeCache.get(a, b);
3107
+ if (previous !== null) {
3108
+ return previous;
3109
+ }
3110
+ previous = mergeCache.get(b, a);
3111
+ if (previous !== null) {
3112
+ return previous;
3113
+ }
3114
+ }
3115
+ const rootMerge = mergeRoot(a, b, rootIsWildcard);
3116
+ if (rootMerge !== null) {
3117
+ if (mergeCache !== null) {
3118
+ mergeCache.set(a, b, rootMerge);
3119
+ }
3120
+ return rootMerge;
3121
+ }
3122
+ if (a.returnState === b.returnState) {
3123
+ const parent = merge(a.parent, b.parent, rootIsWildcard, mergeCache);
3124
+ if (parent === a.parent) {
3125
+ return a;
3126
+ }
3127
+ if (parent === b.parent) {
3128
+ return b;
3129
+ }
3130
+ const spc = createSingletonPredictionContext(parent, a.returnState);
3131
+ if (mergeCache !== null) {
3132
+ mergeCache.set(a, b, spc);
3133
+ }
3134
+ return spc;
3135
+ } else {
3136
+ let singleParent = null;
3137
+ if (a === b || a.parent !== null && a.parent.equals(b.parent)) {
3138
+ singleParent = a.parent;
3139
+ }
3140
+ if (singleParent !== null) {
3141
+ const payloads2 = [a.returnState, b.returnState];
3142
+ if (a.returnState > b.returnState) {
3143
+ payloads2[0] = b.returnState;
3144
+ payloads2[1] = a.returnState;
3145
+ }
3146
+ const parents2 = [singleParent, singleParent];
3147
+ const apc = new ArrayPredictionContext(parents2, payloads2);
3148
+ if (mergeCache !== null) {
3149
+ mergeCache.set(a, b, apc);
3150
+ }
3151
+ return apc;
3152
+ }
3153
+ const payloads = [a.returnState, b.returnState];
3154
+ let parents = [a.parent, b.parent];
3155
+ if (a.returnState > b.returnState) {
3156
+ payloads[0] = b.returnState;
3157
+ payloads[1] = a.returnState;
3158
+ parents = [b.parent, a.parent];
3159
+ }
3160
+ const aNew = new ArrayPredictionContext(parents, payloads);
3161
+ if (mergeCache !== null) {
3162
+ mergeCache.set(a, b, aNew);
3163
+ }
3164
+ return aNew;
3165
+ }
3166
+ }, "mergeSingletons");
3167
+ var mergeRoot = /* @__PURE__ */ __name((a, b, rootIsWildcard) => {
3168
+ if (rootIsWildcard) {
3169
+ if (a === EmptyPredictionContext.instance || b === EmptyPredictionContext.instance) {
3170
+ return EmptyPredictionContext.instance;
3171
+ }
3172
+ } else {
3173
+ if (a === EmptyPredictionContext.instance && b === EmptyPredictionContext.instance) {
3174
+ return EmptyPredictionContext.instance;
3175
+ }
3176
+ if (a === EmptyPredictionContext.instance) {
3177
+ const payloads = [
3178
+ b.returnState,
3179
+ PredictionContext.EMPTY_RETURN_STATE
3180
+ ];
3181
+ const parents = [b.parent, null];
3182
+ return new ArrayPredictionContext(parents, payloads);
3183
+ }
3184
+ if (b === EmptyPredictionContext.instance) {
3185
+ const payloads = [a.returnState, PredictionContext.EMPTY_RETURN_STATE];
3186
+ const parents = [a.parent, null];
3187
+ return new ArrayPredictionContext(parents, payloads);
3188
+ }
3189
+ }
3190
+ return null;
3191
+ }, "mergeRoot");
3192
+
3193
+ // src/atn/LL1Analyzer.ts
3194
+ var LL1Analyzer = class _LL1Analyzer {
3195
+ constructor(atn) {
3196
+ this.atn = atn;
3197
+ }
3198
+ static {
3199
+ __name(this, "LL1Analyzer");
3200
+ }
3201
+ /**
3202
+ * Special value added to the lookahead sets to indicate that we hit
3203
+ * a predicate during analysis if `seeThruPreds==false`.
3204
+ */
3205
+ static hitPredicate = Token.INVALID_TYPE;
3206
+ /**
3207
+ * Calculates the SLL(1) expected lookahead set for each outgoing transition
3208
+ * of an {@link ATNState}. The returned array has one element for each
3209
+ * outgoing transition in `s`. If the closure from transition
3210
+ * _i_ leads to a semantic predicate before matching a symbol, the
3211
+ * element at index *i* of the result will be `undefined`.
3212
+ *
3213
+ * @param s the ATN state
3214
+ * @returns the expected symbols for each outgoing transition of `s`.
3215
+ */
3216
+ getDecisionLookahead(s) {
3217
+ const count = s.transitions.length;
3218
+ const look = new Array(count);
3219
+ for (let alt = 0; alt < count; alt++) {
3220
+ const set = new IntervalSet();
3221
+ const lookBusy = new HashSet();
3222
+ this.doLook(
3223
+ s.transitions[alt].target,
3224
+ void 0,
3225
+ EmptyPredictionContext.instance,
3226
+ set,
3227
+ lookBusy,
3228
+ new BitSet(),
3229
+ false,
3230
+ false
3231
+ );
3232
+ if (set.length > 0 && !set.contains(_LL1Analyzer.hitPredicate)) {
3233
+ look[alt] = set;
3234
+ }
3235
+ }
3236
+ return look;
3237
+ }
3238
+ /**
3239
+ * Compute set of tokens that can follow `s` in the ATN in the
3240
+ * specified `ctx`.
3241
+ *
3242
+ * If `ctx` is `null` and the end of the rule containing
3243
+ * `s` is reached, {@link Token//EPSILON} is added to the result set.
3244
+ * If `ctx` is not `null` and the end of the outermost rule is
3245
+ * reached, {@link Token//EOF} is added to the result set.
3246
+ *
3247
+ * @param s the ATN state
3248
+ * @param stopState the ATN state to stop at. This can be a
3249
+ * {@link BlockEndState} to detect epsilon paths through a closure.
3250
+ * @param ctx the complete parser context, or `null` if the context
3251
+ * should be ignored
3252
+ *
3253
+ * @returns The set of tokens that can follow `s` in the ATN in the
3254
+ * specified `ctx`.
3255
+ */
3256
+ look(s, stopState, ctx) {
3257
+ const r = new IntervalSet();
3258
+ const lookContext = ctx ? predictionContextFromRuleContext(this.atn, ctx) : null;
3259
+ this.doLook(s, stopState, lookContext, r, new HashSet(), new BitSet(), true, true);
3260
+ return r;
3261
+ }
3262
+ /**
3263
+ * Compute set of tokens that can follow `s` in the ATN in the
3264
+ * specified `ctx`.
3265
+ *
3266
+ * If `ctx` is `null` and `stopState` or the end of the
3267
+ * rule containing `s` is reached, {@link Token//EPSILON} is added to
3268
+ * the result set. If `ctx` is not `null` and `addEOF` is
3269
+ * `true` and `stopState` or the end of the outermost rule is
3270
+ * reached, {@link Token//EOF} is added to the result set.
3271
+ *
3272
+ * @param s the ATN state.
3273
+ * @param stopState the ATN state to stop at. This can be a
3274
+ * {@link BlockEndState} to detect epsilon paths through a closure.
3275
+ * @param ctx The outer context, or `null` if the outer context should
3276
+ * not be used.
3277
+ * @param look The result lookahead set.
3278
+ * @param lookBusy A set used for preventing epsilon closures in the ATN
3279
+ * from causing a stack overflow. Outside code should pass
3280
+ * `new CustomizedSet<ATNConfig>` for this argument.
3281
+ * @param calledRuleStack A set used for preventing left recursion in the
3282
+ * ATN from causing a stack overflow. Outside code should pass
3283
+ * `new BitSet()` for this argument.
3284
+ * @param seeThruPreds `true` to true semantic predicates as
3285
+ * implicitly `true` and "see through them", otherwise `false`
3286
+ * to treat semantic predicates as opaque and add {@link hitPredicate} to the
3287
+ * result if one is encountered.
3288
+ * @param addEOF Add {@link Token//EOF} to the result if the end of the
3289
+ * outermost context is reached. This parameter has no effect if `ctx`
3290
+ * is `null`.
3291
+ */
3292
+ doLook(s, stopState, ctx, look, lookBusy, calledRuleStack, seeThruPreds, addEOF) {
3293
+ const c = ATNConfig.createWithContext(s, 0, ctx);
3294
+ if (lookBusy.get(c)) {
3295
+ return;
3296
+ }
3297
+ lookBusy.add(c);
3298
+ if (s === stopState) {
3299
+ if (!ctx) {
3300
+ look.addOne(Token.EPSILON);
3301
+ return;
3302
+ } else if (ctx.isEmpty() && addEOF) {
3303
+ look.addOne(Token.EOF);
3304
+ return;
3305
+ }
3306
+ }
3307
+ if (s.constructor.stateType === ATNState.RULE_STOP) {
3308
+ if (!ctx) {
3309
+ look.addOne(Token.EPSILON);
3310
+ return;
3311
+ } else if (ctx.isEmpty() && addEOF) {
3312
+ look.addOne(Token.EOF);
3313
+ return;
3314
+ }
3315
+ if (ctx !== EmptyPredictionContext.instance) {
3316
+ const removed = calledRuleStack.get(s.ruleIndex);
3317
+ try {
3318
+ calledRuleStack.clear(s.ruleIndex);
3319
+ for (let i = 0; i < ctx.length; i++) {
3320
+ const returnState = this.atn.states[ctx.getReturnState(i)];
3321
+ this.doLook(
3322
+ returnState,
3323
+ stopState,
3324
+ ctx.getParent(i),
3325
+ look,
3326
+ lookBusy,
3327
+ calledRuleStack,
3328
+ seeThruPreds,
3329
+ addEOF
3330
+ );
3331
+ }
3332
+ } finally {
3333
+ if (removed) {
3334
+ calledRuleStack.set(s.ruleIndex);
3335
+ }
3336
+ }
3337
+ return;
3338
+ }
3339
+ }
3340
+ for (const t of s.transitions) {
3341
+ switch (t.transitionType) {
3342
+ case Transition.RULE: {
3343
+ if (calledRuleStack.get(t.target.ruleIndex)) {
3344
+ continue;
3345
+ }
3346
+ const newContext = createSingletonPredictionContext(
3347
+ ctx ?? void 0,
3348
+ t.followState.stateNumber
3349
+ );
3350
+ try {
3351
+ calledRuleStack.set(t.target.ruleIndex);
3352
+ this.doLook(
3353
+ t.target,
3354
+ stopState,
3355
+ newContext,
3356
+ look,
3357
+ lookBusy,
3358
+ calledRuleStack,
3359
+ seeThruPreds,
3360
+ addEOF
3361
+ );
3362
+ } finally {
3363
+ calledRuleStack.clear(t.target.ruleIndex);
3364
+ }
3365
+ break;
3366
+ }
3367
+ case Transition.PREDICATE:
3368
+ case Transition.PRECEDENCE: {
3369
+ if (seeThruPreds) {
3370
+ this.doLook(t.target, stopState, ctx, look, lookBusy, calledRuleStack, seeThruPreds, addEOF);
3371
+ } else {
3372
+ look.addOne(_LL1Analyzer.hitPredicate);
3373
+ }
3374
+ break;
3375
+ }
3376
+ case Transition.WILDCARD: {
3377
+ look.addRange(Token.MIN_USER_TOKEN_TYPE, this.atn.maxTokenType);
3378
+ break;
3379
+ }
3380
+ default: {
3381
+ if (t.isEpsilon) {
3382
+ this.doLook(t.target, stopState, ctx, look, lookBusy, calledRuleStack, seeThruPreds, addEOF);
3383
+ } else {
3384
+ let set = t.label;
3385
+ if (set) {
3386
+ if (t instanceof NotSetTransition) {
3387
+ set = set.complement(Token.MIN_USER_TOKEN_TYPE, this.atn.maxTokenType);
3388
+ }
3389
+ look.addSet(set);
3390
+ }
3391
+ }
3392
+ break;
3393
+ }
3394
+ }
3395
+ }
3396
+ }
3397
+ };
3398
+
3399
+ // src/atn/ATN.ts
3400
+ var ATN = class {
3401
+ static {
3402
+ __name(this, "ATN");
3403
+ }
3404
+ static INVALID_ALT_NUMBER = 0;
3405
+ /** Represents the type of recognizer an ATN applies to */
3406
+ static LEXER = 0;
3407
+ static PARSER = 1;
3408
+ /**
3409
+ * Used for runtime deserialization of ATNs from strings
3410
+ * The type of the ATN.
3411
+ */
3412
+ grammarType;
3413
+ /** The maximum value for any symbol recognized by a transition in the ATN. */
3414
+ maxTokenType;
3415
+ states = [];
3416
+ /**
3417
+ * Each subrule/rule is a decision point and we must track them so we
3418
+ * can go back later and build DFA predictors for them. This includes
3419
+ * all the rules, subrules, optional blocks, ()+, ()* etc...
3420
+ */
3421
+ decisionToState = [];
3422
+ /** Maps from rule index to starting state number. */
3423
+ ruleToStartState = [];
3424
+ // Initialized by the ATN deserializer.
3425
+ /** Maps from rule index to stop state number. */
3426
+ ruleToStopState = [];
3427
+ // Initialized by the ATN deserializer.
3428
+ modeNameToStartState = /* @__PURE__ */ new Map();
3429
+ /**
3430
+ * For lexer ATNs, this maps the rule index to the resulting token type.
3431
+ * For parser ATNs, this maps the rule index to the generated bypass token
3432
+ * type if the {@link ATNDeserializationOptions//isGenerateRuleBypassTransitions}
3433
+ * deserialization option was specified; otherwise, this is `null`
3434
+ */
3435
+ ruleToTokenType = [];
3436
+ // Initialized by the ATN deserializer.
3437
+ /**
3438
+ * For lexer ATNs, this is an array of {@link LexerAction} objects which may
3439
+ * be referenced by action transitions in the ATN
3440
+ */
3441
+ lexerActions = [];
3442
+ modeToStartState = [];
3443
+ analyzer;
3444
+ constructor(grammarType, maxTokenType) {
3445
+ this.grammarType = grammarType;
3446
+ this.maxTokenType = maxTokenType;
3447
+ this.analyzer = new LL1Analyzer(this);
3448
+ }
3449
+ /**
3450
+ * Compute the set of valid tokens that can occur starting in state `s`.
3451
+ * If `ctx` is null, the set of tokens will not include what can follow
3452
+ * the rule surrounding `s`. In other words, the set will be
3453
+ * restricted to tokens reachable staying within `s`'s rule.
3454
+ */
3455
+ nextTokens(atnState, ctx) {
3456
+ if (!ctx && atnState.nextTokenWithinRule) {
3457
+ return atnState.nextTokenWithinRule;
3458
+ }
3459
+ const next = this.analyzer.look(atnState, void 0, ctx);
3460
+ if (!ctx) {
3461
+ atnState.nextTokenWithinRule = next;
3462
+ }
3463
+ return next;
3464
+ }
3465
+ addState(state) {
3466
+ if (state) {
3467
+ state.stateNumber = this.states.length;
3468
+ }
3469
+ this.states.push(state);
3470
+ }
3471
+ removeState(state) {
3472
+ this.states[state.stateNumber] = null;
3473
+ }
3474
+ defineDecisionState(s) {
3475
+ this.decisionToState.push(s);
3476
+ s.decision = this.decisionToState.length - 1;
3477
+ return s.decision;
3478
+ }
3479
+ getDecisionState(decision) {
3480
+ if (this.decisionToState.length === 0) {
3481
+ return null;
3482
+ } else {
3483
+ return this.decisionToState[decision];
3484
+ }
3485
+ }
3486
+ getNumberOfDecisions() {
3487
+ return this.decisionToState.length;
3488
+ }
3489
+ /**
3490
+ * Computes the set of input symbols which could follow ATN state number
3491
+ * `stateNumber` in the specified full `context`. This method
3492
+ * considers the complete parser context, but does not evaluate semantic
3493
+ * predicates (i.e. all predicates encountered during the calculation are
3494
+ * assumed true). If a path in the ATN exists from the starting state to the
3495
+ * {@link RuleStopState} of the outermost context without matching any
3496
+ * symbols, {@link Token//EOF} is added to the returned set.
3497
+ *
3498
+ * If `context` is `null`, it is treated as
3499
+ * {@link ParserRuleContext//EMPTY}.
3500
+ *
3501
+ * @param stateNumber the ATN state number
3502
+ * @param context the full parse context
3503
+ *
3504
+ * @returns {IntervalSet} The set of potentially valid input symbols which could follow the
3505
+ * specified state in the specified context.
3506
+ *
3507
+ * @throws IllegalArgumentException if the ATN does not contain a state with
3508
+ * number `stateNumber`
3509
+ */
3510
+ getExpectedTokens(stateNumber, context) {
3511
+ if (stateNumber < 0 || stateNumber >= this.states.length) {
3512
+ throw new Error("Invalid state number.");
3513
+ }
3514
+ const s = this.states[stateNumber];
3515
+ let following = this.nextTokens(s);
3516
+ if (!following.contains(Token.EPSILON)) {
3517
+ return following;
3518
+ }
3519
+ let ctx = context;
3520
+ const expected = new IntervalSet();
3521
+ expected.addSet(following);
3522
+ expected.removeOne(Token.EPSILON);
3523
+ while (ctx !== null && ctx.invokingState >= 0 && following.contains(Token.EPSILON)) {
3524
+ const invokingState = this.states[ctx.invokingState];
3525
+ const rt = invokingState.transitions[0];
3526
+ following = this.nextTokens(rt.followState);
3527
+ expected.addSet(following);
3528
+ expected.removeOne(Token.EPSILON);
3529
+ ctx = ctx.parent;
3530
+ }
3531
+ if (following.contains(Token.EPSILON)) {
3532
+ expected.addOne(Token.EOF);
3533
+ }
3534
+ return expected;
3535
+ }
3536
+ };
3537
+
3538
+ // src/atn/RuleStopState.ts
3539
+ var RuleStopState = class extends ATNState {
3540
+ static {
3541
+ __name(this, "RuleStopState");
3542
+ }
3543
+ static stateType = ATNState.RULE_STOP;
3544
+ };
3545
+
3546
+ // src/atn/ATNConfigSet.ts
3547
+ var KeyTypeEqualityComparer = class _KeyTypeEqualityComparer {
3548
+ static {
3549
+ __name(this, "KeyTypeEqualityComparer");
3550
+ }
3551
+ static instance = new _KeyTypeEqualityComparer();
3552
+ hashCode(config) {
3553
+ let hashCode = 7;
3554
+ hashCode = 31 * hashCode + config.state.stateNumber;
3555
+ hashCode = 31 * hashCode + config.alt;
3556
+ hashCode = 31 * hashCode + config.semanticContext.hashCode();
3557
+ return hashCode;
3558
+ }
3559
+ equals(a, b) {
3560
+ if (a === b) {
3561
+ return true;
3562
+ }
3563
+ return a.state.stateNumber === b.state.stateNumber && a.alt === b.alt && a.semanticContext.equals(b.semanticContext);
3564
+ }
3565
+ };
3566
+ var ATNConfigSet = class {
3567
+ static {
3568
+ __name(this, "ATNConfigSet");
3569
+ }
3570
+ /**
3571
+ * The reason that we need this is because we don't want the hash map to use
3572
+ * the standard hash code and equals. We need all configurations with the
3573
+ * same
3574
+ * `(s,i,_,semctx)` to be equal. Unfortunately, this key effectively
3575
+ * doubles
3576
+ * the number of objects associated with ATNConfigs. The other solution is
3577
+ * to
3578
+ * use a hash table that lets us specify the equals/hashCode operation.
3579
+ * All configs but hashed by (s, i, _, pi) not including context. Wiped out
3580
+ * when we go readonly as this set becomes a DFA state
3581
+ */
3582
+ configLookup = new HashSet(KeyTypeEqualityComparer.instance);
3583
+ // Track the elements as they are added to the set; supports get(i).
3584
+ configs = [];
3585
+ uniqueAlt = 0;
3586
+ /**
3587
+ * Used in parser and lexer. In lexer, it indicates we hit a pred
3588
+ * while computing a closure operation. Don't make a DFA state from this
3589
+ */
3590
+ hasSemanticContext = false;
3591
+ dipsIntoOuterContext = false;
3592
+ /**
3593
+ * Indicates that this configuration set is part of a full context
3594
+ * LL prediction. It will be used to determine how to merge $. With SLL
3595
+ * it's a wildcard whereas it is not for LL context merge
3596
+ */
3597
+ fullCtx = false;
3598
+ /**
3599
+ * Indicates that the set of configurations is read-only. Do not
3600
+ * allow any code to manipulate the set; DFA states will point at
3601
+ * the sets and they must not change. This does not protect the other
3602
+ * fields; in particular, conflictingAlts is set after
3603
+ * we've made this readonly
3604
+ */
3605
+ readOnly = false;
3606
+ conflictingAlts = null;
3607
+ /**
3608
+ * Tracks the first config that has a rule stop state. Avoids frequent linear search for that, when adding
3609
+ * a DFA state in the lexer ATN simulator.
3610
+ */
3611
+ firstStopState;
3612
+ #cachedHashCode = -1;
3613
+ constructor(fullCtxOrOldSet) {
3614
+ if (fullCtxOrOldSet !== void 0) {
3615
+ if (typeof fullCtxOrOldSet === "boolean") {
3616
+ this.fullCtx = fullCtxOrOldSet ?? true;
3617
+ } else {
3618
+ const old = fullCtxOrOldSet;
3619
+ this.addAll(old.configs);
3620
+ this.uniqueAlt = old.uniqueAlt;
3621
+ this.conflictingAlts = old.conflictingAlts;
3622
+ this.hasSemanticContext = old.hasSemanticContext;
3623
+ this.dipsIntoOuterContext = old.dipsIntoOuterContext;
3624
+ }
3625
+ }
3626
+ }
3627
+ [Symbol.iterator]() {
3628
+ return this.configs[Symbol.iterator]();
3629
+ }
3630
+ /**
3631
+ * Adding a new config means merging contexts with existing configs for
3632
+ * `(s, i, pi, _)`, where `s` is the {@link ATNConfig.state}, `i` is the {@link ATNConfig.alt}, and
3633
+ * `pi` is the {@link ATNConfig.semanticContext}. We use `(s,i,pi)` as key.
3634
+ *
3635
+ * This method updates {@link dipsIntoOuterContext} and
3636
+ * {@link hasSemanticContext} when necessary.
3637
+ */
3638
+ add(config, mergeCache = null) {
3639
+ if (this.readOnly) {
3640
+ throw new Error("This set is readonly");
3641
+ }
3642
+ if (!this.firstStopState && config.state.constructor.stateType === ATNState.RULE_STOP) {
3643
+ this.firstStopState = config;
3644
+ }
3645
+ this.hasSemanticContext ||= config.semanticContext !== SemanticContext.NONE;
3646
+ this.dipsIntoOuterContext ||= config.reachesIntoOuterContext;
3647
+ const existing = this.configLookup.getOrAdd(config);
3648
+ if (existing === config) {
3649
+ this.#cachedHashCode = -1;
3650
+ this.configs.push(config);
3651
+ return;
3652
+ }
3653
+ const rootIsWildcard = !this.fullCtx;
3654
+ const merged = merge(existing.context, config.context, rootIsWildcard, mergeCache);
3655
+ existing.reachesIntoOuterContext ||= config.reachesIntoOuterContext;
3656
+ existing.precedenceFilterSuppressed ||= config.precedenceFilterSuppressed;
3657
+ existing.context = merged;
3658
+ }
3659
+ /** Return a List holding list of configs */
3660
+ get elements() {
3661
+ return this.configs;
3662
+ }
3663
+ /**
3664
+ * Gets the complete set of represented alternatives for the configuration set.
3665
+ *
3666
+ * @returns the set of represented alternatives in this configuration set
3667
+ */
3668
+ getAlts() {
3669
+ const alts = new BitSet();
3670
+ for (const config of this.configs) {
3671
+ alts.set(config.alt);
3672
+ }
3673
+ return alts;
3674
+ }
3675
+ getPredicates() {
3676
+ const preds = [];
3677
+ for (const config of this.configs) {
3678
+ if (config.semanticContext !== SemanticContext.NONE) {
3679
+ preds.push(config.semanticContext);
3680
+ }
3681
+ }
3682
+ return preds;
3683
+ }
3684
+ getStates() {
3685
+ const states = new HashSet();
3686
+ for (const config of this.configs) {
3687
+ states.add(config.state);
3688
+ }
3689
+ return states;
3690
+ }
3691
+ optimizeConfigs(interpreter) {
3692
+ if (this.readOnly) {
3693
+ throw new Error("This set is readonly");
3694
+ }
3695
+ if (this.configLookup.size === 0) {
3696
+ return;
3697
+ }
3698
+ for (const config of this.configs) {
3699
+ config.context = interpreter.getCachedContext(config.context);
3700
+ }
3701
+ }
3702
+ addAll(coll) {
3703
+ for (const config of coll) {
3704
+ this.add(config);
3705
+ }
3706
+ return false;
3707
+ }
3708
+ equals(other) {
3709
+ if (this === other) {
3710
+ return true;
3711
+ }
3712
+ if (this.fullCtx === other.fullCtx && this.uniqueAlt === other.uniqueAlt && this.conflictingAlts === other.conflictingAlts && this.hasSemanticContext === other.hasSemanticContext && this.dipsIntoOuterContext === other.dipsIntoOuterContext && equalArrays(this.configs, other.configs)) {
3713
+ return true;
3714
+ }
3715
+ return false;
3716
+ }
3717
+ hashCode() {
3718
+ if (this.#cachedHashCode === -1) {
3719
+ this.#cachedHashCode = this.computeHashCode();
3720
+ }
3721
+ return this.#cachedHashCode;
3722
+ }
3723
+ get length() {
3724
+ return this.configs.length;
3725
+ }
3726
+ isEmpty() {
3727
+ return this.configs.length === 0;
3728
+ }
3729
+ contains(item) {
3730
+ if (this.configLookup === null) {
3731
+ throw new Error("This method is not implemented for readonly sets.");
3732
+ }
3733
+ return this.configLookup.contains(item);
3734
+ }
3735
+ containsFast(item) {
3736
+ if (this.configLookup === null) {
3737
+ throw new Error("This method is not implemented for readonly sets.");
3738
+ }
3739
+ return this.configLookup.contains(item);
3740
+ }
3741
+ clear() {
3742
+ if (this.readOnly) {
3743
+ throw new Error("This set is readonly");
3744
+ }
3745
+ this.configs = [];
3746
+ this.#cachedHashCode = -1;
3747
+ this.configLookup = new HashSet(KeyTypeEqualityComparer.instance);
3748
+ }
3749
+ setReadonly(readOnly) {
3750
+ this.readOnly = readOnly;
3751
+ if (readOnly) {
3752
+ this.configLookup = null;
3753
+ }
3754
+ }
3755
+ toString() {
3756
+ return arrayToString(this.configs) + (this.hasSemanticContext ? ",hasSemanticContext=" + this.hasSemanticContext : "") + (this.uniqueAlt !== ATN.INVALID_ALT_NUMBER ? ",uniqueAlt=" + this.uniqueAlt : "") + (this.conflictingAlts !== null ? ",conflictingAlts=" + this.conflictingAlts : "") + (this.dipsIntoOuterContext ? ",dipsIntoOuterContext" : "");
3757
+ }
3758
+ computeHashCode() {
3759
+ let hash = MurmurHash.initialize();
3760
+ this.configs.forEach((config) => {
3761
+ hash = MurmurHash.update(hash, config.hashCode());
3762
+ });
3763
+ hash = MurmurHash.finish(hash, this.configs.length);
3764
+ return hash;
3765
+ }
3766
+ };
3767
+
3768
+ // src/atn/PredictionMode.ts
3769
+ var SubsetEqualityComparer = class _SubsetEqualityComparer {
3770
+ static {
3771
+ __name(this, "SubsetEqualityComparer");
3772
+ }
3773
+ static instance = new _SubsetEqualityComparer();
3774
+ hashCode(config) {
3775
+ let hashCode = MurmurHash.initialize(7);
3776
+ hashCode = MurmurHash.update(hashCode, config.state.stateNumber);
3777
+ hashCode = MurmurHash.updateFromComparable(hashCode, config.context);
3778
+ hashCode = MurmurHash.finish(hashCode, 2);
3779
+ return hashCode;
3780
+ }
3781
+ equals(a, b) {
3782
+ return a.state.stateNumber === b.state.stateNumber && (a.context?.equals(b.context) ?? true);
3783
+ }
3784
+ };
3785
+ var PredictionMode = class _PredictionMode {
3786
+ static {
3787
+ __name(this, "PredictionMode");
3788
+ }
3789
+ /**
3790
+ * The SLL(*) prediction mode. This prediction mode ignores the current
3791
+ * parser context when making predictions. This is the fastest prediction
3792
+ * mode, and provides correct results for many grammars. This prediction
3793
+ * mode is more powerful than the prediction mode provided by ANTLR 3, but
3794
+ * may result in syntax errors for grammar and input combinations which are
3795
+ * not SLL.
3796
+ *
3797
+ *
3798
+ * When using this prediction mode, the parser will either return a correct
3799
+ * parse tree (i.e. the same parse tree that would be returned with the
3800
+ * {@link LL} prediction mode), or it will report a syntax error. If a
3801
+ * syntax error is encountered when using the {@link SLL} prediction mode,
3802
+ * it may be due to either an actual syntax error in the input or indicate
3803
+ * that the particular combination of grammar and input requires the more
3804
+ * powerful {@link LL} prediction abilities to complete successfully.
3805
+ *
3806
+ *
3807
+ * This prediction mode does not provide any guarantees for prediction
3808
+ * behavior for syntactically-incorrect inputs.
3809
+ */
3810
+ static SLL = 0;
3811
+ /**
3812
+ * The LL(*) prediction mode. This prediction mode allows the current parser
3813
+ * context to be used for resolving SLL conflicts that occur during
3814
+ * prediction. This is the fastest prediction mode that guarantees correct
3815
+ * parse results for all combinations of grammars with syntactically correct
3816
+ * inputs.
3817
+ *
3818
+ *
3819
+ * When using this prediction mode, the parser will make correct decisions
3820
+ * for all syntactically-correct grammar and input combinations. However, in
3821
+ * cases where the grammar is truly ambiguous this prediction mode might not
3822
+ * report a precise answer for *exactly which* alternatives are
3823
+ * ambiguous.
3824
+ *
3825
+ *
3826
+ * This prediction mode does not provide any guarantees for prediction
3827
+ * behavior for syntactically-incorrect inputs.
3828
+ */
3829
+ static LL = 1;
3830
+ /**
3831
+ *
3832
+ * The LL(*) prediction mode with exact ambiguity detection. In addition to
3833
+ * the correctness guarantees provided by the {@link LL} prediction mode,
3834
+ * this prediction mode instructs the prediction algorithm to determine the
3835
+ * complete and exact set of ambiguous alternatives for every ambiguous
3836
+ * decision encountered while parsing.
3837
+ *
3838
+ *
3839
+ * This prediction mode may be used for diagnosing ambiguities during
3840
+ * grammar development. Due to the performance overhead of calculating sets
3841
+ * of ambiguous alternatives, this prediction mode should be avoided when
3842
+ * the exact results are not necessary.
3843
+ *
3844
+ *
3845
+ * This prediction mode does not provide any guarantees for prediction
3846
+ * behavior for syntactically-incorrect inputs.
3847
+ */
3848
+ static LL_EXACT_AMBIG_DETECTION = 2;
3849
+ /**
3850
+ *
3851
+ *Computes the SLL prediction termination condition.
3852
+ *
3853
+ *
3854
+ *This method computes the SLL prediction termination condition for both of
3855
+ *the following cases.
3856
+ *
3857
+ * - The usual SLL+LL fallback upon SLL conflict
3858
+ * - Pure SLL without LL fallback
3859
+ *
3860
+ ***COMBINED SLL+LL PARSING**
3861
+ *
3862
+ *When LL-fallback is enabled upon SLL conflict, correct predictions are
3863
+ *ensured regardless of how the termination condition is computed by this
3864
+ *method. Due to the substantially higher cost of LL prediction, the
3865
+ *prediction should only fall back to LL when the additional lookahead
3866
+ *cannot lead to a unique SLL prediction.
3867
+ *
3868
+ *Assuming combined SLL+LL parsing, an SLL configuration set with only
3869
+ *conflicting subsets should fall back to full LL, even if the
3870
+ *configuration sets don't resolve to the same alternative (e.g.
3871
+ *`{1,2`} and `{3,4`}. If there is at least one non-conflicting
3872
+ *configuration, SLL could continue with the hopes that more lookahead will
3873
+ *resolve via one of those non-conflicting configurations.
3874
+ *
3875
+ *Here's the prediction termination rule them: SLL (for SLL+LL parsing)
3876
+ *stops when it sees only conflicting configuration subsets. In contrast,
3877
+ *full LL keeps going when there is uncertainty.
3878
+ *
3879
+ ***HEURISTIC**
3880
+ *
3881
+ *As a heuristic, we stop prediction when we see any conflicting subset
3882
+ *unless we see a state that only has one alternative associated with it.
3883
+ *The single-alt-state thing lets prediction continue upon rules like
3884
+ *(otherwise, it would admit defeat too soon):
3885
+ *
3886
+ *`[12|1|[], 6|2|[], 12|2|[]]. s : (ID | ID ID?) ';' ;`
3887
+ *
3888
+ *When the ATN simulation reaches the state before `';'`, it has a
3889
+ *DFA state that looks like: `[12|1|[], 6|2|[], 12|2|[]]`. Naturally
3890
+ *`12|1|[]` and `12|2|[]` conflict, but we cannot stop
3891
+ *processing this node because alternative to has another way to continue,
3892
+ *via `[6|2|[]]`.
3893
+ *
3894
+ *It also let's us continue for this rule:
3895
+ *
3896
+ *`[1|1|[], 1|2|[], 8|3|[]] a : A | A | A B ;`
3897
+ *
3898
+ *After matching input A, we reach the stop state for rule A, state 1.
3899
+ *State 8 is the state right before B. Clearly alternatives 1 and 2
3900
+ *conflict and no amount of further lookahead will separate the two.
3901
+ *However, alternative 3 will be able to continue and so we do not stop
3902
+ *working on this state. In the previous example, we're concerned with
3903
+ *states associated with the conflicting alternatives. Here alt 3 is not
3904
+ *associated with the conflicting configs, but since we can continue
3905
+ *looking for input reasonably, don't declare the state done.
3906
+ *
3907
+ ***PURE SLL PARSING**
3908
+ *
3909
+ *To handle pure SLL parsing, all we have to do is make sure that we
3910
+ *combine stack contexts for configurations that differ only by semantic
3911
+ *predicate. From there, we can do the usual SLL termination heuristic.
3912
+ *
3913
+ ***PREDICATES IN SLL+LL PARSING**
3914
+ *
3915
+ *SLL decisions don't evaluate predicates until after they reach DFA stop
3916
+ *states because they need to create the DFA cache that works in all
3917
+ *semantic situations. In contrast, full LL evaluates predicates collected
3918
+ *during start state computation so it can ignore predicates thereafter.
3919
+ *This means that SLL termination detection can totally ignore semantic
3920
+ *predicates.
3921
+ *
3922
+ *Implementation-wise, {@link ATNConfigSet} combines stack contexts but not
3923
+ *semantic predicate contexts so we might see two configurations like the
3924
+ *following.
3925
+ *
3926
+ *`(s, 1, x, {`), (s, 1, x', {p})}
3927
+ *
3928
+ *Before testing these configurations against others, we have to merge
3929
+ *`x` and `x'` (without modifying the existing configurations).
3930
+ *For example, we test `(x+x')==x''` when looking for conflicts in
3931
+ *the following configurations.
3932
+ *
3933
+ *`(s, 1, x, {`), (s, 1, x', {p}), (s, 2, x'', {})}
3934
+ *
3935
+ *If the configuration set has predicates (as indicated by
3936
+ *{@link ATNConfigSet//hasSemanticContext}), this algorithm makes a copy of
3937
+ *the configurations to strip out all of the predicates so that a standard
3938
+ *{@link ATNConfigSet} will merge everything ignoring predicates.
3939
+ */
3940
+ static hasSLLConflictTerminatingPrediction(mode, configs) {
3941
+ if (_PredictionMode.allConfigsInRuleStopStates(configs)) {
3942
+ return true;
3943
+ }
3944
+ if (mode === _PredictionMode.SLL) {
3945
+ if (configs.hasSemanticContext) {
3946
+ const dup = new ATNConfigSet();
3947
+ for (let c of configs) {
3948
+ c = ATNConfig.duplicate(c, SemanticContext.NONE);
3949
+ dup.add(c);
3950
+ }
3951
+ configs = dup;
3952
+ }
3953
+ }
3954
+ const altSets = _PredictionMode.getConflictingAltSubsets(configs);
3955
+ return _PredictionMode.hasConflictingAltSet(altSets) && !_PredictionMode.hasStateAssociatedWithOneAlt(configs);
3956
+ }
3957
+ /**
3958
+ * Checks if any configuration in `configs` is in a
3959
+ * {@link RuleStopState}. Configurations meeting this condition have reached
3960
+ * the end of the decision rule (local context) or end of start rule (full
3961
+ * context).
3962
+ *
3963
+ * @param configs the configuration set to test
3964
+ * @returns `true` if any configuration in `configs` is in a
3965
+ * {@link RuleStopState}, otherwise `false`
3966
+ */
3967
+ static hasConfigInRuleStopState(configs) {
3968
+ for (const c of configs) {
3969
+ if (c.state instanceof RuleStopState) {
3970
+ return true;
3971
+ }
3972
+ }
3973
+ return false;
3974
+ }
3975
+ /**
3976
+ * Checks if all configurations in `configs` are in a
3977
+ * {@link RuleStopState}. Configurations meeting this condition have reached
3978
+ * the end of the decision rule (local context) or end of start rule (full
3979
+ * context).
3980
+ *
3981
+ * @param configs the configuration set to test
3982
+ * @returns `true` if all configurations in `configs` are in a
3983
+ * {@link RuleStopState}, otherwise `false`
3984
+ */
3985
+ static allConfigsInRuleStopStates(configs) {
3986
+ for (const c of configs) {
3987
+ if (!(c.state instanceof RuleStopState)) {
3988
+ return false;
3989
+ }
3990
+ }
3991
+ return true;
3992
+ }
3993
+ /**
3994
+ *
3995
+ * Full LL prediction termination.
3996
+ *
3997
+ * Can we stop looking ahead during ATN simulation or is there some
3998
+ * uncertainty as to which alternative we will ultimately pick, after
3999
+ * consuming more input? Even if there are partial conflicts, we might know
4000
+ * that everything is going to resolve to the same minimum alternative. That
4001
+ * means we can stop since no more lookahead will change that fact. On the
4002
+ * other hand, there might be multiple conflicts that resolve to different
4003
+ * minimums. That means we need more look ahead to decide which of those
4004
+ * alternatives we should predict.
4005
+ *
4006
+ * The basic idea is to split the set of configurations `C`, into
4007
+ * conflicting subsets `(s, _, ctx, _)` and singleton subsets with
4008
+ * non-conflicting configurations. Two configurations conflict if they have
4009
+ * identical {@link ATNConfig.state} and {@link ATNConfig.context} values
4010
+ * but different {@link ATNConfig.alt} value, e.g. `(s, i, ctx, _)`
4011
+ * and `(s, j, ctx, _)` for `i!=j`.
4012
+ *
4013
+ * Reduce these configuration subsets to the set of possible alternatives.
4014
+ * You can compute the alternative subsets in one pass as follows:
4015
+ *
4016
+ * `A_s,ctx = {i | (s, i, ctx, _)`} for each configuration in
4017
+ * `C` holding `s` and `ctx` fixed.
4018
+ *
4019
+ * Or in pseudo-code, for each configuration `c` in `C`:
4020
+ *
4021
+ * ```
4022
+ * map[c] U= c.{@link ATNConfig.alt alt} // map hash/equals uses s and x, not
4023
+ * alt and not pred
4024
+ * ```
4025
+ *
4026
+ * The values in `map` are the set of `A_s,ctx` sets.
4027
+ *
4028
+ * If `|A_s,ctx|=1` then there is no conflict associated with
4029
+ * `s` and `ctx`.
4030
+ *
4031
+ * Reduce the subsets to singletons by choosing a minimum of each subset. If
4032
+ * the union of these alternative subsets is a singleton, then no amount of
4033
+ * more lookahead will help us. We will always pick that alternative. If,
4034
+ * however, there is more than one alternative, then we are uncertain which
4035
+ * alternative to predict and must continue looking for resolution. We may
4036
+ * or may not discover an ambiguity in the future, even if there are no
4037
+ * conflicting subsets this round.
4038
+ *
4039
+ * The biggest sin is to terminate early because it means we've made a
4040
+ * decision but were uncertain as to the eventual outcome. We haven't used
4041
+ * enough lookahead. On the other hand, announcing a conflict too late is no
4042
+ * big deal; you will still have the conflict. It's just inefficient. It
4043
+ * might even look until the end of file.
4044
+ *
4045
+ * No special consideration for semantic predicates is required because
4046
+ * predicates are evaluated on-the-fly for full LL prediction, ensuring that
4047
+ * no configuration contains a semantic context during the termination
4048
+ * check.
4049
+ *
4050
+ * **CONFLICTING CONFIGS**
4051
+ *
4052
+ * Two configurations `(s, i, x)` and `(s, j, x')`, conflict when `i!=j` but `x=x'`. Because we merge all
4053
+ * `(s, i, _)` configurations together, that means that there are at most `n` configurations associated with state
4054
+ * `s` for `n` possible alternatives in the decision. The merged stacks complicate the comparison of configuration
4055
+ * contexts `x` and `x'`. Sam checks to see if one is a subset of the other by calling merge and checking to see
4056
+ * if the merged result is either `x` or `x'`. If the `x` associated with lowest alternative `i` is the superset,
4057
+ * then `i` is the only possible prediction since the others resolve to `min(i)` as well. However, if `x` is
4058
+ * associated with `j>i` then at least one stack configuration for `j` is not in conflict with alternative `i`.
4059
+ * The algorithm should keep going, looking for more lookahead due to the uncertainty.
4060
+ *
4061
+ * For simplicity, I'm doing a equality check between `x` and `x'` that lets the algorithm continue to consume
4062
+ * lookahead longer than necessary. The reason I like the equality is of course the simplicity but also because
4063
+ * that is the test you need to detect the alternatives that are actually in conflict.
4064
+ *
4065
+ * **CONTINUE/STOP RULE**
4066
+ *
4067
+ * Continue if union of resolved alternative sets from non-conflicting and conflicting alternative subsets has more
4068
+ * than one alternative. We are uncertain about which alternative to predict.
4069
+ *
4070
+ * The complete set of alternatives, `[i for (_,i,_)]`, tells us which alternatives are still in the running for
4071
+ * the amount of input we've consumed at this point. The conflicting sets let us to strip away configurations that
4072
+ * won't lead to more states because we resolve conflicts to the configuration with a minimum alternate for the
4073
+ * conflicting set.
4074
+ *
4075
+ * **CASES**
4076
+ *
4077
+ * - no conflicts and more than 1 alternative in set => continue
4078
+ * - `(s, 1, x)`, `(s, 2, x)`, `(s, 3, z)`, `(s', 1, y)`, `(s', 2, y)` yields non-conflicting set `{3`} U
4079
+ * conflicting sets `min({1,2`)} U `min({1,2`)} = `{1,3`} => continue
4080
+ * - `(s, 1, x)`, `(s, 2, x)`, `(s', 1, y)`, `(s', 2, y)`, `(s'', 1, z)` yields non-conflicting set `{1`} U
4081
+ * conflicting sets `min({1,2`)} U `min({1,2`)} = `{1`} => stop and predict 1
4082
+ * - `(s, 1, x)`, `(s, 2, x)`, `(s', 1, y)`, `(s', 2, y)` yields conflicting, reduced sets `{1`} U
4083
+ * `{1`} = `{1`} => stop and predict 1, can announce ambiguity `{1,2`}
4084
+ * - `(s, 1, x)`, `(s, 2, x)`, `(s', 2, y)`, `(s', 3, y)` yields conflicting, reduced sets `{1`} U
4085
+ * `{2`} = `{1,2`} => continue
4086
+ * - `(s, 1, x)`, `(s, 2, x)`, `(s', 3, y)`, `(s', 4, y)` yields conflicting, reduced sets `{1`} U
4087
+ * `{3`} = `{1,3`} => continue
4088
+ *
4089
+ * **EXACT AMBIGUITY DETECTION**
4090
+ *
4091
+ *If all states report the same conflicting set of alternatives, then we
4092
+ *know we have the exact ambiguity set.
4093
+ *
4094
+ * `|A_*i*|>1` and `A_*i* = A_*j*` for all *i*, *j*.
4095
+ *
4096
+ * In other words, we continue examining lookahead until all `A_i` have more than one alternative and all `A_i`
4097
+ * are the same. If `A={{1,2`, {1,3}}}, then regular LL prediction would terminate because the resolved set
4098
+ * is `{1`}. To determine what the real ambiguity is, we have to know whether the ambiguity is between one and
4099
+ * two or one and three so we keep going. We can only stop prediction when we need exact ambiguity detection when
4100
+ * the sets look like `A={{1,2`}} or `{{1,2`,{1,2}}}, etc...
4101
+ */
4102
+ static resolvesToJustOneViableAlt(altSets) {
4103
+ return _PredictionMode.getSingleViableAlt(altSets);
4104
+ }
4105
+ /**
4106
+ * Determines if every alternative subset in `altSets` contains more
4107
+ * than one alternative.
4108
+ *
4109
+ * @param altSets a collection of alternative subsets
4110
+ * @returns `true` if every {@link BitSet} in `altSets` has
4111
+ * {@link BitSet//cardinality cardinality} > 1, otherwise `false`
4112
+ */
4113
+ static allSubsetsConflict(altSets) {
4114
+ return !_PredictionMode.hasNonConflictingAltSet(altSets);
4115
+ }
4116
+ /**
4117
+ * Determines if any single alternative subset in `altSets` contains
4118
+ * exactly one alternative.
4119
+ *
4120
+ * @param altSets a collection of alternative subsets
4121
+ * @returns `true` if `altSets` contains a {@link BitSet} with
4122
+ * {@link BitSet//cardinality cardinality} 1, otherwise `false`
4123
+ */
4124
+ static hasNonConflictingAltSet(altSets) {
4125
+ for (const alts of altSets) {
4126
+ if (alts.length === 1) {
4127
+ return true;
4128
+ }
4129
+ }
4130
+ return false;
4131
+ }
4132
+ /**
4133
+ * Determines if any single alternative subset in `altSets` contains
4134
+ * more than one alternative.
4135
+ *
4136
+ * @param altSets a collection of alternative subsets
4137
+ * @returns `true` if `altSets` contains a {@link BitSet} with
4138
+ * {@link BitSet//cardinality cardinality} > 1, otherwise `false`
4139
+ */
4140
+ static hasConflictingAltSet(altSets) {
4141
+ for (const alts of altSets) {
4142
+ if (alts.length > 1) {
4143
+ return true;
4144
+ }
4145
+ }
4146
+ return false;
4147
+ }
4148
+ /**
4149
+ * Determines if every alternative subset in `altSets` is equivalent.
4150
+ *
4151
+ * @param altSets a collection of alternative subsets
4152
+ * @returns `true` if every member of `altSets` is equal to the
4153
+ * others, otherwise `false`
4154
+ */
4155
+ static allSubsetsEqual(altSets) {
4156
+ let first = null;
4157
+ for (const alts of altSets) {
4158
+ if (first === null) {
4159
+ first = alts;
4160
+ } else if (alts !== first) {
4161
+ return false;
4162
+ }
4163
+ }
4164
+ return true;
4165
+ }
4166
+ /**
4167
+ * Returns the unique alternative predicted by all alternative subsets in
4168
+ * `altSets`. If no such alternative exists, this method returns
4169
+ * {@link ATN.INVALID_ALT_NUMBER}.
4170
+ *
4171
+ * @param altSets a collection of alternative subsets
4172
+ */
4173
+ static getUniqueAlt(altSets) {
4174
+ const all = _PredictionMode.getAlts(altSets);
4175
+ if (all.length === 1) {
4176
+ return all.nextSetBit(0);
4177
+ } else {
4178
+ return ATN.INVALID_ALT_NUMBER;
4179
+ }
4180
+ }
4181
+ /**
4182
+ * Gets the complete set of represented alternatives for a collection of
4183
+ * alternative subsets. This method returns the union of each {@link BitSet}
4184
+ * in `altSets`.
4185
+ *
4186
+ * @param altSets a collection of alternative subsets
4187
+ * @returns the set of represented alternatives in `altSets`
4188
+ */
4189
+ static getAlts(altSets) {
4190
+ const all = new BitSet();
4191
+ altSets.forEach((alts) => {
4192
+ all.or(alts);
4193
+ });
4194
+ return all;
4195
+ }
4196
+ /**
4197
+ * This function gets the conflicting alt subsets from a configuration set.
4198
+ * For each configuration `c` in `configs`:
4199
+ *
4200
+ * ```
4201
+ * map[c] U= c.{@link ATNConfig.alt alt} // map hash/equals uses s and x, not
4202
+ * alt and not pred
4203
+ * ```
4204
+ */
4205
+ static getConflictingAltSubsets(configs) {
4206
+ const configToAlts = new HashMap(SubsetEqualityComparer.instance);
4207
+ for (const cfg of configs) {
4208
+ let alts = configToAlts.get(cfg);
4209
+ if (!alts) {
4210
+ alts = new BitSet();
4211
+ configToAlts.set(cfg, alts);
4212
+ }
4213
+ alts.set(cfg.alt);
4214
+ }
4215
+ return Array.from(configToAlts.values());
4216
+ }
4217
+ /**
4218
+ * Get a map from state to alt subset from a configuration set. For each configuration `c` in `configs`:
4219
+ *
4220
+ * ```
4221
+ * map[c.state] = c.alt
4222
+ * ```
4223
+ */
4224
+ static getStateToAltMap(configs) {
4225
+ const m2 = new HashMap(ObjectEqualityComparator.instance);
4226
+ for (const c of configs) {
4227
+ let alts = m2.get(c.state);
4228
+ if (!alts) {
4229
+ alts = new BitSet();
4230
+ m2.set(c.state, alts);
4231
+ }
4232
+ alts.set(c.alt);
4233
+ }
4234
+ return m2;
4235
+ }
4236
+ static hasStateAssociatedWithOneAlt(configs) {
4237
+ const counts = {};
4238
+ for (const c of configs) {
4239
+ const stateNumber = c.state.stateNumber;
4240
+ if (!counts[stateNumber]) {
4241
+ counts[stateNumber] = 0;
4242
+ }
4243
+ counts[stateNumber]++;
4244
+ }
4245
+ return Object.values(counts).some((count) => {
4246
+ return count === 1;
4247
+ });
4248
+ }
4249
+ static getSingleViableAlt(altSets) {
4250
+ let result = null;
4251
+ for (const alts of altSets) {
4252
+ const minAlt = alts.nextSetBit(0);
4253
+ if (result === null) {
4254
+ result = minAlt;
4255
+ } else if (result !== minAlt) {
4256
+ return ATN.INVALID_ALT_NUMBER;
4257
+ }
4258
+ }
4259
+ return result ?? 0;
4260
+ }
4261
+ };
4262
+ export {
4263
+ PredictionMode
4264
+ };