expressir 1.2.3 → 1.2.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (328) hide show
  1. checksums.yaml +4 -4
  2. data/.cross_rubies +0 -6
  3. data/.github/workflows/rake.yml +223 -31
  4. data/.gitignore +7 -1
  5. data/.gitmodules +3 -0
  6. data/.rubocop.yml +13 -4
  7. data/README.adoc +8 -0
  8. data/Rakefile +4 -1
  9. data/bin/console +0 -1
  10. data/bin/rspec +3 -3
  11. data/exe/expressir +4 -2
  12. data/exe/format +1 -1
  13. data/exe/format-test +25 -25
  14. data/exe/generate-parser +16 -13
  15. data/expressir.gemspec +11 -9
  16. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/CMakeLists.txt +44 -9
  17. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/antlr4cpp-vs2013.vcxproj +11 -5
  18. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/antlr4cpp-vs2013.vcxproj.filters +0 -3
  19. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/antlr4cpp-vs2015.vcxproj +11 -4
  20. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/antlr4cpp-vs2015.vcxproj.filters +0 -3
  21. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/antlr4cpp-vs2017.vcxproj +11 -4
  22. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/antlr4cpp-vs2017.vcxproj.filters +0 -3
  23. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/antlr4cpp-vs2019.vcxproj +19 -4
  24. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/antlr4cpp-vs2019.vcxproj.filters +0 -3
  25. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/antlrcpp.xcodeproj/project.pbxproj +51 -35
  26. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/antlrcpp.xcodeproj/xcshareddata/xcschemes/antlr4.xcscheme +1 -1
  27. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/antlrcpp.xcodeproj/xcshareddata/xcschemes/antlr4_ios.xcscheme +1 -5
  28. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/antlrcpp.xcodeproj/xcshareddata/xcschemes/antlr4_static.xcscheme +1 -5
  29. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/ANTLRFileStream.cpp +1 -12
  30. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/ANTLRFileStream.h +9 -6
  31. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/ANTLRInputStream.cpp +43 -18
  32. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/ANTLRInputStream.h +16 -6
  33. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/CommonToken.cpp +2 -4
  34. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/CommonTokenFactory.cpp +1 -1
  35. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/CommonTokenFactory.h +1 -1
  36. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/DefaultErrorStrategy.cpp +16 -13
  37. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/Exceptions.cpp +2 -2
  38. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/Exceptions.h +2 -2
  39. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/FailedPredicateException.cpp +5 -4
  40. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/FailedPredicateException.h +1 -1
  41. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/IntStream.h +1 -1
  42. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/Lexer.cpp +2 -3
  43. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/Lexer.h +9 -9
  44. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/LexerInterpreter.cpp +0 -15
  45. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/LexerInterpreter.h +1 -7
  46. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/ListTokenSource.cpp +2 -2
  47. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/ListTokenSource.h +2 -2
  48. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/Parser.cpp +51 -31
  49. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/Parser.h +1 -7
  50. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/ParserInterpreter.cpp +27 -39
  51. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/ParserInterpreter.h +1 -7
  52. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/ParserRuleContext.cpp +20 -23
  53. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/ParserRuleContext.h +21 -21
  54. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/ProxyErrorListener.cpp +4 -4
  55. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/RecognitionException.cpp +0 -1
  56. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/Recognizer.cpp +16 -27
  57. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/Recognizer.h +12 -17
  58. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/RuleContext.cpp +4 -3
  59. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/RuleContext.h +5 -1
  60. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/RuntimeMetaData.cpp +2 -1
  61. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/Token.h +7 -7
  62. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/TokenSource.h +1 -1
  63. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/TokenStreamRewriter.cpp +6 -6
  64. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/TokenStreamRewriter.h +4 -2
  65. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/UnbufferedCharStream.cpp +15 -18
  66. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/UnbufferedCharStream.h +12 -18
  67. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/Version.h +42 -0
  68. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/Vocabulary.cpp +13 -53
  69. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/Vocabulary.h +11 -27
  70. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/antlr4-common.h +19 -58
  71. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/antlr4-runtime.h +7 -5
  72. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATN.cpp +6 -57
  73. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATN.h +35 -15
  74. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNConfig.cpp +29 -36
  75. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNConfig.h +36 -27
  76. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNConfigSet.cpp +58 -54
  77. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNConfigSet.h +77 -31
  78. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNDeserializationOptions.cpp +22 -32
  79. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNDeserializationOptions.h +22 -24
  80. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNDeserializer.cpp +335 -464
  81. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNDeserializer.h +9 -62
  82. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNSimulator.cpp +9 -39
  83. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNSimulator.h +6 -22
  84. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNState.cpp +10 -26
  85. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNState.h +42 -36
  86. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNStateType.cpp +33 -0
  87. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNStateType.h +36 -0
  88. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ActionTransition.cpp +2 -6
  89. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ActionTransition.h +4 -2
  90. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ArrayPredictionContext.cpp +49 -22
  91. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ArrayPredictionContext.h +20 -12
  92. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/AtomTransition.cpp +1 -5
  93. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/AtomTransition.h +5 -2
  94. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/BasicBlockStartState.h +4 -2
  95. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/BasicState.h +4 -2
  96. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/BlockEndState.h +5 -3
  97. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/BlockStartState.h +10 -1
  98. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/DecisionInfo.h +1 -1
  99. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/DecisionState.cpp +0 -5
  100. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/DecisionState.h +12 -8
  101. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/EpsilonTransition.cpp +2 -6
  102. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/EpsilonTransition.h +6 -3
  103. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LL1Analyzer.cpp +139 -108
  104. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LL1Analyzer.h +10 -43
  105. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerATNConfig.cpp +16 -33
  106. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerATNConfig.h +12 -12
  107. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerATNSimulator.cpp +69 -82
  108. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerATNSimulator.h +17 -28
  109. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerAction.cpp +12 -6
  110. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerAction.h +45 -11
  111. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerActionExecutor.cpp +48 -44
  112. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerActionExecutor.h +31 -18
  113. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerActionType.h +3 -1
  114. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerChannelAction.cpp +14 -26
  115. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerChannelAction.h +12 -16
  116. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerCustomAction.cpp +15 -32
  117. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerCustomAction.h +12 -24
  118. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerIndexedCustomAction.cpp +23 -29
  119. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerIndexedCustomAction.h +13 -19
  120. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerModeAction.cpp +13 -26
  121. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerModeAction.h +12 -16
  122. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerMoreAction.cpp +6 -17
  123. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerMoreAction.h +12 -16
  124. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerPopModeAction.cpp +6 -17
  125. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerPopModeAction.h +12 -16
  126. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerPushModeAction.cpp +13 -26
  127. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerPushModeAction.h +12 -16
  128. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerSkipAction.cpp +6 -17
  129. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerSkipAction.h +11 -15
  130. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerTypeAction.cpp +13 -26
  131. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerTypeAction.h +13 -17
  132. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LoopEndState.h +5 -1
  133. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/NotSetTransition.cpp +1 -6
  134. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/NotSetTransition.h +4 -2
  135. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/OrderedATNConfigSet.cpp +6 -2
  136. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/OrderedATNConfigSet.h +8 -3
  137. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ParserATNSimulator.cpp +169 -152
  138. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ParserATNSimulator.h +26 -19
  139. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ParserATNSimulatorOptions.h +50 -0
  140. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PlusBlockStartState.h +5 -1
  141. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PlusLoopbackState.h +5 -2
  142. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PrecedencePredicateTransition.cpp +2 -11
  143. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PrecedencePredicateTransition.h +15 -9
  144. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredicateEvalInfo.cpp +2 -2
  145. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredicateEvalInfo.h +2 -2
  146. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredicateTransition.cpp +4 -14
  147. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredicateTransition.h +22 -11
  148. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredictionContext.cpp +255 -338
  149. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredictionContext.h +87 -116
  150. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredictionContextCache.cpp +56 -0
  151. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredictionContextCache.h +64 -0
  152. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredictionContextMergeCache.cpp +167 -0
  153. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredictionContextMergeCache.h +101 -0
  154. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredictionContextMergeCacheOptions.h +71 -0
  155. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredictionContextType.h +21 -0
  156. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredictionMode.cpp +18 -17
  157. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredictionMode.h +1 -1
  158. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ProfilingATNSimulator.cpp +2 -2
  159. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ProfilingATNSimulator.h +2 -2
  160. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/RangeTransition.cpp +1 -5
  161. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/RangeTransition.h +4 -2
  162. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/RuleStartState.h +4 -3
  163. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/RuleStopState.h +4 -2
  164. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/RuleTransition.cpp +1 -5
  165. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/RuleTransition.h +5 -3
  166. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/SemanticContext.cpp +197 -156
  167. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/SemanticContext.h +92 -81
  168. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/SemanticContextType.h +23 -0
  169. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/SerializedATNView.h +101 -0
  170. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/SetTransition.cpp +2 -6
  171. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/SetTransition.h +11 -3
  172. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/SingletonPredictionContext.cpp +39 -34
  173. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/SingletonPredictionContext.h +17 -10
  174. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/StarBlockStartState.h +5 -2
  175. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/StarLoopEntryState.h +4 -2
  176. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/StarLoopbackState.cpp +6 -6
  177. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/StarLoopbackState.h +6 -2
  178. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/TokensStartState.h +5 -2
  179. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/Transition.cpp +1 -9
  180. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/Transition.h +11 -22
  181. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/TransitionType.cpp +27 -0
  182. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/TransitionType.h +33 -0
  183. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/WildcardTransition.cpp +1 -5
  184. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/WildcardTransition.h +4 -2
  185. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/dfa/DFA.cpp +11 -23
  186. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/dfa/DFA.h +20 -15
  187. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/dfa/DFASerializer.cpp +2 -9
  188. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/dfa/DFASerializer.h +4 -4
  189. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/dfa/DFAState.cpp +9 -50
  190. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/dfa/DFAState.h +57 -48
  191. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/dfa/LexerDFASerializer.cpp +1 -4
  192. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/dfa/LexerDFASerializer.h +3 -4
  193. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/InterpreterDataReader.cpp +2 -2
  194. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/InterpreterDataReader.h +3 -1
  195. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/Interval.cpp +1 -29
  196. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/Interval.h +10 -10
  197. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/IntervalSet.cpp +15 -28
  198. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/IntervalSet.h +1 -9
  199. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/MurmurHash.cpp +54 -68
  200. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/MurmurHash.h +35 -9
  201. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/Any.cpp +0 -5
  202. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/Any.h +1 -155
  203. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/Arrays.cpp +2 -2
  204. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/Arrays.h +39 -0
  205. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/BitSet.h +1 -1
  206. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/CPPUtils.cpp +13 -54
  207. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/CPPUtils.h +16 -29
  208. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/Casts.h +34 -0
  209. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/Declarations.h +0 -2
  210. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/StringUtils.cpp +25 -23
  211. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/StringUtils.h +2 -40
  212. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/Unicode.h +28 -0
  213. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/Utf8.cpp +242 -0
  214. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/Utf8.h +54 -0
  215. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/AbstractParseTreeVisitor.h +13 -12
  216. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ErrorNode.h +7 -2
  217. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ErrorNodeImpl.cpp +36 -5
  218. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ErrorNodeImpl.h +14 -4
  219. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/IterativeParseTreeWalker.cpp +14 -19
  220. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ParseTree.cpp +0 -3
  221. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ParseTree.h +14 -5
  222. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ParseTreeType.h +22 -0
  223. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ParseTreeVisitor.h +4 -4
  224. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ParseTreeWalker.cpp +8 -9
  225. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ParseTreeWalker.h +30 -6
  226. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/TerminalNode.h +10 -2
  227. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/TerminalNodeImpl.cpp +2 -5
  228. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/TerminalNodeImpl.h +4 -5
  229. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/Trees.cpp +1 -1
  230. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/pattern/ParseTreePattern.cpp +1 -1
  231. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/pattern/ParseTreePatternMatcher.cpp +1 -2
  232. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPath.cpp +1 -1
  233. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathLexer.cpp +128 -119
  234. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathLexer.h +18 -27
  235. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathRuleElement.cpp +1 -1
  236. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathTokenElement.cpp +1 -1
  237. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/tests/Utf8Test.cpp +110 -0
  238. data/ext/express-parser/antlrgen/Express.interp +1 -1
  239. data/ext/express-parser/antlrgen/ExpressBaseListener.cpp +1 -1
  240. data/ext/express-parser/antlrgen/ExpressBaseListener.h +1 -1
  241. data/ext/express-parser/antlrgen/ExpressBaseVisitor.cpp +1 -1
  242. data/ext/express-parser/antlrgen/ExpressBaseVisitor.h +200 -200
  243. data/ext/express-parser/antlrgen/ExpressLexer.cpp +645 -1129
  244. data/ext/express-parser/antlrgen/ExpressLexer.h +20 -27
  245. data/ext/express-parser/antlrgen/ExpressLexer.interp +1 -1
  246. data/ext/express-parser/antlrgen/ExpressListener.cpp +1 -1
  247. data/ext/express-parser/antlrgen/ExpressListener.h +1 -1
  248. data/ext/express-parser/antlrgen/ExpressParser.cpp +1754 -1447
  249. data/ext/express-parser/antlrgen/ExpressParser.h +219 -223
  250. data/ext/express-parser/antlrgen/ExpressVisitor.cpp +1 -1
  251. data/ext/express-parser/antlrgen/ExpressVisitor.h +200 -200
  252. data/ext/express-parser/express_parser.cpp +165 -101
  253. data/ext/express-parser/extconf.rb +14 -14
  254. data/lib/expressir/config.rb +1 -1
  255. data/lib/expressir/express/parser.rb +17 -15
  256. data/lib/expressir/express/visitor.rb +7 -3
  257. data/lib/expressir/model.rb +78 -78
  258. data/lib/expressir/version.rb +1 -1
  259. data/rakelib/antlr4-native.rake +161 -0
  260. data/rakelib/cross-ruby.rake +213 -162
  261. data/spec/acceptance/version_spec.rb +17 -2
  262. data/spec/expressir/express/cache_spec.rb +23 -5
  263. data/spec/expressir/express/formatter_spec.rb +54 -8
  264. data/spec/expressir/express/parser_spec.rb +47 -11
  265. data/spec/expressir/model/model_element_spec.rb +198 -146
  266. data/spec/spec_helper.rb +7 -0
  267. metadata +79 -91
  268. data/demo.rb +0 -18
  269. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNSerializer.cpp +0 -621
  270. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNSerializer.h +0 -61
  271. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/AbstractPredicateTransition.cpp +0 -14
  272. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/AbstractPredicateTransition.h +0 -24
  273. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/BasicBlockStartState.cpp +0 -12
  274. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/BasicState.cpp +0 -12
  275. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/BlockEndState.cpp +0 -15
  276. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/BlockStartState.cpp +0 -9
  277. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/EmptyPredictionContext.cpp +0 -35
  278. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/EmptyPredictionContext.h +0 -27
  279. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LoopEndState.cpp +0 -12
  280. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/Makefile +0 -67
  281. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PlusBlockStartState.cpp +0 -12
  282. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PlusLoopbackState.cpp +0 -12
  283. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/RuleStartState.cpp +0 -16
  284. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/RuleStopState.cpp +0 -12
  285. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/StarBlockStartState.cpp +0 -12
  286. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/StarLoopEntryState.cpp +0 -15
  287. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/TokensStartState.cpp +0 -12
  288. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/guid.cpp +0 -303
  289. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/guid.h +0 -112
  290. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ErrorNode.cpp +0 -9
  291. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/TerminalNode.cpp +0 -9
  292. data/original/examples/ap233/ap233e1_arm_lf_stepmod-2010-11-12.exp +0 -9589
  293. data/original/examples/ap233/ap233e1_arm_lf_stepmod-2010-11-12.owl +0 -36619
  294. data/original/examples/ap233/ap233e1_arm_lf_stepmod-2010-11-12.xml +0 -13294
  295. data/original/examples/employment/eclipse/.project +0 -17
  296. data/original/examples/employment/eclipse/Export/Employment.png +0 -0
  297. data/original/examples/employment/eclipse/Express/employment_schema.exp +0 -33
  298. data/original/examples/employment/eclipse/Express/employment_schema.xmi +0 -77
  299. data/original/examples/employment/eclipse/Express/employment_schema.xml +0 -93
  300. data/original/examples/employment/eclipse/Models/Employment.uml +0 -4
  301. data/original/examples/employment/eclipse/Models/Employment.umldi +0 -240
  302. data/original/examples/employment/eclipse/readme.txt +0 -7
  303. data/original/examples/employment/employment_schema.exp +0 -33
  304. data/original/examples/employment/employment_schema.rb +0 -232
  305. data/original/examples/employment/employment_schema.xml +0 -93
  306. data/original/examples/employment/employment_schema___module.rb +0 -46
  307. data/original/examples/employment/employment_schema___p28attr.rb +0 -126
  308. data/original/examples/employment/employment_schema___p28inst.rb +0 -26
  309. data/original/examples/employment/example_employment_data.xml +0 -1
  310. data/original/examples/employment/example_employment_data_copy.xml +0 -1
  311. data/original/examples/employment/example_employment_reader.rb +0 -30
  312. data/original/examples/employment/example_employment_writer.rb +0 -51
  313. data/original/examples/plcs/ap239e1_arm_lf_dexlib_2010-01-06.exp +0 -3710
  314. data/original/examples/plcs/ap239e1_arm_lf_dexlib_2010-01-06.owl +0 -35880
  315. data/original/examples/plcs/ap239e1_arm_lf_dexlib_2010-01-06.xmi +0 -15357
  316. data/original/examples/plcs/ap239e1_arm_lf_dexlib_2010-01-06.xml +0 -9468
  317. data/original/examples/plcs/ap239e2_arm_lf_stepmod-2010-01-25.exp +0 -8404
  318. data/original/examples/plcs/ap239e2_arm_lf_stepmod-2010-01-25.owl +0 -43147
  319. data/original/examples/plcs/ap239e2_arm_lf_stepmod-2010-01-25.xmi +0 -18341
  320. data/original/examples/plcs/ap239e2_arm_lf_stepmod-2010-01-25.xml +0 -11632
  321. data/original/exp2ruby.rb +0 -525
  322. data/original/expsm.rb +0 -34
  323. data/original/mapping_owl.rb +0 -1018
  324. data/original/mapping_sysml.rb +0 -2281
  325. data/original/mapping_uml2.rb +0 -599
  326. data/original/mapping_uml2_eclipse.rb +0 -433
  327. data/original/reeper.rb +0 -134
  328. data/spec/expressr_spec.rb +0 -5
@@ -33,12 +33,13 @@
33
33
  #include "atn/SetTransition.h"
34
34
  #include "atn/NotSetTransition.h"
35
35
  #include "atn/WildcardTransition.h"
36
+ #include "atn/TransitionType.h"
36
37
  #include "Token.h"
37
38
 
38
39
  #include "misc/IntervalSet.h"
39
40
  #include "Exceptions.h"
40
41
  #include "support/CPPUtils.h"
41
- #include "support/StringUtils.h"
42
+ #include "support/Casts.h"
42
43
 
43
44
  #include "atn/LexerCustomAction.h"
44
45
  #include "atn/LexerChannelAction.h"
@@ -51,118 +52,210 @@
51
52
 
52
53
  #include "atn/ATNDeserializer.h"
53
54
 
55
+ #include <cassert>
56
+ #include <mutex>
54
57
  #include <string>
58
+ #include <vector>
55
59
 
56
60
  using namespace antlr4;
57
61
  using namespace antlr4::atn;
58
62
  using namespace antlrcpp;
59
63
 
60
- const size_t ATNDeserializer::SERIALIZED_VERSION = 3;
61
-
62
64
  namespace {
63
65
 
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
- }
66
+ void checkCondition(bool condition, std::string_view message) {
67
+ if (!condition) {
68
+ throw IllegalStateException(std::string(message));
69
+ }
70
+ }
71
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
- }
72
+ void checkCondition(bool condition) {
73
+ checkCondition(condition, "");
74
+ }
77
75
 
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
- }
76
+ /**
77
+ * Analyze the {@link StarLoopEntryState} states in the specified ATN to set
78
+ * the {@link StarLoopEntryState#isPrecedenceDecision} field to the
79
+ * correct value.
80
+ *
81
+ * @param atn The ATN.
82
+ */
83
+ void markPrecedenceDecisions(const ATN &atn) {
84
+ for (ATNState *state : atn.states) {
85
+ if (!StarLoopEntryState::is(state)) {
86
+ continue;
87
+ }
95
88
 
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);
89
+ /* We analyze the ATN to determine if this ATN decision state is the
90
+ * decision for the closure block that determines whether a
91
+ * precedence rule should continue or complete.
92
+ */
93
+ if (atn.ruleToStartState[state->ruleIndex]->isLeftRecursiveRule) {
94
+ ATNState *maybeLoopEndState = state->transitions[state->transitions.size() - 1]->target;
95
+ if (LoopEndState::is(maybeLoopEndState)) {
96
+ if (maybeLoopEndState->epsilonOnlyTransitions && RuleStopState::is(maybeLoopEndState->transitions[0]->target)) {
97
+ downCast<StarLoopEntryState*>(state)->isPrecedenceDecision = true;
98
+ }
99
+ }
100
+ }
100
101
  }
101
- sets.push_back(set);
102
102
  }
103
- }
104
103
 
105
- }
104
+ Ref<const LexerAction> lexerActionFactory(LexerActionType type, int data1, int data2) {
105
+ switch (type) {
106
+ case LexerActionType::CHANNEL:
107
+ return std::make_shared<LexerChannelAction>(data1);
106
108
 
107
- ATNDeserializer::ATNDeserializer(): ATNDeserializer(ATNDeserializationOptions::getDefaultOptions()) {
108
- }
109
+ case LexerActionType::CUSTOM:
110
+ return std::make_shared<LexerCustomAction>(data1, data2);
109
111
 
110
- ATNDeserializer::ATNDeserializer(const ATNDeserializationOptions& dso): deserializationOptions(dso) {
111
- }
112
+ case LexerActionType::MODE:
113
+ return std::make_shared< LexerModeAction>(data1);
112
114
 
113
- ATNDeserializer::~ATNDeserializer() {
114
- }
115
+ case LexerActionType::MORE:
116
+ return LexerMoreAction::getInstance();
115
117
 
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
- }
118
+ case LexerActionType::POP_MODE:
119
+ return LexerPopModeAction::getInstance();
123
120
 
124
- Guid ATNDeserializer::ADDED_LEXER_ACTIONS() {
125
- return Guid("AADB8D7E-AEEF-4415-AD2B-8204D6CF042E");
126
- }
121
+ case LexerActionType::PUSH_MODE:
122
+ return std::make_shared<LexerPushModeAction>(data1);
127
123
 
128
- Guid ATNDeserializer::ADDED_UNICODE_SMP() {
129
- return Guid("59627784-3BE5-417A-B9EB-8131A7286089");
130
- }
124
+ case LexerActionType::SKIP:
125
+ return LexerSkipAction::getInstance();
131
126
 
132
- Guid ATNDeserializer::SERIALIZED_UUID() {
133
- return ADDED_UNICODE_SMP();
134
- }
127
+ case LexerActionType::TYPE:
128
+ return std::make_shared<LexerTypeAction>(data1);
135
129
 
136
- Guid ATNDeserializer::BASE_SERIALIZED_UUID() {
137
- return Guid("33761B2D-78BB-4A43-8B0B-4F5BEE8AACF3");
138
- }
130
+ default:
131
+ throw IllegalArgumentException("The specified lexer action type " + std::to_string(static_cast<size_t>(type)) +
132
+ " is not valid.");
133
+ }
134
+ }
139
135
 
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
- }
136
+ ConstTransitionPtr edgeFactory(const ATN &atn, TransitionType type, size_t trg, size_t arg1, size_t arg2,
137
+ size_t arg3, const std::vector<misc::IntervalSet> &sets) {
138
+ ATNState *target = atn.states[trg];
139
+ switch (type) {
140
+ case TransitionType::EPSILON:
141
+ return std::make_unique<EpsilonTransition>(target);
142
+ case TransitionType::RANGE:
143
+ if (arg3 != 0) {
144
+ return std::make_unique<RangeTransition>(target, Token::EOF, arg2);
145
+ } else {
146
+ return std::make_unique<RangeTransition>(target, arg1, arg2);
147
+ }
148
+ case TransitionType::RULE:
149
+ return std::make_unique<RuleTransition>(downCast<RuleStartState*>(atn.states[arg1]), arg2, (int)arg3, target);
150
+ case TransitionType::PREDICATE:
151
+ return std::make_unique<PredicateTransition>(target, arg1, arg2, arg3 != 0);
152
+ case TransitionType::PRECEDENCE:
153
+ return std::make_unique<PrecedencePredicateTransition>(target, (int)arg1);
154
+ case TransitionType::ATOM:
155
+ if (arg3 != 0) {
156
+ return std::make_unique<AtomTransition>(target, Token::EOF);
157
+ } else {
158
+ return std::make_unique<AtomTransition>(target, arg1);
159
+ }
160
+ case TransitionType::ACTION:
161
+ return std::make_unique<ActionTransition>(target, arg1, arg2, arg3 != 0);
162
+ case TransitionType::SET:
163
+ return std::make_unique<SetTransition>(target, sets[arg1]);
164
+ case TransitionType::NOT_SET:
165
+ return std::make_unique<NotSetTransition>(target, sets[arg1]);
166
+ case TransitionType::WILDCARD:
167
+ return std::make_unique<WildcardTransition>(target);
168
+ }
169
+
170
+ throw IllegalArgumentException("The specified transition type is not valid.");
171
+ }
144
172
 
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;
173
+ /* mem check: all created instances are freed in the d-tor of the ATN. */
174
+ ATNState* stateFactory(ATNStateType type, size_t ruleIndex) {
175
+ ATNState *s;
176
+ switch (type) {
177
+ case ATNStateType::INVALID:
178
+ return nullptr;
179
+ case ATNStateType::BASIC :
180
+ s = new BasicState();
181
+ break;
182
+ case ATNStateType::RULE_START :
183
+ s = new RuleStartState();
184
+ break;
185
+ case ATNStateType::BLOCK_START :
186
+ s = new BasicBlockStartState();
187
+ break;
188
+ case ATNStateType::PLUS_BLOCK_START :
189
+ s = new PlusBlockStartState();
190
+ break;
191
+ case ATNStateType::STAR_BLOCK_START :
192
+ s = new StarBlockStartState();
193
+ break;
194
+ case ATNStateType::TOKEN_START :
195
+ s = new TokensStartState();
196
+ break;
197
+ case ATNStateType::RULE_STOP :
198
+ s = new RuleStopState();
199
+ break;
200
+ case ATNStateType::BLOCK_END :
201
+ s = new BlockEndState();
202
+ break;
203
+ case ATNStateType::STAR_LOOP_BACK :
204
+ s = new StarLoopbackState();
205
+ break;
206
+ case ATNStateType::STAR_LOOP_ENTRY :
207
+ s = new StarLoopEntryState();
208
+ break;
209
+ case ATNStateType::PLUS_LOOP_BACK :
210
+ s = new PlusLoopbackState();
211
+ break;
212
+ case ATNStateType::LOOP_END :
213
+ s = new LoopEndState();
214
+ break;
215
+ default :
216
+ std::string message = "The specified state type " + std::to_string(static_cast<size_t>(type)) + " is not valid.";
217
+ throw IllegalArgumentException(message);
218
+ }
219
+ assert(s->getStateType() == type);
220
+ s->ruleIndex = ruleIndex;
221
+ return s;
149
222
  }
150
- auto actualIterator = std::find(SUPPORTED_UUIDS().begin(), SUPPORTED_UUIDS().end(), actualUuid);
151
- if (actualIterator == SUPPORTED_UUIDS().end()) {
152
- return false;
223
+
224
+ ssize_t readUnicodeInt32(SerializedATNView data, int& p) {
225
+ return static_cast<ssize_t>(data[p++]);
153
226
  }
154
227
 
155
- return std::distance(featureIterator, actualIterator) >= 0;
156
- }
228
+ void deserializeSets(
229
+ SerializedATNView data,
230
+ int& p,
231
+ std::vector<misc::IntervalSet>& sets) {
232
+ size_t nsets = data[p++];
233
+ sets.reserve(sets.size() + nsets);
234
+ for (size_t i = 0; i < nsets; i++) {
235
+ size_t nintervals = data[p++];
236
+ misc::IntervalSet set;
237
+
238
+ bool containsEof = data[p++] != 0;
239
+ if (containsEof) {
240
+ set.add(-1);
241
+ }
157
242
 
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;
243
+ for (size_t j = 0; j < nintervals; j++) {
244
+ auto a = readUnicodeInt32(data, p);
245
+ auto b = readUnicodeInt32(data, p);
246
+ set.add(a, b);
247
+ }
248
+ sets.push_back(set);
249
+ }
164
250
  }
165
251
 
252
+ }
253
+
254
+ ATNDeserializer::ATNDeserializer() : ATNDeserializer(ATNDeserializationOptions::getDefaultOptions()) {}
255
+
256
+ ATNDeserializer::ATNDeserializer(ATNDeserializationOptions deserializationOptions) : _deserializationOptions(std::move(deserializationOptions)) {}
257
+
258
+ std::unique_ptr<ATN> ATNDeserializer::deserialize(SerializedATNView data) const {
166
259
  int p = 0;
167
260
  int version = data[p++];
168
261
  if (version != SERIALIZED_VERSION) {
@@ -171,60 +264,48 @@ ATN ATNDeserializer::deserialize(const std::vector<uint16_t>& input) {
171
264
  throw UnsupportedOperationException(reason);
172
265
  }
173
266
 
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
267
  ATNType grammarType = (ATNType)data[p++];
188
268
  size_t maxTokenType = data[p++];
189
- ATN atn(grammarType, maxTokenType);
269
+ auto atn = std::make_unique<ATN>(grammarType, maxTokenType);
190
270
 
191
271
  //
192
272
  // STATES
193
273
  //
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
- }
274
+ {
275
+ std::vector<std::pair<LoopEndState*, size_t>> loopBackStateNumbers;
276
+ std::vector<std::pair<BlockStartState*, size_t>> endStateNumbers;
277
+ size_t nstates = data[p++];
278
+ atn->states.reserve(nstates);
279
+ loopBackStateNumbers.reserve(nstates); // Reserve worst case size, its short lived.
280
+ endStateNumbers.reserve(nstates); // Reserve worst case size, its short lived.
281
+ for (size_t i = 0; i < nstates; i++) {
282
+ ATNStateType stype = static_cast<ATNStateType>(data[p++]);
283
+ // ignore bad type of states
284
+ if (stype == ATNStateType::INVALID) {
285
+ atn->addState(nullptr);
286
+ continue;
287
+ }
204
288
 
205
- size_t ruleIndex = data[p++];
206
- if (ruleIndex == 0xFFFF) {
207
- ruleIndex = INVALID_INDEX;
289
+ size_t ruleIndex = data[p++];
290
+ ATNState *s = stateFactory(stype, ruleIndex);
291
+ if (stype == ATNStateType::LOOP_END) { // special case
292
+ int loopBackStateNumber = data[p++];
293
+ loopBackStateNumbers.push_back({ downCast<LoopEndState*>(s), loopBackStateNumber });
294
+ } else if (BlockStartState::is(s)) {
295
+ int endStateNumber = data[p++];
296
+ endStateNumbers.push_back({ downCast<BlockStartState*>(s), endStateNumber });
297
+ }
298
+ atn->addState(s);
208
299
  }
209
300
 
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 });
301
+ // delay the assignment of loop back and end states until we know all the state instances have been initialized
302
+ for (auto &pair : loopBackStateNumbers) {
303
+ pair.first->loopBackState = atn->states[pair.second];
217
304
  }
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
305
 
226
- for (auto &pair : endStateNumbers) {
227
- pair.first->endState = (BlockEndState*)atn.states[pair.second];
306
+ for (auto &pair : endStateNumbers) {
307
+ pair.first->endState = downCast<BlockEndState*>(atn->states[pair.second]);
308
+ }
228
309
  }
229
310
 
230
311
  size_t numNonGreedyStates = data[p++];
@@ -232,118 +313,102 @@ ATN ATNDeserializer::deserialize(const std::vector<uint16_t>& input) {
232
313
  size_t stateNumber = data[p++];
233
314
  // The serialized ATN must be specifying the right states, so that the
234
315
  // cast below is correct.
235
- ((DecisionState *)atn.states[stateNumber])->nonGreedy = true;
316
+ downCast<DecisionState*>(atn->states[stateNumber])->nonGreedy = true;
236
317
  }
237
318
 
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
- }
319
+ size_t numPrecedenceStates = data[p++];
320
+ for (size_t i = 0; i < numPrecedenceStates; i++) {
321
+ size_t stateNumber = data[p++];
322
+ downCast<RuleStartState*>(atn->states[stateNumber])->isLeftRecursiveRule = true;
244
323
  }
245
324
 
246
325
  //
247
326
  // RULES
248
327
  //
249
328
  size_t nrules = data[p++];
329
+ atn->ruleToStartState.reserve(nrules);
250
330
  for (size_t i = 0; i < nrules; i++) {
251
331
  size_t s = data[p++];
252
332
  // 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) {
333
+ RuleStartState *startState = downCast<RuleStartState*>(atn->states[s]);
334
+ atn->ruleToStartState.push_back(startState);
335
+ if (atn->grammarType == ATNType::LEXER) {
256
336
  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
- }
337
+ atn->ruleToTokenType.push_back(tokenType);
269
338
  }
270
339
  }
271
340
 
272
- atn.ruleToStopState.resize(nrules);
273
- for (ATNState *state : atn.states) {
274
- if (!is<RuleStopState*>(state)) {
341
+ atn->ruleToStopState.resize(nrules);
342
+ for (ATNState *state : atn->states) {
343
+ if (!RuleStopState::is(state)) {
275
344
  continue;
276
345
  }
277
346
 
278
- RuleStopState *stopState = static_cast<RuleStopState*>(state);
279
- atn.ruleToStopState[state->ruleIndex] = stopState;
280
- atn.ruleToStartState[state->ruleIndex]->stopState = stopState;
347
+ RuleStopState *stopState = downCast<RuleStopState*>(state);
348
+ atn->ruleToStopState[state->ruleIndex] = stopState;
349
+ atn->ruleToStartState[state->ruleIndex]->stopState = stopState;
281
350
  }
282
351
 
283
352
  //
284
353
  // MODES
285
354
  //
286
355
  size_t nmodes = data[p++];
356
+ atn->modeToStartState.reserve(nmodes);
287
357
  for (size_t i = 0; i < nmodes; i++) {
288
358
  size_t s = data[p++];
289
- atn.modeToStartState.push_back(static_cast<TokensStartState*>(atn.states[s]));
359
+ atn->modeToStartState.push_back(downCast<TokensStartState*>(atn->states[s]));
290
360
  }
291
361
 
292
362
  //
293
363
  // SETS
294
364
  //
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;
365
+ {
366
+ std::vector<misc::IntervalSet> sets;
367
+
368
+ deserializeSets(data, p, sets);
369
+ sets.shrink_to_fit();
370
+
371
+ //
372
+ // EDGES
373
+ //
374
+ int nedges = data[p++];
375
+ for (int i = 0; i < nedges; i++) {
376
+ size_t src = data[p];
377
+ size_t trg = data[p + 1];
378
+ TransitionType ttype = static_cast<TransitionType>(data[p + 2]);
379
+ size_t arg1 = data[p + 3];
380
+ size_t arg2 = data[p + 4];
381
+ size_t arg3 = data[p + 5];
382
+ ConstTransitionPtr trans = edgeFactory(*atn, ttype, trg, arg1, arg2, arg3, sets);
383
+ ATNState *srcState = atn->states[src];
384
+ srcState->addTransition(std::move(trans));
385
+ p += 6;
386
+ }
321
387
  }
322
-
323
388
  // edges for rule stop states can be derived, so they aren't serialized
324
- for (ATNState *state : atn.states) {
389
+ for (ATNState *state : atn->states) {
325
390
  for (size_t i = 0; i < state->transitions.size(); i++) {
326
- Transition *t = state->transitions[i];
327
- if (!is<RuleTransition*>(t)) {
391
+ const Transition *t = state->transitions[i].get();
392
+ if (!RuleTransition::is(t)) {
328
393
  continue;
329
394
  }
330
395
 
331
- RuleTransition *ruleTransition = static_cast<RuleTransition*>(t);
396
+ const RuleTransition *ruleTransition = downCast<const RuleTransition*>(t);
332
397
  size_t outermostPrecedenceReturn = INVALID_INDEX;
333
- if (atn.ruleToStartState[ruleTransition->target->ruleIndex]->isLeftRecursiveRule) {
398
+ if (atn->ruleToStartState[ruleTransition->target->ruleIndex]->isLeftRecursiveRule) {
334
399
  if (ruleTransition->precedence == 0) {
335
400
  outermostPrecedenceReturn = ruleTransition->target->ruleIndex;
336
401
  }
337
402
  }
338
403
 
339
- EpsilonTransition *returnTransition = new EpsilonTransition(ruleTransition->followState, outermostPrecedenceReturn); /* mem check: freed in ANTState d-tor */
340
- atn.ruleToStopState[ruleTransition->target->ruleIndex]->addTransition(returnTransition);
404
+ ConstTransitionPtr returnTransition = std::make_unique<EpsilonTransition>(ruleTransition->followState, outermostPrecedenceReturn);
405
+ atn->ruleToStopState[ruleTransition->target->ruleIndex]->addTransition(std::move(returnTransition));
341
406
  }
342
407
  }
343
408
 
344
- for (ATNState *state : atn.states) {
345
- if (is<BlockStartState *>(state)) {
346
- BlockStartState *startState = static_cast<BlockStartState *>(state);
409
+ for (ATNState *state : atn->states) {
410
+ if (BlockStartState::is(state)) {
411
+ BlockStartState *startState = downCast<BlockStartState*>(state);
347
412
 
348
413
  // we need to know the end state to set its start state
349
414
  if (startState->endState == nullptr) {
@@ -355,23 +420,23 @@ ATN ATNDeserializer::deserialize(const std::vector<uint16_t>& input) {
355
420
  throw IllegalStateException();
356
421
  }
357
422
 
358
- startState->endState->startState = static_cast<BlockStartState*>(state);
423
+ startState->endState->startState = downCast<BlockStartState*>(state);
359
424
  }
360
425
 
361
- if (is<PlusLoopbackState*>(state)) {
362
- PlusLoopbackState *loopbackState = static_cast<PlusLoopbackState *>(state);
426
+ if (PlusLoopbackState::is(state)) {
427
+ PlusLoopbackState *loopbackState = downCast<PlusLoopbackState*>(state);
363
428
  for (size_t i = 0; i < loopbackState->transitions.size(); i++) {
364
429
  ATNState *target = loopbackState->transitions[i]->target;
365
- if (is<PlusBlockStartState *>(target)) {
366
- (static_cast<PlusBlockStartState *>(target))->loopBackState = loopbackState;
430
+ if (PlusBlockStartState::is(target)) {
431
+ (downCast<PlusBlockStartState*>(target))->loopBackState = loopbackState;
367
432
  }
368
433
  }
369
- } else if (is<StarLoopbackState *>(state)) {
370
- StarLoopbackState *loopbackState = static_cast<StarLoopbackState *>(state);
434
+ } else if (StarLoopbackState::is(state)) {
435
+ StarLoopbackState *loopbackState = downCast<StarLoopbackState*>(state);
371
436
  for (size_t i = 0; i < loopbackState->transitions.size(); i++) {
372
437
  ATNState *target = loopbackState->transitions[i]->target;
373
- if (is<StarLoopEntryState *>(target)) {
374
- (static_cast<StarLoopEntryState*>(target))->loopBackState = loopbackState;
438
+ if (StarLoopEntryState::is(target)) {
439
+ downCast<StarLoopEntryState*>(target)->loopBackState = loopbackState;
375
440
  }
376
441
  }
377
442
  }
@@ -381,104 +446,76 @@ ATN ATNDeserializer::deserialize(const std::vector<uint16_t>& input) {
381
446
  // DECISIONS
382
447
  //
383
448
  size_t ndecisions = data[p++];
384
- for (size_t i = 1; i <= ndecisions; i++) {
449
+ atn->decisionToState.reserve(ndecisions);
450
+ for (size_t i = 0; i < ndecisions; i++) {
385
451
  size_t s = data[p++];
386
- DecisionState *decState = dynamic_cast<DecisionState*>(atn.states[s]);
452
+ DecisionState *decState = downCast<DecisionState*>(atn->states[s]);
387
453
  if (decState == nullptr)
388
454
  throw IllegalStateException();
389
455
 
390
- atn.decisionToState.push_back(decState);
391
- decState->decision = (int)i - 1;
456
+ atn->decisionToState.push_back(decState);
457
+ decState->decision = static_cast<int>(i);
392
458
  }
393
459
 
394
460
  //
395
461
  // LEXER ACTIONS
396
462
  //
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
- }
463
+ if (atn->grammarType == ATNType::LEXER) {
464
+ atn->lexerActions.resize(data[p++]);
465
+ for (size_t i = 0; i < atn->lexerActions.size(); i++) {
466
+ LexerActionType actionType = static_cast<LexerActionType>(data[p++]);
467
+ int data1 = data[p++];
468
+ int data2 = data[p++];
469
+ atn->lexerActions[i] = lexerActionFactory(actionType, data1, data2);
433
470
  }
434
471
  }
435
472
 
436
- markPrecedenceDecisions(atn);
473
+ markPrecedenceDecisions(*atn);
437
474
 
438
- if (deserializationOptions.isVerifyATN()) {
439
- verifyATN(atn);
475
+ if (_deserializationOptions.isVerifyATN()) {
476
+ verifyATN(*atn);
440
477
  }
441
478
 
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);
479
+ if (_deserializationOptions.isGenerateRuleBypassTransitions() && atn->grammarType == ATNType::PARSER) {
480
+ atn->ruleToTokenType.resize(atn->ruleToStartState.size());
481
+ for (size_t i = 0; i < atn->ruleToStartState.size(); i++) {
482
+ atn->ruleToTokenType[i] = static_cast<int>(atn->maxTokenType + i + 1);
446
483
  }
447
484
 
448
- for (std::vector<RuleStartState*>::size_type i = 0; i < atn.ruleToStartState.size(); i++) {
485
+ for (std::vector<RuleStartState*>::size_type i = 0; i < atn->ruleToStartState.size(); i++) {
449
486
  BasicBlockStartState *bypassStart = new BasicBlockStartState(); /* mem check: freed in ATN d-tor */
450
- bypassStart->ruleIndex = (int)i;
451
- atn.addState(bypassStart);
487
+ bypassStart->ruleIndex = static_cast<int>(i);
488
+ atn->addState(bypassStart);
452
489
 
453
490
  BlockEndState *bypassStop = new BlockEndState(); /* mem check: freed in ATN d-tor */
454
- bypassStop->ruleIndex = (int)i;
455
- atn.addState(bypassStop);
491
+ bypassStop->ruleIndex = static_cast<int>(i);
492
+ atn->addState(bypassStop);
456
493
 
457
494
  bypassStart->endState = bypassStop;
458
- atn.defineDecisionState(bypassStart);
495
+ atn->defineDecisionState(bypassStart);
459
496
 
460
497
  bypassStop->startState = bypassStart;
461
498
 
462
499
  ATNState *endState;
463
- Transition *excludeTransition = nullptr;
464
- if (atn.ruleToStartState[i]->isLeftRecursiveRule) {
500
+ const Transition *excludeTransition = nullptr;
501
+ if (atn->ruleToStartState[i]->isLeftRecursiveRule) {
465
502
  // wrap from the beginning of the rule to the StarLoopEntryState
466
503
  endState = nullptr;
467
- for (ATNState *state : atn.states) {
504
+ for (ATNState *state : atn->states) {
468
505
  if (state->ruleIndex != i) {
469
506
  continue;
470
507
  }
471
508
 
472
- if (!is<StarLoopEntryState*>(state)) {
509
+ if (!StarLoopEntryState::is(state)) {
473
510
  continue;
474
511
  }
475
512
 
476
513
  ATNState *maybeLoopEndState = state->transitions[state->transitions.size() - 1]->target;
477
- if (!is<LoopEndState*>(maybeLoopEndState)) {
514
+ if (!LoopEndState::is(maybeLoopEndState)) {
478
515
  continue;
479
516
  }
480
517
 
481
- if (maybeLoopEndState->epsilonOnlyTransitions && is<RuleStopState*>(maybeLoopEndState->transitions[0]->target)) {
518
+ if (maybeLoopEndState->epsilonOnlyTransitions && RuleStopState::is(maybeLoopEndState->transitions[0]->target)) {
482
519
  endState = state;
483
520
  break;
484
521
  }
@@ -489,78 +526,50 @@ ATN ATNDeserializer::deserialize(const std::vector<uint16_t>& input) {
489
526
 
490
527
  }
491
528
 
492
- excludeTransition = (static_cast<StarLoopEntryState*>(endState))->loopBackState->transitions[0];
529
+ excludeTransition = (static_cast<StarLoopEntryState*>(endState))->loopBackState->transitions[0].get();
493
530
  } else {
494
- endState = atn.ruleToStopState[i];
531
+ endState = atn->ruleToStopState[i];
495
532
  }
496
533
 
497
534
  // 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) {
535
+ for (ATNState *state : atn->states) {
536
+ for (auto &transition : state->transitions) {
537
+ if (transition.get() == excludeTransition) {
501
538
  continue;
502
539
  }
503
540
 
504
541
  if (transition->target == endState) {
505
- transition->target = bypassStop;
542
+ const_cast<Transition*>(transition.get())->target = bypassStop;
506
543
  }
507
544
  }
508
545
  }
509
546
 
510
547
  // 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);
548
+ while (atn->ruleToStartState[i]->transitions.size() > 0) {
549
+ ConstTransitionPtr transition = atn->ruleToStartState[i]->removeTransition(atn->ruleToStartState[i]->transitions.size() - 1);
550
+ bypassStart->addTransition(std::move(transition));
514
551
  }
515
552
 
516
553
  // 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 */
554
+ atn->ruleToStartState[i]->addTransition(std::make_unique<EpsilonTransition>(bypassStart));
555
+ bypassStop->addTransition(std::make_unique<EpsilonTransition>(endState));
519
556
 
520
557
  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 */
558
+ atn->addState(matchState);
559
+ matchState->addTransition(std::make_unique<AtomTransition>(bypassStop, atn->ruleToTokenType[i]));
560
+ bypassStart->addTransition(std::make_unique<EpsilonTransition>(matchState));
524
561
  }
525
562
 
526
- if (deserializationOptions.isVerifyATN()) {
563
+ if (_deserializationOptions.isVerifyATN()) {
527
564
  // reverify after modification
528
- verifyATN(atn);
565
+ verifyATN(*atn);
529
566
  }
530
567
  }
531
568
 
532
569
  return atn;
533
570
  }
534
571
 
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) {
572
+ void ATNDeserializer::verifyATN(const ATN &atn) const {
564
573
  // verify assumptions
565
574
  for (ATNState *state : atn.states) {
566
575
  if (state == nullptr) {
@@ -569,190 +578,52 @@ void ATNDeserializer::verifyATN(const ATN &atn) {
569
578
 
570
579
  checkCondition(state->epsilonOnlyTransitions || state->transitions.size() <= 1);
571
580
 
572
- if (is<PlusBlockStartState *>(state)) {
573
- checkCondition((static_cast<PlusBlockStartState *>(state))->loopBackState != nullptr);
581
+ if (PlusBlockStartState::is(state)) {
582
+ checkCondition((downCast<PlusBlockStartState*>(state))->loopBackState != nullptr);
574
583
  }
575
584
 
576
- if (is<StarLoopEntryState *>(state)) {
577
- StarLoopEntryState *starLoopEntryState = static_cast<StarLoopEntryState*>(state);
585
+ if (StarLoopEntryState::is(state)) {
586
+ StarLoopEntryState *starLoopEntryState = downCast<StarLoopEntryState*>(state);
578
587
  checkCondition(starLoopEntryState->loopBackState != nullptr);
579
588
  checkCondition(starLoopEntryState->transitions.size() == 2);
580
589
 
581
- if (is<StarBlockStartState *>(starLoopEntryState->transitions[0]->target)) {
582
- checkCondition(static_cast<LoopEndState *>(starLoopEntryState->transitions[1]->target) != nullptr);
590
+ if (StarBlockStartState::is(starLoopEntryState->transitions[0]->target)) {
591
+ checkCondition(downCast<LoopEndState*>(starLoopEntryState->transitions[1]->target) != nullptr);
583
592
  checkCondition(!starLoopEntryState->nonGreedy);
584
- } else if (is<LoopEndState *>(starLoopEntryState->transitions[0]->target)) {
585
- checkCondition(is<StarBlockStartState *>(starLoopEntryState->transitions[1]->target));
593
+ } else if (LoopEndState::is(starLoopEntryState->transitions[0]->target)) {
594
+ checkCondition(StarBlockStartState::is(starLoopEntryState->transitions[1]->target));
586
595
  checkCondition(starLoopEntryState->nonGreedy);
587
596
  } else {
588
597
  throw IllegalStateException();
589
-
590
598
  }
591
599
  }
592
600
 
593
- if (is<StarLoopbackState *>(state)) {
601
+ if (StarLoopbackState::is(state)) {
594
602
  checkCondition(state->transitions.size() == 1);
595
- checkCondition(is<StarLoopEntryState *>(state->transitions[0]->target));
603
+ checkCondition(StarLoopEntryState::is(state->transitions[0]->target));
596
604
  }
597
605
 
598
- if (is<LoopEndState *>(state)) {
599
- checkCondition((static_cast<LoopEndState *>(state))->loopBackState != nullptr);
606
+ if (LoopEndState::is(state)) {
607
+ checkCondition((downCast<LoopEndState*>(state))->loopBackState != nullptr);
600
608
  }
601
609
 
602
- if (is<RuleStartState *>(state)) {
603
- checkCondition((static_cast<RuleStartState *>(state))->stopState != nullptr);
610
+ if (RuleStartState::is(state)) {
611
+ checkCondition((downCast<RuleStartState*>(state))->stopState != nullptr);
604
612
  }
605
613
 
606
- if (is<BlockStartState *>(state)) {
607
- checkCondition((static_cast<BlockStartState *>(state))->endState != nullptr);
614
+ if (BlockStartState::is(state)) {
615
+ checkCondition((downCast<BlockStartState*>(state))->endState != nullptr);
608
616
  }
609
617
 
610
- if (is<BlockEndState *>(state)) {
611
- checkCondition((static_cast<BlockEndState *>(state))->startState != nullptr);
618
+ if (BlockEndState::is(state)) {
619
+ checkCondition((downCast<BlockEndState*>(state))->startState != nullptr);
612
620
  }
613
621
 
614
- if (is<DecisionState *>(state)) {
615
- DecisionState *decisionState = static_cast<DecisionState *>(state);
622
+ if (DecisionState::is(state)) {
623
+ DecisionState *decisionState = downCast<DecisionState*>(state);
616
624
  checkCondition(decisionState->transitions.size() <= 1 || decisionState->decision >= 0);
617
625
  } else {
618
- checkCondition(state->transitions.size() <= 1 || is<RuleStopState *>(state));
626
+ checkCondition(state->transitions.size() <= 1 || RuleStopState::is(state));
619
627
  }
620
628
  }
621
629
  }
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
- }