did_parser 1.0.0
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 +7 -0
- data/Gemfile +12 -0
- data/Rakefile +28 -0
- data/did_parser.gemspec +31 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/ANTLRErrorListener.cpp +10 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/ANTLRErrorListener.h +167 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/ANTLRErrorStrategy.cpp +10 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/ANTLRErrorStrategy.h +121 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/ANTLRFileStream.cpp +23 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/ANTLRFileStream.h +30 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/ANTLRInputStream.cpp +180 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/ANTLRInputStream.h +79 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/BailErrorStrategy.cpp +61 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/BailErrorStrategy.h +59 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/BaseErrorListener.cpp +25 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/BaseErrorListener.h +36 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/BufferedTokenStream.cpp +414 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/BufferedTokenStream.h +200 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/CharStream.cpp +11 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/CharStream.h +37 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/CommonToken.cpp +193 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/CommonToken.h +158 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/CommonTokenFactory.cpp +39 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/CommonTokenFactory.h +74 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/CommonTokenStream.cpp +78 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/CommonTokenStream.h +79 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/ConsoleErrorListener.cpp +15 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/ConsoleErrorListener.h +35 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/DefaultErrorStrategy.cpp +336 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/DefaultErrorStrategy.h +466 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/DiagnosticErrorListener.cpp +84 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/DiagnosticErrorListener.h +80 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/Exceptions.cpp +64 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/Exceptions.h +99 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/FailedPredicateException.cpp +52 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/FailedPredicateException.h +32 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/InputMismatchException.cpp +18 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/InputMismatchException.h +24 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/IntStream.cpp +12 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/IntStream.h +218 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/InterpreterRuleContext.cpp +19 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/InterpreterRuleContext.h +45 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/Lexer.cpp +294 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/Lexer.h +196 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/LexerInterpreter.cpp +60 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/LexerInterpreter.h +46 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/LexerNoViableAltException.cpp +36 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/LexerNoViableAltException.h +31 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/ListTokenSource.cpp +92 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/ListTokenSource.h +88 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/NoViableAltException.cpp +46 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/NoViableAltException.h +42 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/Parser.cpp +668 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/Parser.h +461 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/ParserInterpreter.cpp +294 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/ParserInterpreter.h +173 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/ParserRuleContext.cpp +138 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/ParserRuleContext.h +147 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/ProxyErrorListener.cpp +53 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/ProxyErrorListener.h +38 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/RecognitionException.cpp +65 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/RecognitionException.h +98 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/Recognizer.cpp +156 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/Recognizer.h +159 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/RuleContext.cpp +144 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/RuleContext.h +141 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/RuleContextWithAltNum.cpp +27 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/RuleContextWithAltNum.h +32 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/RuntimeMetaData.cpp +54 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/RuntimeMetaData.h +155 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/Token.cpp +9 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/Token.h +92 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/TokenFactory.h +30 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/TokenSource.cpp +9 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/TokenSource.h +85 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/TokenStream.cpp +11 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/TokenStream.h +137 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/TokenStreamRewriter.cpp +425 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/TokenStreamRewriter.h +295 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/UnbufferedCharStream.cpp +208 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/UnbufferedCharStream.h +117 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/UnbufferedTokenStream.cpp +270 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/UnbufferedTokenStream.h +115 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/Version.h +42 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/Vocabulary.cpp +64 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/Vocabulary.h +177 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/WritableToken.cpp +9 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/WritableToken.h +23 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/antlr4-common.h +98 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/antlr4-runtime.h +169 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATN.cpp +158 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATN.h +132 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNConfig.cpp +106 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNConfig.h +157 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNConfigSet.cpp +232 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNConfigSet.h +156 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNDeserializationOptions.cpp +54 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNDeserializationOptions.h +48 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNDeserializer.cpp +629 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNDeserializer.h +32 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNSimulator.cpp +33 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNSimulator.h +71 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNState.cpp +56 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNState.h +139 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNStateType.cpp +33 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNStateType.h +36 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNType.h +20 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ActionTransition.cpp +29 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ActionTransition.h +35 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/AmbiguityInfo.cpp +16 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/AmbiguityInfo.h +68 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ArrayPredictionContext.cpp +109 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ArrayPredictionContext.h +51 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/AtomTransition.cpp +27 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/AtomTransition.h +33 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/BasicBlockStartState.h +24 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/BasicState.h +23 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/BlockEndState.h +26 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/BlockStartState.h +30 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ContextSensitivityInfo.cpp +14 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ContextSensitivityInfo.h +47 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/DecisionEventInfo.cpp +14 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/DecisionEventInfo.h +70 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/DecisionInfo.cpp +25 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/DecisionInfo.h +227 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/DecisionState.cpp +12 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/DecisionState.h +34 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/EpsilonTransition.cpp +31 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/EpsilonTransition.h +42 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ErrorInfo.cpp +15 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ErrorInfo.h +43 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LL1Analyzer.cpp +189 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LL1Analyzer.h +76 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerATNConfig.cpp +67 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerATNConfig.h +44 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerATNSimulator.cpp +615 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerATNSimulator.h +199 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerAction.cpp +15 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerAction.h +100 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerActionExecutor.cpp +111 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerActionExecutor.h +128 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerActionType.h +57 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerChannelAction.cpp +43 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerChannelAction.h +59 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerCustomAction.cpp +45 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerCustomAction.h +75 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerIndexedCustomAction.cpp +57 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerIndexedCustomAction.h +76 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerModeAction.cpp +43 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerModeAction.h +57 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerMoreAction.cpp +36 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerMoreAction.h +53 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerPopModeAction.cpp +36 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerPopModeAction.h +53 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerPushModeAction.cpp +43 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerPushModeAction.h +57 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerSkipAction.cpp +36 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerSkipAction.h +51 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerTypeAction.cpp +43 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerTypeAction.h +51 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LookaheadEventInfo.cpp +16 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LookaheadEventInfo.h +42 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LoopEndState.h +26 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/NotSetTransition.cpp +22 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/NotSetTransition.h +27 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/OrderedATNConfigSet.cpp +16 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/OrderedATNConfigSet.h +25 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ParseInfo.cpp +102 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ParseInfo.h +102 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ParserATNSimulator.cpp +1383 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ParserATNSimulator.h +911 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ParserATNSimulatorOptions.h +50 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PlusBlockStartState.h +29 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PlusLoopbackState.h +25 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PrecedencePredicateTransition.cpp +23 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PrecedencePredicateTransition.h +35 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredicateEvalInfo.cpp +17 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredicateEvalInfo.h +62 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredicateTransition.cpp +24 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredicateTransition.h +50 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredictionContext.cpp +579 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredictionContext.h +225 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredictionContextCache.cpp +56 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredictionContextCache.h +64 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredictionContextMergeCache.cpp +167 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredictionContextMergeCache.h +101 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredictionContextMergeCacheOptions.h +71 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredictionContextType.h +21 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredictionMode.cpp +202 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredictionMode.h +436 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ProfilingATNSimulator.cpp +179 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ProfilingATNSimulator.h +60 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/RangeTransition.cpp +26 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/RangeTransition.h +31 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/RuleStartState.h +26 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/RuleStopState.h +27 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/RuleTransition.cpp +33 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/RuleTransition.h +42 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/SemanticContext.cpp +418 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/SemanticContext.h +233 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/SemanticContextType.h +23 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/SerializedATNView.h +101 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/SetTransition.cpp +28 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/SetTransition.h +38 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/SingletonPredictionContext.cpp +86 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/SingletonPredictionContext.h +43 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/StarBlockStartState.h +24 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/StarLoopEntryState.h +37 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/StarLoopbackState.cpp +19 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/StarLoopbackState.h +25 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/TokensStartState.h +24 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/Transition.cpp +36 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/Transition.h +65 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/TransitionType.cpp +27 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/TransitionType.h +33 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/WildcardTransition.cpp +21 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/WildcardTransition.h +27 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/dfa/DFA.cpp +115 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/dfa/DFA.h +96 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/dfa/DFASerializer.cpp +60 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/dfa/DFASerializer.h +32 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/dfa/DFAState.cpp +59 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/dfa/DFAState.h +153 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/dfa/LexerDFASerializer.cpp +17 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/dfa/LexerDFASerializer.h +22 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/InterpreterDataReader.cpp +124 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/InterpreterDataReader.h +33 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/Interval.cpp +61 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/Interval.h +84 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/IntervalSet.cpp +508 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/IntervalSet.h +190 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/MurmurHash.cpp +120 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/MurmurHash.h +102 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/Predicate.cpp +4 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/Predicate.h +21 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/support/Any.cpp +8 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/support/Any.h +16 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/support/Arrays.cpp +43 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/support/Arrays.h +149 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/support/BitSet.h +76 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/support/CPPUtils.cpp +207 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/support/CPPUtils.h +65 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/support/Casts.h +34 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/support/Declarations.h +161 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/support/StringUtils.cpp +38 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/support/StringUtils.h +16 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/support/Unicode.h +28 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/support/Utf8.cpp +242 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/support/Utf8.h +54 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/AbstractParseTreeVisitor.h +129 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ErrorNode.h +24 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ErrorNodeImpl.cpp +54 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ErrorNodeImpl.h +43 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/IterativeParseTreeWalker.cpp +66 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/IterativeParseTreeWalker.h +53 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ParseTree.cpp +12 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ParseTree.h +111 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ParseTreeListener.cpp +9 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ParseTreeListener.h +39 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ParseTreeProperty.h +50 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ParseTreeType.h +22 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ParseTreeVisitor.cpp +9 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ParseTreeVisitor.h +57 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ParseTreeWalker.cpp +48 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ParseTreeWalker.h +55 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/TerminalNode.h +40 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/TerminalNodeImpl.cpp +54 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/TerminalNodeImpl.h +32 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/Trees.cpp +241 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/Trees.h +78 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/pattern/Chunk.cpp +9 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/pattern/Chunk.h +44 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/pattern/ParseTreeMatch.cpp +69 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/pattern/ParseTreeMatch.h +132 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/pattern/ParseTreePattern.cpp +64 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/pattern/ParseTreePattern.h +105 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/pattern/ParseTreePatternMatcher.cpp +370 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/pattern/ParseTreePatternMatcher.h +185 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/pattern/RuleTagToken.cpp +77 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/pattern/RuleTagToken.h +117 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/pattern/TagChunk.cpp +39 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/pattern/TagChunk.h +86 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/pattern/TextChunk.cpp +28 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/pattern/TextChunk.h +51 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/pattern/TokenTagToken.cpp +36 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/pattern/TokenTagToken.h +80 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPath.cpp +154 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPath.h +86 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathElement.cpp +31 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathElement.h +40 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathLexer.cpp +182 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathLexer.h +47 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathLexerErrorListener.cpp +13 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathLexerErrorListener.h +22 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathRuleAnywhereElement.cpp +20 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathRuleAnywhereElement.h +27 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathRuleElement.cpp +30 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathRuleElement.h +26 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathTokenAnywhereElement.cpp +20 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathTokenAnywhereElement.h +25 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathTokenElement.cpp +33 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathTokenElement.h +26 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathWildcardAnywhereElement.cpp +23 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathWildcardAnywhereElement.h +23 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathWildcardElement.cpp +24 -0
- data/ext/did_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathWildcardElement.h +23 -0
- data/ext/did_parser/antlrgen/DIDLexer.cpp +225 -0
- data/ext/did_parser/antlrgen/DIDLexer.h +52 -0
- data/ext/did_parser/antlrgen/DIDLexer.interp +93 -0
- data/ext/did_parser/antlrgen/DIDLexer.tokens +42 -0
- data/ext/did_parser/antlrgen/DIDParser.cpp +2042 -0
- data/ext/did_parser/antlrgen/DIDParser.h +537 -0
- data/ext/did_parser/antlrgen/DIDParser.interp +74 -0
- data/ext/did_parser/antlrgen/DIDParser.tokens +42 -0
- data/ext/did_parser/antlrgen/DIDParserBaseListener.cpp +7 -0
- data/ext/did_parser/antlrgen/DIDParserBaseListener.h +104 -0
- data/ext/did_parser/antlrgen/DIDParserBaseVisitor.cpp +7 -0
- data/ext/did_parser/antlrgen/DIDParserBaseVisitor.h +124 -0
- data/ext/did_parser/antlrgen/DIDParserListener.cpp +7 -0
- data/ext/did_parser/antlrgen/DIDParserListener.h +97 -0
- data/ext/did_parser/antlrgen/DIDParserVisitor.cpp +7 -0
- data/ext/did_parser/antlrgen/DIDParserVisitor.h +76 -0
- data/ext/did_parser/did_parser.cpp +2996 -0
- data/ext/did_parser/extconf.rb +38 -0
- data/lib/did_parser/version.rb +3 -0
- data/lib/did_parser.rb +2 -0
- metadata +382 -0
|
@@ -0,0 +1,579 @@
|
|
|
1
|
+
/* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.
|
|
2
|
+
* Use of this file is governed by the BSD 3-clause license that
|
|
3
|
+
* can be found in the LICENSE.txt file in the project root.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
#include "atn/SingletonPredictionContext.h"
|
|
7
|
+
#include "misc/MurmurHash.h"
|
|
8
|
+
#include "atn/ArrayPredictionContext.h"
|
|
9
|
+
#include "atn/PredictionContextCache.h"
|
|
10
|
+
#include "atn/PredictionContextMergeCache.h"
|
|
11
|
+
#include "RuleContext.h"
|
|
12
|
+
#include "ParserRuleContext.h"
|
|
13
|
+
#include "atn/RuleTransition.h"
|
|
14
|
+
#include "support/Arrays.h"
|
|
15
|
+
#include "support/CPPUtils.h"
|
|
16
|
+
#include "support/Casts.h"
|
|
17
|
+
|
|
18
|
+
#include "atn/PredictionContext.h"
|
|
19
|
+
|
|
20
|
+
using namespace antlr4;
|
|
21
|
+
using namespace antlr4::misc;
|
|
22
|
+
using namespace antlr4::atn;
|
|
23
|
+
using namespace antlrcpp;
|
|
24
|
+
|
|
25
|
+
namespace {
|
|
26
|
+
|
|
27
|
+
void combineCommonParents(std::vector<Ref<const PredictionContext>> &parents) {
|
|
28
|
+
std::unordered_set<Ref<const PredictionContext>> uniqueParents;
|
|
29
|
+
uniqueParents.reserve(parents.size());
|
|
30
|
+
for (const auto &parent : parents) {
|
|
31
|
+
uniqueParents.insert(parent);
|
|
32
|
+
}
|
|
33
|
+
for (auto &parent : parents) {
|
|
34
|
+
parent = *uniqueParents.find(parent);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
Ref<const PredictionContext> getCachedContextImpl(const Ref<const PredictionContext> &context,
|
|
39
|
+
PredictionContextCache &contextCache,
|
|
40
|
+
std::unordered_map<Ref<const PredictionContext>,
|
|
41
|
+
Ref<const PredictionContext>> &visited) {
|
|
42
|
+
if (context->isEmpty()) {
|
|
43
|
+
return context;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
{
|
|
47
|
+
auto iterator = visited.find(context);
|
|
48
|
+
if (iterator != visited.end()) {
|
|
49
|
+
return iterator->second; // Not necessarly the same as context.
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
auto cached = contextCache.get(context);
|
|
54
|
+
if (cached) {
|
|
55
|
+
visited[context] = cached;
|
|
56
|
+
return cached;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
bool changed = false;
|
|
60
|
+
|
|
61
|
+
std::vector<Ref<const PredictionContext>> parents(context->size());
|
|
62
|
+
for (size_t i = 0; i < parents.size(); i++) {
|
|
63
|
+
auto parent = getCachedContextImpl(context->getParent(i), contextCache, visited);
|
|
64
|
+
if (changed || parent != context->getParent(i)) {
|
|
65
|
+
if (!changed) {
|
|
66
|
+
parents.clear();
|
|
67
|
+
for (size_t j = 0; j < context->size(); j++) {
|
|
68
|
+
parents.push_back(context->getParent(j));
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
changed = true;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
parents[i] = std::move(parent);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (!changed) {
|
|
79
|
+
visited[context] = context;
|
|
80
|
+
contextCache.put(context);
|
|
81
|
+
return context;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
Ref<const PredictionContext> updated;
|
|
85
|
+
if (parents.empty()) {
|
|
86
|
+
updated = PredictionContext::EMPTY;
|
|
87
|
+
} else if (parents.size() == 1) {
|
|
88
|
+
updated = SingletonPredictionContext::create(std::move(parents[0]), context->getReturnState(0));
|
|
89
|
+
contextCache.put(updated);
|
|
90
|
+
} else {
|
|
91
|
+
updated = std::make_shared<ArrayPredictionContext>(std::move(parents), downCast<const ArrayPredictionContext*>(context.get())->returnStates);
|
|
92
|
+
contextCache.put(updated);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
visited[updated] = updated;
|
|
96
|
+
visited[context] = updated;
|
|
97
|
+
|
|
98
|
+
return updated;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
void getAllContextNodesImpl(const Ref<const PredictionContext> &context,
|
|
102
|
+
std::vector<Ref<const PredictionContext>> &nodes,
|
|
103
|
+
std::unordered_set<const PredictionContext*> &visited) {
|
|
104
|
+
|
|
105
|
+
if (visited.find(context.get()) != visited.end()) {
|
|
106
|
+
return; // Already done.
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
visited.insert(context.get());
|
|
110
|
+
nodes.push_back(context);
|
|
111
|
+
|
|
112
|
+
for (size_t i = 0; i < context->size(); i++) {
|
|
113
|
+
getAllContextNodesImpl(context->getParent(i), nodes, visited);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
size_t insertOrAssignNodeId(std::unordered_map<const PredictionContext*, size_t> &nodeIds, size_t &nodeId, const PredictionContext *node) {
|
|
118
|
+
auto existing = nodeIds.find(node);
|
|
119
|
+
if (existing != nodeIds.end()) {
|
|
120
|
+
return existing->second;
|
|
121
|
+
}
|
|
122
|
+
return nodeIds.insert({node, nodeId++}).first->second;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const Ref<const PredictionContext> PredictionContext::EMPTY = std::make_shared<SingletonPredictionContext>(nullptr, PredictionContext::EMPTY_RETURN_STATE);
|
|
128
|
+
|
|
129
|
+
//----------------- PredictionContext ----------------------------------------------------------------------------------
|
|
130
|
+
|
|
131
|
+
PredictionContext::PredictionContext(PredictionContextType contextType) : _contextType(contextType), _hashCode(0) {}
|
|
132
|
+
|
|
133
|
+
PredictionContext::PredictionContext(PredictionContext&& other) : _contextType(other._contextType), _hashCode(other._hashCode.exchange(0, std::memory_order_relaxed)) {}
|
|
134
|
+
|
|
135
|
+
Ref<const PredictionContext> PredictionContext::fromRuleContext(const ATN &atn, RuleContext *outerContext) {
|
|
136
|
+
if (outerContext == nullptr) {
|
|
137
|
+
return PredictionContext::EMPTY;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// if we are in RuleContext of start rule, s, then PredictionContext
|
|
141
|
+
// is EMPTY. Nobody called us. (if we are empty, return empty)
|
|
142
|
+
if (outerContext->parent == nullptr || outerContext == &ParserRuleContext::EMPTY) {
|
|
143
|
+
return PredictionContext::EMPTY;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// If we have a parent, convert it to a PredictionContext graph
|
|
147
|
+
auto parent = PredictionContext::fromRuleContext(atn, RuleContext::is(outerContext->parent) ? downCast<RuleContext*>(outerContext->parent) : nullptr);
|
|
148
|
+
const auto *transition = downCast<const RuleTransition*>(atn.states[outerContext->invokingState]->transitions[0].get());
|
|
149
|
+
return SingletonPredictionContext::create(std::move(parent), transition->followState->stateNumber);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
bool PredictionContext::hasEmptyPath() const {
|
|
153
|
+
// since EMPTY_RETURN_STATE can only appear in the last position, we check last one
|
|
154
|
+
return getReturnState(size() - 1) == EMPTY_RETURN_STATE;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
size_t PredictionContext::hashCode() const {
|
|
158
|
+
auto hash = cachedHashCode();
|
|
159
|
+
if (hash == 0) {
|
|
160
|
+
hash = hashCodeImpl();
|
|
161
|
+
if (hash == 0) {
|
|
162
|
+
hash = std::numeric_limits<size_t>::max();
|
|
163
|
+
}
|
|
164
|
+
_hashCode.store(hash, std::memory_order_relaxed);
|
|
165
|
+
}
|
|
166
|
+
return hash;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
Ref<const PredictionContext> PredictionContext::merge(Ref<const PredictionContext> a, Ref<const PredictionContext> b,
|
|
170
|
+
bool rootIsWildcard, PredictionContextMergeCache *mergeCache) {
|
|
171
|
+
assert(a && b);
|
|
172
|
+
|
|
173
|
+
// share same graph if both same
|
|
174
|
+
if (a == b || *a == *b) {
|
|
175
|
+
return a;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const auto aType = a->getContextType();
|
|
179
|
+
const auto bType = b->getContextType();
|
|
180
|
+
|
|
181
|
+
if (aType == PredictionContextType::SINGLETON && bType == PredictionContextType::SINGLETON) {
|
|
182
|
+
return mergeSingletons(std::static_pointer_cast<const SingletonPredictionContext>(std::move(a)),
|
|
183
|
+
std::static_pointer_cast<const SingletonPredictionContext>(std::move(b)), rootIsWildcard, mergeCache);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// At least one of a or b is array.
|
|
187
|
+
// If one is $ and rootIsWildcard, return $ as * wildcard.
|
|
188
|
+
if (rootIsWildcard) {
|
|
189
|
+
if (a == PredictionContext::EMPTY) {
|
|
190
|
+
return a;
|
|
191
|
+
}
|
|
192
|
+
if (b == PredictionContext::EMPTY) {
|
|
193
|
+
return b;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// convert singleton so both are arrays to normalize
|
|
198
|
+
Ref<const ArrayPredictionContext> left;
|
|
199
|
+
if (aType == PredictionContextType::SINGLETON) {
|
|
200
|
+
left = std::make_shared<ArrayPredictionContext>(downCast<const SingletonPredictionContext&>(*a));
|
|
201
|
+
} else {
|
|
202
|
+
left = std::static_pointer_cast<const ArrayPredictionContext>(std::move(a));
|
|
203
|
+
}
|
|
204
|
+
Ref<const ArrayPredictionContext> right;
|
|
205
|
+
if (bType == PredictionContextType::SINGLETON) {
|
|
206
|
+
right = std::make_shared<ArrayPredictionContext>(downCast<const SingletonPredictionContext&>(*b));
|
|
207
|
+
} else {
|
|
208
|
+
right = std::static_pointer_cast<const ArrayPredictionContext>(std::move(b));
|
|
209
|
+
}
|
|
210
|
+
return mergeArrays(std::move(left), std::move(right), rootIsWildcard, mergeCache);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
Ref<const PredictionContext> PredictionContext::mergeSingletons(Ref<const SingletonPredictionContext> a, Ref<const SingletonPredictionContext> b,
|
|
214
|
+
bool rootIsWildcard, PredictionContextMergeCache *mergeCache) {
|
|
215
|
+
|
|
216
|
+
if (mergeCache) {
|
|
217
|
+
auto existing = mergeCache->get(a, b);
|
|
218
|
+
if (existing) {
|
|
219
|
+
return existing;
|
|
220
|
+
}
|
|
221
|
+
existing = mergeCache->get(b, a);
|
|
222
|
+
if (existing) {
|
|
223
|
+
return existing;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
auto rootMerge = mergeRoot(a, b, rootIsWildcard);
|
|
228
|
+
if (rootMerge) {
|
|
229
|
+
if (mergeCache) {
|
|
230
|
+
return mergeCache->put(a, b, std::move(rootMerge));
|
|
231
|
+
}
|
|
232
|
+
return rootMerge;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
const auto& parentA = a->parent;
|
|
236
|
+
const auto& parentB = b->parent;
|
|
237
|
+
if (a->returnState == b->returnState) { // a == b
|
|
238
|
+
auto parent = merge(parentA, parentB, rootIsWildcard, mergeCache);
|
|
239
|
+
|
|
240
|
+
// If parent is same as existing a or b parent or reduced to a parent, return it.
|
|
241
|
+
if (parent == parentA) { // ax + bx = ax, if a=b
|
|
242
|
+
return a;
|
|
243
|
+
}
|
|
244
|
+
if (parent == parentB) { // ax + bx = bx, if a=b
|
|
245
|
+
return b;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
// else: ax + ay = a'[x,y]
|
|
249
|
+
// merge parents x and y, giving array node with x,y then remainders
|
|
250
|
+
// of those graphs. dup a, a' points at merged array
|
|
251
|
+
// new joined parent so create new singleton pointing to it, a'
|
|
252
|
+
auto c = SingletonPredictionContext::create(std::move(parent), a->returnState);
|
|
253
|
+
if (mergeCache) {
|
|
254
|
+
return mergeCache->put(a, b, std::move(c));
|
|
255
|
+
}
|
|
256
|
+
return c;
|
|
257
|
+
}
|
|
258
|
+
// a != b payloads differ
|
|
259
|
+
// see if we can collapse parents due to $+x parents if local ctx
|
|
260
|
+
Ref<const PredictionContext> singleParent;
|
|
261
|
+
if (a == b || (*parentA == *parentB)) { // ax + bx = [a,b]x
|
|
262
|
+
singleParent = parentA;
|
|
263
|
+
}
|
|
264
|
+
if (singleParent) { // parents are same, sort payloads and use same parent
|
|
265
|
+
std::vector<size_t> payloads = { a->returnState, b->returnState };
|
|
266
|
+
if (a->returnState > b->returnState) {
|
|
267
|
+
payloads[0] = b->returnState;
|
|
268
|
+
payloads[1] = a->returnState;
|
|
269
|
+
}
|
|
270
|
+
std::vector<Ref<const PredictionContext>> parents = { singleParent, singleParent };
|
|
271
|
+
auto c = std::make_shared<ArrayPredictionContext>(std::move(parents), std::move(payloads));
|
|
272
|
+
if (mergeCache) {
|
|
273
|
+
return mergeCache->put(a, b, std::move(c));
|
|
274
|
+
}
|
|
275
|
+
return c;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
// parents differ and can't merge them. Just pack together
|
|
279
|
+
// into array; can't merge.
|
|
280
|
+
// ax + by = [ax,by]
|
|
281
|
+
if (a->returnState > b->returnState) { // sort by payload
|
|
282
|
+
std::vector<size_t> payloads = { b->returnState, a->returnState };
|
|
283
|
+
std::vector<Ref<const PredictionContext>> parents = { b->parent, a->parent };
|
|
284
|
+
auto c = std::make_shared<ArrayPredictionContext>(std::move(parents), std::move(payloads));
|
|
285
|
+
if (mergeCache) {
|
|
286
|
+
return mergeCache->put(a, b, std::move(c));
|
|
287
|
+
}
|
|
288
|
+
return c;
|
|
289
|
+
}
|
|
290
|
+
std::vector<size_t> payloads = {a->returnState, b->returnState};
|
|
291
|
+
std::vector<Ref<const PredictionContext>> parents = { a->parent, b->parent };
|
|
292
|
+
auto c = std::make_shared<ArrayPredictionContext>(std::move(parents), std::move(payloads));
|
|
293
|
+
if (mergeCache) {
|
|
294
|
+
return mergeCache->put(a, b, std::move(c));
|
|
295
|
+
}
|
|
296
|
+
return c;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
Ref<const PredictionContext> PredictionContext::mergeRoot(Ref<const SingletonPredictionContext> a, Ref<const SingletonPredictionContext> b,
|
|
300
|
+
bool rootIsWildcard) {
|
|
301
|
+
if (rootIsWildcard) {
|
|
302
|
+
if (a == EMPTY) { // * + b = *
|
|
303
|
+
return EMPTY;
|
|
304
|
+
}
|
|
305
|
+
if (b == EMPTY) { // a + * = *
|
|
306
|
+
return EMPTY;
|
|
307
|
+
}
|
|
308
|
+
} else {
|
|
309
|
+
if (a == EMPTY && b == EMPTY) { // $ + $ = $
|
|
310
|
+
return EMPTY;
|
|
311
|
+
}
|
|
312
|
+
if (a == EMPTY) { // $ + x = [$,x]
|
|
313
|
+
std::vector<size_t> payloads = { b->returnState, EMPTY_RETURN_STATE };
|
|
314
|
+
std::vector<Ref<const PredictionContext>> parents = { b->parent, nullptr };
|
|
315
|
+
return std::make_shared<ArrayPredictionContext>(std::move(parents), std::move(payloads));
|
|
316
|
+
}
|
|
317
|
+
if (b == EMPTY) { // x + $ = [$,x] ($ is always first if present)
|
|
318
|
+
std::vector<size_t> payloads = { a->returnState, EMPTY_RETURN_STATE };
|
|
319
|
+
std::vector<Ref<const PredictionContext>> parents = { a->parent, nullptr };
|
|
320
|
+
return std::make_shared<ArrayPredictionContext>(std::move(parents), std::move(payloads));
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
return nullptr;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
Ref<const PredictionContext> PredictionContext::mergeArrays(Ref<const ArrayPredictionContext> a, Ref<const ArrayPredictionContext> b,
|
|
327
|
+
bool rootIsWildcard, PredictionContextMergeCache *mergeCache) {
|
|
328
|
+
|
|
329
|
+
if (mergeCache) {
|
|
330
|
+
auto existing = mergeCache->get(a, b);
|
|
331
|
+
if (existing) {
|
|
332
|
+
return existing;
|
|
333
|
+
}
|
|
334
|
+
existing = mergeCache->get(b, a);
|
|
335
|
+
if (existing) {
|
|
336
|
+
return existing;
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
// merge sorted payloads a + b => M
|
|
341
|
+
size_t i = 0; // walks a
|
|
342
|
+
size_t j = 0; // walks b
|
|
343
|
+
size_t k = 0; // walks target M array
|
|
344
|
+
|
|
345
|
+
std::vector<size_t> mergedReturnStates(a->returnStates.size() + b->returnStates.size());
|
|
346
|
+
std::vector<Ref<const PredictionContext>> mergedParents(a->returnStates.size() + b->returnStates.size());
|
|
347
|
+
|
|
348
|
+
// walk and merge to yield mergedParents, mergedReturnStates
|
|
349
|
+
while (i < a->returnStates.size() && j < b->returnStates.size()) {
|
|
350
|
+
const auto& parentA = a->parents[i];
|
|
351
|
+
const auto& parentB = b->parents[j];
|
|
352
|
+
if (a->returnStates[i] == b->returnStates[j]) {
|
|
353
|
+
// same payload (stack tops are equal), must yield merged singleton
|
|
354
|
+
size_t payload = a->returnStates[i];
|
|
355
|
+
// $+$ = $
|
|
356
|
+
bool both$ = payload == EMPTY_RETURN_STATE && !parentA && !parentB;
|
|
357
|
+
bool ax_ax = (parentA && parentB) && *parentA == *parentB; // ax+ax -> ax
|
|
358
|
+
if (both$ || ax_ax) {
|
|
359
|
+
mergedParents[k] = parentA; // choose left
|
|
360
|
+
mergedReturnStates[k] = payload;
|
|
361
|
+
} else { // ax+ay -> a'[x,y]
|
|
362
|
+
mergedParents[k] = merge(parentA, parentB, rootIsWildcard, mergeCache);
|
|
363
|
+
mergedReturnStates[k] = payload;
|
|
364
|
+
}
|
|
365
|
+
i++; // hop over left one as usual
|
|
366
|
+
j++; // but also skip one in right side since we merge
|
|
367
|
+
} else if (a->returnStates[i] < b->returnStates[j]) { // copy a[i] to M
|
|
368
|
+
mergedParents[k] = parentA;
|
|
369
|
+
mergedReturnStates[k] = a->returnStates[i];
|
|
370
|
+
i++;
|
|
371
|
+
} else { // b > a, copy b[j] to M
|
|
372
|
+
mergedParents[k] = parentB;
|
|
373
|
+
mergedReturnStates[k] = b->returnStates[j];
|
|
374
|
+
j++;
|
|
375
|
+
}
|
|
376
|
+
k++;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
// copy over any payloads remaining in either array
|
|
380
|
+
if (i < a->returnStates.size()) {
|
|
381
|
+
for (auto p = i; p < a->returnStates.size(); p++) {
|
|
382
|
+
mergedParents[k] = a->parents[p];
|
|
383
|
+
mergedReturnStates[k] = a->returnStates[p];
|
|
384
|
+
k++;
|
|
385
|
+
}
|
|
386
|
+
} else {
|
|
387
|
+
for (auto p = j; p < b->returnStates.size(); p++) {
|
|
388
|
+
mergedParents[k] = b->parents[p];
|
|
389
|
+
mergedReturnStates[k] = b->returnStates[p];
|
|
390
|
+
k++;
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
// trim merged if we combined a few that had same stack tops
|
|
395
|
+
if (k < mergedParents.size()) { // write index < last position; trim
|
|
396
|
+
if (k == 1) { // for just one merged element, return singleton top
|
|
397
|
+
auto c = SingletonPredictionContext::create(std::move(mergedParents[0]), mergedReturnStates[0]);
|
|
398
|
+
if (mergeCache) {
|
|
399
|
+
return mergeCache->put(a, b, std::move(c));
|
|
400
|
+
}
|
|
401
|
+
return c;
|
|
402
|
+
}
|
|
403
|
+
mergedParents.resize(k);
|
|
404
|
+
mergedReturnStates.resize(k);
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
ArrayPredictionContext m(std::move(mergedParents), std::move(mergedReturnStates));
|
|
408
|
+
|
|
409
|
+
// if we created same array as a or b, return that instead
|
|
410
|
+
// TODO: track whether this is possible above during merge sort for speed
|
|
411
|
+
if (m == *a) {
|
|
412
|
+
if (mergeCache) {
|
|
413
|
+
return mergeCache->put(a, b, a);
|
|
414
|
+
}
|
|
415
|
+
return a;
|
|
416
|
+
}
|
|
417
|
+
if (m == *b) {
|
|
418
|
+
if (mergeCache) {
|
|
419
|
+
return mergeCache->put(a, b, b);
|
|
420
|
+
}
|
|
421
|
+
return b;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
combineCommonParents(m.parents);
|
|
425
|
+
auto c = std::make_shared<ArrayPredictionContext>(std::move(m));
|
|
426
|
+
if (mergeCache) {
|
|
427
|
+
return mergeCache->put(a, b, std::move(c));
|
|
428
|
+
}
|
|
429
|
+
return c;
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
std::string PredictionContext::toDOTString(const Ref<const PredictionContext> &context) {
|
|
433
|
+
if (context == nullptr) {
|
|
434
|
+
return "";
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
std::stringstream ss;
|
|
438
|
+
ss << "digraph G {\n" << "rankdir=LR;\n";
|
|
439
|
+
|
|
440
|
+
std::vector<Ref<const PredictionContext>> nodes = getAllContextNodes(context);
|
|
441
|
+
std::unordered_map<const PredictionContext*, size_t> nodeIds;
|
|
442
|
+
size_t nodeId = 0;
|
|
443
|
+
|
|
444
|
+
for (const auto ¤t : nodes) {
|
|
445
|
+
if (current->getContextType() == PredictionContextType::SINGLETON) {
|
|
446
|
+
std::string s = std::to_string(insertOrAssignNodeId(nodeIds, nodeId, current.get()));
|
|
447
|
+
ss << " s" << s;
|
|
448
|
+
std::string returnState = std::to_string(current->getReturnState(0));
|
|
449
|
+
if (current == PredictionContext::EMPTY) {
|
|
450
|
+
returnState = "$";
|
|
451
|
+
}
|
|
452
|
+
ss << " [label=\"" << returnState << "\"];\n";
|
|
453
|
+
continue;
|
|
454
|
+
}
|
|
455
|
+
Ref<const ArrayPredictionContext> arr = std::static_pointer_cast<const ArrayPredictionContext>(current);
|
|
456
|
+
ss << " s" << insertOrAssignNodeId(nodeIds, nodeId, arr.get()) << " [shape=box, label=\"" << "[";
|
|
457
|
+
bool first = true;
|
|
458
|
+
for (auto inv : arr->returnStates) {
|
|
459
|
+
if (!first) {
|
|
460
|
+
ss << ", ";
|
|
461
|
+
}
|
|
462
|
+
if (inv == EMPTY_RETURN_STATE) {
|
|
463
|
+
ss << "$";
|
|
464
|
+
} else {
|
|
465
|
+
ss << inv;
|
|
466
|
+
}
|
|
467
|
+
first = false;
|
|
468
|
+
}
|
|
469
|
+
ss << "]";
|
|
470
|
+
ss << "\"];\n";
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
for (const auto ¤t : nodes) {
|
|
474
|
+
if (current == EMPTY) {
|
|
475
|
+
continue;
|
|
476
|
+
}
|
|
477
|
+
for (size_t i = 0; i < current->size(); i++) {
|
|
478
|
+
if (!current->getParent(i)) {
|
|
479
|
+
continue;
|
|
480
|
+
}
|
|
481
|
+
ss << " s" << insertOrAssignNodeId(nodeIds, nodeId, current.get()) << "->" << "s" << insertOrAssignNodeId(nodeIds, nodeId, current->getParent(i).get());
|
|
482
|
+
if (current->size() > 1) {
|
|
483
|
+
ss << " [label=\"parent[" << i << "]\"];\n";
|
|
484
|
+
} else {
|
|
485
|
+
ss << ";\n";
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
ss << "}\n";
|
|
491
|
+
return ss.str();
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
// The "visited" map is just a temporary structure to control the retrieval process (which is recursive).
|
|
495
|
+
Ref<const PredictionContext> PredictionContext::getCachedContext(const Ref<const PredictionContext> &context,
|
|
496
|
+
PredictionContextCache &contextCache) {
|
|
497
|
+
std::unordered_map<Ref<const PredictionContext>, Ref<const PredictionContext>> visited;
|
|
498
|
+
return getCachedContextImpl(context, contextCache, visited);
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
std::vector<Ref<const PredictionContext>> PredictionContext::getAllContextNodes(const Ref<const PredictionContext> &context) {
|
|
502
|
+
std::vector<Ref<const PredictionContext>> nodes;
|
|
503
|
+
std::unordered_set<const PredictionContext*> visited;
|
|
504
|
+
getAllContextNodesImpl(context, nodes, visited);
|
|
505
|
+
return nodes;
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
std::vector<std::string> PredictionContext::toStrings(Recognizer *recognizer, int currentState) const {
|
|
509
|
+
return toStrings(recognizer, EMPTY, currentState);
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
std::vector<std::string> PredictionContext::toStrings(Recognizer *recognizer, const Ref<const PredictionContext> &stop, int currentState) const {
|
|
513
|
+
|
|
514
|
+
std::vector<std::string> result;
|
|
515
|
+
|
|
516
|
+
for (size_t perm = 0; ; perm++) {
|
|
517
|
+
size_t offset = 0;
|
|
518
|
+
bool last = true;
|
|
519
|
+
const PredictionContext *p = this;
|
|
520
|
+
size_t stateNumber = currentState;
|
|
521
|
+
|
|
522
|
+
std::stringstream ss;
|
|
523
|
+
ss << "[";
|
|
524
|
+
bool outerContinue = false;
|
|
525
|
+
while (!p->isEmpty() && p != stop.get()) {
|
|
526
|
+
size_t index = 0;
|
|
527
|
+
if (p->size() > 0) {
|
|
528
|
+
size_t bits = 1;
|
|
529
|
+
while ((1ULL << bits) < p->size()) {
|
|
530
|
+
bits++;
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
size_t mask = (1 << bits) - 1;
|
|
534
|
+
index = (perm >> offset) & mask;
|
|
535
|
+
last &= index >= p->size() - 1;
|
|
536
|
+
if (index >= p->size()) {
|
|
537
|
+
outerContinue = true;
|
|
538
|
+
break;
|
|
539
|
+
}
|
|
540
|
+
offset += bits;
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
if (recognizer != nullptr) {
|
|
544
|
+
if (ss.tellp() > 1) {
|
|
545
|
+
// first char is '[', if more than that this isn't the first rule
|
|
546
|
+
ss << ' ';
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
const ATN &atn = recognizer->getATN();
|
|
550
|
+
ATNState *s = atn.states[stateNumber];
|
|
551
|
+
std::string ruleName = recognizer->getRuleNames()[s->ruleIndex];
|
|
552
|
+
ss << ruleName;
|
|
553
|
+
} else if (p->getReturnState(index) != EMPTY_RETURN_STATE) {
|
|
554
|
+
if (!p->isEmpty()) {
|
|
555
|
+
if (ss.tellp() > 1) {
|
|
556
|
+
// first char is '[', if more than that this isn't the first rule
|
|
557
|
+
ss << ' ';
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
ss << p->getReturnState(index);
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
stateNumber = p->getReturnState(index);
|
|
564
|
+
p = p->getParent(index).get();
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
if (outerContinue)
|
|
568
|
+
continue;
|
|
569
|
+
|
|
570
|
+
ss << "]";
|
|
571
|
+
result.push_back(ss.str());
|
|
572
|
+
|
|
573
|
+
if (last) {
|
|
574
|
+
break;
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
return result;
|
|
579
|
+
}
|