python3-parser 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +13 -0
- data/README.md +59 -0
- data/Rakefile +21 -0
- data/ext/python3-parser/Python3LexerBase.cpp +112 -0
- data/ext/python3-parser/Python3LexerBase.h +34 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/ANTLRErrorListener.cpp +10 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/ANTLRErrorListener.h +167 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/ANTLRErrorStrategy.cpp +10 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/ANTLRErrorStrategy.h +121 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/ANTLRFileStream.cpp +34 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/ANTLRFileStream.h +27 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/ANTLRInputStream.cpp +155 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/ANTLRInputStream.h +69 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/BailErrorStrategy.cpp +61 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/BailErrorStrategy.h +59 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/BaseErrorListener.cpp +25 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/BaseErrorListener.h +36 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/BufferedTokenStream.cpp +414 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/BufferedTokenStream.h +200 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/CharStream.cpp +11 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/CharStream.h +37 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/CommonToken.cpp +195 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/CommonToken.h +158 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/CommonTokenFactory.cpp +39 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/CommonTokenFactory.h +74 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/CommonTokenStream.cpp +78 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/CommonTokenStream.h +79 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/ConsoleErrorListener.cpp +15 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/ConsoleErrorListener.h +35 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/DefaultErrorStrategy.cpp +333 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/DefaultErrorStrategy.h +466 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/DiagnosticErrorListener.cpp +84 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/DiagnosticErrorListener.h +80 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/Exceptions.cpp +64 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/Exceptions.h +99 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/FailedPredicateException.cpp +51 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/FailedPredicateException.h +32 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/InputMismatchException.cpp +18 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/InputMismatchException.h +24 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/IntStream.cpp +12 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/IntStream.h +218 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/InterpreterRuleContext.cpp +19 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/InterpreterRuleContext.h +45 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/Lexer.cpp +295 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/Lexer.h +196 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/LexerInterpreter.cpp +75 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/LexerInterpreter.h +52 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/LexerNoViableAltException.cpp +36 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/LexerNoViableAltException.h +31 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/ListTokenSource.cpp +92 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/ListTokenSource.h +88 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/NoViableAltException.cpp +46 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/NoViableAltException.h +42 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/Parser.cpp +648 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/Parser.h +467 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/ParserInterpreter.cpp +306 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/ParserInterpreter.h +179 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/ParserRuleContext.cpp +141 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/ParserRuleContext.h +147 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/ProxyErrorListener.cpp +53 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/ProxyErrorListener.h +38 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/RecognitionException.cpp +66 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/RecognitionException.h +98 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/Recognizer.cpp +167 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/Recognizer.h +164 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/RuleContext.cpp +143 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/RuleContext.h +137 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/RuleContextWithAltNum.cpp +27 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/RuleContextWithAltNum.h +32 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/RuntimeMetaData.cpp +53 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/RuntimeMetaData.h +155 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/Token.cpp +9 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/Token.h +92 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/TokenFactory.h +30 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/TokenSource.cpp +9 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/TokenSource.h +85 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/TokenStream.cpp +11 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/TokenStream.h +137 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/TokenStreamRewriter.cpp +425 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/TokenStreamRewriter.h +293 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/UnbufferedCharStream.cpp +211 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/UnbufferedCharStream.h +123 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/UnbufferedTokenStream.cpp +270 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/UnbufferedTokenStream.h +115 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/Vocabulary.cpp +104 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/Vocabulary.h +193 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/WritableToken.cpp +9 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/WritableToken.h +23 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/antlr4-common.h +137 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/antlr4-runtime.h +167 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATN.cpp +209 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATN.h +112 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNConfig.cpp +113 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNConfig.h +148 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNConfigSet.cpp +228 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNConfigSet.h +110 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNDeserializationOptions.cpp +64 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNDeserializationOptions.h +50 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNDeserializer.cpp +758 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNDeserializer.h +85 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNSerializer.cpp +621 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNSerializer.h +61 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNSimulator.cpp +63 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNSimulator.h +87 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNState.cpp +72 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNState.h +133 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNType.h +20 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/AbstractPredicateTransition.cpp +14 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/AbstractPredicateTransition.h +24 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ActionTransition.cpp +33 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ActionTransition.h +33 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/AmbiguityInfo.cpp +16 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/AmbiguityInfo.h +68 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ArrayPredictionContext.cpp +82 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ArrayPredictionContext.h +43 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/AtomTransition.cpp +31 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/AtomTransition.h +30 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/BasicBlockStartState.cpp +12 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/BasicBlockStartState.h +22 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/BasicState.cpp +12 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/BasicState.h +21 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/BlockEndState.cpp +15 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/BlockEndState.h +24 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/BlockStartState.cpp +9 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/BlockStartState.h +21 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ContextSensitivityInfo.cpp +14 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ContextSensitivityInfo.h +47 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/DecisionEventInfo.cpp +14 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/DecisionEventInfo.h +70 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/DecisionInfo.cpp +25 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/DecisionInfo.h +227 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/DecisionState.cpp +17 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/DecisionState.h +30 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/EmptyPredictionContext.cpp +35 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/EmptyPredictionContext.h +27 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/EpsilonTransition.cpp +35 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/EpsilonTransition.h +39 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ErrorInfo.cpp +15 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ErrorInfo.h +43 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LL1Analyzer.cpp +158 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LL1Analyzer.h +109 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerATNConfig.cpp +84 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerATNConfig.h +44 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerATNSimulator.cpp +628 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerATNSimulator.h +210 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerAction.cpp +9 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerAction.h +66 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerActionExecutor.cpp +107 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerActionExecutor.h +115 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerActionType.h +55 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerChannelAction.cpp +55 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerChannelAction.h +63 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerCustomAction.cpp +62 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerCustomAction.h +87 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerIndexedCustomAction.cpp +63 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerIndexedCustomAction.h +82 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerModeAction.cpp +56 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerModeAction.h +61 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerMoreAction.cpp +47 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerMoreAction.h +57 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerPopModeAction.cpp +47 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerPopModeAction.h +57 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerPushModeAction.cpp +56 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerPushModeAction.h +61 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerSkipAction.cpp +47 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerSkipAction.h +55 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerTypeAction.cpp +56 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerTypeAction.h +55 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LookaheadEventInfo.cpp +16 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LookaheadEventInfo.h +42 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LoopEndState.cpp +12 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LoopEndState.h +22 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/NotSetTransition.cpp +27 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/NotSetTransition.h +25 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/OrderedATNConfigSet.cpp +12 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/OrderedATNConfigSet.h +20 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ParseInfo.cpp +102 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ParseInfo.h +102 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ParserATNSimulator.cpp +1366 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ParserATNSimulator.h +904 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PlusBlockStartState.cpp +12 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PlusBlockStartState.h +25 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PlusLoopbackState.cpp +12 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PlusLoopbackState.h +22 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PrecedencePredicateTransition.cpp +32 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PrecedencePredicateTransition.h +29 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredicateEvalInfo.cpp +17 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredicateEvalInfo.h +62 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredicateTransition.cpp +34 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredicateTransition.h +39 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredictionContext.cpp +662 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredictionContext.h +254 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredictionMode.cpp +201 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredictionMode.h +436 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ProfilingATNSimulator.cpp +179 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ProfilingATNSimulator.h +60 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/RangeTransition.cpp +30 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/RangeTransition.h +29 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/RuleStartState.cpp +16 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/RuleStartState.h +25 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/RuleStopState.cpp +12 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/RuleStopState.h +25 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/RuleTransition.cpp +37 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/RuleTransition.h +40 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/SemanticContext.cpp +377 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/SemanticContext.h +222 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/SetTransition.cpp +32 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/SetTransition.h +30 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/SingletonPredictionContext.cpp +81 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/SingletonPredictionContext.h +36 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/StarBlockStartState.cpp +12 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/StarBlockStartState.h +21 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/StarLoopEntryState.cpp +15 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/StarLoopEntryState.h +35 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/StarLoopbackState.cpp +19 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/StarLoopbackState.h +21 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/TokensStartState.cpp +12 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/TokensStartState.h +21 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/Transition.cpp +44 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/Transition.h +76 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/WildcardTransition.cpp +25 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/WildcardTransition.h +25 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/dfa/DFA.cpp +127 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/dfa/DFA.h +91 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/dfa/DFASerializer.cpp +67 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/dfa/DFASerializer.h +32 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/dfa/DFAState.cpp +100 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/dfa/DFAState.h +144 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/dfa/LexerDFASerializer.cpp +20 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/dfa/LexerDFASerializer.h +23 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/InterpreterDataReader.cpp +124 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/InterpreterDataReader.h +31 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/Interval.cpp +89 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/Interval.h +84 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/IntervalSet.cpp +521 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/IntervalSet.h +198 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/MurmurHash.cpp +134 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/MurmurHash.h +76 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/Predicate.cpp +4 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/Predicate.h +21 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/Any.cpp +13 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/Any.h +170 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/Arrays.cpp +43 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/Arrays.h +110 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/BitSet.h +76 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/CPPUtils.cpp +248 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/CPPUtils.h +78 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/Declarations.h +163 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/StringUtils.cpp +36 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/StringUtils.h +54 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/guid.cpp +303 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/guid.h +112 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/AbstractParseTreeVisitor.h +128 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ErrorNode.cpp +9 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ErrorNode.h +19 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ErrorNodeImpl.cpp +23 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ErrorNodeImpl.h +33 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/IterativeParseTreeWalker.cpp +71 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/IterativeParseTreeWalker.h +53 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ParseTree.cpp +15 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ParseTree.h +102 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ParseTreeListener.cpp +9 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ParseTreeListener.h +39 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ParseTreeProperty.h +50 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ParseTreeVisitor.cpp +9 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ParseTreeVisitor.h +57 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ParseTreeWalker.cpp +49 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ParseTreeWalker.h +31 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/TerminalNode.cpp +9 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/TerminalNode.h +32 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/TerminalNodeImpl.cpp +57 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/TerminalNodeImpl.h +33 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/Trees.cpp +241 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/Trees.h +78 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/pattern/Chunk.cpp +9 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/pattern/Chunk.h +44 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/pattern/ParseTreeMatch.cpp +69 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/pattern/ParseTreeMatch.h +132 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/pattern/ParseTreePattern.cpp +64 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/pattern/ParseTreePattern.h +105 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/pattern/ParseTreePatternMatcher.cpp +371 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/pattern/ParseTreePatternMatcher.h +185 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/pattern/RuleTagToken.cpp +77 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/pattern/RuleTagToken.h +117 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/pattern/TagChunk.cpp +39 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/pattern/TagChunk.h +86 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/pattern/TextChunk.cpp +28 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/pattern/TextChunk.h +51 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/pattern/TokenTagToken.cpp +36 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/pattern/TokenTagToken.h +80 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPath.cpp +154 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPath.h +86 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathElement.cpp +31 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathElement.h +40 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathLexer.cpp +173 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathLexer.h +56 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathLexerErrorListener.cpp +13 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathLexerErrorListener.h +22 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathRuleAnywhereElement.cpp +20 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathRuleAnywhereElement.h +27 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathRuleElement.cpp +30 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathRuleElement.h +26 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathTokenAnywhereElement.cpp +20 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathTokenAnywhereElement.h +25 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathTokenElement.cpp +33 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathTokenElement.h +26 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathWildcardAnywhereElement.cpp +23 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathWildcardAnywhereElement.h +23 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathWildcardElement.cpp +24 -0
- data/ext/python3-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathWildcardElement.h +23 -0
- data/ext/python3-parser/antlrgen/Python3Lexer.cpp +1024 -0
- data/ext/python3-parser/antlrgen/Python3Lexer.h +91 -0
- data/ext/python3-parser/antlrgen/Python3Lexer.interp +339 -0
- data/ext/python3-parser/antlrgen/Python3Lexer.tokens +181 -0
- data/ext/python3-parser/antlrgen/Python3Parser.cpp +10550 -0
- data/ext/python3-parser/antlrgen/Python3Parser.h +1811 -0
- data/ext/python3-parser/antlrgen/Python3Parser.interp +295 -0
- data/ext/python3-parser/antlrgen/Python3Parser.tokens +181 -0
- data/ext/python3-parser/antlrgen/Python3ParserBaseListener.cpp +7 -0
- data/ext/python3-parser/antlrgen/Python3ParserBaseListener.h +284 -0
- data/ext/python3-parser/antlrgen/Python3ParserBaseVisitor.cpp +7 -0
- data/ext/python3-parser/antlrgen/Python3ParserBaseVisitor.h +364 -0
- data/ext/python3-parser/antlrgen/Python3ParserListener.cpp +7 -0
- data/ext/python3-parser/antlrgen/Python3ParserListener.h +277 -0
- data/ext/python3-parser/antlrgen/Python3ParserVisitor.cpp +7 -0
- data/ext/python3-parser/antlrgen/Python3ParserVisitor.h +196 -0
- data/ext/python3-parser/extconf.rb +34 -0
- data/ext/python3-parser/python3_parser.cpp +10103 -0
- data/lib/python3-parser.rb +2 -0
- data/lib/python3-parser/version.rb +3 -0
- data/python3-parser.gemspec +31 -0
- data/spec/parser_spec.rb +105 -0
- data/spec/spec_helper.rb +9 -0
- metadata +391 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 64bd94c7c78eb31b83c654763d4c850d2c8ea3b9ae219169b24ff9a26a8747db
|
4
|
+
data.tar.gz: e19434ed9e852798b30f7688c093d2527baa7a3ac337898b74b8b53e015f49b4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d3d6f9737246323e4a93dfb54ca95960e27ef0f7adee22b7b00e5b1d880e70ebb6e97f0a705d132c2bd8df21088bd030673110c64745777878a4743aabdd2deb
|
7
|
+
data.tar.gz: 8b88052b4973af6cd75b9c5a39f5eef107da4992df0dce963bdd03dc44d48b9e3d48a129a469b7301625afb0e1a07f00254ef5a9b5d2a80894a54c204048bdcc
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
# python3-parser-rb
|
2
|
+
|
3
|
+
A Python 3 parser for Ruby.
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
Parse some Python 3 code and walk over the parse tree with a visitor:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
require 'python3-parser'
|
11
|
+
|
12
|
+
# from https://rosettacode.org/wiki/Roman_numerals/Decode#Python
|
13
|
+
python_code = <<~END
|
14
|
+
_rdecode = dict(zip('MDCLXVI', (1000, 500, 100, 50, 10, 5, 1)))
|
15
|
+
|
16
|
+
def decode(roman):
|
17
|
+
result = 0
|
18
|
+
for r, r1 in zip(roman, roman[1:]):
|
19
|
+
rd, rd1 = _rdecode[r], _rdecode[r1]
|
20
|
+
result += -rd if rd < rd1 else rd
|
21
|
+
return result + _rdecode[roman[-1]]
|
22
|
+
|
23
|
+
if __name__ == '__main__':
|
24
|
+
for r in 'MCMXC MMVIII MDCLXVI'.split():
|
25
|
+
print(r, decode(r))
|
26
|
+
END
|
27
|
+
|
28
|
+
class MyFuncVisitor < Python3Parser::Visitor
|
29
|
+
def visit_funcdef(ctx)
|
30
|
+
puts ctx.NAME.text
|
31
|
+
visit_children(ctx)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
parser = Python3Parser::Parser.parse(python_code)
|
36
|
+
parser.visit(MyFuncVisitor.new)
|
37
|
+
```
|
38
|
+
|
39
|
+
The script above should print `"decode"` when executed, since `decode` is the only function defined in the Python code snippet.
|
40
|
+
|
41
|
+
## Technology
|
42
|
+
|
43
|
+
Want to target Ruby with your own ANTLR grammars? Check out the [antlr-gemerator](https://github.com/camertron/antlr-gemerator).
|
44
|
+
|
45
|
+
## Caveats
|
46
|
+
|
47
|
+
See the caveats listed in [antlr4-native's README](https://github.com/camertron/antlr4-native-rb#caveats).
|
48
|
+
|
49
|
+
## System Requirements
|
50
|
+
|
51
|
+
See the system requirements listed in [antlr4-native's README](https://github.com/camertron/antlr4-native-rb#system-requirements).
|
52
|
+
|
53
|
+
## License
|
54
|
+
|
55
|
+
Licensed under the MIT license. See LICENSE.txt for details.
|
56
|
+
|
57
|
+
## Authors
|
58
|
+
|
59
|
+
* Cameron C. Dutro: http://github.com/camertron
|
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
require 'antlr4-native'
|
3
|
+
|
4
|
+
Bundler::GemHelper.install_tasks
|
5
|
+
|
6
|
+
task :generate do
|
7
|
+
generator = Antlr4Native::Generator.new(
|
8
|
+
grammar_files: ['Python3Lexer.g4', 'Python3Parser.g4'],
|
9
|
+
output_dir: 'ext',
|
10
|
+
parser_root_method: 'file_input'
|
11
|
+
)
|
12
|
+
|
13
|
+
generator.generate
|
14
|
+
end
|
15
|
+
|
16
|
+
task :compile do
|
17
|
+
Dir.chdir(File.join(%w(ext python3-parser))) do
|
18
|
+
load 'extconf.rb'
|
19
|
+
exec 'make -j 4'
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,112 @@
|
|
1
|
+
#include "Python3Lexer.h"
|
2
|
+
#include "Python3Parser.h"
|
3
|
+
|
4
|
+
Python3LexerBase::Python3LexerBase(antlr4::CharStream *input) : Lexer(input) {
|
5
|
+
tokens = new std::list<antlr4::Token*>();
|
6
|
+
indents = new std::stack<int>();
|
7
|
+
lastToken = nullptr;
|
8
|
+
}
|
9
|
+
|
10
|
+
Python3LexerBase::~Python3LexerBase() {
|
11
|
+
for (auto i = tokens -> begin(); i != tokens -> end(); i ++) {
|
12
|
+
delete *i;
|
13
|
+
}
|
14
|
+
|
15
|
+
delete tokens;
|
16
|
+
delete indents;
|
17
|
+
}
|
18
|
+
|
19
|
+
bool Python3LexerBase::atStartOfInput() {
|
20
|
+
return getCharPositionInLine() == 0 && getLine() == 1;
|
21
|
+
}
|
22
|
+
|
23
|
+
void Python3LexerBase::emit(std::unique_ptr<antlr4::Token> newToken) {
|
24
|
+
auto copy = new antlr4::CommonToken(newToken.get());
|
25
|
+
tokens -> push_back(copy);
|
26
|
+
antlr4::Lexer::emit(std::move(newToken));
|
27
|
+
}
|
28
|
+
|
29
|
+
void Python3LexerBase::emitp(antlr4::Token* newToken) {
|
30
|
+
auto copy = new antlr4::CommonToken(newToken);
|
31
|
+
tokens -> push_back(copy);
|
32
|
+
|
33
|
+
auto uniqueToken = std::unique_ptr<antlr4::Token>(newToken);
|
34
|
+
antlr4::Lexer::emit(std::move(uniqueToken));
|
35
|
+
}
|
36
|
+
|
37
|
+
std::unique_ptr<antlr4::Token> Python3LexerBase::nextToken() {
|
38
|
+
// Check if the end-of-file is ahead and there are still some DEDENTS expected.
|
39
|
+
if (_input -> LA(1) == Python3Parser::EOF && !indents -> empty()) {
|
40
|
+
// Remove any trailing EOF tokens from our buffer.
|
41
|
+
tokens -> remove_if(
|
42
|
+
[](auto&& cur) {
|
43
|
+
return cur -> getType() == Python3Parser::EOF;
|
44
|
+
}
|
45
|
+
);
|
46
|
+
|
47
|
+
// // First emit an extra line break that serves as the end of the statement.
|
48
|
+
emitp(commonToken(Python3Parser::NEWLINE, "\n"));
|
49
|
+
|
50
|
+
// Now emit as much DEDENT tokens as needed.
|
51
|
+
while (!indents -> empty()) {
|
52
|
+
emitp(createDedent());
|
53
|
+
indents -> pop();
|
54
|
+
}
|
55
|
+
|
56
|
+
// // Put the EOF back on the token stream.
|
57
|
+
emitp(commonToken(Python3Parser::EOF, "<EOF>"));
|
58
|
+
}
|
59
|
+
|
60
|
+
auto next = antlr4::Lexer::nextToken();
|
61
|
+
|
62
|
+
if (next.get() -> getChannel() == antlr4::Token::DEFAULT_CHANNEL) {
|
63
|
+
// Keep track of the last token on the default channel.
|
64
|
+
lastToken = new antlr4::CommonToken(next.get());
|
65
|
+
}
|
66
|
+
|
67
|
+
if (tokens -> empty()) {
|
68
|
+
return next;
|
69
|
+
} else {
|
70
|
+
auto frontToken = std::unique_ptr<antlr4::Token>(tokens -> front());
|
71
|
+
tokens -> pop_front();
|
72
|
+
return frontToken;
|
73
|
+
}
|
74
|
+
}
|
75
|
+
|
76
|
+
antlr4::CommonToken* Python3LexerBase::commonToken(size_t type, std::string text) {
|
77
|
+
int stop = getCharIndex() - 1;
|
78
|
+
int start = text.empty() ? stop : stop - text.length() + 1;
|
79
|
+
return new antlr4::CommonToken({ this, _input }, type, antlr4::Lexer::DEFAULT_TOKEN_CHANNEL, start, stop);
|
80
|
+
}
|
81
|
+
|
82
|
+
antlr4::CommonToken* Python3LexerBase::createDedent() {
|
83
|
+
auto dedent = commonToken(Python3Parser::DEDENT, "");
|
84
|
+
dedent -> setLine(lastToken -> getLine());
|
85
|
+
return dedent;
|
86
|
+
}
|
87
|
+
|
88
|
+
// Calculates the indentation of the provided spaces, taking the
|
89
|
+
// following rules into account:
|
90
|
+
//
|
91
|
+
// "Tabs are replaced (from left to right) by one to eight spaces
|
92
|
+
// such that the total number of characters up to and including
|
93
|
+
// the replacement is a multiple of eight [...]"
|
94
|
+
//
|
95
|
+
// -- https://docs.python.org/3.1/reference/lexical_analysis.html#indentation
|
96
|
+
int Python3LexerBase::getIndentationCount(std::string spaces) {
|
97
|
+
int count = 0;
|
98
|
+
|
99
|
+
for (size_t i = 0; i < spaces.length(); i ++) {
|
100
|
+
switch (spaces.at(i)) {
|
101
|
+
case '\t':
|
102
|
+
count += 8 - (count % 8);
|
103
|
+
break;
|
104
|
+
|
105
|
+
default:
|
106
|
+
// A normal space char.
|
107
|
+
count ++;
|
108
|
+
}
|
109
|
+
}
|
110
|
+
|
111
|
+
return count;
|
112
|
+
}
|
@@ -0,0 +1,34 @@
|
|
1
|
+
#pragma once
|
2
|
+
|
3
|
+
#include <list>
|
4
|
+
#include <stack>
|
5
|
+
|
6
|
+
#include "antlr4-runtime.h"
|
7
|
+
|
8
|
+
class Python3LexerBase : public antlr4::Lexer {
|
9
|
+
public:
|
10
|
+
Python3LexerBase(antlr4::CharStream *input);
|
11
|
+
~Python3LexerBase();
|
12
|
+
|
13
|
+
virtual void emitp(antlr4::Token* newToken);
|
14
|
+
|
15
|
+
virtual void emit(std::unique_ptr<antlr4::Token> newToken) override;
|
16
|
+
virtual std::unique_ptr<antlr4::Token> nextToken() override;
|
17
|
+
|
18
|
+
bool atStartOfInput();
|
19
|
+
|
20
|
+
static int getIndentationCount(std::string spaces);
|
21
|
+
|
22
|
+
protected:
|
23
|
+
antlr4::CommonToken* commonToken(size_t type, std::string text);
|
24
|
+
antlr4::CommonToken* createDedent();
|
25
|
+
|
26
|
+
// A queue where extra tokens are pushed on (see the NEWLINE lexer rule).
|
27
|
+
std::list<antlr4::Token*>* tokens;
|
28
|
+
// The stack that keeps track of the indentation level.
|
29
|
+
std::stack<int>* indents;
|
30
|
+
// The amount of opened braces, brackets and parenthesis.
|
31
|
+
int opened = 0;
|
32
|
+
// The most recently produced token.
|
33
|
+
antlr4::Token* lastToken;
|
34
|
+
};
|
@@ -0,0 +1,10 @@
|
|
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 "ANTLRErrorListener.h"
|
7
|
+
|
8
|
+
antlr4::ANTLRErrorListener::~ANTLRErrorListener()
|
9
|
+
{
|
10
|
+
}
|
@@ -0,0 +1,167 @@
|
|
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
|
+
#pragma once
|
7
|
+
|
8
|
+
#include "RecognitionException.h"
|
9
|
+
|
10
|
+
namespace antlrcpp {
|
11
|
+
class BitSet;
|
12
|
+
}
|
13
|
+
|
14
|
+
namespace antlr4 {
|
15
|
+
|
16
|
+
/// How to emit recognition errors (an interface in Java).
|
17
|
+
class ANTLR4CPP_PUBLIC ANTLRErrorListener {
|
18
|
+
public:
|
19
|
+
virtual ~ANTLRErrorListener();
|
20
|
+
|
21
|
+
/// <summary>
|
22
|
+
/// Upon syntax error, notify any interested parties. This is not how to
|
23
|
+
/// recover from errors or compute error messages. <seealso cref="ANTLRErrorStrategy"/>
|
24
|
+
/// specifies how to recover from syntax errors and how to compute error
|
25
|
+
/// messages. This listener's job is simply to emit a computed message,
|
26
|
+
/// though it has enough information to create its own message in many cases.
|
27
|
+
/// <p/>
|
28
|
+
/// The <seealso cref="RecognitionException"/> is non-null for all syntax errors except
|
29
|
+
/// when we discover mismatched token errors that we can recover from
|
30
|
+
/// in-line, without returning from the surrounding rule (via the single
|
31
|
+
/// token insertion and deletion mechanism).
|
32
|
+
/// </summary>
|
33
|
+
/// <param name="recognizer">
|
34
|
+
/// What parser got the error. From this
|
35
|
+
/// object, you can access the context as well
|
36
|
+
/// as the input stream. </param>
|
37
|
+
/// <param name="offendingSymbol">
|
38
|
+
/// The offending token in the input token
|
39
|
+
/// stream, unless recognizer is a lexer (then it's null). If
|
40
|
+
/// no viable alternative error, {@code e} has token at which we
|
41
|
+
/// started production for the decision. </param>
|
42
|
+
/// <param name="line">
|
43
|
+
/// The line number in the input where the error occurred. </param>
|
44
|
+
/// <param name="charPositionInLine">
|
45
|
+
/// The character position within that line where the error occurred. </param>
|
46
|
+
/// <param name="msg">
|
47
|
+
/// The message to emit. </param>
|
48
|
+
/// <param name="e">
|
49
|
+
/// The exception generated by the parser that led to
|
50
|
+
/// the reporting of an error. It is null in the case where
|
51
|
+
/// the parser was able to recover in line without exiting the
|
52
|
+
/// surrounding rule. </param>
|
53
|
+
virtual void syntaxError(Recognizer *recognizer, Token *offendingSymbol, size_t line,
|
54
|
+
size_t charPositionInLine, const std::string &msg, std::exception_ptr e) = 0;
|
55
|
+
|
56
|
+
/**
|
57
|
+
* This method is called by the parser when a full-context prediction
|
58
|
+
* results in an ambiguity.
|
59
|
+
*
|
60
|
+
* <p>Each full-context prediction which does not result in a syntax error
|
61
|
+
* will call either {@link #reportContextSensitivity} or
|
62
|
+
* {@link #reportAmbiguity}.</p>
|
63
|
+
*
|
64
|
+
* <p>When {@code ambigAlts} is not null, it contains the set of potentially
|
65
|
+
* viable alternatives identified by the prediction algorithm. When
|
66
|
+
* {@code ambigAlts} is null, use {@link ATNConfigSet#getAlts} to obtain the
|
67
|
+
* represented alternatives from the {@code configs} argument.</p>
|
68
|
+
*
|
69
|
+
* <p>When {@code exact} is {@code true}, <em>all</em> of the potentially
|
70
|
+
* viable alternatives are truly viable, i.e. this is reporting an exact
|
71
|
+
* ambiguity. When {@code exact} is {@code false}, <em>at least two</em> of
|
72
|
+
* the potentially viable alternatives are viable for the current input, but
|
73
|
+
* the prediction algorithm terminated as soon as it determined that at
|
74
|
+
* least the <em>minimum</em> potentially viable alternative is truly
|
75
|
+
* viable.</p>
|
76
|
+
*
|
77
|
+
* <p>When the {@link PredictionMode#LL_EXACT_AMBIG_DETECTION} prediction
|
78
|
+
* mode is used, the parser is required to identify exact ambiguities so
|
79
|
+
* {@code exact} will always be {@code true}.</p>
|
80
|
+
*
|
81
|
+
* <p>This method is not used by lexers.</p>
|
82
|
+
*
|
83
|
+
* @param recognizer the parser instance
|
84
|
+
* @param dfa the DFA for the current decision
|
85
|
+
* @param startIndex the input index where the decision started
|
86
|
+
* @param stopIndex the input input where the ambiguity was identified
|
87
|
+
* @param exact {@code true} if the ambiguity is exactly known, otherwise
|
88
|
+
* {@code false}. This is always {@code true} when
|
89
|
+
* {@link PredictionMode#LL_EXACT_AMBIG_DETECTION} is used.
|
90
|
+
* @param ambigAlts the potentially ambiguous alternatives, or {@code null}
|
91
|
+
* to indicate that the potentially ambiguous alternatives are the complete
|
92
|
+
* set of represented alternatives in {@code configs}
|
93
|
+
* @param configs the ATN configuration set where the ambiguity was
|
94
|
+
* identified
|
95
|
+
*/
|
96
|
+
virtual void reportAmbiguity(Parser *recognizer, const dfa::DFA &dfa, size_t startIndex, size_t stopIndex, bool exact,
|
97
|
+
const antlrcpp::BitSet &ambigAlts, atn::ATNConfigSet *configs) = 0;
|
98
|
+
|
99
|
+
/**
|
100
|
+
* This method is called when an SLL conflict occurs and the parser is about
|
101
|
+
* to use the full context information to make an LL decision.
|
102
|
+
*
|
103
|
+
* <p>If one or more configurations in {@code configs} contains a semantic
|
104
|
+
* predicate, the predicates are evaluated before this method is called. The
|
105
|
+
* subset of alternatives which are still viable after predicates are
|
106
|
+
* evaluated is reported in {@code conflictingAlts}.</p>
|
107
|
+
*
|
108
|
+
* <p>This method is not used by lexers.</p>
|
109
|
+
*
|
110
|
+
* @param recognizer the parser instance
|
111
|
+
* @param dfa the DFA for the current decision
|
112
|
+
* @param startIndex the input index where the decision started
|
113
|
+
* @param stopIndex the input index where the SLL conflict occurred
|
114
|
+
* @param conflictingAlts The specific conflicting alternatives. If this is
|
115
|
+
* {@code null}, the conflicting alternatives are all alternatives
|
116
|
+
* represented in {@code configs}. At the moment, conflictingAlts is non-null
|
117
|
+
* (for the reference implementation, but Sam's optimized version can see this
|
118
|
+
* as null).
|
119
|
+
* @param configs the ATN configuration set where the SLL conflict was
|
120
|
+
* detected
|
121
|
+
*/
|
122
|
+
virtual void reportAttemptingFullContext(Parser *recognizer, const dfa::DFA &dfa, size_t startIndex, size_t stopIndex,
|
123
|
+
const antlrcpp::BitSet &conflictingAlts, atn::ATNConfigSet *configs) = 0;
|
124
|
+
|
125
|
+
/**
|
126
|
+
* This method is called by the parser when a full-context prediction has a
|
127
|
+
* unique result.
|
128
|
+
*
|
129
|
+
* <p>Each full-context prediction which does not result in a syntax error
|
130
|
+
* will call either {@link #reportContextSensitivity} or
|
131
|
+
* {@link #reportAmbiguity}.</p>
|
132
|
+
*
|
133
|
+
* <p>For prediction implementations that only evaluate full-context
|
134
|
+
* predictions when an SLL conflict is found (including the default
|
135
|
+
* {@link ParserATNSimulator} implementation), this method reports cases
|
136
|
+
* where SLL conflicts were resolved to unique full-context predictions,
|
137
|
+
* i.e. the decision was context-sensitive. This report does not necessarily
|
138
|
+
* indicate a problem, and it may appear even in completely unambiguous
|
139
|
+
* grammars.</p>
|
140
|
+
*
|
141
|
+
* <p>{@code configs} may have more than one represented alternative if the
|
142
|
+
* full-context prediction algorithm does not evaluate predicates before
|
143
|
+
* beginning the full-context prediction. In all cases, the final prediction
|
144
|
+
* is passed as the {@code prediction} argument.</p>
|
145
|
+
*
|
146
|
+
* <p>Note that the definition of "context sensitivity" in this method
|
147
|
+
* differs from the concept in {@link DecisionInfo#contextSensitivities}.
|
148
|
+
* This method reports all instances where an SLL conflict occurred but LL
|
149
|
+
* parsing produced a unique result, whether or not that unique result
|
150
|
+
* matches the minimum alternative in the SLL conflicting set.</p>
|
151
|
+
*
|
152
|
+
* <p>This method is not used by lexers.</p>
|
153
|
+
*
|
154
|
+
* @param recognizer the parser instance
|
155
|
+
* @param dfa the DFA for the current decision
|
156
|
+
* @param startIndex the input index where the decision started
|
157
|
+
* @param stopIndex the input index where the context sensitivity was
|
158
|
+
* finally determined
|
159
|
+
* @param prediction the unambiguous result of the full-context prediction
|
160
|
+
* @param configs the ATN configuration set where the unambiguous prediction
|
161
|
+
* was determined
|
162
|
+
*/
|
163
|
+
virtual void reportContextSensitivity(Parser *recognizer, const dfa::DFA &dfa, size_t startIndex, size_t stopIndex,
|
164
|
+
size_t prediction, atn::ATNConfigSet *configs) = 0;
|
165
|
+
};
|
166
|
+
|
167
|
+
} // namespace antlr4
|
@@ -0,0 +1,10 @@
|
|
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 "ANTLRErrorStrategy.h"
|
7
|
+
|
8
|
+
antlr4::ANTLRErrorStrategy::~ANTLRErrorStrategy()
|
9
|
+
{
|
10
|
+
}
|