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
@@ -10,34 +10,34 @@
10
10
  namespace antlr4 {
11
11
  namespace atn {
12
12
 
13
- class ANTLR4CPP_PUBLIC LexerATNConfig : public ATNConfig {
13
+ class ANTLR4CPP_PUBLIC LexerATNConfig final : public ATNConfig {
14
14
  public:
15
- LexerATNConfig(ATNState *state, int alt, Ref<PredictionContext> const& context);
16
- LexerATNConfig(ATNState *state, int alt, Ref<PredictionContext> const& context, Ref<LexerActionExecutor> const& lexerActionExecutor);
15
+ LexerATNConfig(ATNState *state, int alt, Ref<const PredictionContext> context);
16
+ LexerATNConfig(ATNState *state, int alt, Ref<const PredictionContext> context, Ref<const LexerActionExecutor> lexerActionExecutor);
17
17
 
18
- LexerATNConfig(Ref<LexerATNConfig> const& c, ATNState *state);
19
- LexerATNConfig(Ref<LexerATNConfig> const& c, ATNState *state, Ref<LexerActionExecutor> const& lexerActionExecutor);
20
- LexerATNConfig(Ref<LexerATNConfig> const& c, ATNState *state, Ref<PredictionContext> const& context);
18
+ LexerATNConfig(LexerATNConfig const& other, ATNState *state);
19
+ LexerATNConfig(LexerATNConfig const& other, ATNState *state, Ref<const LexerActionExecutor> lexerActionExecutor);
20
+ LexerATNConfig(LexerATNConfig const& other, ATNState *state, Ref<const PredictionContext> context);
21
21
 
22
22
  /**
23
23
  * Gets the {@link LexerActionExecutor} capable of executing the embedded
24
24
  * action(s) for the current configuration.
25
25
  */
26
- Ref<LexerActionExecutor> getLexerActionExecutor() const;
27
- bool hasPassedThroughNonGreedyDecision();
26
+ const Ref<const LexerActionExecutor>& getLexerActionExecutor() const { return _lexerActionExecutor; }
27
+ bool hasPassedThroughNonGreedyDecision() const { return _passedThroughNonGreedyDecision; }
28
28
 
29
29
  virtual size_t hashCode() const override;
30
30
 
31
- bool operator == (const LexerATNConfig& other) const;
31
+ bool operator==(const LexerATNConfig& other) const;
32
32
 
33
33
  private:
34
34
  /**
35
35
  * This is the backing field for {@link #getLexerActionExecutor}.
36
36
  */
37
- const Ref<LexerActionExecutor> _lexerActionExecutor;
38
- const bool _passedThroughNonGreedyDecision;
37
+ const Ref<const LexerActionExecutor> _lexerActionExecutor;
38
+ const bool _passedThroughNonGreedyDecision = false;
39
39
 
40
- static bool checkNonGreedyDecision(Ref<LexerATNConfig> const& source, ATNState *target);
40
+ static bool checkNonGreedyDecision(LexerATNConfig const& source, ATNState *target);
41
41
  };
42
42
 
43
43
  } // namespace atn
@@ -20,7 +20,6 @@
20
20
  #include "dfa/DFAState.h"
21
21
  #include "atn/LexerATNConfig.h"
22
22
  #include "atn/LexerActionExecutor.h"
23
- #include "atn/EmptyPredictionContext.h"
24
23
 
25
24
  #include "atn/LexerATNSimulator.h"
26
25
 
@@ -31,25 +30,10 @@ using namespace antlr4;
31
30
  using namespace antlr4::atn;
32
31
  using namespace antlrcpp;
33
32
 
34
- LexerATNSimulator::SimState::~SimState() {
35
- }
36
-
37
33
  void LexerATNSimulator::SimState::reset() {
38
- index = INVALID_INDEX;
39
- line = 0;
40
- charPos = INVALID_INDEX;
41
- dfaState = nullptr; // Don't delete. It's just a reference.
42
- }
43
-
44
- void LexerATNSimulator::SimState::InitializeInstanceFields() {
45
- index = INVALID_INDEX;
46
- line = 0;
47
- charPos = INVALID_INDEX;
34
+ *this = SimState();
48
35
  }
49
36
 
50
- int LexerATNSimulator::match_calls = 0;
51
-
52
-
53
37
  LexerATNSimulator::LexerATNSimulator(const ATN &atn, std::vector<dfa::DFA> &decisionToDFA,
54
38
  PredictionContextCache &sharedContextCache)
55
39
  : LexerATNSimulator(nullptr, atn, decisionToDFA, sharedContextCache) {
@@ -69,7 +53,6 @@ void LexerATNSimulator::copyState(LexerATNSimulator *simulator) {
69
53
  }
70
54
 
71
55
  size_t LexerATNSimulator::match(CharStream *input, size_t mode) {
72
- match_calls++;
73
56
  _mode = mode;
74
57
  ssize_t mark = input->mark();
75
58
 
@@ -80,10 +63,15 @@ size_t LexerATNSimulator::match(CharStream *input, size_t mode) {
80
63
  _startIndex = input->index();
81
64
  _prevAccept.reset();
82
65
  const dfa::DFA &dfa = _decisionToDFA[mode];
83
- if (dfa.s0 == nullptr) {
66
+ dfa::DFAState* s0;
67
+ {
68
+ std::shared_lock<std::shared_mutex> stateLock(atn._stateMutex);
69
+ s0 = dfa.s0;
70
+ }
71
+ if (s0 == nullptr) {
84
72
  return matchATN(input);
85
73
  } else {
86
- return execATN(input, dfa.s0);
74
+ return execATN(input, s0);
87
75
  }
88
76
  }
89
77
 
@@ -111,10 +99,7 @@ size_t LexerATNSimulator::matchATN(CharStream *input) {
111
99
  bool suppressEdge = s0_closure->hasSemanticContext;
112
100
  s0_closure->hasSemanticContext = false;
113
101
 
114
- dfa::DFAState *next = addDFAState(s0_closure.release());
115
- if (!suppressEdge) {
116
- _decisionToDFA[_mode].s0 = next;
117
- }
102
+ dfa::DFAState *next = addDFAState(s0_closure.release(), suppressEdge);
118
103
 
119
104
  size_t predict = execATN(input, next);
120
105
 
@@ -182,7 +167,7 @@ size_t LexerATNSimulator::execATN(CharStream *input, dfa::DFAState *ds0) {
182
167
 
183
168
  dfa::DFAState *LexerATNSimulator::getExistingTargetState(dfa::DFAState *s, size_t t) {
184
169
  dfa::DFAState* retval = nullptr;
185
- _edgeLock.readLock();
170
+ std::shared_lock<std::shared_mutex> edgeLock(atn._edgeMutex);
186
171
  if (t <= MAX_DFA_EDGE) {
187
172
  auto iterator = s->edges.find(t - MIN_DFA_EDGE);
188
173
  #if DEBUG_ATN == 1
@@ -194,7 +179,6 @@ dfa::DFAState *LexerATNSimulator::getExistingTargetState(dfa::DFAState *s, size_
194
179
  if (iterator != s->edges.end())
195
180
  retval = iterator->second;
196
181
  }
197
- _edgeLock.readUnlock();
198
182
  return retval;
199
183
  }
200
184
 
@@ -209,9 +193,9 @@ dfa::DFAState *LexerATNSimulator::computeTargetState(CharStream *input, dfa::DFA
209
193
  if (!reach->hasSemanticContext) {
210
194
  // we got nowhere on t, don't throw out this knowledge; it'd
211
195
  // cause a failover from DFA later.
212
- delete reach;
213
196
  addDFAEdge(s, t, ERROR.get());
214
197
  }
198
+ delete reach;
215
199
 
216
200
  // stop when we can't match any more char
217
201
  return ERROR.get();
@@ -223,8 +207,7 @@ dfa::DFAState *LexerATNSimulator::computeTargetState(CharStream *input, dfa::DFA
223
207
 
224
208
  size_t LexerATNSimulator::failOrAccept(CharStream *input, ATNConfigSet *reach, size_t t) {
225
209
  if (_prevAccept.dfaState != nullptr) {
226
- Ref<LexerActionExecutor> lexerActionExecutor = _prevAccept.dfaState->lexerActionExecutor;
227
- accept(input, lexerActionExecutor, _startIndex, _prevAccept.index, _prevAccept.line, _prevAccept.charPos);
210
+ accept(input, _prevAccept.dfaState->lexerActionExecutor, _startIndex, _prevAccept.index, _prevAccept.line, _prevAccept.charPos);
228
211
  return _prevAccept.dfaState->prediction;
229
212
  } else {
230
213
  // if no accept and EOF is first char, return EOF
@@ -241,7 +224,7 @@ void LexerATNSimulator::getReachableConfigSet(CharStream *input, ATNConfigSet *c
241
224
  // than a config that already reached an accept state for the same rule
242
225
  size_t skipAlt = ATN::INVALID_ALT_NUMBER;
243
226
 
244
- for (auto c : closure_->configs) {
227
+ for (const auto &c : closure_->configs) {
245
228
  bool currentAltReachedAcceptState = c->alt == skipAlt;
246
229
  if (currentAltReachedAcceptState && (std::static_pointer_cast<LexerATNConfig>(c))->hasPassedThroughNonGreedyDecision()) {
247
230
  continue;
@@ -253,17 +236,17 @@ void LexerATNSimulator::getReachableConfigSet(CharStream *input, ATNConfigSet *c
253
236
 
254
237
  size_t n = c->state->transitions.size();
255
238
  for (size_t ti = 0; ti < n; ti++) { // for each transition
256
- Transition *trans = c->state->transitions[ti];
239
+ const Transition *trans = c->state->transitions[ti].get();
257
240
  ATNState *target = getReachableTarget(trans, (int)t);
258
241
  if (target != nullptr) {
259
- Ref<LexerActionExecutor> lexerActionExecutor = std::static_pointer_cast<LexerATNConfig>(c)->getLexerActionExecutor();
242
+ auto lexerActionExecutor = downCast<const LexerATNConfig&>(*c).getLexerActionExecutor();
260
243
  if (lexerActionExecutor != nullptr) {
261
244
  lexerActionExecutor = lexerActionExecutor->fixOffsetBeforeMatch((int)input->index() - (int)_startIndex);
262
245
  }
263
246
 
264
247
  bool treatEofAsEpsilon = t == Token::EOF;
265
- Ref<LexerATNConfig> config = std::make_shared<LexerATNConfig>(std::static_pointer_cast<LexerATNConfig>(c),
266
- target, lexerActionExecutor);
248
+ Ref<LexerATNConfig> config = std::make_shared<LexerATNConfig>(downCast<const LexerATNConfig&>(*c),
249
+ target, std::move(lexerActionExecutor));
267
250
 
268
251
  if (closure(input, config, reach, currentAltReachedAcceptState, true, treatEofAsEpsilon)) {
269
252
  // any remaining configs for this alt have a lower priority than
@@ -276,7 +259,7 @@ void LexerATNSimulator::getReachableConfigSet(CharStream *input, ATNConfigSet *c
276
259
  }
277
260
  }
278
261
 
279
- void LexerATNSimulator::accept(CharStream *input, const Ref<LexerActionExecutor> &lexerActionExecutor, size_t /*startIndex*/,
262
+ void LexerATNSimulator::accept(CharStream *input, const Ref<const LexerActionExecutor> &lexerActionExecutor, size_t /*startIndex*/,
280
263
  size_t index, size_t line, size_t charPos) {
281
264
  #if DEBUG_ATN == 1
282
265
  std::cout << "ACTION ";
@@ -293,7 +276,7 @@ void LexerATNSimulator::accept(CharStream *input, const Ref<LexerActionExecutor>
293
276
  }
294
277
  }
295
278
 
296
- atn::ATNState *LexerATNSimulator::getReachableTarget(Transition *trans, size_t t) {
279
+ atn::ATNState *LexerATNSimulator::getReachableTarget(const Transition *trans, size_t t) {
297
280
  if (trans->matches(t, Lexer::MIN_CHAR_VALUE, Lexer::MAX_CHAR_VALUE)) {
298
281
  return trans->target;
299
282
  }
@@ -302,7 +285,7 @@ atn::ATNState *LexerATNSimulator::getReachableTarget(Transition *trans, size_t t
302
285
  }
303
286
 
304
287
  std::unique_ptr<ATNConfigSet> LexerATNSimulator::computeStartState(CharStream *input, ATNState *p) {
305
- Ref<PredictionContext> initialContext = PredictionContext::EMPTY; // ml: the purpose of this assignment is unclear
288
+ Ref<const PredictionContext> initialContext = PredictionContext::EMPTY; // ml: the purpose of this assignment is unclear
306
289
  std::unique_ptr<ATNConfigSet> configs(new OrderedATNConfigSet());
307
290
  for (size_t i = 0; i < p->transitions.size(); i++) {
308
291
  ATNState *target = p->transitions[i]->target;
@@ -319,7 +302,7 @@ bool LexerATNSimulator::closure(CharStream *input, const Ref<LexerATNConfig> &co
319
302
  std::cout << "closure(" << config->toString(true) << ")" << std::endl;
320
303
  #endif
321
304
 
322
- if (is<RuleStopState *>(config->state)) {
305
+ if (config->state != nullptr && config->state->getStateType() == ATNStateType::RULE_STOP) {
323
306
  #if DEBUG_ATN == 1
324
307
  if (_recog != nullptr) {
325
308
  std::cout << "closure at " << _recog->getRuleNames()[config->state->ruleIndex] << " rule stop " << config << std::endl;
@@ -333,7 +316,7 @@ bool LexerATNSimulator::closure(CharStream *input, const Ref<LexerATNConfig> &co
333
316
  configs->add(config);
334
317
  return true;
335
318
  } else {
336
- configs->add(std::make_shared<LexerATNConfig>(config, config->state, PredictionContext::EMPTY));
319
+ configs->add(std::make_shared<LexerATNConfig>(*config, config->state, PredictionContext::EMPTY));
337
320
  currentAltReachedAcceptState = true;
338
321
  }
339
322
  }
@@ -341,9 +324,9 @@ bool LexerATNSimulator::closure(CharStream *input, const Ref<LexerATNConfig> &co
341
324
  if (config->context != nullptr && !config->context->isEmpty()) {
342
325
  for (size_t i = 0; i < config->context->size(); i++) {
343
326
  if (config->context->getReturnState(i) != PredictionContext::EMPTY_RETURN_STATE) {
344
- std::weak_ptr<PredictionContext> newContext = config->context->getParent(i); // "pop" return state
327
+ Ref<const PredictionContext> newContext = config->context->getParent(i); // "pop" return state
345
328
  ATNState *returnState = atn.states[config->context->getReturnState(i)];
346
- Ref<LexerATNConfig> c = std::make_shared<LexerATNConfig>(config, returnState, newContext.lock());
329
+ Ref<LexerATNConfig> c = std::make_shared<LexerATNConfig>(*config, returnState, newContext);
347
330
  currentAltReachedAcceptState = closure(input, c, configs, currentAltReachedAcceptState, speculative, treatEofAsEpsilon);
348
331
  }
349
332
  }
@@ -361,7 +344,7 @@ bool LexerATNSimulator::closure(CharStream *input, const Ref<LexerATNConfig> &co
361
344
 
362
345
  ATNState *p = config->state;
363
346
  for (size_t i = 0; i < p->transitions.size(); i++) {
364
- Transition *t = p->transitions[i];
347
+ const Transition *t = p->transitions[i].get();
365
348
  Ref<LexerATNConfig> c = getEpsilonTarget(input, config, t, configs, speculative, treatEofAsEpsilon);
366
349
  if (c != nullptr) {
367
350
  currentAltReachedAcceptState = closure(input, c, configs, currentAltReachedAcceptState, speculative, treatEofAsEpsilon);
@@ -371,22 +354,22 @@ bool LexerATNSimulator::closure(CharStream *input, const Ref<LexerATNConfig> &co
371
354
  return currentAltReachedAcceptState;
372
355
  }
373
356
 
374
- Ref<LexerATNConfig> LexerATNSimulator::getEpsilonTarget(CharStream *input, const Ref<LexerATNConfig> &config, Transition *t,
357
+ Ref<LexerATNConfig> LexerATNSimulator::getEpsilonTarget(CharStream *input, const Ref<LexerATNConfig> &config, const Transition *t,
375
358
  ATNConfigSet *configs, bool speculative, bool treatEofAsEpsilon) {
376
359
 
377
360
  Ref<LexerATNConfig> c = nullptr;
378
- switch (t->getSerializationType()) {
379
- case Transition::RULE: {
380
- RuleTransition *ruleTransition = static_cast<RuleTransition*>(t);
381
- Ref<PredictionContext> newContext = SingletonPredictionContext::create(config->context, ruleTransition->followState->stateNumber);
382
- c = std::make_shared<LexerATNConfig>(config, t->target, newContext);
361
+ switch (t->getTransitionType()) {
362
+ case TransitionType::RULE: {
363
+ const RuleTransition *ruleTransition = static_cast<const RuleTransition*>(t);
364
+ Ref<const PredictionContext> newContext = SingletonPredictionContext::create(config->context, ruleTransition->followState->stateNumber);
365
+ c = std::make_shared<LexerATNConfig>(*config, t->target, newContext);
383
366
  break;
384
367
  }
385
368
 
386
- case Transition::PRECEDENCE:
369
+ case TransitionType::PRECEDENCE:
387
370
  throw UnsupportedOperationException("Precedence predicates are not supported in lexers.");
388
371
 
389
- case Transition::PREDICATE: {
372
+ case TransitionType::PREDICATE: {
390
373
  /* Track traversing semantic predicates. If we traverse,
391
374
  we cannot add a DFA state for this "reach" computation
392
375
  because the DFA would not test the predicate again in the
@@ -405,20 +388,20 @@ Ref<LexerATNConfig> LexerATNSimulator::getEpsilonTarget(CharStream *input, const
405
388
  states reached by traversing predicates. Since this is when we
406
389
  test them, we cannot cash the DFA state target of ID.
407
390
  */
408
- PredicateTransition *pt = static_cast<PredicateTransition*>(t);
391
+ const PredicateTransition *pt = static_cast<const PredicateTransition*>(t);
409
392
 
410
393
  #if DEBUG_ATN == 1
411
- std::cout << "EVAL rule " << pt->ruleIndex << ":" << pt->predIndex << std::endl;
394
+ std::cout << "EVAL rule " << pt->getRuleIndex() << ":" << pt->getPredIndex() << std::endl;
412
395
  #endif
413
396
 
414
397
  configs->hasSemanticContext = true;
415
- if (evaluatePredicate(input, pt->ruleIndex, pt->predIndex, speculative)) {
416
- c = std::make_shared<LexerATNConfig>(config, t->target);
398
+ if (evaluatePredicate(input, pt->getRuleIndex(), pt->getPredIndex(), speculative)) {
399
+ c = std::make_shared<LexerATNConfig>(*config, t->target);
417
400
  }
418
401
  break;
419
402
  }
420
403
 
421
- case Transition::ACTION:
404
+ case TransitionType::ACTION:
422
405
  if (config->context == nullptr|| config->context->hasEmptyPath()) {
423
406
  // execute actions anywhere in the start rule for a token.
424
407
  //
@@ -432,27 +415,27 @@ Ref<LexerATNConfig> LexerATNSimulator::getEpsilonTarget(CharStream *input, const
432
415
  // getEpsilonTarget to return two configurations, so
433
416
  // additional modifications are needed before we can support
434
417
  // the split operation.
435
- Ref<LexerActionExecutor> lexerActionExecutor = LexerActionExecutor::append(config->getLexerActionExecutor(),
436
- atn.lexerActions[static_cast<ActionTransition *>(t)->actionIndex]);
437
- c = std::make_shared<LexerATNConfig>(config, t->target, lexerActionExecutor);
418
+ auto lexerActionExecutor = LexerActionExecutor::append(config->getLexerActionExecutor(),
419
+ atn.lexerActions[static_cast<const ActionTransition *>(t)->actionIndex]);
420
+ c = std::make_shared<LexerATNConfig>(*config, t->target, std::move(lexerActionExecutor));
438
421
  break;
439
422
  }
440
423
  else {
441
424
  // ignore actions in referenced rules
442
- c = std::make_shared<LexerATNConfig>(config, t->target);
425
+ c = std::make_shared<LexerATNConfig>(*config, t->target);
443
426
  break;
444
427
  }
445
428
 
446
- case Transition::EPSILON:
447
- c = std::make_shared<LexerATNConfig>(config, t->target);
429
+ case TransitionType::EPSILON:
430
+ c = std::make_shared<LexerATNConfig>(*config, t->target);
448
431
  break;
449
432
 
450
- case Transition::ATOM:
451
- case Transition::RANGE:
452
- case Transition::SET:
433
+ case TransitionType::ATOM:
434
+ case TransitionType::RANGE:
435
+ case TransitionType::SET:
453
436
  if (treatEofAsEpsilon) {
454
437
  if (t->matches(Token::EOF, Lexer::MIN_CHAR_VALUE, Lexer::MAX_CHAR_VALUE)) {
455
- c = std::make_shared<LexerATNConfig>(config, t->target);
438
+ c = std::make_shared<LexerATNConfig>(*config, t->target);
456
439
  break;
457
440
  }
458
441
  }
@@ -530,12 +513,15 @@ void LexerATNSimulator::addDFAEdge(dfa::DFAState *p, size_t t, dfa::DFAState *q)
530
513
  return;
531
514
  }
532
515
 
533
- _edgeLock.writeLock();
516
+ std::unique_lock<std::shared_mutex> edgeLock(atn._edgeMutex);
534
517
  p->edges[t - MIN_DFA_EDGE] = q; // connect
535
- _edgeLock.writeUnlock();
536
518
  }
537
519
 
538
520
  dfa::DFAState *LexerATNSimulator::addDFAState(ATNConfigSet *configs) {
521
+ return addDFAState(configs, true);
522
+ }
523
+
524
+ dfa::DFAState *LexerATNSimulator::addDFAState(ATNConfigSet *configs, bool suppressEdge) {
539
525
  /* the lexer evaluates predicates on-the-fly; by this point configs
540
526
  * should not contain any configurations with unevaluated predicates.
541
527
  */
@@ -543,8 +529,8 @@ dfa::DFAState *LexerATNSimulator::addDFAState(ATNConfigSet *configs) {
543
529
 
544
530
  dfa::DFAState *proposed = new dfa::DFAState(std::unique_ptr<ATNConfigSet>(configs)); /* mem-check: managed by the DFA or deleted below */
545
531
  Ref<ATNConfig> firstConfigWithRuleStopState = nullptr;
546
- for (auto &c : configs->configs) {
547
- if (is<RuleStopState *>(c->state)) {
532
+ for (const auto &c : configs->configs) {
533
+ if (RuleStopState::is(c->state)) {
548
534
  firstConfigWithRuleStopState = c;
549
535
  break;
550
536
  }
@@ -552,28 +538,29 @@ dfa::DFAState *LexerATNSimulator::addDFAState(ATNConfigSet *configs) {
552
538
 
553
539
  if (firstConfigWithRuleStopState != nullptr) {
554
540
  proposed->isAcceptState = true;
555
- proposed->lexerActionExecutor = std::dynamic_pointer_cast<LexerATNConfig>(firstConfigWithRuleStopState)->getLexerActionExecutor();
541
+ proposed->lexerActionExecutor = downCast<const LexerATNConfig&>(*firstConfigWithRuleStopState).getLexerActionExecutor();
556
542
  proposed->prediction = atn.ruleToTokenType[firstConfigWithRuleStopState->state->ruleIndex];
557
543
  }
558
544
 
559
545
  dfa::DFA &dfa = _decisionToDFA[_mode];
560
546
 
561
- _stateLock.writeLock();
562
- if (!dfa.states.empty()) {
563
- auto iterator = dfa.states.find(proposed);
564
- if (iterator != dfa.states.end()) {
547
+ {
548
+ std::unique_lock<std::shared_mutex> stateLock(atn._stateMutex);
549
+ auto [existing, inserted] = dfa.states.insert(proposed);
550
+ if (!inserted) {
565
551
  delete proposed;
566
- _stateLock.writeUnlock();
567
- return *iterator;
552
+ proposed = *existing;
553
+ } else {
554
+ // Previously we did a lookup, then set fields, then inserted. It was `dfa.states.size()`,
555
+ // since we already inserted we need to subtract one.
556
+ proposed->stateNumber = static_cast<int>(dfa.states.size() - 1);
557
+ proposed->configs->setReadonly(true);
558
+ }
559
+ if (!suppressEdge) {
560
+ dfa.s0 = proposed;
568
561
  }
569
562
  }
570
563
 
571
- proposed->stateNumber = (int)dfa.states.size();
572
- proposed->configs->setReadonly(true);
573
-
574
- dfa.states.insert(proposed);
575
- _stateLock.writeUnlock();
576
-
577
564
  return proposed;
578
565
  }
579
566
 
@@ -5,6 +5,8 @@
5
5
 
6
6
  #pragma once
7
7
 
8
+ #include <atomic>
9
+
8
10
  #include "atn/ATNSimulator.h"
9
11
  #include "atn/LexerATNConfig.h"
10
12
  #include "atn/ATNConfigSet.h"
@@ -15,31 +17,18 @@ namespace atn {
15
17
  /// "dup" of ParserInterpreter
16
18
  class ANTLR4CPP_PUBLIC LexerATNSimulator : public ATNSimulator {
17
19
  protected:
18
- class SimState {
19
- public:
20
- virtual ~SimState();
21
-
22
- protected:
23
- size_t index;
24
- size_t line;
25
- size_t charPos;
26
- dfa::DFAState *dfaState;
27
- virtual void reset();
28
- friend class LexerATNSimulator;
29
-
30
- private:
31
- void InitializeInstanceFields();
32
-
33
- public:
34
- SimState() {
35
- InitializeInstanceFields();
36
- }
37
- };
20
+ struct ANTLR4CPP_PUBLIC SimState final {
21
+ size_t index = INVALID_INDEX;
22
+ size_t line = 0;
23
+ size_t charPos = INVALID_INDEX;
24
+ dfa::DFAState *dfaState = nullptr;
38
25
 
26
+ void reset();
27
+ };
39
28
 
40
29
  public:
41
- static const size_t MIN_DFA_EDGE = 0;
42
- static const size_t MAX_DFA_EDGE = 127; // forces unicode to stay in ATN
30
+ static constexpr size_t MIN_DFA_EDGE = 0;
31
+ static constexpr size_t MAX_DFA_EDGE = 127; // forces unicode to stay in ATN
43
32
 
44
33
  protected:
45
34
  /// <summary>
@@ -82,11 +71,9 @@ namespace atn {
82
71
  SimState _prevAccept;
83
72
 
84
73
  public:
85
- static int match_calls;
86
-
87
74
  LexerATNSimulator(const ATN &atn, std::vector<dfa::DFA> &decisionToDFA, PredictionContextCache &sharedContextCache);
88
75
  LexerATNSimulator(Lexer *recog, const ATN &atn, std::vector<dfa::DFA> &decisionToDFA, PredictionContextCache &sharedContextCache);
89
- virtual ~LexerATNSimulator () {}
76
+ virtual ~LexerATNSimulator() = default;
90
77
 
91
78
  virtual void copyState(LexerATNSimulator *simulator);
92
79
  virtual size_t match(CharStream *input, size_t mode);
@@ -133,10 +120,10 @@ namespace atn {
133
120
  void getReachableConfigSet(CharStream *input, ATNConfigSet *closure_, // closure_ as we have a closure() already
134
121
  ATNConfigSet *reach, size_t t);
135
122
 
136
- virtual void accept(CharStream *input, const Ref<LexerActionExecutor> &lexerActionExecutor, size_t startIndex, size_t index,
123
+ virtual void accept(CharStream *input, const Ref<const LexerActionExecutor> &lexerActionExecutor, size_t startIndex, size_t index,
137
124
  size_t line, size_t charPos);
138
125
 
139
- virtual ATNState *getReachableTarget(Transition *trans, size_t t);
126
+ virtual ATNState *getReachableTarget(const Transition *trans, size_t t);
140
127
 
141
128
  virtual std::unique_ptr<ATNConfigSet> computeStartState(CharStream *input, ATNState *p);
142
129
 
@@ -153,7 +140,7 @@ namespace atn {
153
140
  bool currentAltReachedAcceptState, bool speculative, bool treatEofAsEpsilon);
154
141
 
155
142
  // side-effect: can alter configs.hasSemanticContext
156
- virtual Ref<LexerATNConfig> getEpsilonTarget(CharStream *input, const Ref<LexerATNConfig> &config, Transition *t,
143
+ virtual Ref<LexerATNConfig> getEpsilonTarget(CharStream *input, const Ref<LexerATNConfig> &config, const Transition *t,
157
144
  ATNConfigSet *configs, bool speculative, bool treatEofAsEpsilon);
158
145
 
159
146
  /// <summary>
@@ -190,6 +177,8 @@ namespace atn {
190
177
  /// </summary>
191
178
  virtual dfa::DFAState *addDFAState(ATNConfigSet *configs);
192
179
 
180
+ virtual dfa::DFAState *addDFAState(ATNConfigSet *configs, bool suppressEdge);
181
+
193
182
  public:
194
183
  dfa::DFA& getDFA(size_t mode);
195
184
 
@@ -1,9 +1,15 @@
1
- /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.
2
- * Use of this file is governed by the BSD 3-clause license that
3
- * can be found in the LICENSE.txt file in the project root.
4
- */
5
-
6
1
  #include "LexerAction.h"
7
2
 
8
- antlr4::atn::LexerAction::~LexerAction() {
3
+ using namespace antlr4::atn;
4
+
5
+ size_t LexerAction::hashCode() const {
6
+ auto hash = cachedHashCode();
7
+ if (hash == 0) {
8
+ hash = hashCodeImpl();
9
+ if (hash == 0) {
10
+ hash = std::numeric_limits<size_t>::max();
11
+ }
12
+ _hashCode.store(hash, std::memory_order_relaxed);
13
+ }
14
+ return hash;
9
15
  }
@@ -21,13 +21,17 @@ namespace atn {
21
21
  /// </summary>
22
22
  class ANTLR4CPP_PUBLIC LexerAction {
23
23
  public:
24
- virtual ~LexerAction();
24
+ virtual ~LexerAction() = default;
25
25
 
26
26
  /// <summary>
27
27
  /// Gets the serialization type of the lexer action.
28
28
  /// </summary>
29
29
  /// <returns> The serialization type of the lexer action. </returns>
30
- virtual LexerActionType getActionType() const = 0;
30
+ ///
31
+ /// IMPORTANT: Unlike Java, this returns LexerActionType::INDEXED_CUSTOM for instances of
32
+ /// LexerIndexedCustomAction. If you need the wrapped action type, use
33
+ /// LexerIndexedCustomAction::getAction()->getActionType().
34
+ LexerActionType getActionType() const { return _actionType; }
31
35
 
32
36
  /// <summary>
33
37
  /// Gets whether the lexer action is position-dependent. Position-dependent
@@ -42,7 +46,7 @@ namespace atn {
42
46
  /// <returns> {@code true} if the lexer action semantics can be affected by the
43
47
  /// position of the input <seealso cref="CharStream"/> at the time it is executed;
44
48
  /// otherwise, {@code false}. </returns>
45
- virtual bool isPositionDependent() const = 0;
49
+ bool isPositionDependent() const { return _positionDependent; }
46
50
 
47
51
  /// <summary>
48
52
  /// Execute the lexer action in the context of the specified <seealso cref="Lexer"/>.
@@ -51,16 +55,46 @@ namespace atn {
51
55
  /// positioned correctly prior to calling this method.</para>
52
56
  /// </summary>
53
57
  /// <param name="lexer"> The lexer instance. </param>
54
- virtual void execute(Lexer *lexer) = 0;
58
+ virtual void execute(Lexer *lexer) const = 0;
55
59
 
56
- virtual size_t hashCode() const = 0;
57
- virtual bool operator == (const LexerAction &obj) const = 0;
58
- virtual bool operator != (const LexerAction &obj) const {
59
- return !(*this == obj);
60
- }
60
+ size_t hashCode() const;
61
+
62
+ virtual bool equals(const LexerAction &other) const = 0;
61
63
 
62
64
  virtual std::string toString() const = 0;
65
+
66
+ protected:
67
+ LexerAction(LexerActionType actionType, bool positionDependent)
68
+ : _actionType(actionType), _hashCode(0), _positionDependent(positionDependent) {}
69
+
70
+ virtual size_t hashCodeImpl() const = 0;
71
+
72
+ size_t cachedHashCode() const { return _hashCode.load(std::memory_order_relaxed); }
73
+
74
+ private:
75
+ const LexerActionType _actionType;
76
+ mutable std::atomic<size_t> _hashCode;
77
+ const bool _positionDependent;
78
+ };
79
+
80
+ inline bool operator==(const LexerAction &lhs, const LexerAction &rhs) {
81
+ return lhs.equals(rhs);
82
+ }
83
+
84
+ inline bool operator!=(const LexerAction &lhs, const LexerAction &rhs) {
85
+ return !operator==(lhs, rhs);
86
+ }
87
+
88
+ } // namespace atn
89
+ } // namespace antlr4
90
+
91
+ namespace std {
92
+
93
+ template <>
94
+ struct hash<::antlr4::atn::LexerAction> {
95
+ size_t operator()(const ::antlr4::atn::LexerAction &lexerAction) const {
96
+ return lexerAction.hashCode();
97
+ }
63
98
  };
64
99
 
65
- } // namespace atn
66
- } // namespace antlr4
100
+ } // namespace std