expressir 1.2.4 → 1.2.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (312) hide show
  1. checksums.yaml +4 -4
  2. data/.cross_rubies +0 -6
  3. data/.github/workflows/rake.yml +200 -21
  4. data/.gitignore +7 -2
  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 +12 -10
  16. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/CMakeLists.txt +44 -34
  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 +11 -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 +20 -20
  26. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/ANTLRFileStream.cpp +0 -6
  27. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/ANTLRInputStream.cpp +30 -19
  28. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/ANTLRInputStream.h +13 -10
  29. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/CommonToken.cpp +2 -4
  30. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/DefaultErrorStrategy.cpp +16 -13
  31. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/Exceptions.cpp +2 -2
  32. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/Exceptions.h +2 -2
  33. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/FailedPredicateException.cpp +5 -4
  34. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/FailedPredicateException.h +1 -1
  35. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/IntStream.h +0 -6
  36. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/Lexer.cpp +0 -1
  37. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/Lexer.h +0 -13
  38. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/LexerInterpreter.cpp +0 -15
  39. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/LexerInterpreter.h +1 -7
  40. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/Parser.cpp +47 -27
  41. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/Parser.h +0 -6
  42. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/ParserInterpreter.cpp +27 -39
  43. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/ParserInterpreter.h +1 -7
  44. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/ParserRuleContext.cpp +19 -22
  45. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/ParserRuleContext.h +20 -20
  46. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/RecognitionException.cpp +0 -1
  47. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/Recognizer.cpp +16 -27
  48. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/Recognizer.h +10 -21
  49. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/RuleContext.cpp +4 -3
  50. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/RuleContext.h +5 -1
  51. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/RuntimeMetaData.cpp +2 -1
  52. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/Token.h +0 -32
  53. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/TokenStreamRewriter.cpp +1 -1
  54. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/TokenStreamRewriter.h +2 -7
  55. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/UnbufferedCharStream.cpp +15 -18
  56. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/UnbufferedCharStream.h +12 -18
  57. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/Version.h +42 -0
  58. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/Vocabulary.cpp +13 -45
  59. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/Vocabulary.h +11 -26
  60. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/antlr4-common.h +19 -61
  61. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/antlr4-runtime.h +7 -5
  62. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATN.cpp +4 -55
  63. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATN.h +34 -20
  64. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNConfig.cpp +30 -35
  65. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNConfig.h +35 -32
  66. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNConfigSet.cpp +58 -54
  67. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNConfigSet.h +77 -31
  68. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNDeserializationOptions.cpp +22 -32
  69. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNDeserializationOptions.h +22 -24
  70. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNDeserializer.cpp +335 -462
  71. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNDeserializer.h +9 -68
  72. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNSimulator.cpp +9 -39
  73. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNSimulator.h +6 -22
  74. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNState.cpp +10 -26
  75. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNState.h +41 -42
  76. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNStateType.cpp +33 -0
  77. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNStateType.h +36 -0
  78. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ActionTransition.cpp +2 -6
  79. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ActionTransition.h +4 -2
  80. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ArrayPredictionContext.cpp +49 -22
  81. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ArrayPredictionContext.h +20 -12
  82. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/AtomTransition.cpp +1 -5
  83. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/AtomTransition.h +5 -2
  84. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/BasicBlockStartState.h +4 -2
  85. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/BasicState.h +4 -2
  86. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/BlockEndState.h +5 -3
  87. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/BlockStartState.h +10 -1
  88. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/DecisionInfo.h +1 -1
  89. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/DecisionState.cpp +0 -5
  90. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/DecisionState.h +12 -8
  91. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/EpsilonTransition.cpp +2 -6
  92. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/EpsilonTransition.h +6 -3
  93. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LL1Analyzer.cpp +139 -106
  94. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LL1Analyzer.h +9 -48
  95. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerATNConfig.cpp +16 -33
  96. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerATNConfig.h +12 -12
  97. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerATNSimulator.cpp +69 -82
  98. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerATNSimulator.h +15 -33
  99. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerAction.cpp +12 -6
  100. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerAction.h +45 -11
  101. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerActionExecutor.cpp +48 -44
  102. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerActionExecutor.h +31 -18
  103. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerActionType.h +3 -1
  104. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerChannelAction.cpp +14 -26
  105. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerChannelAction.h +12 -16
  106. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerCustomAction.cpp +15 -32
  107. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerCustomAction.h +12 -24
  108. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerIndexedCustomAction.cpp +23 -29
  109. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerIndexedCustomAction.h +13 -19
  110. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerModeAction.cpp +13 -26
  111. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerModeAction.h +12 -16
  112. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerMoreAction.cpp +6 -17
  113. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerMoreAction.h +12 -16
  114. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerPopModeAction.cpp +6 -17
  115. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerPopModeAction.h +12 -16
  116. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerPushModeAction.cpp +13 -26
  117. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerPushModeAction.h +12 -16
  118. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerSkipAction.cpp +6 -17
  119. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerSkipAction.h +11 -15
  120. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerTypeAction.cpp +13 -26
  121. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerTypeAction.h +13 -17
  122. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LoopEndState.h +5 -1
  123. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/NotSetTransition.cpp +1 -6
  124. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/NotSetTransition.h +4 -2
  125. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/OrderedATNConfigSet.cpp +6 -2
  126. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/OrderedATNConfigSet.h +8 -3
  127. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ParserATNSimulator.cpp +164 -151
  128. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ParserATNSimulator.h +26 -19
  129. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ParserATNSimulatorOptions.h +50 -0
  130. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PlusBlockStartState.h +5 -1
  131. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PlusLoopbackState.h +5 -2
  132. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PrecedencePredicateTransition.cpp +2 -11
  133. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PrecedencePredicateTransition.h +15 -9
  134. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredicateEvalInfo.cpp +2 -2
  135. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredicateEvalInfo.h +2 -2
  136. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredicateTransition.cpp +4 -14
  137. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredicateTransition.h +22 -11
  138. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredictionContext.cpp +255 -338
  139. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredictionContext.h +86 -127
  140. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredictionContextCache.cpp +56 -0
  141. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredictionContextCache.h +64 -0
  142. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredictionContextMergeCache.cpp +167 -0
  143. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredictionContextMergeCache.h +101 -0
  144. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredictionContextMergeCacheOptions.h +71 -0
  145. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredictionContextType.h +21 -0
  146. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredictionMode.cpp +18 -17
  147. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredictionMode.h +1 -1
  148. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ProfilingATNSimulator.cpp +2 -2
  149. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ProfilingATNSimulator.h +2 -2
  150. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/RangeTransition.cpp +1 -5
  151. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/RangeTransition.h +4 -2
  152. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/RuleStartState.h +4 -3
  153. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/RuleStopState.h +4 -2
  154. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/RuleTransition.cpp +1 -5
  155. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/RuleTransition.h +5 -3
  156. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/SemanticContext.cpp +197 -156
  157. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/SemanticContext.h +92 -81
  158. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/SemanticContextType.h +23 -0
  159. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/SerializedATNView.h +101 -0
  160. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/SetTransition.cpp +2 -6
  161. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/SetTransition.h +11 -3
  162. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/SingletonPredictionContext.cpp +39 -34
  163. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/SingletonPredictionContext.h +17 -10
  164. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/StarBlockStartState.h +5 -2
  165. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/StarLoopEntryState.h +4 -2
  166. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/StarLoopbackState.cpp +6 -6
  167. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/StarLoopbackState.h +6 -2
  168. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/TokensStartState.h +5 -2
  169. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/Transition.cpp +1 -9
  170. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/Transition.h +11 -22
  171. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/TransitionType.cpp +27 -0
  172. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/TransitionType.h +33 -0
  173. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/WildcardTransition.cpp +1 -5
  174. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/WildcardTransition.h +4 -2
  175. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/dfa/DFA.cpp +9 -21
  176. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/dfa/DFA.h +20 -15
  177. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/dfa/DFASerializer.cpp +1 -8
  178. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/dfa/DFASerializer.h +4 -4
  179. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/dfa/DFAState.cpp +9 -50
  180. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/dfa/DFAState.h +57 -48
  181. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/dfa/LexerDFASerializer.cpp +1 -4
  182. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/dfa/LexerDFASerializer.h +3 -4
  183. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/InterpreterDataReader.cpp +2 -2
  184. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/InterpreterDataReader.h +3 -1
  185. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/Interval.cpp +1 -29
  186. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/Interval.h +10 -10
  187. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/IntervalSet.cpp +7 -20
  188. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/IntervalSet.h +1 -9
  189. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/MurmurHash.cpp +54 -68
  190. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/MurmurHash.h +34 -14
  191. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/Any.cpp +0 -5
  192. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/Any.h +1 -155
  193. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/Arrays.h +39 -0
  194. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/BitSet.h +1 -1
  195. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/CPPUtils.cpp +12 -53
  196. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/CPPUtils.h +16 -29
  197. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/Casts.h +34 -0
  198. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/Declarations.h +0 -2
  199. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/StringUtils.cpp +25 -33
  200. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/StringUtils.h +2 -62
  201. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/Unicode.h +28 -0
  202. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/Utf8.cpp +242 -0
  203. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/Utf8.h +54 -0
  204. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/AbstractParseTreeVisitor.h +13 -12
  205. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ErrorNode.h +7 -2
  206. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ErrorNodeImpl.cpp +36 -5
  207. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ErrorNodeImpl.h +14 -4
  208. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/IterativeParseTreeWalker.cpp +14 -19
  209. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ParseTree.cpp +0 -3
  210. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ParseTree.h +13 -4
  211. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ParseTreeType.h +22 -0
  212. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ParseTreeVisitor.h +4 -4
  213. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ParseTreeWalker.cpp +8 -9
  214. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ParseTreeWalker.h +4 -4
  215. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/TerminalNode.h +10 -2
  216. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/TerminalNodeImpl.cpp +2 -5
  217. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/TerminalNodeImpl.h +4 -5
  218. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/pattern/ParseTreePatternMatcher.cpp +1 -2
  219. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathLexer.cpp +128 -119
  220. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathLexer.h +18 -27
  221. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/tests/Utf8Test.cpp +110 -0
  222. data/ext/express-parser/antlrgen/Express.interp +1 -1
  223. data/ext/express-parser/antlrgen/ExpressBaseListener.cpp +1 -1
  224. data/ext/express-parser/antlrgen/ExpressBaseListener.h +1 -1
  225. data/ext/express-parser/antlrgen/ExpressBaseVisitor.cpp +1 -1
  226. data/ext/express-parser/antlrgen/ExpressBaseVisitor.h +200 -200
  227. data/ext/express-parser/antlrgen/ExpressLexer.cpp +645 -1129
  228. data/ext/express-parser/antlrgen/ExpressLexer.h +20 -27
  229. data/ext/express-parser/antlrgen/ExpressLexer.interp +1 -1
  230. data/ext/express-parser/antlrgen/ExpressListener.cpp +1 -1
  231. data/ext/express-parser/antlrgen/ExpressListener.h +1 -1
  232. data/ext/express-parser/antlrgen/ExpressParser.cpp +1754 -1447
  233. data/ext/express-parser/antlrgen/ExpressParser.h +219 -223
  234. data/ext/express-parser/antlrgen/ExpressVisitor.cpp +1 -1
  235. data/ext/express-parser/antlrgen/ExpressVisitor.h +200 -200
  236. data/ext/express-parser/express_parser.cpp +294 -86
  237. data/ext/express-parser/extconf.rb +13 -12
  238. data/lib/expressir/config.rb +1 -1
  239. data/lib/expressir/express/parser.rb +3 -4
  240. data/lib/expressir/express/visitor.rb +7 -5
  241. data/lib/expressir/model.rb +78 -78
  242. data/lib/expressir/version.rb +1 -1
  243. data/rakelib/antlr4-native.rake +161 -0
  244. data/rakelib/cross-ruby.rake +213 -162
  245. data/spec/acceptance/version_spec.rb +17 -2
  246. data/spec/expressir/express/cache_spec.rb +23 -5
  247. data/spec/expressir/express/formatter_spec.rb +54 -8
  248. data/spec/expressir/express/parser_spec.rb +47 -11
  249. data/spec/expressir/model/model_element_spec.rb +198 -146
  250. data/spec/spec_helper.rb +7 -0
  251. metadata +81 -93
  252. data/demo.rb +0 -18
  253. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNSerializer.cpp +0 -621
  254. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNSerializer.h +0 -61
  255. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/AbstractPredicateTransition.cpp +0 -14
  256. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/AbstractPredicateTransition.h +0 -24
  257. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/BasicBlockStartState.cpp +0 -12
  258. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/BasicState.cpp +0 -12
  259. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/BlockEndState.cpp +0 -15
  260. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/BlockStartState.cpp +0 -9
  261. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/EmptyPredictionContext.cpp +0 -35
  262. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/EmptyPredictionContext.h +0 -27
  263. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LoopEndState.cpp +0 -12
  264. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/Makefile +0 -67
  265. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PlusBlockStartState.cpp +0 -12
  266. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PlusLoopbackState.cpp +0 -12
  267. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/RuleStartState.cpp +0 -16
  268. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/RuleStopState.cpp +0 -12
  269. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/StarBlockStartState.cpp +0 -12
  270. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/StarLoopEntryState.cpp +0 -15
  271. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/TokensStartState.cpp +0 -12
  272. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/guid.cpp +0 -303
  273. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/guid.h +0 -112
  274. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ErrorNode.cpp +0 -9
  275. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/TerminalNode.cpp +0 -9
  276. data/original/examples/ap233/ap233e1_arm_lf_stepmod-2010-11-12.exp +0 -9589
  277. data/original/examples/ap233/ap233e1_arm_lf_stepmod-2010-11-12.owl +0 -36619
  278. data/original/examples/ap233/ap233e1_arm_lf_stepmod-2010-11-12.xml +0 -13294
  279. data/original/examples/employment/eclipse/.project +0 -17
  280. data/original/examples/employment/eclipse/Export/Employment.png +0 -0
  281. data/original/examples/employment/eclipse/Express/employment_schema.exp +0 -33
  282. data/original/examples/employment/eclipse/Express/employment_schema.xmi +0 -77
  283. data/original/examples/employment/eclipse/Express/employment_schema.xml +0 -93
  284. data/original/examples/employment/eclipse/Models/Employment.uml +0 -4
  285. data/original/examples/employment/eclipse/Models/Employment.umldi +0 -240
  286. data/original/examples/employment/eclipse/readme.txt +0 -7
  287. data/original/examples/employment/employment_schema.exp +0 -33
  288. data/original/examples/employment/employment_schema.rb +0 -232
  289. data/original/examples/employment/employment_schema.xml +0 -93
  290. data/original/examples/employment/employment_schema___module.rb +0 -46
  291. data/original/examples/employment/employment_schema___p28attr.rb +0 -126
  292. data/original/examples/employment/employment_schema___p28inst.rb +0 -26
  293. data/original/examples/employment/example_employment_data.xml +0 -1
  294. data/original/examples/employment/example_employment_data_copy.xml +0 -1
  295. data/original/examples/employment/example_employment_reader.rb +0 -30
  296. data/original/examples/employment/example_employment_writer.rb +0 -51
  297. data/original/examples/plcs/ap239e1_arm_lf_dexlib_2010-01-06.exp +0 -3710
  298. data/original/examples/plcs/ap239e1_arm_lf_dexlib_2010-01-06.owl +0 -35880
  299. data/original/examples/plcs/ap239e1_arm_lf_dexlib_2010-01-06.xmi +0 -15357
  300. data/original/examples/plcs/ap239e1_arm_lf_dexlib_2010-01-06.xml +0 -9468
  301. data/original/examples/plcs/ap239e2_arm_lf_stepmod-2010-01-25.exp +0 -8404
  302. data/original/examples/plcs/ap239e2_arm_lf_stepmod-2010-01-25.owl +0 -43147
  303. data/original/examples/plcs/ap239e2_arm_lf_stepmod-2010-01-25.xmi +0 -18341
  304. data/original/examples/plcs/ap239e2_arm_lf_stepmod-2010-01-25.xml +0 -11632
  305. data/original/exp2ruby.rb +0 -525
  306. data/original/expsm.rb +0 -34
  307. data/original/mapping_owl.rb +0 -1018
  308. data/original/mapping_sysml.rb +0 -2281
  309. data/original/mapping_uml2.rb +0 -599
  310. data/original/mapping_uml2_eclipse.rb +0 -433
  311. data/original/reeper.rb +0 -134
  312. data/spec/expressr_spec.rb +0 -5
@@ -28,10 +28,25 @@
28
28
 
29
29
  using namespace antlr4;
30
30
  using namespace antlr4::atn;
31
-
32
31
  using namespace antlrcpp;
33
32
 
34
- std::map<std::vector<uint16_t>, atn::ATN> Parser::bypassAltsAtnCache;
33
+ namespace {
34
+
35
+ struct BypassAltsAtnCache final {
36
+ std::shared_mutex mutex;
37
+ /// This field maps from the serialized ATN string to the deserialized <seealso cref="ATN"/> with
38
+ /// bypass alternatives.
39
+ ///
40
+ /// <seealso cref= ATNDeserializationOptions#isGenerateRuleBypassTransitions() </seealso>
41
+ std::map<std::vector<int32_t>, std::unique_ptr<const atn::ATN>, std::less<>> map;
42
+ };
43
+
44
+ BypassAltsAtnCache* getBypassAltsAtnCache() {
45
+ static BypassAltsAtnCache* const instance = new BypassAltsAtnCache();
46
+ return instance;
47
+ }
48
+
49
+ }
35
50
 
36
51
  Parser::TraceListener::TraceListener(Parser *outerInstance_) : outerInstance(outerInstance_) {
37
52
  }
@@ -212,27 +227,32 @@ TokenFactory<CommonToken>* Parser::getTokenFactory() {
212
227
  return _input->getTokenSource()->getTokenFactory();
213
228
  }
214
229
 
215
-
216
230
  const atn::ATN& Parser::getATNWithBypassAlts() {
217
- std::vector<uint16_t> serializedAtn = getSerializedATN();
231
+ auto serializedAtn = getSerializedATN();
218
232
  if (serializedAtn.empty()) {
219
233
  throw UnsupportedOperationException("The current parser does not support an ATN with bypass alternatives.");
220
234
  }
221
-
222
- std::lock_guard<std::mutex> lck(_mutex);
223
-
224
235
  // XXX: using the entire serialized ATN as key into the map is a big resource waste.
225
236
  // How large can that thing become?
226
- if (bypassAltsAtnCache.find(serializedAtn) == bypassAltsAtnCache.end())
237
+ auto *cache = getBypassAltsAtnCache();
227
238
  {
228
- atn::ATNDeserializationOptions deserializationOptions;
229
- deserializationOptions.setGenerateRuleBypassTransitions(true);
230
-
231
- atn::ATNDeserializer deserializer(deserializationOptions);
232
- bypassAltsAtnCache[serializedAtn] = deserializer.deserialize(serializedAtn);
239
+ std::shared_lock<std::shared_mutex> lock(cache->mutex);
240
+ auto existing = cache->map.find(serializedAtn);
241
+ if (existing != cache->map.end()) {
242
+ return *existing->second;
243
+ }
233
244
  }
234
245
 
235
- return bypassAltsAtnCache[serializedAtn];
246
+ std::unique_lock<std::shared_mutex> lock(cache->mutex);
247
+ auto existing = cache->map.find(serializedAtn);
248
+ if (existing != cache->map.end()) {
249
+ return *existing->second;
250
+ }
251
+ atn::ATNDeserializationOptions deserializationOptions;
252
+ deserializationOptions.setGenerateRuleBypassTransitions(true);
253
+ atn::ATNDeserializer deserializer(deserializationOptions);
254
+ auto atn = deserializer.deserialize(serializedAtn);
255
+ return *cache->map.insert(std::make_pair(std::vector<int32_t>(serializedAtn.begin(), serializedAtn.end()), std::move(atn))).first->second;
236
256
  }
237
257
 
238
258
  tree::pattern::ParseTreePattern Parser::compileParseTreePattern(const std::string &pattern, int patternRuleIndex) {
@@ -328,8 +348,7 @@ void Parser::addContextToParseTree() {
328
348
  if (_ctx->parent == nullptr)
329
349
  return;
330
350
 
331
- ParserRuleContext *parent = dynamic_cast<ParserRuleContext *>(_ctx->parent);
332
- parent->addChild(_ctx);
351
+ downCast<ParserRuleContext*>(_ctx->parent)->addChild(_ctx);
333
352
  }
334
353
 
335
354
  void Parser::enterRule(ParserRuleContext *localctx, size_t state, size_t /*ruleIndex*/) {
@@ -357,7 +376,7 @@ void Parser::exitRule() {
357
376
  triggerExitRuleEvent();
358
377
  }
359
378
  setState(_ctx->invokingState);
360
- _ctx = dynamic_cast<ParserRuleContext *>(_ctx->parent);
379
+ _ctx = downCast<ParserRuleContext*>(_ctx->parent);
361
380
  }
362
381
 
363
382
  void Parser::enterOuterAlt(ParserRuleContext *localctx, size_t altNum) {
@@ -367,7 +386,7 @@ void Parser::enterOuterAlt(ParserRuleContext *localctx, size_t altNum) {
367
386
  // that is previous child of parse tree
368
387
  if (_buildParseTrees && _ctx != localctx) {
369
388
  if (_ctx->parent != nullptr) {
370
- ParserRuleContext *parent = dynamic_cast<ParserRuleContext *>(_ctx->parent);
389
+ ParserRuleContext *parent = downCast<ParserRuleContext*>(_ctx->parent);
371
390
  parent->removeLastChild();
372
391
  parent->addChild(localctx);
373
392
  }
@@ -423,7 +442,7 @@ void Parser::unrollRecursionContexts(ParserRuleContext *parentctx) {
423
442
  if (_parseListeners.size() > 0) {
424
443
  while (_ctx != parentctx) {
425
444
  triggerExitRuleEvent();
426
- _ctx = dynamic_cast<ParserRuleContext *>(_ctx->parent);
445
+ _ctx = downCast<ParserRuleContext*>(_ctx->parent);
427
446
  }
428
447
  } else {
429
448
  _ctx = parentctx;
@@ -446,7 +465,7 @@ ParserRuleContext* Parser::getInvokingContext(size_t ruleIndex) {
446
465
  }
447
466
  if (p->parent == nullptr)
448
467
  break;
449
- p = dynamic_cast<ParserRuleContext *>(p->parent);
468
+ p = downCast<ParserRuleContext*>(p->parent);
450
469
  }
451
470
  return nullptr;
452
471
  }
@@ -484,13 +503,13 @@ bool Parser::isExpectedToken(size_t symbol) {
484
503
 
485
504
  while (ctx && ctx->invokingState != ATNState::INVALID_STATE_NUMBER && following.contains(Token::EPSILON)) {
486
505
  atn::ATNState *invokingState = atn.states[ctx->invokingState];
487
- atn::RuleTransition *rt = static_cast<atn::RuleTransition*>(invokingState->transitions[0]);
506
+ const atn::RuleTransition *rt = static_cast<const atn::RuleTransition*>(invokingState->transitions[0].get());
488
507
  following = atn.nextTokens(rt->followState);
489
508
  if (following.contains(symbol)) {
490
509
  return true;
491
510
  }
492
511
 
493
- ctx = dynamic_cast<ParserRuleContext *>(ctx->parent);
512
+ ctx = downCast<ParserRuleContext*>(ctx->parent);
494
513
  }
495
514
 
496
515
  if (following.contains(Token::EPSILON) && symbol == EOF) {
@@ -543,9 +562,10 @@ std::vector<std::string> Parser::getRuleInvocationStack(RuleContext *p) {
543
562
  } else {
544
563
  stack.push_back(ruleNames[ruleIndex]);
545
564
  }
546
- if (p->parent == nullptr)
565
+ if (!RuleContext::is(run->parent)) {
547
566
  break;
548
- run = dynamic_cast<RuleContext *>(run->parent);
567
+ }
568
+ run = downCast<RuleContext*>(run->parent);
549
569
  }
550
570
  return stack;
551
571
  }
@@ -589,12 +609,12 @@ std::string Parser::getSourceName() {
589
609
  }
590
610
 
591
611
  atn::ParseInfo Parser::getParseInfo() const {
592
- atn::ProfilingATNSimulator *interp = getInterpreter<atn::ProfilingATNSimulator>();
593
- return atn::ParseInfo(interp);
612
+ atn::ParserATNSimulator *simulator = getInterpreter<atn::ParserATNSimulator>();
613
+ return atn::ParseInfo(dynamic_cast<atn::ProfilingATNSimulator*>(simulator));
594
614
  }
595
615
 
596
616
  void Parser::setProfile(bool profile) {
597
- atn::ParserATNSimulator *interp = getInterpreter<atn::ProfilingATNSimulator>();
617
+ atn::ParserATNSimulator *interp = getInterpreter<atn::ParserATNSimulator>();
598
618
  atn::PredictionMode saveMode = interp != nullptr ? interp->getPredictionMode() : atn::PredictionMode::LL;
599
619
  if (profile) {
600
620
  if (!is<atn::ProfilingATNSimulator *>(interp)) {
@@ -448,12 +448,6 @@ namespace antlr4 {
448
448
  tree::ParseTreeTracker _tracker;
449
449
 
450
450
  private:
451
- /// This field maps from the serialized ATN string to the deserialized <seealso cref="ATN"/> with
452
- /// bypass alternatives.
453
- ///
454
- /// <seealso cref= ATNDeserializationOptions#isGenerateRuleBypassTransitions() </seealso>
455
- static std::map<std::vector<uint16_t>, atn::ATN> bypassAltsAtnCache;
456
-
457
451
  /// When setTrace(true) is called, a reference to the
458
452
  /// TraceListener is stored here so it can be easily removed in a
459
453
  /// later call to setTrace(false). The listener itself is
@@ -26,6 +26,7 @@
26
26
  #include "tree/ErrorNode.h"
27
27
 
28
28
  #include "support/CPPUtils.h"
29
+ #include "support/Casts.h"
29
30
 
30
31
  #include "ParserInterpreter.h"
31
32
 
@@ -35,19 +36,10 @@ using namespace antlr4::misc;
35
36
 
36
37
  using namespace antlrcpp;
37
38
 
38
- ParserInterpreter::ParserInterpreter(const std::string &grammarFileName, const std::vector<std::string>& tokenNames,
39
- const std::vector<std::string>& ruleNames, const atn::ATN &atn, TokenStream *input)
40
- : ParserInterpreter(grammarFileName, dfa::Vocabulary::fromTokenNames(tokenNames), ruleNames, atn, input) {
41
- }
42
-
43
39
  ParserInterpreter::ParserInterpreter(const std::string &grammarFileName, const dfa::Vocabulary &vocabulary,
44
40
  const std::vector<std::string> &ruleNames, const atn::ATN &atn, TokenStream *input)
45
41
  : Parser(input), _grammarFileName(grammarFileName), _atn(atn), _ruleNames(ruleNames), _vocabulary(vocabulary) {
46
42
 
47
- for (size_t i = 0; i < atn.maxTokenType; ++i) {
48
- _tokenNames.push_back(vocabulary.getDisplayName(i));
49
- }
50
-
51
43
  // init decision DFA
52
44
  for (size_t i = 0; i < atn.getNumberOfDecisions(); ++i) {
53
45
  atn::DecisionState *decisionState = atn.getDecisionState(i);
@@ -72,10 +64,6 @@ const atn::ATN& ParserInterpreter::getATN() const {
72
64
  return _atn;
73
65
  }
74
66
 
75
- const std::vector<std::string>& ParserInterpreter::getTokenNames() const {
76
- return _tokenNames;
77
- }
78
-
79
67
  const dfa::Vocabulary& ParserInterpreter::getVocabulary() const {
80
68
  return _vocabulary;
81
69
  }
@@ -102,7 +90,7 @@ ParserRuleContext* ParserInterpreter::parse(size_t startRuleIndex) {
102
90
  while (true) {
103
91
  atn::ATNState *p = getATNState();
104
92
  switch (p->getStateType()) {
105
- case atn::ATNState::RULE_STOP :
93
+ case atn::ATNStateType::RULE_STOP :
106
94
  // pop; return from rule
107
95
  if (_ctx->isEmpty()) {
108
96
  if (startRuleStartState->isLeftRecursiveRule) {
@@ -161,16 +149,16 @@ atn::ATNState* ParserInterpreter::getATNState() {
161
149
 
162
150
  void ParserInterpreter::visitState(atn::ATNState *p) {
163
151
  size_t predictedAlt = 1;
164
- if (is<DecisionState *>(p)) {
165
- predictedAlt = visitDecisionState(dynamic_cast<DecisionState *>(p));
152
+ if (DecisionState::is(p)) {
153
+ predictedAlt = visitDecisionState(downCast<DecisionState*>(p));
166
154
  }
167
155
 
168
- atn::Transition *transition = p->transitions[predictedAlt - 1];
169
- switch (transition->getSerializationType()) {
170
- case atn::Transition::EPSILON:
171
- if (p->getStateType() == ATNState::STAR_LOOP_ENTRY &&
172
- (dynamic_cast<StarLoopEntryState *>(p))->isPrecedenceDecision &&
173
- !is<LoopEndState *>(transition->target)) {
156
+ const atn::Transition *transition = p->transitions[predictedAlt - 1].get();
157
+ switch (transition->getTransitionType()) {
158
+ case atn::TransitionType::EPSILON:
159
+ if (p->getStateType() == ATNStateType::STAR_LOOP_ENTRY &&
160
+ (downCast<StarLoopEntryState *>(p))->isPrecedenceDecision &&
161
+ !LoopEndState::is(transition->target)) {
174
162
  // We are at the start of a left recursive rule's (...)* loop
175
163
  // and we're not taking the exit branch of loop.
176
164
  InterpreterRuleContext *localctx = createInterpreterRuleContext(_parentContextStack.top().first,
@@ -179,56 +167,56 @@ void ParserInterpreter::visitState(atn::ATNState *p) {
179
167
  }
180
168
  break;
181
169
 
182
- case atn::Transition::ATOM:
183
- match(static_cast<int>(static_cast<atn::AtomTransition*>(transition)->_label));
170
+ case atn::TransitionType::ATOM:
171
+ match(static_cast<int>(static_cast<const atn::AtomTransition*>(transition)->_label));
184
172
  break;
185
173
 
186
- case atn::Transition::RANGE:
187
- case atn::Transition::SET:
188
- case atn::Transition::NOT_SET:
174
+ case atn::TransitionType::RANGE:
175
+ case atn::TransitionType::SET:
176
+ case atn::TransitionType::NOT_SET:
189
177
  if (!transition->matches(static_cast<int>(_input->LA(1)), Token::MIN_USER_TOKEN_TYPE, Lexer::MAX_CHAR_VALUE)) {
190
178
  recoverInline();
191
179
  }
192
180
  matchWildcard();
193
181
  break;
194
182
 
195
- case atn::Transition::WILDCARD:
183
+ case atn::TransitionType::WILDCARD:
196
184
  matchWildcard();
197
185
  break;
198
186
 
199
- case atn::Transition::RULE:
187
+ case atn::TransitionType::RULE:
200
188
  {
201
189
  atn::RuleStartState *ruleStartState = static_cast<atn::RuleStartState*>(transition->target);
202
190
  size_t ruleIndex = ruleStartState->ruleIndex;
203
191
  InterpreterRuleContext *newctx = createInterpreterRuleContext(_ctx, p->stateNumber, ruleIndex);
204
192
  if (ruleStartState->isLeftRecursiveRule) {
205
- enterRecursionRule(newctx, ruleStartState->stateNumber, ruleIndex, static_cast<atn::RuleTransition*>(transition)->precedence);
193
+ enterRecursionRule(newctx, ruleStartState->stateNumber, ruleIndex, static_cast<const atn::RuleTransition*>(transition)->precedence);
206
194
  } else {
207
195
  enterRule(newctx, transition->target->stateNumber, ruleIndex);
208
196
  }
209
197
  }
210
198
  break;
211
199
 
212
- case atn::Transition::PREDICATE:
200
+ case atn::TransitionType::PREDICATE:
213
201
  {
214
- atn::PredicateTransition *predicateTransition = static_cast<atn::PredicateTransition*>(transition);
215
- if (!sempred(_ctx, predicateTransition->ruleIndex, predicateTransition->predIndex)) {
202
+ const atn::PredicateTransition *predicateTransition = static_cast<const atn::PredicateTransition*>(transition);
203
+ if (!sempred(_ctx, predicateTransition->getRuleIndex(), predicateTransition->getPredIndex())) {
216
204
  throw FailedPredicateException(this);
217
205
  }
218
206
  }
219
207
  break;
220
208
 
221
- case atn::Transition::ACTION:
209
+ case atn::TransitionType::ACTION:
222
210
  {
223
- atn::ActionTransition *actionTransition = static_cast<atn::ActionTransition*>(transition);
211
+ const atn::ActionTransition *actionTransition = static_cast<const atn::ActionTransition*>(transition);
224
212
  action(_ctx, actionTransition->ruleIndex, actionTransition->actionIndex);
225
213
  }
226
214
  break;
227
215
 
228
- case atn::Transition::PRECEDENCE:
216
+ case atn::TransitionType::PRECEDENCE:
229
217
  {
230
- if (!precpred(_ctx, static_cast<atn::PrecedencePredicateTransition*>(transition)->precedence)) {
231
- throw FailedPredicateException(this, "precpred(_ctx, " + std::to_string(static_cast<atn::PrecedencePredicateTransition*>(transition)->precedence) + ")");
218
+ if (!precpred(_ctx, static_cast<const atn::PrecedencePredicateTransition*>(transition)->getPrecedence())) {
219
+ throw FailedPredicateException(this, "precpred(_ctx, " + std::to_string(static_cast<const atn::PrecedencePredicateTransition*>(transition)->getPrecedence()) + ")");
232
220
  }
233
221
  }
234
222
  break;
@@ -272,7 +260,7 @@ void ParserInterpreter::visitRuleStopState(atn::ATNState *p) {
272
260
  exitRule();
273
261
  }
274
262
 
275
- atn::RuleTransition *ruleTransition = static_cast<atn::RuleTransition*>(_atn.states[getState()]->transitions[0]);
263
+ const atn::RuleTransition *ruleTransition = static_cast<const atn::RuleTransition*>(_atn.states[getState()]->transitions[0].get());
276
264
  setState(ruleTransition->followState->stateNumber);
277
265
  }
278
266
 
@@ -9,6 +9,7 @@
9
9
  #include "atn/ATN.h"
10
10
  #include "support/BitSet.h"
11
11
  #include "atn/PredictionContext.h"
12
+ #include "atn/PredictionContextCache.h"
12
13
  #include "Vocabulary.h"
13
14
 
14
15
  namespace antlr4 {
@@ -29,9 +30,6 @@ namespace antlr4 {
29
30
  /// </summary>
30
31
  class ANTLR4CPP_PUBLIC ParserInterpreter : public Parser {
31
32
  public:
32
- // @deprecated
33
- ParserInterpreter(const std::string &grammarFileName, const std::vector<std::string>& tokenNames,
34
- const std::vector<std::string>& ruleNames, const atn::ATN &atn, TokenStream *input);
35
33
  ParserInterpreter(const std::string &grammarFileName, const dfa::Vocabulary &vocabulary,
36
34
  const std::vector<std::string> &ruleNames, const atn::ATN &atn, TokenStream *input);
37
35
  ~ParserInterpreter();
@@ -40,9 +38,6 @@ namespace antlr4 {
40
38
 
41
39
  virtual const atn::ATN& getATN() const override;
42
40
 
43
- // @deprecated
44
- virtual const std::vector<std::string>& getTokenNames() const override;
45
-
46
41
  virtual const dfa::Vocabulary& getVocabulary() const override;
47
42
 
48
43
  virtual const std::vector<std::string>& getRuleNames() const override;
@@ -110,7 +105,6 @@ namespace antlr4 {
110
105
 
111
106
  protected:
112
107
  const std::string _grammarFileName;
113
- std::vector<std::string> _tokenNames;
114
108
  const atn::ATN &_atn;
115
109
 
116
110
  std::vector<std::string> _ruleNames;
@@ -9,6 +9,7 @@
9
9
  #include "Parser.h"
10
10
  #include "Token.h"
11
11
 
12
+ #include "support/Casts.h"
12
13
  #include "support/CPPUtils.h"
13
14
 
14
15
  #include "ParserRuleContext.h"
@@ -39,10 +40,9 @@ void ParserRuleContext::copyFrom(ParserRuleContext *ctx) {
39
40
  // copy any error nodes to alt label node
40
41
  if (!ctx->children.empty()) {
41
42
  for (auto *child : ctx->children) {
42
- auto *errorNode = dynamic_cast<ErrorNode *>(child);
43
- if (errorNode != nullptr) {
44
- errorNode->setParent(this);
45
- children.push_back(errorNode);
43
+ if (ErrorNode::is(child)) {
44
+ downCast<ErrorNode*>(child)->setParent(this);
45
+ children.push_back(child);
46
46
  }
47
47
  }
48
48
 
@@ -76,39 +76,36 @@ void ParserRuleContext::removeLastChild() {
76
76
  }
77
77
  }
78
78
 
79
- tree::TerminalNode* ParserRuleContext::getToken(size_t ttype, size_t i) {
79
+ tree::TerminalNode* ParserRuleContext::getToken(size_t ttype, size_t i) const {
80
80
  if (i >= children.size()) {
81
81
  return nullptr;
82
82
  }
83
-
84
83
  size_t j = 0; // what token with ttype have we found?
85
- for (auto *o : children) {
86
- if (is<tree::TerminalNode *>(o)) {
87
- tree::TerminalNode *tnode = dynamic_cast<tree::TerminalNode *>(o);
88
- Token *symbol = tnode->getSymbol();
84
+ for (auto *child : children) {
85
+ if (TerminalNode::is(child)) {
86
+ tree::TerminalNode *typedChild = downCast<tree::TerminalNode*>(child);
87
+ Token *symbol = typedChild->getSymbol();
89
88
  if (symbol->getType() == ttype) {
90
89
  if (j++ == i) {
91
- return tnode;
90
+ return typedChild;
92
91
  }
93
92
  }
94
93
  }
95
94
  }
96
-
97
95
  return nullptr;
98
96
  }
99
97
 
100
- std::vector<tree::TerminalNode *> ParserRuleContext::getTokens(size_t ttype) {
101
- std::vector<tree::TerminalNode *> tokens;
102
- for (auto &o : children) {
103
- if (is<tree::TerminalNode *>(o)) {
104
- tree::TerminalNode *tnode = dynamic_cast<tree::TerminalNode *>(o);
105
- Token *symbol = tnode->getSymbol();
98
+ std::vector<tree::TerminalNode *> ParserRuleContext::getTokens(size_t ttype) const {
99
+ std::vector<tree::TerminalNode*> tokens;
100
+ for (auto *child : children) {
101
+ if (TerminalNode::is(child)) {
102
+ tree::TerminalNode *typedChild = downCast<tree::TerminalNode*>(child);
103
+ Token *symbol = typedChild->getSymbol();
106
104
  if (symbol->getType() == ttype) {
107
- tokens.push_back(tnode);
105
+ tokens.push_back(typedChild);
108
106
  }
109
107
  }
110
108
  }
111
-
112
109
  return tokens;
113
110
  }
114
111
 
@@ -123,11 +120,11 @@ misc::Interval ParserRuleContext::getSourceInterval() {
123
120
  return misc::Interval(start->getTokenIndex(), stop->getTokenIndex());
124
121
  }
125
122
 
126
- Token* ParserRuleContext::getStart() {
123
+ Token* ParserRuleContext::getStart() const {
127
124
  return start;
128
125
  }
129
126
 
130
- Token* ParserRuleContext::getStop() {
127
+ Token* ParserRuleContext::getStop() const {
131
128
  return stop;
132
129
  }
133
130
 
@@ -67,7 +67,6 @@ namespace antlr4 {
67
67
 
68
68
  ParserRuleContext();
69
69
  ParserRuleContext(ParserRuleContext *parent, size_t invokingStateNumber);
70
- virtual ~ParserRuleContext() {}
71
70
 
72
71
  /** COPY a ctx (I'm deliberately not using copy constructor) to avoid
73
72
  * confusion with creating node with parent. Does not copy children
@@ -88,23 +87,22 @@ namespace antlr4 {
88
87
  /// Used by enterOuterAlt to toss out a RuleContext previously added as
89
88
  /// we entered a rule. If we have # label, we will need to remove
90
89
  /// generic ruleContext object.
91
- virtual void removeLastChild();
90
+ void removeLastChild();
92
91
 
93
- virtual tree::TerminalNode* getToken(size_t ttype, std::size_t i);
92
+ tree::TerminalNode* getToken(size_t ttype, std::size_t i) const;
94
93
 
95
- virtual std::vector<tree::TerminalNode *> getTokens(size_t ttype);
94
+ std::vector<tree::TerminalNode*> getTokens(size_t ttype) const;
96
95
 
97
96
  template<typename T>
98
- T* getRuleContext(size_t i) {
99
- if (children.empty()) {
100
- return nullptr;
101
- }
102
-
97
+ T* getRuleContext(size_t i) const {
98
+ static_assert(std::is_base_of_v<RuleContext, T>, "T must be derived from RuleContext");
103
99
  size_t j = 0; // what element have we found with ctxType?
104
- for (auto &child : children) {
105
- if (antlrcpp::is<T *>(child)) {
106
- if (j++ == i) {
107
- return dynamic_cast<T *>(child);
100
+ for (auto *child : children) {
101
+ if (RuleContext::is(child)) {
102
+ if (auto *typedChild = dynamic_cast<T*>(child); typedChild != nullptr) {
103
+ if (j++ == i) {
104
+ return typedChild;
105
+ }
108
106
  }
109
107
  }
110
108
  }
@@ -112,14 +110,16 @@ namespace antlr4 {
112
110
  }
113
111
 
114
112
  template<typename T>
115
- std::vector<T *> getRuleContexts() {
116
- std::vector<T *> contexts;
113
+ std::vector<T*> getRuleContexts() const {
114
+ static_assert(std::is_base_of_v<RuleContext, T>, "T must be derived from RuleContext");
115
+ std::vector<T*> contexts;
117
116
  for (auto *child : children) {
118
- if (antlrcpp::is<T *>(child)) {
119
- contexts.push_back(dynamic_cast<T *>(child));
117
+ if (RuleContext::is(child)) {
118
+ if (auto *typedChild = dynamic_cast<T*>(child); typedChild != nullptr) {
119
+ contexts.push_back(typedChild);
120
+ }
120
121
  }
121
122
  }
122
-
123
123
  return contexts;
124
124
  }
125
125
 
@@ -130,14 +130,14 @@ namespace antlr4 {
130
130
  * Note that the range from start to stop is inclusive, so for rules that do not consume anything
131
131
  * (for example, zero length or error productions) this token may exceed stop.
132
132
  */
133
- virtual Token *getStart();
133
+ Token* getStart() const;
134
134
 
135
135
  /**
136
136
  * Get the final token in this context.
137
137
  * Note that the range from start to stop is inclusive, so for rules that do not consume anything
138
138
  * (for example, zero length or error productions) this token may precede start.
139
139
  */
140
- virtual Token *getStop();
140
+ Token* getStop() const;
141
141
 
142
142
  /// <summary>
143
143
  /// Used for rule context info debugging during parse-time, not so much for ATN debugging </summary>
@@ -5,7 +5,6 @@
5
5
 
6
6
  #include "atn/ATN.h"
7
7
  #include "Recognizer.h"
8
- #include "support/StringUtils.h"
9
8
  #include "ParserRuleContext.h"
10
9
  #include "misc/IntervalSet.h"
11
10
 
@@ -6,11 +6,11 @@
6
6
  #include "ConsoleErrorListener.h"
7
7
  #include "RecognitionException.h"
8
8
  #include "support/CPPUtils.h"
9
- #include "support/StringUtils.h"
10
9
  #include "Token.h"
11
10
  #include "atn/ATN.h"
12
11
  #include "atn/ATNSimulator.h"
13
12
  #include "support/CPPUtils.h"
13
+ #include "support/StringUtils.h"
14
14
 
15
15
  #include "Vocabulary.h"
16
16
 
@@ -19,7 +19,7 @@
19
19
  using namespace antlr4;
20
20
  using namespace antlr4::atn;
21
21
 
22
- std::map<const dfa::Vocabulary*, std::map<std::string, size_t>> Recognizer::_tokenTypeMapCache;
22
+ std::map<const dfa::Vocabulary*, std::map<std::string_view, size_t>> Recognizer::_tokenTypeMapCache;
23
23
  std::map<std::vector<std::string>, std::map<std::string, size_t>> Recognizer::_ruleIndexMapCache;
24
24
 
25
25
  Recognizer::Recognizer() {
@@ -30,31 +30,26 @@ Recognizer::Recognizer() {
30
30
  Recognizer::~Recognizer() {
31
31
  }
32
32
 
33
- dfa::Vocabulary const& Recognizer::getVocabulary() const {
34
- static dfa::Vocabulary vocabulary = dfa::Vocabulary::fromTokenNames(getTokenNames());
35
- return vocabulary;
36
- }
37
-
38
- std::map<std::string, size_t> Recognizer::getTokenTypeMap() {
33
+ std::map<std::string_view, size_t> Recognizer::getTokenTypeMap() {
39
34
  const dfa::Vocabulary& vocabulary = getVocabulary();
40
35
 
41
36
  std::lock_guard<std::mutex> lck(_mutex);
42
- std::map<std::string, size_t> result;
37
+ std::map<std::string_view, size_t> result;
43
38
  auto iterator = _tokenTypeMapCache.find(&vocabulary);
44
39
  if (iterator != _tokenTypeMapCache.end()) {
45
40
  result = iterator->second;
46
41
  } else {
47
42
  for (size_t i = 0; i <= getATN().maxTokenType; ++i) {
48
- std::string literalName = vocabulary.getLiteralName(i);
43
+ std::string_view literalName = vocabulary.getLiteralName(i);
49
44
  if (!literalName.empty()) {
50
45
  result[literalName] = i;
51
46
  }
52
47
 
53
- std::string symbolicName = vocabulary.getSymbolicName(i);
48
+ std::string_view symbolicName = vocabulary.getSymbolicName(i);
54
49
  if (!symbolicName.empty()) {
55
50
  result[symbolicName] = i;
56
51
  }
57
- }
52
+ }
58
53
  result["EOF"] = EOF;
59
54
  _tokenTypeMapCache[&vocabulary] = result;
60
55
  }
@@ -80,8 +75,8 @@ std::map<std::string, size_t> Recognizer::getRuleIndexMap() {
80
75
  return result;
81
76
  }
82
77
 
83
- size_t Recognizer::getTokenType(const std::string &tokenName) {
84
- const std::map<std::string, size_t> &map = getTokenTypeMap();
78
+ size_t Recognizer::getTokenType(std::string_view tokenName) {
79
+ const std::map<std::string_view, size_t> &map = getTokenTypeMap();
85
80
  auto iterator = map.find(tokenName);
86
81
  if (iterator == map.end())
87
82
  return Token::INVALID_TYPE;
@@ -118,11 +113,13 @@ std::string Recognizer::getTokenErrorDisplay(Token *t) {
118
113
  }
119
114
  }
120
115
 
121
- antlrcpp::replaceAll(s, "\n", "\\n");
122
- antlrcpp::replaceAll(s, "\r","\\r");
123
- antlrcpp::replaceAll(s, "\t", "\\t");
124
-
125
- return "'" + s + "'";
116
+ std::string result;
117
+ result.reserve(s.size() + 2);
118
+ result.push_back('\'');
119
+ antlrcpp::escapeWhitespace(result, s);
120
+ result.push_back('\'');
121
+ result.shrink_to_fit();
122
+ return result;
126
123
  }
127
124
 
128
125
  void Recognizer::addErrorListener(ANTLRErrorListener *listener) {
@@ -152,14 +149,6 @@ bool Recognizer::precpred(RuleContext * /*localctx*/, int /*precedence*/) {
152
149
  void Recognizer::action(RuleContext * /*localctx*/, size_t /*ruleIndex*/, size_t /*actionIndex*/) {
153
150
  }
154
151
 
155
- size_t Recognizer::getState() const {
156
- return _stateNumber;
157
- }
158
-
159
- void Recognizer::setState(size_t atnState) {
160
- _stateNumber = atnState;
161
- }
162
-
163
152
  void Recognizer::InitializeInstanceFields() {
164
153
  _stateNumber = ATNState::INVALID_STATE_NUMBER;
165
154
  _interpreter = nullptr;