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