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
@@ -10,12 +10,12 @@
|
|
10
10
|
#include "misc/IntervalSet.h"
|
11
11
|
#include "Parser.h"
|
12
12
|
#include "CommonTokenStream.h"
|
13
|
-
#include "atn/EmptyPredictionContext.h"
|
14
13
|
#include "atn/NotSetTransition.h"
|
15
14
|
#include "atn/AtomTransition.h"
|
16
15
|
#include "atn/RuleTransition.h"
|
17
16
|
#include "atn/PredicateTransition.h"
|
18
17
|
#include "atn/PrecedencePredicateTransition.h"
|
18
|
+
#include "atn/SingletonPredictionContext.h"
|
19
19
|
#include "atn/ActionTransition.h"
|
20
20
|
#include "atn/EpsilonTransition.h"
|
21
21
|
#include "atn/RuleStopState.h"
|
@@ -31,6 +31,7 @@
|
|
31
31
|
|
32
32
|
#include "Vocabulary.h"
|
33
33
|
#include "support/Arrays.h"
|
34
|
+
#include "support/Casts.h"
|
34
35
|
|
35
36
|
#include "atn/ParserATNSimulator.h"
|
36
37
|
|
@@ -53,7 +54,13 @@ ParserATNSimulator::ParserATNSimulator(const ATN &atn, std::vector<dfa::DFA> &de
|
|
53
54
|
|
54
55
|
ParserATNSimulator::ParserATNSimulator(Parser *parser, const ATN &atn, std::vector<dfa::DFA> &decisionToDFA,
|
55
56
|
PredictionContextCache &sharedContextCache)
|
56
|
-
:
|
57
|
+
: ParserATNSimulator(parser, atn, decisionToDFA, sharedContextCache, ParserATNSimulatorOptions()) {}
|
58
|
+
|
59
|
+
ParserATNSimulator::ParserATNSimulator(Parser *parser, const ATN &atn, std::vector<dfa::DFA> &decisionToDFA,
|
60
|
+
PredictionContextCache &sharedContextCache,
|
61
|
+
const ParserATNSimulatorOptions &options)
|
62
|
+
: ATNSimulator(atn, sharedContextCache), decisionToDFA(decisionToDFA), parser(parser),
|
63
|
+
mergeCache(options.getPredictionContextMergeCacheOptions()) {
|
57
64
|
InitializeInstanceFields();
|
58
65
|
}
|
59
66
|
|
@@ -87,28 +94,37 @@ size_t ParserATNSimulator::adaptivePredict(TokenStream *input, size_t decision,
|
|
87
94
|
// Now we are certain to have a specific decision's DFA
|
88
95
|
// But, do we still need an initial state?
|
89
96
|
auto onExit = finally([this, input, index, m] {
|
90
|
-
mergeCache.
|
97
|
+
if (mergeCache.getOptions().getClearEveryN() != 0) {
|
98
|
+
if (++_mergeCacheCounter == mergeCache.getOptions().getClearEveryN()) {
|
99
|
+
mergeCache.clear();
|
100
|
+
_mergeCacheCounter = 0;
|
101
|
+
}
|
102
|
+
}
|
91
103
|
_dfa = nullptr;
|
92
104
|
input->seek(index);
|
93
105
|
input->release(m);
|
94
106
|
});
|
95
107
|
|
96
108
|
dfa::DFAState *s0;
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
109
|
+
{
|
110
|
+
std::shared_lock<std::shared_mutex> stateLock(atn._stateMutex);
|
111
|
+
if (dfa.isPrecedenceDfa()) {
|
112
|
+
// the start state for a precedence DFA depends on the current
|
113
|
+
// parser precedence, and is provided by a DFA method.
|
114
|
+
std::shared_lock<std::shared_mutex> edgeLock(atn._edgeMutex);
|
115
|
+
s0 = dfa.getPrecedenceStartState(parser->getPrecedence());
|
116
|
+
} else {
|
117
|
+
// the start state for a "regular" DFA is just s0
|
118
|
+
s0 = dfa.s0;
|
119
|
+
}
|
104
120
|
}
|
105
121
|
|
106
122
|
if (s0 == nullptr) {
|
107
|
-
|
108
|
-
std::unique_ptr<
|
109
|
-
|
110
|
-
|
111
|
-
|
123
|
+
auto s0_closure = computeStartState(dfa.atnStartState, &ParserRuleContext::EMPTY, false);
|
124
|
+
std::unique_ptr<dfa::DFAState> newState;
|
125
|
+
std::unique_ptr<dfa::DFAState> oldState;
|
126
|
+
std::unique_lock<std::shared_mutex> stateLock(atn._stateMutex);
|
127
|
+
dfa::DFAState* ds0 = dfa.s0;
|
112
128
|
if (dfa.isPrecedenceDfa()) {
|
113
129
|
/* If this is a precedence DFA, we use applyPrecedenceFilter
|
114
130
|
* to convert the computed start state to a precedence start
|
@@ -116,26 +132,22 @@ size_t ParserATNSimulator::adaptivePredict(TokenStream *input, size_t decision,
|
|
116
132
|
* appropriate start state for the precedence level rather
|
117
133
|
* than simply setting DFA.s0.
|
118
134
|
*/
|
119
|
-
|
120
|
-
|
121
|
-
s0 = addDFAState(dfa, newState);
|
122
|
-
|
123
|
-
|
124
|
-
delete newState; // If there was already a state with this config set we don't need the new one.
|
125
|
-
}
|
135
|
+
ds0->configs = std::move(s0_closure); // not used for prediction but useful to know start configs anyway
|
136
|
+
newState = std::make_unique<dfa::DFAState>(applyPrecedenceFilter(ds0->configs.get()));
|
137
|
+
s0 = addDFAState(dfa, newState.get());
|
138
|
+
std::unique_lock<std::shared_mutex> edgeLock(atn._edgeMutex);
|
139
|
+
dfa.setPrecedenceStartState(parser->getPrecedence(), s0);
|
126
140
|
} else {
|
127
|
-
|
128
|
-
s0 = addDFAState(dfa, newState);
|
129
|
-
|
130
|
-
|
131
|
-
delete dfa.s0; // Delete existing s0 DFA state, if there's any.
|
141
|
+
newState = std::make_unique<dfa::DFAState>(std::move(s0_closure));
|
142
|
+
s0 = addDFAState(dfa, newState.get());
|
143
|
+
if (ds0 != s0) {
|
144
|
+
oldState.reset(ds0);
|
132
145
|
dfa.s0 = s0;
|
133
146
|
}
|
134
|
-
if (s0 != newState) {
|
135
|
-
delete newState; // If there was already a state with this config set we don't need the new one.
|
136
|
-
}
|
137
147
|
}
|
138
|
-
|
148
|
+
if (s0 == newState.get()) {
|
149
|
+
newState.release();
|
150
|
+
}
|
139
151
|
}
|
140
152
|
|
141
153
|
// We can start with an existing DFA.
|
@@ -220,7 +232,7 @@ size_t ParserATNSimulator::execATN(dfa::DFA &dfa, dfa::DFAState *s0, TokenStream
|
|
220
232
|
#endif
|
221
233
|
|
222
234
|
bool fullCtx = true;
|
223
|
-
|
235
|
+
std::unique_ptr<ATNConfigSet> s0_closure = computeStartState(dfa.atnStartState, outerContext, fullCtx);
|
224
236
|
reportAttemptingFullContext(dfa, conflictingAlts, D->configs.get(), startIndex, input->index());
|
225
237
|
size_t alt = execATNWithFullContext(dfa, D, s0_closure.get(), input, startIndex, outerContext);
|
226
238
|
return alt;
|
@@ -260,10 +272,9 @@ size_t ParserATNSimulator::execATN(dfa::DFA &dfa, dfa::DFAState *s0, TokenStream
|
|
260
272
|
|
261
273
|
dfa::DFAState *ParserATNSimulator::getExistingTargetState(dfa::DFAState *previousD, size_t t) {
|
262
274
|
dfa::DFAState* retval;
|
263
|
-
|
275
|
+
std::shared_lock<std::shared_mutex> edgeLock(atn._edgeMutex);
|
264
276
|
auto iterator = previousD->edges.find(t);
|
265
277
|
retval = (iterator == previousD->edges.end()) ? nullptr : iterator->second;
|
266
|
-
_edgeLock.readUnlock();
|
267
278
|
return retval;
|
268
279
|
}
|
269
280
|
|
@@ -315,7 +326,7 @@ void ParserATNSimulator::predicateDFAState(dfa::DFAState *dfaState, DecisionStat
|
|
315
326
|
// Update DFA so reach becomes accept state with (predicate,alt)
|
316
327
|
// pairs if preds found for conflicting alts
|
317
328
|
BitSet altsToCollectPredsFrom = getConflictingAltsOrUniqueAlt(dfaState->configs.get());
|
318
|
-
std::vector<Ref<SemanticContext>> altToPred = getPredsForAmbigAlts(altsToCollectPredsFrom, dfaState->configs.get(), nalts);
|
329
|
+
std::vector<Ref<const SemanticContext>> altToPred = getPredsForAmbigAlts(altsToCollectPredsFrom, dfaState->configs.get(), nalts);
|
319
330
|
if (!altToPred.empty()) {
|
320
331
|
dfaState->predicates = getPredicatePredictions(altsToCollectPredsFrom, altToPred);
|
321
332
|
dfaState->prediction = ATN::INVALID_ALT_NUMBER; // make sure we use preds
|
@@ -452,8 +463,8 @@ std::unique_ptr<ATNConfigSet> ParserATNSimulator::computeReachSet(ATNConfigSet *
|
|
452
463
|
std::vector<Ref<ATNConfig>> skippedStopStates;
|
453
464
|
|
454
465
|
// First figure out where we can reach on input t
|
455
|
-
for (auto &c : closure_->configs) {
|
456
|
-
if (is
|
466
|
+
for (const auto &c : closure_->configs) {
|
467
|
+
if (RuleStopState::is(c->state)) {
|
457
468
|
assert(c->context->isEmpty());
|
458
469
|
|
459
470
|
if (fullCtx || t == Token::EOF) {
|
@@ -465,10 +476,10 @@ std::unique_ptr<ATNConfigSet> ParserATNSimulator::computeReachSet(ATNConfigSet *
|
|
465
476
|
|
466
477
|
size_t n = c->state->transitions.size();
|
467
478
|
for (size_t ti = 0; ti < n; ti++) { // for each transition
|
468
|
-
Transition *trans = c->state->transitions[ti];
|
479
|
+
const Transition *trans = c->state->transitions[ti].get();
|
469
480
|
ATNState *target = getReachableTarget(trans, (int)t);
|
470
481
|
if (target != nullptr) {
|
471
|
-
intermediate->add(std::make_shared<ATNConfig>(c, target), &mergeCache);
|
482
|
+
intermediate->add(std::make_shared<ATNConfig>(*c, target), &mergeCache);
|
472
483
|
}
|
473
484
|
}
|
474
485
|
}
|
@@ -507,7 +518,7 @@ std::unique_ptr<ATNConfigSet> ParserATNSimulator::computeReachSet(ATNConfigSet *
|
|
507
518
|
ATNConfig::Set closureBusy;
|
508
519
|
|
509
520
|
bool treatEofAsEpsilon = t == Token::EOF;
|
510
|
-
for (auto c : intermediate->configs) {
|
521
|
+
for (const auto &c : intermediate->configs) {
|
511
522
|
closure(c, reach.get(), closureBusy, false, fullCtx, treatEofAsEpsilon);
|
512
523
|
}
|
513
524
|
}
|
@@ -546,7 +557,7 @@ std::unique_ptr<ATNConfigSet> ParserATNSimulator::computeReachSet(ATNConfigSet *
|
|
546
557
|
if (skippedStopStates.size() > 0 && (!fullCtx || !PredictionModeClass::hasConfigInRuleStopState(reach.get()))) {
|
547
558
|
assert(!skippedStopStates.empty());
|
548
559
|
|
549
|
-
for (auto c : skippedStopStates) {
|
560
|
+
for (const auto &c : skippedStopStates) {
|
550
561
|
reach->add(c, &mergeCache);
|
551
562
|
}
|
552
563
|
}
|
@@ -565,8 +576,8 @@ ATNConfigSet* ParserATNSimulator::removeAllConfigsNotInRuleStopState(ATNConfigSe
|
|
565
576
|
|
566
577
|
ATNConfigSet *result = new ATNConfigSet(configs->fullCtx); /* mem-check: released by caller */
|
567
578
|
|
568
|
-
for (auto &config : configs->configs) {
|
569
|
-
if (
|
579
|
+
for (const auto &config : configs->configs) {
|
580
|
+
if (config->state != nullptr && config->state->getStateType() == ATNStateType::RULE_STOP) {
|
570
581
|
result->add(config, &mergeCache);
|
571
582
|
continue;
|
572
583
|
}
|
@@ -575,7 +586,7 @@ ATNConfigSet* ParserATNSimulator::removeAllConfigsNotInRuleStopState(ATNConfigSe
|
|
575
586
|
misc::IntervalSet nextTokens = atn.nextTokens(config->state);
|
576
587
|
if (nextTokens.contains(Token::EPSILON)) {
|
577
588
|
ATNState *endOfRuleState = atn.ruleToStopState[config->state->ruleIndex];
|
578
|
-
result->add(std::make_shared<ATNConfig>(config, endOfRuleState), &mergeCache);
|
589
|
+
result->add(std::make_shared<ATNConfig>(*config, endOfRuleState), &mergeCache);
|
579
590
|
}
|
580
591
|
}
|
581
592
|
}
|
@@ -585,7 +596,7 @@ ATNConfigSet* ParserATNSimulator::removeAllConfigsNotInRuleStopState(ATNConfigSe
|
|
585
596
|
|
586
597
|
std::unique_ptr<ATNConfigSet> ParserATNSimulator::computeStartState(ATNState *p, RuleContext *ctx, bool fullCtx) {
|
587
598
|
// always at least the implicit call to start rule
|
588
|
-
Ref<PredictionContext> initialContext = PredictionContext::fromRuleContext(atn, ctx);
|
599
|
+
Ref<const PredictionContext> initialContext = PredictionContext::fromRuleContext(atn, ctx);
|
589
600
|
std::unique_ptr<ATNConfigSet> configs(new ATNConfigSet(fullCtx));
|
590
601
|
|
591
602
|
for (size_t i = 0; i < p->transitions.size(); i++) {
|
@@ -599,15 +610,15 @@ std::unique_ptr<ATNConfigSet> ParserATNSimulator::computeStartState(ATNState *p,
|
|
599
610
|
}
|
600
611
|
|
601
612
|
std::unique_ptr<ATNConfigSet> ParserATNSimulator::applyPrecedenceFilter(ATNConfigSet *configs) {
|
602
|
-
std::map<size_t, Ref<PredictionContext>> statesFromAlt1;
|
613
|
+
std::map<size_t, Ref<const PredictionContext>> statesFromAlt1;
|
603
614
|
std::unique_ptr<ATNConfigSet> configSet(new ATNConfigSet(configs->fullCtx));
|
604
|
-
for (
|
615
|
+
for (const auto &config : configs->configs) {
|
605
616
|
// handle alt 1 first
|
606
617
|
if (config->alt != 1) {
|
607
618
|
continue;
|
608
619
|
}
|
609
620
|
|
610
|
-
Ref<SemanticContext> updatedContext = config->semanticContext->evalPrecedence(parser, _outerContext);
|
621
|
+
Ref<const SemanticContext> updatedContext = config->semanticContext->evalPrecedence(parser, _outerContext);
|
611
622
|
if (updatedContext == nullptr) {
|
612
623
|
// the configuration was eliminated
|
613
624
|
continue;
|
@@ -615,14 +626,14 @@ std::unique_ptr<ATNConfigSet> ParserATNSimulator::applyPrecedenceFilter(ATNConfi
|
|
615
626
|
|
616
627
|
statesFromAlt1[config->state->stateNumber] = config->context;
|
617
628
|
if (updatedContext != config->semanticContext) {
|
618
|
-
configSet->add(std::make_shared<ATNConfig>(config, updatedContext), &mergeCache);
|
629
|
+
configSet->add(std::make_shared<ATNConfig>(*config, updatedContext), &mergeCache);
|
619
630
|
}
|
620
631
|
else {
|
621
632
|
configSet->add(config, &mergeCache);
|
622
633
|
}
|
623
634
|
}
|
624
635
|
|
625
|
-
for (
|
636
|
+
for (const auto &config : configs->configs) {
|
626
637
|
if (config->alt == 1) {
|
627
638
|
// already handled
|
628
639
|
continue;
|
@@ -646,7 +657,7 @@ std::unique_ptr<ATNConfigSet> ParserATNSimulator::applyPrecedenceFilter(ATNConfi
|
|
646
657
|
return configSet;
|
647
658
|
}
|
648
659
|
|
649
|
-
atn::ATNState* ParserATNSimulator::getReachableTarget(Transition *trans, size_t ttype) {
|
660
|
+
atn::ATNState* ParserATNSimulator::getReachableTarget(const Transition *trans, size_t ttype) {
|
650
661
|
if (trans->matches(ttype, 0, atn.maxTokenType)) {
|
651
662
|
return trans->target;
|
652
663
|
}
|
@@ -655,7 +666,7 @@ atn::ATNState* ParserATNSimulator::getReachableTarget(Transition *trans, size_t
|
|
655
666
|
}
|
656
667
|
|
657
668
|
// Note that caller must memory manage the returned value from this function
|
658
|
-
std::vector<Ref<SemanticContext>> ParserATNSimulator::getPredsForAmbigAlts(const BitSet &ambigAlts,
|
669
|
+
std::vector<Ref<const SemanticContext>> ParserATNSimulator::getPredsForAmbigAlts(const BitSet &ambigAlts,
|
659
670
|
ATNConfigSet *configs, size_t nalts) {
|
660
671
|
// REACH=[1|1|[]|0:0, 1|2|[]|0:1]
|
661
672
|
/* altToPred starts as an array of all null contexts. The entry at index i
|
@@ -669,9 +680,9 @@ std::vector<Ref<SemanticContext>> ParserATNSimulator::getPredsForAmbigAlts(const
|
|
669
680
|
*
|
670
681
|
* From this, it is clear that NONE||anything==NONE.
|
671
682
|
*/
|
672
|
-
std::vector<Ref<SemanticContext>> altToPred(nalts + 1);
|
683
|
+
std::vector<Ref<const SemanticContext>> altToPred(nalts + 1);
|
673
684
|
|
674
|
-
for (auto &c : configs->configs) {
|
685
|
+
for (const auto &c : configs->configs) {
|
675
686
|
if (ambigAlts.test(c->alt)) {
|
676
687
|
altToPred[c->alt] = SemanticContext::Or(altToPred[c->alt], c->semanticContext);
|
677
688
|
}
|
@@ -697,21 +708,19 @@ std::vector<Ref<SemanticContext>> ParserATNSimulator::getPredsForAmbigAlts(const
|
|
697
708
|
return altToPred;
|
698
709
|
}
|
699
710
|
|
700
|
-
std::vector<dfa::DFAState::PredPrediction
|
701
|
-
|
702
|
-
bool containsPredicate = std::find_if(altToPred.begin(), altToPred.end(), [](Ref<SemanticContext>
|
711
|
+
std::vector<dfa::DFAState::PredPrediction> ParserATNSimulator::getPredicatePredictions(const antlrcpp::BitSet &ambigAlts,
|
712
|
+
const std::vector<Ref<const SemanticContext>> &altToPred) {
|
713
|
+
bool containsPredicate = std::find_if(altToPred.begin(), altToPred.end(), [](const Ref<const SemanticContext> &context) {
|
703
714
|
return context != SemanticContext::NONE;
|
704
715
|
}) != altToPred.end();
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
|
712
|
-
|
713
|
-
if (ambigAlts.test(i)) {
|
714
|
-
pairs.push_back(new dfa::DFAState::PredPrediction(pred, (int)i)); /* mem-check: managed by the DFAState it will be assigned to after return */
|
716
|
+
std::vector<dfa::DFAState::PredPrediction> pairs;
|
717
|
+
if (containsPredicate) {
|
718
|
+
for (size_t i = 1; i < altToPred.size(); i++) {
|
719
|
+
const auto &pred = altToPred[i];
|
720
|
+
assert(pred != nullptr); // unpredicted is indicated by SemanticContext.NONE
|
721
|
+
if (ambigAlts.test(i)) {
|
722
|
+
pairs.emplace_back(pred, static_cast<int>(i));
|
723
|
+
}
|
715
724
|
}
|
716
725
|
}
|
717
726
|
return pairs;
|
@@ -739,8 +748,8 @@ size_t ParserATNSimulator::getSynValidOrSemInvalidAltThatFinishedDecisionEntryRu
|
|
739
748
|
|
740
749
|
size_t ParserATNSimulator::getAltThatFinishedDecisionEntryRule(ATNConfigSet *configs) {
|
741
750
|
misc::IntervalSet alts;
|
742
|
-
for (auto &c : configs->configs) {
|
743
|
-
if (c->getOuterContextDepth() > 0 || (
|
751
|
+
for (const auto &c : configs->configs) {
|
752
|
+
if (c->getOuterContextDepth() > 0 || (c->state != nullptr && c->state->getStateType() == ATNStateType::RULE_STOP && c->context->hasEmptyPath())) {
|
744
753
|
alts.add(c->alt);
|
745
754
|
}
|
746
755
|
}
|
@@ -756,7 +765,7 @@ std::pair<ATNConfigSet *, ATNConfigSet *> ParserATNSimulator::splitAccordingToSe
|
|
756
765
|
// mem-check: both pointers must be freed by the caller.
|
757
766
|
ATNConfigSet *succeeded(new ATNConfigSet(configs->fullCtx));
|
758
767
|
ATNConfigSet *failed(new ATNConfigSet(configs->fullCtx));
|
759
|
-
for (
|
768
|
+
for (const auto &c : configs->configs) {
|
760
769
|
if (c->semanticContext != SemanticContext::NONE) {
|
761
770
|
bool predicateEvaluationResult = evalSemanticContext(c->semanticContext, outerContext, c->alt, configs->fullCtx);
|
762
771
|
if (predicateEvaluationResult) {
|
@@ -771,12 +780,12 @@ std::pair<ATNConfigSet *, ATNConfigSet *> ParserATNSimulator::splitAccordingToSe
|
|
771
780
|
return { succeeded, failed };
|
772
781
|
}
|
773
782
|
|
774
|
-
BitSet ParserATNSimulator::evalSemanticContext(std::vector<dfa::DFAState::PredPrediction
|
783
|
+
BitSet ParserATNSimulator::evalSemanticContext(const std::vector<dfa::DFAState::PredPrediction> &predPredictions,
|
775
784
|
ParserRuleContext *outerContext, bool complete) {
|
776
785
|
BitSet predictions;
|
777
|
-
for (auto prediction : predPredictions) {
|
778
|
-
if (prediction
|
779
|
-
predictions.set(prediction
|
786
|
+
for (const auto &prediction : predPredictions) {
|
787
|
+
if (prediction.pred == SemanticContext::NONE) {
|
788
|
+
predictions.set(prediction.alt);
|
780
789
|
if (!complete) {
|
781
790
|
break;
|
782
791
|
}
|
@@ -784,17 +793,17 @@ BitSet ParserATNSimulator::evalSemanticContext(std::vector<dfa::DFAState::PredPr
|
|
784
793
|
}
|
785
794
|
|
786
795
|
bool fullCtx = false; // in dfa
|
787
|
-
bool predicateEvaluationResult = evalSemanticContext(prediction
|
796
|
+
bool predicateEvaluationResult = evalSemanticContext(prediction.pred, outerContext, prediction.alt, fullCtx);
|
788
797
|
#if DEBUG_ATN == 1 || DEBUG_DFA == 1
|
789
|
-
std::cout << "eval pred " << prediction
|
798
|
+
std::cout << "eval pred " << prediction.toString() << " = " << predicateEvaluationResult << std::endl;
|
790
799
|
#endif
|
791
800
|
|
792
801
|
if (predicateEvaluationResult) {
|
793
802
|
#if DEBUG_ATN == 1 || DEBUG_DFA == 1
|
794
|
-
std::cout << "PREDICT " << prediction
|
803
|
+
std::cout << "PREDICT " << prediction.alt << std::endl;
|
795
804
|
#endif
|
796
805
|
|
797
|
-
predictions.set(prediction
|
806
|
+
predictions.set(prediction.alt);
|
798
807
|
if (!complete) {
|
799
808
|
break;
|
800
809
|
}
|
@@ -804,7 +813,7 @@ BitSet ParserATNSimulator::evalSemanticContext(std::vector<dfa::DFAState::PredPr
|
|
804
813
|
return predictions;
|
805
814
|
}
|
806
815
|
|
807
|
-
bool ParserATNSimulator::evalSemanticContext(Ref<SemanticContext> const& pred, ParserRuleContext *parserCallStack,
|
816
|
+
bool ParserATNSimulator::evalSemanticContext(Ref<const SemanticContext> const& pred, ParserRuleContext *parserCallStack,
|
808
817
|
size_t /*alt*/, bool /*fullCtx*/) {
|
809
818
|
return pred->eval(parser, parserCallStack);
|
810
819
|
}
|
@@ -824,14 +833,14 @@ void ParserATNSimulator::closureCheckingStopState(Ref<ATNConfig> const& config,
|
|
824
833
|
std::cout << "closure(" << config->toString(true) << ")" << std::endl;
|
825
834
|
#endif
|
826
835
|
|
827
|
-
if (
|
836
|
+
if (config->state != nullptr && config->state->getStateType() == ATNStateType::RULE_STOP) {
|
828
837
|
// We hit rule end. If we have context info, use it
|
829
838
|
// run thru all possible stack tops in ctx
|
830
839
|
if (!config->context->isEmpty()) {
|
831
840
|
for (size_t i = 0; i < config->context->size(); i++) {
|
832
841
|
if (config->context->getReturnState(i) == PredictionContext::EMPTY_RETURN_STATE) {
|
833
842
|
if (fullCtx) {
|
834
|
-
configs->add(std::make_shared<ATNConfig>(config, config->state, PredictionContext::EMPTY), &mergeCache);
|
843
|
+
configs->add(std::make_shared<ATNConfig>(*config, config->state, PredictionContext::EMPTY), &mergeCache);
|
835
844
|
continue;
|
836
845
|
} else {
|
837
846
|
// we have no context info, just chase follow links (if greedy)
|
@@ -843,8 +852,8 @@ void ParserATNSimulator::closureCheckingStopState(Ref<ATNConfig> const& config,
|
|
843
852
|
continue;
|
844
853
|
}
|
845
854
|
ATNState *returnState = atn.states[config->context->getReturnState(i)];
|
846
|
-
|
847
|
-
Ref<ATNConfig> c = std::make_shared<ATNConfig>(returnState, config->alt, newContext
|
855
|
+
Ref<const PredictionContext> newContext = config->context->getParent(i); // "pop" return state
|
856
|
+
Ref<ATNConfig> c = std::make_shared<ATNConfig>(returnState, config->alt, newContext, config->semanticContext);
|
848
857
|
// While we have context to pop back from, we may have
|
849
858
|
// gotten that context AFTER having falling off a rule.
|
850
859
|
// Make sure we track that we are now out of context.
|
@@ -884,12 +893,12 @@ void ParserATNSimulator::closure_(Ref<ATNConfig> const& config, ATNConfigSet *co
|
|
884
893
|
if (i == 0 && canDropLoopEntryEdgeInLeftRecursiveRule(config.get()))
|
885
894
|
continue;
|
886
895
|
|
887
|
-
Transition *t = p->transitions[i];
|
888
|
-
bool continueCollecting = !
|
896
|
+
const Transition *t = p->transitions[i].get();
|
897
|
+
bool continueCollecting = !(t != nullptr && t->getTransitionType() == TransitionType::ACTION) && collectPredicates;
|
889
898
|
Ref<ATNConfig> c = getEpsilonTarget(config, t, continueCollecting, depth == 0, fullCtx, treatEofAsEpsilon);
|
890
899
|
if (c != nullptr) {
|
891
900
|
int newDepth = depth;
|
892
|
-
if (
|
901
|
+
if (config->state != nullptr && config->state->getStateType() == ATNStateType::RULE_STOP) {
|
893
902
|
assert(!fullCtx);
|
894
903
|
|
895
904
|
// target fell off end of rule; mark resulting c as having dipped into outer context
|
@@ -905,7 +914,7 @@ void ParserATNSimulator::closure_(Ref<ATNConfig> const& config, ATNConfigSet *co
|
|
905
914
|
closureBusy.insert(c);
|
906
915
|
|
907
916
|
if (_dfa != nullptr && _dfa->isPrecedenceDfa()) {
|
908
|
-
size_t outermostPrecedenceReturn =
|
917
|
+
size_t outermostPrecedenceReturn = downCast<const EpsilonTransition *>(t)->outermostPrecedenceReturn();
|
909
918
|
if (outermostPrecedenceReturn == _dfa->atnStartState->ruleIndex) {
|
910
919
|
c->setPrecedenceFilterSuppressed(true);
|
911
920
|
}
|
@@ -939,7 +948,7 @@ void ParserATNSimulator::closure_(Ref<ATNConfig> const& config, ATNConfigSet *co
|
|
939
948
|
}
|
940
949
|
}
|
941
950
|
|
942
|
-
if (
|
951
|
+
if (t != nullptr && t->getTransitionType() == TransitionType::RULE) {
|
943
952
|
// latch when newDepth goes negative - once we step out of the entry context we can't return
|
944
953
|
if (newDepth >= 0) {
|
945
954
|
newDepth++;
|
@@ -961,7 +970,7 @@ bool ParserATNSimulator::canDropLoopEntryEdgeInLeftRecursiveRule(ATNConfig *conf
|
|
961
970
|
// left-recursion elimination. For efficiency, also check if
|
962
971
|
// the context has an empty stack case. If so, it would mean
|
963
972
|
// global FOLLOW so we can't perform optimization
|
964
|
-
if (p->getStateType() !=
|
973
|
+
if (p->getStateType() != ATNStateType::STAR_LOOP_ENTRY ||
|
965
974
|
!((StarLoopEntryState *)p)->isPrecedenceDecision || // Are we the special loop entry/exit state?
|
966
975
|
config->context->isEmpty() || // If SLL wildcard
|
967
976
|
config->context->hasEmptyPath())
|
@@ -995,7 +1004,7 @@ bool ParserATNSimulator::canDropLoopEntryEdgeInLeftRecursiveRule(ATNConfig *conf
|
|
995
1004
|
|
996
1005
|
// Look for prefix op case like 'not expr', (' type ')' expr
|
997
1006
|
ATNState *returnStateTarget = returnState->transitions[0]->target;
|
998
|
-
if (returnState->getStateType() ==
|
1007
|
+
if (returnState->getStateType() == ATNStateType::BLOCK_END && returnStateTarget == p) {
|
999
1008
|
continue;
|
1000
1009
|
}
|
1001
1010
|
|
@@ -1014,7 +1023,7 @@ bool ParserATNSimulator::canDropLoopEntryEdgeInLeftRecursiveRule(ATNConfig *conf
|
|
1014
1023
|
|
1015
1024
|
// Look for complex prefix 'between expr and expr' case where 2nd expr's
|
1016
1025
|
// return state points at block end state of (...)* internal block
|
1017
|
-
if (returnStateTarget->getStateType() ==
|
1026
|
+
if (returnStateTarget->getStateType() == ATNStateType::BLOCK_END &&
|
1018
1027
|
returnStateTarget->transitions.size() == 1 &&
|
1019
1028
|
returnStateTarget->transitions[0]->isEpsilon() &&
|
1020
1029
|
returnStateTarget->transitions[0]->target == p)
|
@@ -1036,32 +1045,32 @@ std::string ParserATNSimulator::getRuleName(size_t index) {
|
|
1036
1045
|
return "<rule " + std::to_string(index) + ">";
|
1037
1046
|
}
|
1038
1047
|
|
1039
|
-
Ref<ATNConfig> ParserATNSimulator::getEpsilonTarget(Ref<ATNConfig> const& config, Transition *t, bool collectPredicates,
|
1048
|
+
Ref<ATNConfig> ParserATNSimulator::getEpsilonTarget(Ref<ATNConfig> const& config, const Transition *t, bool collectPredicates,
|
1040
1049
|
bool inContext, bool fullCtx, bool treatEofAsEpsilon) {
|
1041
|
-
switch (t->
|
1042
|
-
case
|
1043
|
-
return ruleTransition(config, static_cast<RuleTransition*>(t));
|
1050
|
+
switch (t->getTransitionType()) {
|
1051
|
+
case TransitionType::RULE:
|
1052
|
+
return ruleTransition(config, static_cast<const RuleTransition*>(t));
|
1044
1053
|
|
1045
|
-
case
|
1046
|
-
return precedenceTransition(config, static_cast<PrecedencePredicateTransition*>(t), collectPredicates, inContext, fullCtx);
|
1054
|
+
case TransitionType::PRECEDENCE:
|
1055
|
+
return precedenceTransition(config, static_cast<const PrecedencePredicateTransition*>(t), collectPredicates, inContext, fullCtx);
|
1047
1056
|
|
1048
|
-
case
|
1049
|
-
return predTransition(config, static_cast<PredicateTransition*>(t), collectPredicates, inContext, fullCtx);
|
1057
|
+
case TransitionType::PREDICATE:
|
1058
|
+
return predTransition(config, static_cast<const PredicateTransition*>(t), collectPredicates, inContext, fullCtx);
|
1050
1059
|
|
1051
|
-
case
|
1052
|
-
return actionTransition(config, static_cast<ActionTransition*>(t));
|
1060
|
+
case TransitionType::ACTION:
|
1061
|
+
return actionTransition(config, static_cast<const ActionTransition*>(t));
|
1053
1062
|
|
1054
|
-
case
|
1055
|
-
return std::make_shared<ATNConfig>(config, t->target);
|
1063
|
+
case TransitionType::EPSILON:
|
1064
|
+
return std::make_shared<ATNConfig>(*config, t->target);
|
1056
1065
|
|
1057
|
-
case
|
1058
|
-
case
|
1059
|
-
case
|
1066
|
+
case TransitionType::ATOM:
|
1067
|
+
case TransitionType::RANGE:
|
1068
|
+
case TransitionType::SET:
|
1060
1069
|
// EOF transitions act like epsilon transitions after the first EOF
|
1061
1070
|
// transition is traversed
|
1062
1071
|
if (treatEofAsEpsilon) {
|
1063
1072
|
if (t->matches(Token::EOF, 0, 1)) {
|
1064
|
-
return std::make_shared<ATNConfig>(config, t->target);
|
1073
|
+
return std::make_shared<ATNConfig>(*config, t->target);
|
1065
1074
|
}
|
1066
1075
|
}
|
1067
1076
|
|
@@ -1072,18 +1081,18 @@ Ref<ATNConfig> ParserATNSimulator::getEpsilonTarget(Ref<ATNConfig> const& config
|
|
1072
1081
|
}
|
1073
1082
|
}
|
1074
1083
|
|
1075
|
-
Ref<ATNConfig> ParserATNSimulator::actionTransition(Ref<ATNConfig> const& config, ActionTransition *t) {
|
1084
|
+
Ref<ATNConfig> ParserATNSimulator::actionTransition(Ref<ATNConfig> const& config, const ActionTransition *t) {
|
1076
1085
|
#if DEBUG_DFA == 1
|
1077
1086
|
std::cout << "ACTION edge " << t->ruleIndex << ":" << t->actionIndex << std::endl;
|
1078
1087
|
#endif
|
1079
1088
|
|
1080
|
-
return std::make_shared<ATNConfig>(config, t->target);
|
1089
|
+
return std::make_shared<ATNConfig>(*config, t->target);
|
1081
1090
|
}
|
1082
1091
|
|
1083
|
-
Ref<ATNConfig> ParserATNSimulator::precedenceTransition(Ref<ATNConfig> const& config, PrecedencePredicateTransition *pt,
|
1092
|
+
Ref<ATNConfig> ParserATNSimulator::precedenceTransition(Ref<ATNConfig> const& config, const PrecedencePredicateTransition *pt,
|
1084
1093
|
bool collectPredicates, bool inContext, bool fullCtx) {
|
1085
1094
|
#if DEBUG_DFA == 1
|
1086
|
-
std::cout << "PRED (collectPredicates=" << collectPredicates << ") " << pt->
|
1095
|
+
std::cout << "PRED (collectPredicates=" << collectPredicates << ") " << pt->getPrecedence() << ">=_p" << ", ctx dependent=true" << std::endl;
|
1087
1096
|
if (parser != nullptr) {
|
1088
1097
|
std::cout << "context surrounding pred is " << Arrays::listToString(parser->getRuleInvocationStack(), ", ") << std::endl;
|
1089
1098
|
}
|
@@ -1091,7 +1100,7 @@ Ref<ATNConfig> ParserATNSimulator::precedenceTransition(Ref<ATNConfig> const& co
|
|
1091
1100
|
|
1092
1101
|
Ref<ATNConfig> c;
|
1093
1102
|
if (collectPredicates && inContext) {
|
1094
|
-
|
1103
|
+
const auto &predicate = pt->getPredicate();
|
1095
1104
|
|
1096
1105
|
if (fullCtx) {
|
1097
1106
|
// In full context mode, we can evaluate predicates on-the-fly
|
@@ -1100,17 +1109,17 @@ Ref<ATNConfig> ParserATNSimulator::precedenceTransition(Ref<ATNConfig> const& co
|
|
1100
1109
|
// later during conflict resolution.
|
1101
1110
|
size_t currentPosition = _input->index();
|
1102
1111
|
_input->seek(_startIndex);
|
1103
|
-
bool predSucceeds = evalSemanticContext(
|
1112
|
+
bool predSucceeds = evalSemanticContext(predicate, _outerContext, config->alt, fullCtx);
|
1104
1113
|
_input->seek(currentPosition);
|
1105
1114
|
if (predSucceeds) {
|
1106
|
-
c = std::make_shared<ATNConfig>(config, pt->target); // no pred context
|
1115
|
+
c = std::make_shared<ATNConfig>(*config, pt->target); // no pred context
|
1107
1116
|
}
|
1108
1117
|
} else {
|
1109
|
-
Ref<SemanticContext> newSemCtx = SemanticContext::And(config->semanticContext, predicate);
|
1110
|
-
c = std::make_shared<ATNConfig>(config, pt->target, newSemCtx);
|
1118
|
+
Ref<const SemanticContext> newSemCtx = SemanticContext::And(config->semanticContext, predicate);
|
1119
|
+
c = std::make_shared<ATNConfig>(*config, pt->target, std::move(newSemCtx));
|
1111
1120
|
}
|
1112
1121
|
} else {
|
1113
|
-
c = std::make_shared<ATNConfig>(config, pt->target);
|
1122
|
+
c = std::make_shared<ATNConfig>(*config, pt->target);
|
1114
1123
|
}
|
1115
1124
|
|
1116
1125
|
#if DEBUG_DFA == 1
|
@@ -1120,18 +1129,18 @@ Ref<ATNConfig> ParserATNSimulator::precedenceTransition(Ref<ATNConfig> const& co
|
|
1120
1129
|
return c;
|
1121
1130
|
}
|
1122
1131
|
|
1123
|
-
Ref<ATNConfig> ParserATNSimulator::predTransition(Ref<ATNConfig> const& config, PredicateTransition *pt,
|
1132
|
+
Ref<ATNConfig> ParserATNSimulator::predTransition(Ref<ATNConfig> const& config, const PredicateTransition *pt,
|
1124
1133
|
bool collectPredicates, bool inContext, bool fullCtx) {
|
1125
1134
|
#if DEBUG_DFA == 1
|
1126
|
-
std::cout << "PRED (collectPredicates=" << collectPredicates << ") " << pt->
|
1135
|
+
std::cout << "PRED (collectPredicates=" << collectPredicates << ") " << pt->getRuleIndex() << ":" << pt->getPredIndex() << ", ctx dependent=" << pt->isCtxDependent() << std::endl;
|
1127
1136
|
if (parser != nullptr) {
|
1128
1137
|
std::cout << "context surrounding pred is " << Arrays::listToString(parser->getRuleInvocationStack(), ", ") << std::endl;
|
1129
1138
|
}
|
1130
1139
|
#endif
|
1131
1140
|
|
1132
1141
|
Ref<ATNConfig> c = nullptr;
|
1133
|
-
if (collectPredicates && (!pt->isCtxDependent || (pt->isCtxDependent && inContext))) {
|
1134
|
-
|
1142
|
+
if (collectPredicates && (!pt->isCtxDependent() || (pt->isCtxDependent() && inContext))) {
|
1143
|
+
const auto &predicate = pt->getPredicate();
|
1135
1144
|
if (fullCtx) {
|
1136
1145
|
// In full context mode, we can evaluate predicates on-the-fly
|
1137
1146
|
// during closure, which dramatically reduces the size of
|
@@ -1139,17 +1148,17 @@ Ref<ATNConfig> ParserATNSimulator::predTransition(Ref<ATNConfig> const& config,
|
|
1139
1148
|
// later during conflict resolution.
|
1140
1149
|
size_t currentPosition = _input->index();
|
1141
1150
|
_input->seek(_startIndex);
|
1142
|
-
bool predSucceeds = evalSemanticContext(
|
1151
|
+
bool predSucceeds = evalSemanticContext(predicate, _outerContext, config->alt, fullCtx);
|
1143
1152
|
_input->seek(currentPosition);
|
1144
1153
|
if (predSucceeds) {
|
1145
|
-
c = std::make_shared<ATNConfig>(config, pt->target); // no pred context
|
1154
|
+
c = std::make_shared<ATNConfig>(*config, pt->target); // no pred context
|
1146
1155
|
}
|
1147
1156
|
} else {
|
1148
|
-
Ref<SemanticContext> newSemCtx = SemanticContext::And(config->semanticContext, predicate);
|
1149
|
-
c = std::make_shared<ATNConfig>(config, pt->target, newSemCtx);
|
1157
|
+
Ref<const SemanticContext> newSemCtx = SemanticContext::And(config->semanticContext, predicate);
|
1158
|
+
c = std::make_shared<ATNConfig>(*config, pt->target, std::move(newSemCtx));
|
1150
1159
|
}
|
1151
1160
|
} else {
|
1152
|
-
c = std::make_shared<ATNConfig>(config, pt->target);
|
1161
|
+
c = std::make_shared<ATNConfig>(*config, pt->target);
|
1153
1162
|
}
|
1154
1163
|
|
1155
1164
|
#if DEBUG_DFA == 1
|
@@ -1159,14 +1168,14 @@ Ref<ATNConfig> ParserATNSimulator::predTransition(Ref<ATNConfig> const& config,
|
|
1159
1168
|
return c;
|
1160
1169
|
}
|
1161
1170
|
|
1162
|
-
Ref<ATNConfig> ParserATNSimulator::ruleTransition(Ref<ATNConfig> const& config, RuleTransition *t) {
|
1171
|
+
Ref<ATNConfig> ParserATNSimulator::ruleTransition(Ref<ATNConfig> const& config, const RuleTransition *t) {
|
1163
1172
|
#if DEBUG_DFA == 1
|
1164
1173
|
std::cout << "CALL rule " << getRuleName(t->target->ruleIndex) << ", ctx=" << config->context << std::endl;
|
1165
1174
|
#endif
|
1166
1175
|
|
1167
1176
|
atn::ATNState *returnState = t->followState;
|
1168
|
-
Ref<PredictionContext> newContext = SingletonPredictionContext::create(config->context, returnState->stateNumber);
|
1169
|
-
return std::make_shared<ATNConfig>(config, t->target, newContext);
|
1177
|
+
Ref<const PredictionContext> newContext = SingletonPredictionContext::create(config->context, returnState->stateNumber);
|
1178
|
+
return std::make_shared<ATNConfig>(*config, t->target, newContext);
|
1170
1179
|
}
|
1171
1180
|
|
1172
1181
|
BitSet ParserATNSimulator::getConflictingAlts(ATNConfigSet *configs) {
|
@@ -1189,7 +1198,7 @@ std::string ParserATNSimulator::getTokenName(size_t t) {
|
|
1189
1198
|
return "EOF";
|
1190
1199
|
}
|
1191
1200
|
|
1192
|
-
const dfa::Vocabulary &vocabulary = parser != nullptr ? parser->getVocabulary() : dfa::Vocabulary
|
1201
|
+
const dfa::Vocabulary &vocabulary = parser != nullptr ? parser->getVocabulary() : dfa::Vocabulary();
|
1193
1202
|
std::string displayName = vocabulary.getDisplayName(t);
|
1194
1203
|
if (displayName == std::to_string(t)) {
|
1195
1204
|
return displayName;
|
@@ -1204,18 +1213,20 @@ std::string ParserATNSimulator::getLookaheadName(TokenStream *input) {
|
|
1204
1213
|
|
1205
1214
|
void ParserATNSimulator::dumpDeadEndConfigs(NoViableAltException &nvae) {
|
1206
1215
|
std::cerr << "dead end configs: ";
|
1207
|
-
for (auto c : nvae.getDeadEndConfigs()->configs) {
|
1216
|
+
for (const auto &c : nvae.getDeadEndConfigs()->configs) {
|
1208
1217
|
std::string trans = "no edges";
|
1209
1218
|
if (c->state->transitions.size() > 0) {
|
1210
|
-
Transition *t = c->state->transitions[0];
|
1211
|
-
if (
|
1212
|
-
AtomTransition *at = static_cast<AtomTransition*>(t);
|
1219
|
+
const Transition *t = c->state->transitions[0].get();
|
1220
|
+
if (t != nullptr && t->getTransitionType() == TransitionType::ATOM) {
|
1221
|
+
const AtomTransition *at = static_cast<const AtomTransition*>(t);
|
1213
1222
|
trans = "Atom " + getTokenName(at->_label);
|
1214
|
-
} else if (
|
1215
|
-
SetTransition *st = static_cast<SetTransition*>(t);
|
1216
|
-
|
1217
|
-
trans
|
1218
|
-
|
1223
|
+
} else if (t != nullptr && t->getTransitionType() == TransitionType::SET) {
|
1224
|
+
const SetTransition *st = static_cast<const SetTransition*>(t);
|
1225
|
+
trans = "Set ";
|
1226
|
+
trans += st->set.toString();
|
1227
|
+
} else if (t != nullptr && t->getTransitionType() == TransitionType::NOT_SET) {
|
1228
|
+
const SetTransition *st = static_cast<const NotSetTransition*>(t);
|
1229
|
+
trans = "~Set ";
|
1219
1230
|
trans += st->set.toString();
|
1220
1231
|
}
|
1221
1232
|
}
|
@@ -1230,7 +1241,7 @@ NoViableAltException ParserATNSimulator::noViableAlt(TokenStream *input, ParserR
|
|
1230
1241
|
|
1231
1242
|
size_t ParserATNSimulator::getUniqueAlt(ATNConfigSet *configs) {
|
1232
1243
|
size_t alt = ATN::INVALID_ALT_NUMBER;
|
1233
|
-
for (auto &c : configs->configs) {
|
1244
|
+
for (const auto &c : configs->configs) {
|
1234
1245
|
if (alt == ATN::INVALID_ALT_NUMBER) {
|
1235
1246
|
alt = c->alt; // found first alt
|
1236
1247
|
} else if (c->alt != alt) {
|
@@ -1249,17 +1260,17 @@ dfa::DFAState *ParserATNSimulator::addDFAEdge(dfa::DFA &dfa, dfa::DFAState *from
|
|
1249
1260
|
return nullptr;
|
1250
1261
|
}
|
1251
1262
|
|
1252
|
-
|
1253
|
-
|
1254
|
-
|
1263
|
+
{
|
1264
|
+
std::unique_lock<std::shared_mutex> stateLock(atn._stateMutex);
|
1265
|
+
to = addDFAState(dfa, to); // used existing if possible not incoming
|
1266
|
+
}
|
1255
1267
|
if (from == nullptr || t > (int)atn.maxTokenType) {
|
1256
1268
|
return to;
|
1257
1269
|
}
|
1258
1270
|
|
1259
1271
|
{
|
1260
|
-
|
1272
|
+
std::unique_lock<std::shared_mutex> edgeLock(atn._edgeMutex);
|
1261
1273
|
from->edges[t] = to; // connect
|
1262
|
-
_edgeLock.writeUnlock();
|
1263
1274
|
}
|
1264
1275
|
|
1265
1276
|
#if DEBUG_DFA == 1
|
@@ -1267,7 +1278,7 @@ dfa::DFAState *ParserATNSimulator::addDFAEdge(dfa::DFA &dfa, dfa::DFAState *from
|
|
1267
1278
|
if (parser != nullptr) {
|
1268
1279
|
dfaText = dfa.toString(parser->getVocabulary());
|
1269
1280
|
} else {
|
1270
|
-
dfaText = dfa.toString(dfa::Vocabulary
|
1281
|
+
dfaText = dfa.toString(dfa::Vocabulary());
|
1271
1282
|
}
|
1272
1283
|
std::cout << "DFA=\n" << dfaText << std::endl;
|
1273
1284
|
#endif
|
@@ -1280,19 +1291,21 @@ dfa::DFAState *ParserATNSimulator::addDFAState(dfa::DFA &dfa, dfa::DFAState *D)
|
|
1280
1291
|
return D;
|
1281
1292
|
}
|
1282
1293
|
|
1283
|
-
|
1284
|
-
if
|
1294
|
+
// Optimizing the configs below should not alter the hash code. Thus we can just do an insert
|
1295
|
+
// which will only succeed if an equivalent DFAState does not already exist.
|
1296
|
+
auto [existing, inserted] = dfa.states.insert(D);
|
1297
|
+
if (!inserted) {
|
1285
1298
|
return *existing;
|
1286
1299
|
}
|
1287
1300
|
|
1288
|
-
|
1301
|
+
// Previously we did a lookup, then set fields, then inserted. It was `dfa.states.size()`, since
|
1302
|
+
// we already inserted we need to subtract one.
|
1303
|
+
D->stateNumber = static_cast<int>(dfa.states.size() - 1);
|
1289
1304
|
if (!D->configs->isReadonly()) {
|
1290
1305
|
D->configs->optimizeConfigs(this);
|
1291
1306
|
D->configs->setReadonly(true);
|
1292
1307
|
}
|
1293
1308
|
|
1294
|
-
dfa.states.insert(D);
|
1295
|
-
|
1296
1309
|
#if DEBUG_DFA == 1
|
1297
1310
|
std::cout << "adding new DFA state: " << D << std::endl;
|
1298
1311
|
#endif
|
@@ -1348,7 +1361,9 @@ Parser* ParserATNSimulator::getParser() {
|
|
1348
1361
|
return parser;
|
1349
1362
|
}
|
1350
1363
|
|
1351
|
-
#
|
1364
|
+
#ifdef _MSC_VER
|
1365
|
+
#pragma warning (disable:4996) // 'getenv': This function or variable may be unsafe. Consider using _dupenv_s instead.
|
1366
|
+
#endif
|
1352
1367
|
|
1353
1368
|
bool ParserATNSimulator::getLrLoopSetting() {
|
1354
1369
|
char *var = std::getenv("TURN_OFF_LR_LOOP_ENTRY_BRANCH_OPT");
|
@@ -1358,7 +1373,9 @@ bool ParserATNSimulator::getLrLoopSetting() {
|
|
1358
1373
|
return value == "true" || value == "1";
|
1359
1374
|
}
|
1360
1375
|
|
1376
|
+
#ifdef _MSC_VER
|
1361
1377
|
#pragma warning (default:4996)
|
1378
|
+
#endif
|
1362
1379
|
|
1363
1380
|
void ParserATNSimulator::InitializeInstanceFields() {
|
1364
1381
|
_mode = PredictionMode::LL;
|