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