expressir 0.2.4 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (331) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/release.yml +4 -3
  3. data/Rakefile +0 -9
  4. data/expressir.gemspec +3 -1
  5. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/CMakeLists.txt +118 -0
  6. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/antlr4cpp-vs2013.vcxproj +637 -0
  7. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/antlr4cpp-vs2013.vcxproj.filters +984 -0
  8. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/antlr4cpp-vs2015.vcxproj +652 -0
  9. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/antlr4cpp-vs2015.vcxproj.filters +990 -0
  10. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/antlr4cpp-vs2017.vcxproj +652 -0
  11. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/antlr4cpp-vs2017.vcxproj.filters +990 -0
  12. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/antlr4cpp-vs2019.vcxproj +652 -0
  13. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/antlr4cpp-vs2019.vcxproj.filters +990 -0
  14. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/antlrcpp-ios/Info.plist +26 -0
  15. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/antlrcpp-ios/antlrcpp_ios.h +17 -0
  16. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/antlrcpp.xcodeproj/project.pbxproj +3024 -0
  17. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/antlrcpp.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  18. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/antlrcpp.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
  19. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/antlrcpp.xcodeproj/xcshareddata/xcschemes/antlr4.xcscheme +76 -0
  20. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/antlrcpp.xcodeproj/xcshareddata/xcschemes/antlr4_ios.xcscheme +80 -0
  21. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/antlrcpp.xcodeproj/xcshareddata/xcschemes/antlr4_static.xcscheme +80 -0
  22. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/ANTLRErrorListener.cpp +10 -0
  23. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/ANTLRErrorListener.h +167 -0
  24. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/ANTLRErrorStrategy.cpp +10 -0
  25. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/ANTLRErrorStrategy.h +121 -0
  26. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/ANTLRFileStream.cpp +34 -0
  27. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/ANTLRFileStream.h +27 -0
  28. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/ANTLRInputStream.cpp +155 -0
  29. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/ANTLRInputStream.h +69 -0
  30. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/BailErrorStrategy.cpp +61 -0
  31. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/BailErrorStrategy.h +59 -0
  32. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/BaseErrorListener.cpp +25 -0
  33. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/BaseErrorListener.h +36 -0
  34. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/BufferedTokenStream.cpp +414 -0
  35. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/BufferedTokenStream.h +200 -0
  36. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/CharStream.cpp +11 -0
  37. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/CharStream.h +37 -0
  38. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/CommonToken.cpp +195 -0
  39. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/CommonToken.h +158 -0
  40. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/CommonTokenFactory.cpp +39 -0
  41. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/CommonTokenFactory.h +74 -0
  42. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/CommonTokenStream.cpp +78 -0
  43. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/CommonTokenStream.h +79 -0
  44. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/ConsoleErrorListener.cpp +15 -0
  45. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/ConsoleErrorListener.h +35 -0
  46. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/DefaultErrorStrategy.cpp +333 -0
  47. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/DefaultErrorStrategy.h +466 -0
  48. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/DiagnosticErrorListener.cpp +84 -0
  49. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/DiagnosticErrorListener.h +80 -0
  50. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/Exceptions.cpp +64 -0
  51. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/Exceptions.h +99 -0
  52. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/FailedPredicateException.cpp +51 -0
  53. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/FailedPredicateException.h +32 -0
  54. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/InputMismatchException.cpp +18 -0
  55. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/InputMismatchException.h +24 -0
  56. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/IntStream.cpp +12 -0
  57. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/IntStream.h +218 -0
  58. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/InterpreterRuleContext.cpp +19 -0
  59. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/InterpreterRuleContext.h +45 -0
  60. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/Lexer.cpp +295 -0
  61. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/Lexer.h +196 -0
  62. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/LexerInterpreter.cpp +75 -0
  63. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/LexerInterpreter.h +52 -0
  64. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/LexerNoViableAltException.cpp +36 -0
  65. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/LexerNoViableAltException.h +31 -0
  66. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/ListTokenSource.cpp +92 -0
  67. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/ListTokenSource.h +88 -0
  68. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/NoViableAltException.cpp +46 -0
  69. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/NoViableAltException.h +42 -0
  70. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/Parser.cpp +648 -0
  71. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/Parser.h +467 -0
  72. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/ParserInterpreter.cpp +306 -0
  73. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/ParserInterpreter.h +179 -0
  74. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/ParserRuleContext.cpp +141 -0
  75. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/ParserRuleContext.h +147 -0
  76. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/ProxyErrorListener.cpp +53 -0
  77. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/ProxyErrorListener.h +38 -0
  78. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/RecognitionException.cpp +66 -0
  79. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/RecognitionException.h +98 -0
  80. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/Recognizer.cpp +167 -0
  81. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/Recognizer.h +164 -0
  82. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/RuleContext.cpp +143 -0
  83. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/RuleContext.h +137 -0
  84. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/RuleContextWithAltNum.cpp +27 -0
  85. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/RuleContextWithAltNum.h +32 -0
  86. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/RuntimeMetaData.cpp +53 -0
  87. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/RuntimeMetaData.h +155 -0
  88. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/Token.cpp +9 -0
  89. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/Token.h +92 -0
  90. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/TokenFactory.h +30 -0
  91. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/TokenSource.cpp +9 -0
  92. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/TokenSource.h +85 -0
  93. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/TokenStream.cpp +11 -0
  94. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/TokenStream.h +137 -0
  95. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/TokenStreamRewriter.cpp +425 -0
  96. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/TokenStreamRewriter.h +293 -0
  97. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/UnbufferedCharStream.cpp +211 -0
  98. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/UnbufferedCharStream.h +123 -0
  99. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/UnbufferedTokenStream.cpp +270 -0
  100. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/UnbufferedTokenStream.h +115 -0
  101. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/Vocabulary.cpp +104 -0
  102. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/Vocabulary.h +193 -0
  103. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/WritableToken.cpp +9 -0
  104. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/WritableToken.h +23 -0
  105. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/antlr4-common.h +137 -0
  106. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/antlr4-runtime.h +167 -0
  107. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATN.cpp +209 -0
  108. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATN.h +112 -0
  109. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNConfig.cpp +113 -0
  110. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNConfig.h +148 -0
  111. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNConfigSet.cpp +228 -0
  112. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNConfigSet.h +110 -0
  113. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNDeserializationOptions.cpp +64 -0
  114. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNDeserializationOptions.h +50 -0
  115. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNDeserializer.cpp +758 -0
  116. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNDeserializer.h +85 -0
  117. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNSerializer.cpp +621 -0
  118. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNSerializer.h +61 -0
  119. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNSimulator.cpp +63 -0
  120. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNSimulator.h +87 -0
  121. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNState.cpp +72 -0
  122. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNState.h +133 -0
  123. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNType.h +20 -0
  124. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/AbstractPredicateTransition.cpp +14 -0
  125. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/AbstractPredicateTransition.h +24 -0
  126. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ActionTransition.cpp +33 -0
  127. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ActionTransition.h +33 -0
  128. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/AmbiguityInfo.cpp +16 -0
  129. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/AmbiguityInfo.h +68 -0
  130. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ArrayPredictionContext.cpp +82 -0
  131. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ArrayPredictionContext.h +43 -0
  132. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/AtomTransition.cpp +31 -0
  133. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/AtomTransition.h +30 -0
  134. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/BasicBlockStartState.cpp +12 -0
  135. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/BasicBlockStartState.h +22 -0
  136. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/BasicState.cpp +12 -0
  137. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/BasicState.h +21 -0
  138. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/BlockEndState.cpp +15 -0
  139. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/BlockEndState.h +24 -0
  140. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/BlockStartState.cpp +9 -0
  141. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/BlockStartState.h +21 -0
  142. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ContextSensitivityInfo.cpp +14 -0
  143. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ContextSensitivityInfo.h +47 -0
  144. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/DecisionEventInfo.cpp +14 -0
  145. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/DecisionEventInfo.h +70 -0
  146. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/DecisionInfo.cpp +25 -0
  147. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/DecisionInfo.h +227 -0
  148. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/DecisionState.cpp +17 -0
  149. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/DecisionState.h +30 -0
  150. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/EmptyPredictionContext.cpp +35 -0
  151. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/EmptyPredictionContext.h +27 -0
  152. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/EpsilonTransition.cpp +35 -0
  153. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/EpsilonTransition.h +39 -0
  154. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ErrorInfo.cpp +15 -0
  155. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ErrorInfo.h +43 -0
  156. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LL1Analyzer.cpp +158 -0
  157. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LL1Analyzer.h +109 -0
  158. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerATNConfig.cpp +84 -0
  159. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerATNConfig.h +44 -0
  160. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerATNSimulator.cpp +628 -0
  161. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerATNSimulator.h +210 -0
  162. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerAction.cpp +9 -0
  163. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerAction.h +66 -0
  164. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerActionExecutor.cpp +107 -0
  165. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerActionExecutor.h +115 -0
  166. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerActionType.h +55 -0
  167. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerChannelAction.cpp +55 -0
  168. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerChannelAction.h +63 -0
  169. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerCustomAction.cpp +62 -0
  170. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerCustomAction.h +87 -0
  171. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerIndexedCustomAction.cpp +63 -0
  172. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerIndexedCustomAction.h +82 -0
  173. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerModeAction.cpp +56 -0
  174. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerModeAction.h +61 -0
  175. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerMoreAction.cpp +47 -0
  176. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerMoreAction.h +57 -0
  177. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerPopModeAction.cpp +47 -0
  178. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerPopModeAction.h +57 -0
  179. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerPushModeAction.cpp +56 -0
  180. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerPushModeAction.h +61 -0
  181. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerSkipAction.cpp +47 -0
  182. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerSkipAction.h +55 -0
  183. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerTypeAction.cpp +56 -0
  184. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerTypeAction.h +55 -0
  185. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LookaheadEventInfo.cpp +16 -0
  186. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LookaheadEventInfo.h +42 -0
  187. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LoopEndState.cpp +12 -0
  188. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LoopEndState.h +22 -0
  189. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/Makefile +67 -0
  190. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/NotSetTransition.cpp +27 -0
  191. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/NotSetTransition.h +25 -0
  192. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/OrderedATNConfigSet.cpp +12 -0
  193. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/OrderedATNConfigSet.h +20 -0
  194. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ParseInfo.cpp +102 -0
  195. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ParseInfo.h +102 -0
  196. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ParserATNSimulator.cpp +1366 -0
  197. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ParserATNSimulator.h +904 -0
  198. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PlusBlockStartState.cpp +12 -0
  199. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PlusBlockStartState.h +25 -0
  200. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PlusLoopbackState.cpp +12 -0
  201. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PlusLoopbackState.h +22 -0
  202. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PrecedencePredicateTransition.cpp +32 -0
  203. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PrecedencePredicateTransition.h +29 -0
  204. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredicateEvalInfo.cpp +17 -0
  205. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredicateEvalInfo.h +62 -0
  206. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredicateTransition.cpp +34 -0
  207. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredicateTransition.h +39 -0
  208. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredictionContext.cpp +662 -0
  209. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredictionContext.h +254 -0
  210. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredictionMode.cpp +201 -0
  211. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredictionMode.h +436 -0
  212. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ProfilingATNSimulator.cpp +179 -0
  213. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ProfilingATNSimulator.h +60 -0
  214. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/RangeTransition.cpp +30 -0
  215. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/RangeTransition.h +29 -0
  216. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/RuleStartState.cpp +16 -0
  217. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/RuleStartState.h +25 -0
  218. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/RuleStopState.cpp +12 -0
  219. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/RuleStopState.h +25 -0
  220. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/RuleTransition.cpp +37 -0
  221. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/RuleTransition.h +40 -0
  222. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/SemanticContext.cpp +377 -0
  223. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/SemanticContext.h +222 -0
  224. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/SetTransition.cpp +32 -0
  225. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/SetTransition.h +30 -0
  226. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/SingletonPredictionContext.cpp +81 -0
  227. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/SingletonPredictionContext.h +36 -0
  228. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/StarBlockStartState.cpp +12 -0
  229. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/StarBlockStartState.h +21 -0
  230. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/StarLoopEntryState.cpp +15 -0
  231. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/StarLoopEntryState.h +35 -0
  232. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/StarLoopbackState.cpp +19 -0
  233. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/StarLoopbackState.h +21 -0
  234. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/TokensStartState.cpp +12 -0
  235. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/TokensStartState.h +21 -0
  236. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/Transition.cpp +44 -0
  237. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/Transition.h +76 -0
  238. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/WildcardTransition.cpp +25 -0
  239. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/WildcardTransition.h +25 -0
  240. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/dfa/DFA.cpp +127 -0
  241. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/dfa/DFA.h +91 -0
  242. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/dfa/DFASerializer.cpp +67 -0
  243. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/dfa/DFASerializer.h +32 -0
  244. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/dfa/DFAState.cpp +100 -0
  245. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/dfa/DFAState.h +144 -0
  246. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/dfa/LexerDFASerializer.cpp +20 -0
  247. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/dfa/LexerDFASerializer.h +23 -0
  248. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/InterpreterDataReader.cpp +124 -0
  249. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/InterpreterDataReader.h +31 -0
  250. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/Interval.cpp +89 -0
  251. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/Interval.h +84 -0
  252. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/IntervalSet.cpp +521 -0
  253. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/IntervalSet.h +198 -0
  254. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/MurmurHash.cpp +134 -0
  255. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/MurmurHash.h +76 -0
  256. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/Predicate.cpp +4 -0
  257. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/Predicate.h +21 -0
  258. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/Any.cpp +13 -0
  259. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/Any.h +170 -0
  260. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/Arrays.cpp +43 -0
  261. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/Arrays.h +110 -0
  262. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/BitSet.h +76 -0
  263. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/CPPUtils.cpp +248 -0
  264. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/CPPUtils.h +78 -0
  265. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/Declarations.h +163 -0
  266. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/StringUtils.cpp +36 -0
  267. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/StringUtils.h +54 -0
  268. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/guid.cpp +303 -0
  269. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/guid.h +112 -0
  270. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/AbstractParseTreeVisitor.h +128 -0
  271. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ErrorNode.cpp +9 -0
  272. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ErrorNode.h +19 -0
  273. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ErrorNodeImpl.cpp +23 -0
  274. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ErrorNodeImpl.h +33 -0
  275. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/IterativeParseTreeWalker.cpp +71 -0
  276. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/IterativeParseTreeWalker.h +53 -0
  277. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ParseTree.cpp +15 -0
  278. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ParseTree.h +102 -0
  279. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ParseTreeListener.cpp +9 -0
  280. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ParseTreeListener.h +39 -0
  281. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ParseTreeProperty.h +50 -0
  282. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ParseTreeVisitor.cpp +9 -0
  283. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ParseTreeVisitor.h +57 -0
  284. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ParseTreeWalker.cpp +49 -0
  285. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ParseTreeWalker.h +31 -0
  286. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/TerminalNode.cpp +9 -0
  287. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/TerminalNode.h +32 -0
  288. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/TerminalNodeImpl.cpp +57 -0
  289. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/TerminalNodeImpl.h +33 -0
  290. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/Trees.cpp +241 -0
  291. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/Trees.h +78 -0
  292. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/pattern/Chunk.cpp +9 -0
  293. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/pattern/Chunk.h +44 -0
  294. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/pattern/ParseTreeMatch.cpp +69 -0
  295. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/pattern/ParseTreeMatch.h +132 -0
  296. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/pattern/ParseTreePattern.cpp +64 -0
  297. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/pattern/ParseTreePattern.h +105 -0
  298. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/pattern/ParseTreePatternMatcher.cpp +371 -0
  299. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/pattern/ParseTreePatternMatcher.h +185 -0
  300. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/pattern/RuleTagToken.cpp +77 -0
  301. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/pattern/RuleTagToken.h +117 -0
  302. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/pattern/TagChunk.cpp +39 -0
  303. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/pattern/TagChunk.h +86 -0
  304. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/pattern/TextChunk.cpp +28 -0
  305. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/pattern/TextChunk.h +51 -0
  306. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/pattern/TokenTagToken.cpp +36 -0
  307. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/pattern/TokenTagToken.h +80 -0
  308. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPath.cpp +154 -0
  309. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPath.h +86 -0
  310. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathElement.cpp +31 -0
  311. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathElement.h +40 -0
  312. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathLexer.cpp +173 -0
  313. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathLexer.g4 +64 -0
  314. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathLexer.h +56 -0
  315. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathLexer.tokens +12 -0
  316. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathLexerErrorListener.cpp +13 -0
  317. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathLexerErrorListener.h +22 -0
  318. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathRuleAnywhereElement.cpp +20 -0
  319. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathRuleAnywhereElement.h +27 -0
  320. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathRuleElement.cpp +30 -0
  321. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathRuleElement.h +26 -0
  322. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathTokenAnywhereElement.cpp +20 -0
  323. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathTokenAnywhereElement.h +25 -0
  324. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathTokenElement.cpp +33 -0
  325. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathTokenElement.h +26 -0
  326. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathWildcardAnywhereElement.cpp +23 -0
  327. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathWildcardAnywhereElement.h +23 -0
  328. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathWildcardElement.cpp +24 -0
  329. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathWildcardElement.h +23 -0
  330. data/lib/expressir/version.rb +1 -1
  331. metadata +329 -4
@@ -0,0 +1,110 @@
1
+ /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.
2
+ * Use of this file is governed by the BSD 3-clause license that
3
+ * can be found in the LICENSE.txt file in the project root.
4
+ */
5
+
6
+ #pragma once
7
+
8
+ #include "support/BitSet.h"
9
+ #include "atn/PredictionContext.h"
10
+
11
+ namespace antlr4 {
12
+ namespace atn {
13
+
14
+ /// Specialized set that can track info about the set, with support for combining similar configurations using a
15
+ /// graph-structured stack.
16
+ class ANTLR4CPP_PUBLIC ATNConfigSet {
17
+ public:
18
+ /// Track the elements as they are added to the set; supports get(i)
19
+ std::vector<Ref<ATNConfig>> configs;
20
+
21
+ // TODO: these fields make me pretty uncomfortable but nice to pack up info together, saves recomputation
22
+ // TODO: can we track conflicts as they are added to save scanning configs later?
23
+ size_t uniqueAlt;
24
+
25
+ /** Currently this is only used when we detect SLL conflict; this does
26
+ * not necessarily represent the ambiguous alternatives. In fact,
27
+ * I should also point out that this seems to include predicated alternatives
28
+ * that have predicates that evaluate to false. Computed in computeTargetState().
29
+ */
30
+ antlrcpp::BitSet conflictingAlts;
31
+
32
+ // Used in parser and lexer. In lexer, it indicates we hit a pred
33
+ // while computing a closure operation. Don't make a DFA state from this.
34
+ bool hasSemanticContext;
35
+ bool dipsIntoOuterContext;
36
+
37
+ /// Indicates that this configuration set is part of a full context
38
+ /// LL prediction. It will be used to determine how to merge $. With SLL
39
+ /// it's a wildcard whereas it is not for LL context merge.
40
+ const bool fullCtx;
41
+
42
+ ATNConfigSet(bool fullCtx = true);
43
+ ATNConfigSet(const Ref<ATNConfigSet> &old);
44
+
45
+ virtual ~ATNConfigSet();
46
+
47
+ virtual bool add(const Ref<ATNConfig> &config);
48
+
49
+ /// <summary>
50
+ /// Adding a new config means merging contexts with existing configs for
51
+ /// {@code (s, i, pi, _)}, where {@code s} is the
52
+ /// <seealso cref="ATNConfig#state"/>, {@code i} is the <seealso cref="ATNConfig#alt"/>, and
53
+ /// {@code pi} is the <seealso cref="ATNConfig#semanticContext"/>. We use
54
+ /// {@code (s,i,pi)} as key.
55
+ /// <p/>
56
+ /// This method updates <seealso cref="#dipsIntoOuterContext"/> and
57
+ /// <seealso cref="#hasSemanticContext"/> when necessary.
58
+ /// </summary>
59
+ virtual bool add(const Ref<ATNConfig> &config, PredictionContextMergeCache *mergeCache);
60
+
61
+ virtual std::vector<ATNState *> getStates();
62
+
63
+ /**
64
+ * Gets the complete set of represented alternatives for the configuration
65
+ * set.
66
+ *
67
+ * @return the set of represented alternatives in this configuration set
68
+ *
69
+ * @since 4.3
70
+ */
71
+ antlrcpp::BitSet getAlts();
72
+ virtual std::vector<Ref<SemanticContext>> getPredicates();
73
+
74
+ virtual Ref<ATNConfig> get(size_t i) const;
75
+
76
+ virtual void optimizeConfigs(ATNSimulator *interpreter);
77
+
78
+ bool addAll(const Ref<ATNConfigSet> &other);
79
+
80
+ bool operator == (const ATNConfigSet &other);
81
+ virtual size_t hashCode();
82
+ virtual size_t size();
83
+ virtual bool isEmpty();
84
+ virtual void clear();
85
+ virtual bool isReadonly();
86
+ virtual void setReadonly(bool readonly);
87
+ virtual std::string toString();
88
+
89
+ protected:
90
+ /// Indicates that the set of configurations is read-only. Do not
91
+ /// allow any code to manipulate the set; DFA states will point at
92
+ /// the sets and they must not change. This does not protect the other
93
+ /// fields; in particular, conflictingAlts is set after
94
+ /// we've made this readonly.
95
+ bool _readonly;
96
+
97
+ virtual size_t getHash(ATNConfig *c); // Hash differs depending on set type.
98
+
99
+ private:
100
+ size_t _cachedHashCode;
101
+
102
+ /// All configs but hashed by (s, i, _, pi) not including context. Wiped out
103
+ /// when we go readonly as this set becomes a DFA state.
104
+ std::unordered_map<size_t, ATNConfig *> _configLookup;
105
+
106
+ void InitializeInstanceFields();
107
+ };
108
+
109
+ } // namespace atn
110
+ } // namespace antlr4
@@ -0,0 +1,64 @@
1
+ /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.
2
+ * Use of this file is governed by the BSD 3-clause license that
3
+ * can be found in the LICENSE.txt file in the project root.
4
+ */
5
+
6
+ #include "atn/ATNDeserializationOptions.h"
7
+
8
+ using namespace antlr4::atn;
9
+
10
+ ATNDeserializationOptions ATNDeserializationOptions::defaultOptions;
11
+
12
+ ATNDeserializationOptions::ATNDeserializationOptions() {
13
+ InitializeInstanceFields();
14
+ }
15
+
16
+ ATNDeserializationOptions::ATNDeserializationOptions(ATNDeserializationOptions *options) : ATNDeserializationOptions() {
17
+ this->verifyATN = options->verifyATN;
18
+ this->generateRuleBypassTransitions = options->generateRuleBypassTransitions;
19
+ }
20
+
21
+ ATNDeserializationOptions::~ATNDeserializationOptions() {
22
+ }
23
+
24
+ const ATNDeserializationOptions& ATNDeserializationOptions::getDefaultOptions() {
25
+ return defaultOptions;
26
+ }
27
+
28
+ bool ATNDeserializationOptions::isReadOnly() {
29
+ return readOnly;
30
+ }
31
+
32
+ void ATNDeserializationOptions::makeReadOnly() {
33
+ readOnly = true;
34
+ }
35
+
36
+ bool ATNDeserializationOptions::isVerifyATN() {
37
+ return verifyATN;
38
+ }
39
+
40
+ void ATNDeserializationOptions::setVerifyATN(bool verify) {
41
+ throwIfReadOnly();
42
+ verifyATN = verify;
43
+ }
44
+
45
+ bool ATNDeserializationOptions::isGenerateRuleBypassTransitions() {
46
+ return generateRuleBypassTransitions;
47
+ }
48
+
49
+ void ATNDeserializationOptions::setGenerateRuleBypassTransitions(bool generate) {
50
+ throwIfReadOnly();
51
+ generateRuleBypassTransitions = generate;
52
+ }
53
+
54
+ void ATNDeserializationOptions::throwIfReadOnly() {
55
+ if (isReadOnly()) {
56
+ throw "The object is read only.";
57
+ }
58
+ }
59
+
60
+ void ATNDeserializationOptions::InitializeInstanceFields() {
61
+ readOnly = false;
62
+ verifyATN = true;
63
+ generateRuleBypassTransitions = false;
64
+ }
@@ -0,0 +1,50 @@
1
+ /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.
2
+ * Use of this file is governed by the BSD 3-clause license that
3
+ * can be found in the LICENSE.txt file in the project root.
4
+ */
5
+
6
+ #pragma once
7
+
8
+ #include "antlr4-common.h"
9
+
10
+ namespace antlr4 {
11
+ namespace atn {
12
+
13
+ class ANTLR4CPP_PUBLIC ATNDeserializationOptions {
14
+ private:
15
+ static ATNDeserializationOptions defaultOptions;
16
+
17
+ bool readOnly;
18
+ bool verifyATN;
19
+ bool generateRuleBypassTransitions;
20
+
21
+ public:
22
+ ATNDeserializationOptions();
23
+ ATNDeserializationOptions(ATNDeserializationOptions *options);
24
+ ATNDeserializationOptions(ATNDeserializationOptions const&) = default;
25
+ virtual ~ATNDeserializationOptions();
26
+ ATNDeserializationOptions& operator=(ATNDeserializationOptions const&) = default;
27
+
28
+ static const ATNDeserializationOptions& getDefaultOptions();
29
+
30
+ bool isReadOnly();
31
+
32
+ void makeReadOnly();
33
+
34
+ bool isVerifyATN();
35
+
36
+ void setVerifyATN(bool verify);
37
+
38
+ bool isGenerateRuleBypassTransitions();
39
+
40
+ void setGenerateRuleBypassTransitions(bool generate);
41
+
42
+ protected:
43
+ virtual void throwIfReadOnly();
44
+
45
+ private:
46
+ void InitializeInstanceFields();
47
+ };
48
+
49
+ } // namespace atn
50
+ } // namespace antlr4
@@ -0,0 +1,758 @@
1
+ /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.
2
+ * Use of this file is governed by the BSD 3-clause license that
3
+ * can be found in the LICENSE.txt file in the project root.
4
+ */
5
+
6
+ #include "atn/ATNDeserializationOptions.h"
7
+
8
+ #include "atn/ATNType.h"
9
+ #include "atn/ATNState.h"
10
+ #include "atn/ATN.h"
11
+
12
+ #include "atn/LoopEndState.h"
13
+ #include "atn/DecisionState.h"
14
+ #include "atn/RuleStartState.h"
15
+ #include "atn/RuleStopState.h"
16
+ #include "atn/TokensStartState.h"
17
+ #include "atn/RuleTransition.h"
18
+ #include "atn/EpsilonTransition.h"
19
+ #include "atn/PlusLoopbackState.h"
20
+ #include "atn/PlusBlockStartState.h"
21
+ #include "atn/StarLoopbackState.h"
22
+ #include "atn/BasicBlockStartState.h"
23
+ #include "atn/BasicState.h"
24
+ #include "atn/BlockEndState.h"
25
+ #include "atn/StarLoopEntryState.h"
26
+
27
+ #include "atn/AtomTransition.h"
28
+ #include "atn/StarBlockStartState.h"
29
+ #include "atn/RangeTransition.h"
30
+ #include "atn/PredicateTransition.h"
31
+ #include "atn/PrecedencePredicateTransition.h"
32
+ #include "atn/ActionTransition.h"
33
+ #include "atn/SetTransition.h"
34
+ #include "atn/NotSetTransition.h"
35
+ #include "atn/WildcardTransition.h"
36
+ #include "Token.h"
37
+
38
+ #include "misc/IntervalSet.h"
39
+ #include "Exceptions.h"
40
+ #include "support/CPPUtils.h"
41
+ #include "support/StringUtils.h"
42
+
43
+ #include "atn/LexerCustomAction.h"
44
+ #include "atn/LexerChannelAction.h"
45
+ #include "atn/LexerModeAction.h"
46
+ #include "atn/LexerMoreAction.h"
47
+ #include "atn/LexerPopModeAction.h"
48
+ #include "atn/LexerPushModeAction.h"
49
+ #include "atn/LexerSkipAction.h"
50
+ #include "atn/LexerTypeAction.h"
51
+
52
+ #include "atn/ATNDeserializer.h"
53
+
54
+ #include <string>
55
+
56
+ using namespace antlr4;
57
+ using namespace antlr4::atn;
58
+ using namespace antlrcpp;
59
+
60
+ const size_t ATNDeserializer::SERIALIZED_VERSION = 3;
61
+
62
+ namespace {
63
+
64
+ uint32_t deserializeInt32(const std::vector<uint16_t>& data, size_t offset) {
65
+ return (uint32_t)data[offset] | ((uint32_t)data[offset + 1] << 16);
66
+ }
67
+
68
+ ssize_t readUnicodeInt(const std::vector<uint16_t>& data, int& p) {
69
+ return static_cast<ssize_t>(data[p++]);
70
+ }
71
+
72
+ ssize_t readUnicodeInt32(const std::vector<uint16_t>& data, int& p) {
73
+ auto result = deserializeInt32(data, p);
74
+ p += 2;
75
+ return static_cast<ssize_t>(result);
76
+ }
77
+
78
+ // We templatize this on the function type so the optimizer can inline
79
+ // the 16- or 32-bit readUnicodeInt/readUnicodeInt32 as needed.
80
+ template <typename F>
81
+ void deserializeSets(
82
+ const std::vector<uint16_t>& data,
83
+ int& p,
84
+ std::vector<misc::IntervalSet>& sets,
85
+ F readUnicode) {
86
+ int nsets = data[p++];
87
+ for (int i = 0; i < nsets; i++) {
88
+ int nintervals = data[p++];
89
+ misc::IntervalSet set;
90
+
91
+ bool containsEof = data[p++] != 0;
92
+ if (containsEof) {
93
+ set.add(-1);
94
+ }
95
+
96
+ for (int j = 0; j < nintervals; j++) {
97
+ auto a = readUnicode(data, p);
98
+ auto b = readUnicode(data, p);
99
+ set.add(a, b);
100
+ }
101
+ sets.push_back(set);
102
+ }
103
+ }
104
+
105
+ }
106
+
107
+ ATNDeserializer::ATNDeserializer(): ATNDeserializer(ATNDeserializationOptions::getDefaultOptions()) {
108
+ }
109
+
110
+ ATNDeserializer::ATNDeserializer(const ATNDeserializationOptions& dso): deserializationOptions(dso) {
111
+ }
112
+
113
+ ATNDeserializer::~ATNDeserializer() {
114
+ }
115
+
116
+ /**
117
+ * This value should never change. Updates following this version are
118
+ * reflected as change in the unique ID SERIALIZED_UUID.
119
+ */
120
+ Guid ATNDeserializer::ADDED_PRECEDENCE_TRANSITIONS() {
121
+ return Guid("1DA0C57D-6C06-438A-9B27-10BCB3CE0F61");
122
+ }
123
+
124
+ Guid ATNDeserializer::ADDED_LEXER_ACTIONS() {
125
+ return Guid("AADB8D7E-AEEF-4415-AD2B-8204D6CF042E");
126
+ }
127
+
128
+ Guid ATNDeserializer::ADDED_UNICODE_SMP() {
129
+ return Guid("59627784-3BE5-417A-B9EB-8131A7286089");
130
+ }
131
+
132
+ Guid ATNDeserializer::SERIALIZED_UUID() {
133
+ return ADDED_UNICODE_SMP();
134
+ }
135
+
136
+ Guid ATNDeserializer::BASE_SERIALIZED_UUID() {
137
+ return Guid("33761B2D-78BB-4A43-8B0B-4F5BEE8AACF3");
138
+ }
139
+
140
+ std::vector<Guid>& ATNDeserializer::SUPPORTED_UUIDS() {
141
+ static std::vector<Guid> singleton = { BASE_SERIALIZED_UUID(), ADDED_PRECEDENCE_TRANSITIONS(), ADDED_LEXER_ACTIONS(), ADDED_UNICODE_SMP() };
142
+ return singleton;
143
+ }
144
+
145
+ bool ATNDeserializer::isFeatureSupported(const Guid &feature, const Guid &actualUuid) {
146
+ auto featureIterator = std::find(SUPPORTED_UUIDS().begin(), SUPPORTED_UUIDS().end(), feature);
147
+ if (featureIterator == SUPPORTED_UUIDS().end()) {
148
+ return false;
149
+ }
150
+ auto actualIterator = std::find(SUPPORTED_UUIDS().begin(), SUPPORTED_UUIDS().end(), actualUuid);
151
+ if (actualIterator == SUPPORTED_UUIDS().end()) {
152
+ return false;
153
+ }
154
+
155
+ return std::distance(featureIterator, actualIterator) >= 0;
156
+ }
157
+
158
+ ATN ATNDeserializer::deserialize(const std::vector<uint16_t>& input) {
159
+ // Don't adjust the first value since that's the version number.
160
+ std::vector<uint16_t> data(input.size());
161
+ data[0] = input[0];
162
+ for (size_t i = 1; i < input.size(); ++i) {
163
+ data[i] = input[i] - 2;
164
+ }
165
+
166
+ int p = 0;
167
+ int version = data[p++];
168
+ if (version != SERIALIZED_VERSION) {
169
+ std::string reason = "Could not deserialize ATN with version" + std::to_string(version) + "(expected " + std::to_string(SERIALIZED_VERSION) + ").";
170
+
171
+ throw UnsupportedOperationException(reason);
172
+ }
173
+
174
+ Guid uuid = toUUID(data.data(), p);
175
+ p += 8;
176
+ auto uuidIterator = std::find(SUPPORTED_UUIDS().begin(), SUPPORTED_UUIDS().end(), uuid);
177
+ if (uuidIterator == SUPPORTED_UUIDS().end()) {
178
+ std::string reason = "Could not deserialize ATN with UUID " + uuid.toString() + " (expected " +
179
+ SERIALIZED_UUID().toString() + " or a legacy UUID).";
180
+
181
+ throw UnsupportedOperationException(reason);
182
+ }
183
+
184
+ bool supportsPrecedencePredicates = isFeatureSupported(ADDED_PRECEDENCE_TRANSITIONS(), uuid);
185
+ bool supportsLexerActions = isFeatureSupported(ADDED_LEXER_ACTIONS(), uuid);
186
+
187
+ ATNType grammarType = (ATNType)data[p++];
188
+ size_t maxTokenType = data[p++];
189
+ ATN atn(grammarType, maxTokenType);
190
+
191
+ //
192
+ // STATES
193
+ //
194
+ std::vector<std::pair<LoopEndState*, size_t>> loopBackStateNumbers;
195
+ std::vector<std::pair<BlockStartState*, size_t>> endStateNumbers;
196
+ size_t nstates = data[p++];
197
+ for (size_t i = 0; i < nstates; i++) {
198
+ size_t stype = data[p++];
199
+ // ignore bad type of states
200
+ if (stype == ATNState::ATN_INVALID_TYPE) {
201
+ atn.addState(nullptr);
202
+ continue;
203
+ }
204
+
205
+ size_t ruleIndex = data[p++];
206
+ if (ruleIndex == 0xFFFF) {
207
+ ruleIndex = INVALID_INDEX;
208
+ }
209
+
210
+ ATNState *s = stateFactory(stype, ruleIndex);
211
+ if (stype == ATNState::LOOP_END) { // special case
212
+ int loopBackStateNumber = data[p++];
213
+ loopBackStateNumbers.push_back({ (LoopEndState*)s, loopBackStateNumber });
214
+ } else if (is<BlockStartState*>(s)) {
215
+ int endStateNumber = data[p++];
216
+ endStateNumbers.push_back({ (BlockStartState*)s, endStateNumber });
217
+ }
218
+ atn.addState(s);
219
+ }
220
+
221
+ // delay the assignment of loop back and end states until we know all the state instances have been initialized
222
+ for (auto &pair : loopBackStateNumbers) {
223
+ pair.first->loopBackState = atn.states[pair.second];
224
+ }
225
+
226
+ for (auto &pair : endStateNumbers) {
227
+ pair.first->endState = (BlockEndState*)atn.states[pair.second];
228
+ }
229
+
230
+ size_t numNonGreedyStates = data[p++];
231
+ for (size_t i = 0; i < numNonGreedyStates; i++) {
232
+ size_t stateNumber = data[p++];
233
+ // The serialized ATN must be specifying the right states, so that the
234
+ // cast below is correct.
235
+ ((DecisionState *)atn.states[stateNumber])->nonGreedy = true;
236
+ }
237
+
238
+ if (supportsPrecedencePredicates) {
239
+ size_t numPrecedenceStates = data[p++];
240
+ for (size_t i = 0; i < numPrecedenceStates; i++) {
241
+ size_t stateNumber = data[p++];
242
+ ((RuleStartState *)atn.states[stateNumber])->isLeftRecursiveRule = true;
243
+ }
244
+ }
245
+
246
+ //
247
+ // RULES
248
+ //
249
+ size_t nrules = data[p++];
250
+ for (size_t i = 0; i < nrules; i++) {
251
+ size_t s = data[p++];
252
+ // Also here, the serialized atn must ensure to point to the correct class type.
253
+ RuleStartState *startState = (RuleStartState*)atn.states[s];
254
+ atn.ruleToStartState.push_back(startState);
255
+ if (atn.grammarType == ATNType::LEXER) {
256
+ size_t tokenType = data[p++];
257
+ if (tokenType == 0xFFFF) {
258
+ tokenType = Token::EOF;
259
+ }
260
+
261
+ atn.ruleToTokenType.push_back(tokenType);
262
+
263
+ if (!isFeatureSupported(ADDED_LEXER_ACTIONS(), uuid)) {
264
+ // this piece of unused metadata was serialized prior to the
265
+ // addition of LexerAction
266
+ //int actionIndexIgnored = data[p++];
267
+ p++;
268
+ }
269
+ }
270
+ }
271
+
272
+ atn.ruleToStopState.resize(nrules);
273
+ for (ATNState *state : atn.states) {
274
+ if (!is<RuleStopState*>(state)) {
275
+ continue;
276
+ }
277
+
278
+ RuleStopState *stopState = static_cast<RuleStopState*>(state);
279
+ atn.ruleToStopState[state->ruleIndex] = stopState;
280
+ atn.ruleToStartState[state->ruleIndex]->stopState = stopState;
281
+ }
282
+
283
+ //
284
+ // MODES
285
+ //
286
+ size_t nmodes = data[p++];
287
+ for (size_t i = 0; i < nmodes; i++) {
288
+ size_t s = data[p++];
289
+ atn.modeToStartState.push_back(static_cast<TokensStartState*>(atn.states[s]));
290
+ }
291
+
292
+ //
293
+ // SETS
294
+ //
295
+ std::vector<misc::IntervalSet> sets;
296
+
297
+ // First, deserialize sets with 16-bit arguments <= U+FFFF.
298
+ deserializeSets(data, p, sets, readUnicodeInt);
299
+
300
+ // Next, if the ATN was serialized with the Unicode SMP feature,
301
+ // deserialize sets with 32-bit arguments <= U+10FFFF.
302
+ if (isFeatureSupported(ADDED_UNICODE_SMP(), uuid)) {
303
+ deserializeSets(data, p, sets, readUnicodeInt32);
304
+ }
305
+
306
+ //
307
+ // EDGES
308
+ //
309
+ int nedges = data[p++];
310
+ for (int i = 0; i < nedges; i++) {
311
+ size_t src = data[p];
312
+ size_t trg = data[p + 1];
313
+ size_t ttype = data[p + 2];
314
+ size_t arg1 = data[p + 3];
315
+ size_t arg2 = data[p + 4];
316
+ size_t arg3 = data[p + 5];
317
+ Transition *trans = edgeFactory(atn, ttype, src, trg, arg1, arg2, arg3, sets);
318
+ ATNState *srcState = atn.states[src];
319
+ srcState->addTransition(trans);
320
+ p += 6;
321
+ }
322
+
323
+ // edges for rule stop states can be derived, so they aren't serialized
324
+ for (ATNState *state : atn.states) {
325
+ for (size_t i = 0; i < state->transitions.size(); i++) {
326
+ Transition *t = state->transitions[i];
327
+ if (!is<RuleTransition*>(t)) {
328
+ continue;
329
+ }
330
+
331
+ RuleTransition *ruleTransition = static_cast<RuleTransition*>(t);
332
+ size_t outermostPrecedenceReturn = INVALID_INDEX;
333
+ if (atn.ruleToStartState[ruleTransition->target->ruleIndex]->isLeftRecursiveRule) {
334
+ if (ruleTransition->precedence == 0) {
335
+ outermostPrecedenceReturn = ruleTransition->target->ruleIndex;
336
+ }
337
+ }
338
+
339
+ EpsilonTransition *returnTransition = new EpsilonTransition(ruleTransition->followState, outermostPrecedenceReturn); /* mem check: freed in ANTState d-tor */
340
+ atn.ruleToStopState[ruleTransition->target->ruleIndex]->addTransition(returnTransition);
341
+ }
342
+ }
343
+
344
+ for (ATNState *state : atn.states) {
345
+ if (is<BlockStartState *>(state)) {
346
+ BlockStartState *startState = static_cast<BlockStartState *>(state);
347
+
348
+ // we need to know the end state to set its start state
349
+ if (startState->endState == nullptr) {
350
+ throw IllegalStateException();
351
+ }
352
+
353
+ // block end states can only be associated to a single block start state
354
+ if (startState->endState->startState != nullptr) {
355
+ throw IllegalStateException();
356
+ }
357
+
358
+ startState->endState->startState = static_cast<BlockStartState*>(state);
359
+ }
360
+
361
+ if (is<PlusLoopbackState*>(state)) {
362
+ PlusLoopbackState *loopbackState = static_cast<PlusLoopbackState *>(state);
363
+ for (size_t i = 0; i < loopbackState->transitions.size(); i++) {
364
+ ATNState *target = loopbackState->transitions[i]->target;
365
+ if (is<PlusBlockStartState *>(target)) {
366
+ (static_cast<PlusBlockStartState *>(target))->loopBackState = loopbackState;
367
+ }
368
+ }
369
+ } else if (is<StarLoopbackState *>(state)) {
370
+ StarLoopbackState *loopbackState = static_cast<StarLoopbackState *>(state);
371
+ for (size_t i = 0; i < loopbackState->transitions.size(); i++) {
372
+ ATNState *target = loopbackState->transitions[i]->target;
373
+ if (is<StarLoopEntryState *>(target)) {
374
+ (static_cast<StarLoopEntryState*>(target))->loopBackState = loopbackState;
375
+ }
376
+ }
377
+ }
378
+ }
379
+
380
+ //
381
+ // DECISIONS
382
+ //
383
+ size_t ndecisions = data[p++];
384
+ for (size_t i = 1; i <= ndecisions; i++) {
385
+ size_t s = data[p++];
386
+ DecisionState *decState = dynamic_cast<DecisionState*>(atn.states[s]);
387
+ if (decState == nullptr)
388
+ throw IllegalStateException();
389
+
390
+ atn.decisionToState.push_back(decState);
391
+ decState->decision = (int)i - 1;
392
+ }
393
+
394
+ //
395
+ // LEXER ACTIONS
396
+ //
397
+ if (atn.grammarType == ATNType::LEXER) {
398
+ if (supportsLexerActions) {
399
+ atn.lexerActions.resize(data[p++]);
400
+ for (size_t i = 0; i < atn.lexerActions.size(); i++) {
401
+ LexerActionType actionType = (LexerActionType)data[p++];
402
+ int data1 = data[p++];
403
+ if (data1 == 0xFFFF) {
404
+ data1 = -1;
405
+ }
406
+
407
+ int data2 = data[p++];
408
+ if (data2 == 0xFFFF) {
409
+ data2 = -1;
410
+ }
411
+
412
+ atn.lexerActions[i] = lexerActionFactory(actionType, data1, data2);
413
+ }
414
+ } else {
415
+ // for compatibility with older serialized ATNs, convert the old
416
+ // serialized action index for action transitions to the new
417
+ // form, which is the index of a LexerCustomAction
418
+ for (ATNState *state : atn.states) {
419
+ for (size_t i = 0; i < state->transitions.size(); i++) {
420
+ Transition *transition = state->transitions[i];
421
+ if (!is<ActionTransition *>(transition)) {
422
+ continue;
423
+ }
424
+
425
+ size_t ruleIndex = static_cast<ActionTransition *>(transition)->ruleIndex;
426
+ size_t actionIndex = static_cast<ActionTransition *>(transition)->actionIndex;
427
+ Ref<LexerCustomAction> lexerAction = std::make_shared<LexerCustomAction>(ruleIndex, actionIndex);
428
+ state->transitions[i] = new ActionTransition(transition->target, ruleIndex, atn.lexerActions.size(), false); /* mem-check freed in ATNState d-tor */
429
+ delete transition; // ml: no longer needed since we just replaced it.
430
+ atn.lexerActions.push_back(lexerAction);
431
+ }
432
+ }
433
+ }
434
+ }
435
+
436
+ markPrecedenceDecisions(atn);
437
+
438
+ if (deserializationOptions.isVerifyATN()) {
439
+ verifyATN(atn);
440
+ }
441
+
442
+ if (deserializationOptions.isGenerateRuleBypassTransitions() && atn.grammarType == ATNType::PARSER) {
443
+ atn.ruleToTokenType.resize(atn.ruleToStartState.size());
444
+ for (size_t i = 0; i < atn.ruleToStartState.size(); i++) {
445
+ atn.ruleToTokenType[i] = int(atn.maxTokenType + i + 1);
446
+ }
447
+
448
+ for (std::vector<RuleStartState*>::size_type i = 0; i < atn.ruleToStartState.size(); i++) {
449
+ BasicBlockStartState *bypassStart = new BasicBlockStartState(); /* mem check: freed in ATN d-tor */
450
+ bypassStart->ruleIndex = (int)i;
451
+ atn.addState(bypassStart);
452
+
453
+ BlockEndState *bypassStop = new BlockEndState(); /* mem check: freed in ATN d-tor */
454
+ bypassStop->ruleIndex = (int)i;
455
+ atn.addState(bypassStop);
456
+
457
+ bypassStart->endState = bypassStop;
458
+ atn.defineDecisionState(bypassStart);
459
+
460
+ bypassStop->startState = bypassStart;
461
+
462
+ ATNState *endState;
463
+ Transition *excludeTransition = nullptr;
464
+ if (atn.ruleToStartState[i]->isLeftRecursiveRule) {
465
+ // wrap from the beginning of the rule to the StarLoopEntryState
466
+ endState = nullptr;
467
+ for (ATNState *state : atn.states) {
468
+ if (state->ruleIndex != i) {
469
+ continue;
470
+ }
471
+
472
+ if (!is<StarLoopEntryState*>(state)) {
473
+ continue;
474
+ }
475
+
476
+ ATNState *maybeLoopEndState = state->transitions[state->transitions.size() - 1]->target;
477
+ if (!is<LoopEndState*>(maybeLoopEndState)) {
478
+ continue;
479
+ }
480
+
481
+ if (maybeLoopEndState->epsilonOnlyTransitions && is<RuleStopState*>(maybeLoopEndState->transitions[0]->target)) {
482
+ endState = state;
483
+ break;
484
+ }
485
+ }
486
+
487
+ if (endState == nullptr) {
488
+ throw UnsupportedOperationException("Couldn't identify final state of the precedence rule prefix section.");
489
+
490
+ }
491
+
492
+ excludeTransition = (static_cast<StarLoopEntryState*>(endState))->loopBackState->transitions[0];
493
+ } else {
494
+ endState = atn.ruleToStopState[i];
495
+ }
496
+
497
+ // all non-excluded transitions that currently target end state need to target blockEnd instead
498
+ for (ATNState *state : atn.states) {
499
+ for (Transition *transition : state->transitions) {
500
+ if (transition == excludeTransition) {
501
+ continue;
502
+ }
503
+
504
+ if (transition->target == endState) {
505
+ transition->target = bypassStop;
506
+ }
507
+ }
508
+ }
509
+
510
+ // all transitions leaving the rule start state need to leave blockStart instead
511
+ while (atn.ruleToStartState[i]->transitions.size() > 0) {
512
+ Transition *transition = atn.ruleToStartState[i]->removeTransition(atn.ruleToStartState[i]->transitions.size() - 1);
513
+ bypassStart->addTransition(transition);
514
+ }
515
+
516
+ // link the new states
517
+ atn.ruleToStartState[i]->addTransition(new EpsilonTransition(bypassStart)); /* mem check: freed in ATNState d-tor */
518
+ bypassStop->addTransition(new EpsilonTransition(endState)); /* mem check: freed in ATNState d-tor */
519
+
520
+ ATNState *matchState = new BasicState(); /* mem check: freed in ATN d-tor */
521
+ atn.addState(matchState);
522
+ matchState->addTransition(new AtomTransition(bypassStop, atn.ruleToTokenType[i])); /* mem check: freed in ATNState d-tor */
523
+ bypassStart->addTransition(new EpsilonTransition(matchState)); /* mem check: freed in ATNState d-tor */
524
+ }
525
+
526
+ if (deserializationOptions.isVerifyATN()) {
527
+ // reverify after modification
528
+ verifyATN(atn);
529
+ }
530
+ }
531
+
532
+ return atn;
533
+ }
534
+
535
+ /**
536
+ * Analyze the {@link StarLoopEntryState} states in the specified ATN to set
537
+ * the {@link StarLoopEntryState#isPrecedenceDecision} field to the
538
+ * correct value.
539
+ *
540
+ * @param atn The ATN.
541
+ */
542
+ void ATNDeserializer::markPrecedenceDecisions(const ATN &atn) {
543
+ for (ATNState *state : atn.states) {
544
+ if (!is<StarLoopEntryState *>(state)) {
545
+ continue;
546
+ }
547
+
548
+ /* We analyze the ATN to determine if this ATN decision state is the
549
+ * decision for the closure block that determines whether a
550
+ * precedence rule should continue or complete.
551
+ */
552
+ if (atn.ruleToStartState[state->ruleIndex]->isLeftRecursiveRule) {
553
+ ATNState *maybeLoopEndState = state->transitions[state->transitions.size() - 1]->target;
554
+ if (is<LoopEndState *>(maybeLoopEndState)) {
555
+ if (maybeLoopEndState->epsilonOnlyTransitions && is<RuleStopState *>(maybeLoopEndState->transitions[0]->target)) {
556
+ static_cast<StarLoopEntryState *>(state)->isPrecedenceDecision = true;
557
+ }
558
+ }
559
+ }
560
+ }
561
+ }
562
+
563
+ void ATNDeserializer::verifyATN(const ATN &atn) {
564
+ // verify assumptions
565
+ for (ATNState *state : atn.states) {
566
+ if (state == nullptr) {
567
+ continue;
568
+ }
569
+
570
+ checkCondition(state->epsilonOnlyTransitions || state->transitions.size() <= 1);
571
+
572
+ if (is<PlusBlockStartState *>(state)) {
573
+ checkCondition((static_cast<PlusBlockStartState *>(state))->loopBackState != nullptr);
574
+ }
575
+
576
+ if (is<StarLoopEntryState *>(state)) {
577
+ StarLoopEntryState *starLoopEntryState = static_cast<StarLoopEntryState*>(state);
578
+ checkCondition(starLoopEntryState->loopBackState != nullptr);
579
+ checkCondition(starLoopEntryState->transitions.size() == 2);
580
+
581
+ if (is<StarBlockStartState *>(starLoopEntryState->transitions[0]->target)) {
582
+ checkCondition(static_cast<LoopEndState *>(starLoopEntryState->transitions[1]->target) != nullptr);
583
+ checkCondition(!starLoopEntryState->nonGreedy);
584
+ } else if (is<LoopEndState *>(starLoopEntryState->transitions[0]->target)) {
585
+ checkCondition(is<StarBlockStartState *>(starLoopEntryState->transitions[1]->target));
586
+ checkCondition(starLoopEntryState->nonGreedy);
587
+ } else {
588
+ throw IllegalStateException();
589
+
590
+ }
591
+ }
592
+
593
+ if (is<StarLoopbackState *>(state)) {
594
+ checkCondition(state->transitions.size() == 1);
595
+ checkCondition(is<StarLoopEntryState *>(state->transitions[0]->target));
596
+ }
597
+
598
+ if (is<LoopEndState *>(state)) {
599
+ checkCondition((static_cast<LoopEndState *>(state))->loopBackState != nullptr);
600
+ }
601
+
602
+ if (is<RuleStartState *>(state)) {
603
+ checkCondition((static_cast<RuleStartState *>(state))->stopState != nullptr);
604
+ }
605
+
606
+ if (is<BlockStartState *>(state)) {
607
+ checkCondition((static_cast<BlockStartState *>(state))->endState != nullptr);
608
+ }
609
+
610
+ if (is<BlockEndState *>(state)) {
611
+ checkCondition((static_cast<BlockEndState *>(state))->startState != nullptr);
612
+ }
613
+
614
+ if (is<DecisionState *>(state)) {
615
+ DecisionState *decisionState = static_cast<DecisionState *>(state);
616
+ checkCondition(decisionState->transitions.size() <= 1 || decisionState->decision >= 0);
617
+ } else {
618
+ checkCondition(state->transitions.size() <= 1 || is<RuleStopState *>(state));
619
+ }
620
+ }
621
+ }
622
+
623
+ void ATNDeserializer::checkCondition(bool condition) {
624
+ checkCondition(condition, "");
625
+ }
626
+
627
+ void ATNDeserializer::checkCondition(bool condition, const std::string &message) {
628
+ if (!condition) {
629
+ throw IllegalStateException(message);
630
+ }
631
+ }
632
+
633
+ Guid ATNDeserializer::toUUID(const unsigned short *data, size_t offset) {
634
+ return Guid((uint16_t *)data + offset, true);
635
+ }
636
+
637
+ /* mem check: all created instances are freed in the d-tor of the ATNState they are added to. */
638
+ Transition *ATNDeserializer::edgeFactory(const ATN &atn, size_t type, size_t /*src*/, size_t trg, size_t arg1,
639
+ size_t arg2, size_t arg3,
640
+ const std::vector<misc::IntervalSet> &sets) {
641
+
642
+ ATNState *target = atn.states[trg];
643
+ switch (type) {
644
+ case Transition::EPSILON:
645
+ return new EpsilonTransition(target);
646
+ case Transition::RANGE:
647
+ if (arg3 != 0) {
648
+ return new RangeTransition(target, Token::EOF, arg2);
649
+ } else {
650
+ return new RangeTransition(target, arg1, arg2);
651
+ }
652
+ case Transition::RULE:
653
+ return new RuleTransition(static_cast<RuleStartState*>(atn.states[arg1]), arg2, (int)arg3, target);
654
+ case Transition::PREDICATE:
655
+ return new PredicateTransition(target, arg1, arg2, arg3 != 0);
656
+ case Transition::PRECEDENCE:
657
+ return new PrecedencePredicateTransition(target, (int)arg1);
658
+ case Transition::ATOM:
659
+ if (arg3 != 0) {
660
+ return new AtomTransition(target, Token::EOF);
661
+ } else {
662
+ return new AtomTransition(target, arg1);
663
+ }
664
+ case Transition::ACTION:
665
+ return new ActionTransition(target, arg1, arg2, arg3 != 0);
666
+ case Transition::SET:
667
+ return new SetTransition(target, sets[arg1]);
668
+ case Transition::NOT_SET:
669
+ return new NotSetTransition(target, sets[arg1]);
670
+ case Transition::WILDCARD:
671
+ return new WildcardTransition(target);
672
+ }
673
+
674
+ throw IllegalArgumentException("The specified transition type is not valid.");
675
+ }
676
+
677
+ /* mem check: all created instances are freed in the d-tor of the ATN. */
678
+ ATNState* ATNDeserializer::stateFactory(size_t type, size_t ruleIndex) {
679
+ ATNState *s;
680
+ switch (type) {
681
+ case ATNState::ATN_INVALID_TYPE:
682
+ return nullptr;
683
+ case ATNState::BASIC :
684
+ s = new BasicState();
685
+ break;
686
+ case ATNState::RULE_START :
687
+ s = new RuleStartState();
688
+ break;
689
+ case ATNState::BLOCK_START :
690
+ s = new BasicBlockStartState();
691
+ break;
692
+ case ATNState::PLUS_BLOCK_START :
693
+ s = new PlusBlockStartState();
694
+ break;
695
+ case ATNState::STAR_BLOCK_START :
696
+ s = new StarBlockStartState();
697
+ break;
698
+ case ATNState::TOKEN_START :
699
+ s = new TokensStartState();
700
+ break;
701
+ case ATNState::RULE_STOP :
702
+ s = new RuleStopState();
703
+ break;
704
+ case ATNState::BLOCK_END :
705
+ s = new BlockEndState();
706
+ break;
707
+ case ATNState::STAR_LOOP_BACK :
708
+ s = new StarLoopbackState();
709
+ break;
710
+ case ATNState::STAR_LOOP_ENTRY :
711
+ s = new StarLoopEntryState();
712
+ break;
713
+ case ATNState::PLUS_LOOP_BACK :
714
+ s = new PlusLoopbackState();
715
+ break;
716
+ case ATNState::LOOP_END :
717
+ s = new LoopEndState();
718
+ break;
719
+ default :
720
+ std::string message = "The specified state type " + std::to_string(type) + " is not valid.";
721
+ throw IllegalArgumentException(message);
722
+ }
723
+
724
+ s->ruleIndex = ruleIndex;
725
+ return s;
726
+ }
727
+
728
+ Ref<LexerAction> ATNDeserializer::lexerActionFactory(LexerActionType type, int data1, int data2) {
729
+ switch (type) {
730
+ case LexerActionType::CHANNEL:
731
+ return std::make_shared<LexerChannelAction>(data1);
732
+
733
+ case LexerActionType::CUSTOM:
734
+ return std::make_shared<LexerCustomAction>(data1, data2);
735
+
736
+ case LexerActionType::MODE:
737
+ return std::make_shared< LexerModeAction>(data1);
738
+
739
+ case LexerActionType::MORE:
740
+ return LexerMoreAction::getInstance();
741
+
742
+ case LexerActionType::POP_MODE:
743
+ return LexerPopModeAction::getInstance();
744
+
745
+ case LexerActionType::PUSH_MODE:
746
+ return std::make_shared<LexerPushModeAction>(data1);
747
+
748
+ case LexerActionType::SKIP:
749
+ return LexerSkipAction::getInstance();
750
+
751
+ case LexerActionType::TYPE:
752
+ return std::make_shared<LexerTypeAction>(data1);
753
+
754
+ default:
755
+ throw IllegalArgumentException("The specified lexer action type " + std::to_string(static_cast<size_t>(type)) +
756
+ " is not valid.");
757
+ }
758
+ }