factorial-presto-parser 1.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (331) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +12 -0
  3. data/README.md +47 -0
  4. data/Rakefile +29 -0
  5. data/ext/presto_parser/PrestoErrorListener.cpp +11 -0
  6. data/ext/presto_parser/PrestoErrorListener.h +19 -0
  7. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/ANTLRErrorListener.cpp +10 -0
  8. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/ANTLRErrorListener.h +167 -0
  9. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/ANTLRErrorStrategy.cpp +10 -0
  10. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/ANTLRErrorStrategy.h +121 -0
  11. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/ANTLRFileStream.cpp +23 -0
  12. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/ANTLRFileStream.h +30 -0
  13. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/ANTLRInputStream.cpp +180 -0
  14. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/ANTLRInputStream.h +79 -0
  15. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/BailErrorStrategy.cpp +61 -0
  16. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/BailErrorStrategy.h +59 -0
  17. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/BaseErrorListener.cpp +25 -0
  18. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/BaseErrorListener.h +36 -0
  19. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/BufferedTokenStream.cpp +414 -0
  20. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/BufferedTokenStream.h +200 -0
  21. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/CharStream.cpp +11 -0
  22. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/CharStream.h +37 -0
  23. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/CommonToken.cpp +193 -0
  24. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/CommonToken.h +158 -0
  25. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/CommonTokenFactory.cpp +39 -0
  26. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/CommonTokenFactory.h +74 -0
  27. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/CommonTokenStream.cpp +78 -0
  28. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/CommonTokenStream.h +79 -0
  29. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/ConsoleErrorListener.cpp +15 -0
  30. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/ConsoleErrorListener.h +35 -0
  31. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/DefaultErrorStrategy.cpp +336 -0
  32. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/DefaultErrorStrategy.h +466 -0
  33. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/DiagnosticErrorListener.cpp +84 -0
  34. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/DiagnosticErrorListener.h +80 -0
  35. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/Exceptions.cpp +64 -0
  36. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/Exceptions.h +99 -0
  37. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/FailedPredicateException.cpp +52 -0
  38. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/FailedPredicateException.h +32 -0
  39. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/InputMismatchException.cpp +18 -0
  40. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/InputMismatchException.h +24 -0
  41. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/IntStream.cpp +12 -0
  42. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/IntStream.h +218 -0
  43. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/InterpreterRuleContext.cpp +19 -0
  44. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/InterpreterRuleContext.h +45 -0
  45. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/Lexer.cpp +294 -0
  46. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/Lexer.h +196 -0
  47. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/LexerInterpreter.cpp +60 -0
  48. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/LexerInterpreter.h +46 -0
  49. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/LexerNoViableAltException.cpp +36 -0
  50. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/LexerNoViableAltException.h +31 -0
  51. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/ListTokenSource.cpp +92 -0
  52. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/ListTokenSource.h +88 -0
  53. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/NoViableAltException.cpp +46 -0
  54. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/NoViableAltException.h +42 -0
  55. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/Parser.cpp +668 -0
  56. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/Parser.h +461 -0
  57. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/ParserInterpreter.cpp +294 -0
  58. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/ParserInterpreter.h +173 -0
  59. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/ParserRuleContext.cpp +138 -0
  60. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/ParserRuleContext.h +147 -0
  61. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/ProxyErrorListener.cpp +53 -0
  62. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/ProxyErrorListener.h +38 -0
  63. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/RecognitionException.cpp +65 -0
  64. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/RecognitionException.h +98 -0
  65. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/Recognizer.cpp +156 -0
  66. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/Recognizer.h +159 -0
  67. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/RuleContext.cpp +144 -0
  68. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/RuleContext.h +141 -0
  69. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/RuleContextWithAltNum.cpp +27 -0
  70. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/RuleContextWithAltNum.h +32 -0
  71. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/RuntimeMetaData.cpp +54 -0
  72. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/RuntimeMetaData.h +155 -0
  73. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/Token.cpp +9 -0
  74. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/Token.h +92 -0
  75. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/TokenFactory.h +30 -0
  76. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/TokenSource.cpp +9 -0
  77. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/TokenSource.h +85 -0
  78. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/TokenStream.cpp +11 -0
  79. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/TokenStream.h +137 -0
  80. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/TokenStreamRewriter.cpp +425 -0
  81. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/TokenStreamRewriter.h +295 -0
  82. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/UnbufferedCharStream.cpp +208 -0
  83. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/UnbufferedCharStream.h +117 -0
  84. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/UnbufferedTokenStream.cpp +270 -0
  85. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/UnbufferedTokenStream.h +115 -0
  86. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/Version.h +42 -0
  87. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/Vocabulary.cpp +64 -0
  88. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/Vocabulary.h +177 -0
  89. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/WritableToken.cpp +9 -0
  90. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/WritableToken.h +23 -0
  91. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/antlr4-common.h +98 -0
  92. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/antlr4-runtime.h +169 -0
  93. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATN.cpp +158 -0
  94. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATN.h +132 -0
  95. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNConfig.cpp +106 -0
  96. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNConfig.h +157 -0
  97. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNConfigSet.cpp +232 -0
  98. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNConfigSet.h +156 -0
  99. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNDeserializationOptions.cpp +54 -0
  100. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNDeserializationOptions.h +48 -0
  101. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNDeserializer.cpp +629 -0
  102. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNDeserializer.h +32 -0
  103. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNSimulator.cpp +33 -0
  104. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNSimulator.h +71 -0
  105. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNState.cpp +56 -0
  106. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNState.h +139 -0
  107. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNStateType.cpp +33 -0
  108. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNStateType.h +36 -0
  109. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNType.h +20 -0
  110. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ActionTransition.cpp +29 -0
  111. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ActionTransition.h +35 -0
  112. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/AmbiguityInfo.cpp +16 -0
  113. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/AmbiguityInfo.h +68 -0
  114. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ArrayPredictionContext.cpp +109 -0
  115. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ArrayPredictionContext.h +51 -0
  116. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/AtomTransition.cpp +27 -0
  117. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/AtomTransition.h +33 -0
  118. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/BasicBlockStartState.h +24 -0
  119. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/BasicState.h +23 -0
  120. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/BlockEndState.h +26 -0
  121. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/BlockStartState.h +30 -0
  122. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ContextSensitivityInfo.cpp +14 -0
  123. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ContextSensitivityInfo.h +47 -0
  124. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/DecisionEventInfo.cpp +14 -0
  125. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/DecisionEventInfo.h +70 -0
  126. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/DecisionInfo.cpp +25 -0
  127. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/DecisionInfo.h +227 -0
  128. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/DecisionState.cpp +12 -0
  129. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/DecisionState.h +34 -0
  130. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/EpsilonTransition.cpp +31 -0
  131. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/EpsilonTransition.h +42 -0
  132. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ErrorInfo.cpp +15 -0
  133. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ErrorInfo.h +43 -0
  134. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LL1Analyzer.cpp +189 -0
  135. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LL1Analyzer.h +76 -0
  136. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerATNConfig.cpp +67 -0
  137. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerATNConfig.h +44 -0
  138. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerATNSimulator.cpp +615 -0
  139. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerATNSimulator.h +199 -0
  140. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerAction.cpp +15 -0
  141. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerAction.h +100 -0
  142. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerActionExecutor.cpp +111 -0
  143. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerActionExecutor.h +128 -0
  144. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerActionType.h +57 -0
  145. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerChannelAction.cpp +43 -0
  146. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerChannelAction.h +59 -0
  147. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerCustomAction.cpp +45 -0
  148. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerCustomAction.h +75 -0
  149. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerIndexedCustomAction.cpp +57 -0
  150. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerIndexedCustomAction.h +76 -0
  151. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerModeAction.cpp +43 -0
  152. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerModeAction.h +57 -0
  153. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerMoreAction.cpp +36 -0
  154. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerMoreAction.h +53 -0
  155. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerPopModeAction.cpp +36 -0
  156. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerPopModeAction.h +53 -0
  157. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerPushModeAction.cpp +43 -0
  158. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerPushModeAction.h +57 -0
  159. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerSkipAction.cpp +36 -0
  160. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerSkipAction.h +51 -0
  161. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerTypeAction.cpp +43 -0
  162. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerTypeAction.h +51 -0
  163. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LookaheadEventInfo.cpp +16 -0
  164. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LookaheadEventInfo.h +42 -0
  165. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LoopEndState.h +26 -0
  166. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/NotSetTransition.cpp +22 -0
  167. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/NotSetTransition.h +27 -0
  168. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/OrderedATNConfigSet.cpp +16 -0
  169. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/OrderedATNConfigSet.h +25 -0
  170. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ParseInfo.cpp +102 -0
  171. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ParseInfo.h +102 -0
  172. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ParserATNSimulator.cpp +1383 -0
  173. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ParserATNSimulator.h +911 -0
  174. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ParserATNSimulatorOptions.h +50 -0
  175. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PlusBlockStartState.h +29 -0
  176. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PlusLoopbackState.h +25 -0
  177. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PrecedencePredicateTransition.cpp +23 -0
  178. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PrecedencePredicateTransition.h +35 -0
  179. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredicateEvalInfo.cpp +17 -0
  180. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredicateEvalInfo.h +62 -0
  181. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredicateTransition.cpp +24 -0
  182. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredicateTransition.h +50 -0
  183. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredictionContext.cpp +579 -0
  184. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredictionContext.h +225 -0
  185. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredictionContextCache.cpp +56 -0
  186. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredictionContextCache.h +64 -0
  187. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredictionContextMergeCache.cpp +167 -0
  188. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredictionContextMergeCache.h +101 -0
  189. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredictionContextMergeCacheOptions.h +71 -0
  190. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredictionContextType.h +21 -0
  191. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredictionMode.cpp +202 -0
  192. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredictionMode.h +436 -0
  193. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ProfilingATNSimulator.cpp +179 -0
  194. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ProfilingATNSimulator.h +60 -0
  195. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/RangeTransition.cpp +26 -0
  196. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/RangeTransition.h +31 -0
  197. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/RuleStartState.h +26 -0
  198. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/RuleStopState.h +27 -0
  199. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/RuleTransition.cpp +33 -0
  200. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/RuleTransition.h +42 -0
  201. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/SemanticContext.cpp +418 -0
  202. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/SemanticContext.h +233 -0
  203. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/SemanticContextType.h +23 -0
  204. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/SerializedATNView.h +101 -0
  205. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/SetTransition.cpp +28 -0
  206. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/SetTransition.h +38 -0
  207. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/SingletonPredictionContext.cpp +86 -0
  208. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/SingletonPredictionContext.h +43 -0
  209. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/StarBlockStartState.h +24 -0
  210. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/StarLoopEntryState.h +37 -0
  211. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/StarLoopbackState.cpp +19 -0
  212. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/StarLoopbackState.h +25 -0
  213. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/TokensStartState.h +24 -0
  214. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/Transition.cpp +36 -0
  215. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/Transition.h +65 -0
  216. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/TransitionType.cpp +27 -0
  217. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/TransitionType.h +33 -0
  218. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/WildcardTransition.cpp +21 -0
  219. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/WildcardTransition.h +27 -0
  220. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/dfa/DFA.cpp +115 -0
  221. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/dfa/DFA.h +96 -0
  222. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/dfa/DFASerializer.cpp +60 -0
  223. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/dfa/DFASerializer.h +32 -0
  224. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/dfa/DFAState.cpp +59 -0
  225. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/dfa/DFAState.h +153 -0
  226. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/dfa/LexerDFASerializer.cpp +17 -0
  227. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/dfa/LexerDFASerializer.h +22 -0
  228. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/InterpreterDataReader.cpp +124 -0
  229. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/InterpreterDataReader.h +33 -0
  230. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/Interval.cpp +61 -0
  231. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/Interval.h +84 -0
  232. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/IntervalSet.cpp +508 -0
  233. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/IntervalSet.h +190 -0
  234. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/MurmurHash.cpp +120 -0
  235. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/MurmurHash.h +102 -0
  236. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/Predicate.cpp +4 -0
  237. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/Predicate.h +21 -0
  238. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/support/Any.cpp +8 -0
  239. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/support/Any.h +16 -0
  240. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/support/Arrays.cpp +43 -0
  241. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/support/Arrays.h +149 -0
  242. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/support/BitSet.h +76 -0
  243. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/support/CPPUtils.cpp +207 -0
  244. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/support/CPPUtils.h +65 -0
  245. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/support/Casts.h +34 -0
  246. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/support/Declarations.h +161 -0
  247. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/support/StringUtils.cpp +38 -0
  248. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/support/StringUtils.h +16 -0
  249. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/support/Unicode.h +28 -0
  250. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/support/Utf8.cpp +242 -0
  251. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/support/Utf8.h +54 -0
  252. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/AbstractParseTreeVisitor.h +129 -0
  253. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ErrorNode.h +24 -0
  254. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ErrorNodeImpl.cpp +54 -0
  255. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ErrorNodeImpl.h +43 -0
  256. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/IterativeParseTreeWalker.cpp +66 -0
  257. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/IterativeParseTreeWalker.h +53 -0
  258. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ParseTree.cpp +12 -0
  259. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ParseTree.h +111 -0
  260. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ParseTreeListener.cpp +9 -0
  261. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ParseTreeListener.h +39 -0
  262. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ParseTreeProperty.h +50 -0
  263. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ParseTreeType.h +22 -0
  264. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ParseTreeVisitor.cpp +9 -0
  265. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ParseTreeVisitor.h +57 -0
  266. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ParseTreeWalker.cpp +48 -0
  267. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ParseTreeWalker.h +55 -0
  268. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/TerminalNode.h +40 -0
  269. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/TerminalNodeImpl.cpp +54 -0
  270. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/TerminalNodeImpl.h +32 -0
  271. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/Trees.cpp +241 -0
  272. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/Trees.h +78 -0
  273. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/pattern/Chunk.cpp +9 -0
  274. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/pattern/Chunk.h +44 -0
  275. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/pattern/ParseTreeMatch.cpp +69 -0
  276. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/pattern/ParseTreeMatch.h +132 -0
  277. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/pattern/ParseTreePattern.cpp +64 -0
  278. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/pattern/ParseTreePattern.h +105 -0
  279. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/pattern/ParseTreePatternMatcher.cpp +370 -0
  280. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/pattern/ParseTreePatternMatcher.h +185 -0
  281. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/pattern/RuleTagToken.cpp +77 -0
  282. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/pattern/RuleTagToken.h +117 -0
  283. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/pattern/TagChunk.cpp +39 -0
  284. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/pattern/TagChunk.h +86 -0
  285. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/pattern/TextChunk.cpp +28 -0
  286. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/pattern/TextChunk.h +51 -0
  287. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/pattern/TokenTagToken.cpp +36 -0
  288. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/pattern/TokenTagToken.h +80 -0
  289. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPath.cpp +154 -0
  290. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPath.h +86 -0
  291. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathElement.cpp +31 -0
  292. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathElement.h +40 -0
  293. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathLexer.cpp +182 -0
  294. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathLexer.h +47 -0
  295. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathLexerErrorListener.cpp +13 -0
  296. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathLexerErrorListener.h +22 -0
  297. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathRuleAnywhereElement.cpp +20 -0
  298. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathRuleAnywhereElement.h +27 -0
  299. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathRuleElement.cpp +30 -0
  300. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathRuleElement.h +26 -0
  301. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathTokenAnywhereElement.cpp +20 -0
  302. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathTokenAnywhereElement.h +25 -0
  303. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathTokenElement.cpp +33 -0
  304. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathTokenElement.h +26 -0
  305. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathWildcardAnywhereElement.cpp +23 -0
  306. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathWildcardAnywhereElement.h +23 -0
  307. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathWildcardElement.cpp +24 -0
  308. data/ext/presto_parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathWildcardElement.h +23 -0
  309. data/ext/presto_parser/antlrgen/Presto.interp +496 -0
  310. data/ext/presto_parser/antlrgen/Presto.tokens +409 -0
  311. data/ext/presto_parser/antlrgen/PrestoBaseListener.cpp +7 -0
  312. data/ext/presto_parser/antlrgen/PrestoBaseListener.h +392 -0
  313. data/ext/presto_parser/antlrgen/PrestoBaseVisitor.cpp +7 -0
  314. data/ext/presto_parser/antlrgen/PrestoBaseVisitor.h +508 -0
  315. data/ext/presto_parser/antlrgen/PrestoLexer.cpp +882 -0
  316. data/ext/presto_parser/antlrgen/PrestoLexer.h +88 -0
  317. data/ext/presto_parser/antlrgen/PrestoLexer.interp +656 -0
  318. data/ext/presto_parser/antlrgen/PrestoLexer.tokens +408 -0
  319. data/ext/presto_parser/antlrgen/PrestoListener.cpp +7 -0
  320. data/ext/presto_parser/antlrgen/PrestoListener.h +385 -0
  321. data/ext/presto_parser/antlrgen/PrestoParser.cpp +12729 -0
  322. data/ext/presto_parser/antlrgen/PrestoParser.h +2358 -0
  323. data/ext/presto_parser/antlrgen/PrestoVisitor.cpp +7 -0
  324. data/ext/presto_parser/antlrgen/PrestoVisitor.h +268 -0
  325. data/ext/presto_parser/extconf.rb +39 -0
  326. data/ext/presto_parser/presto_parser.cpp +14430 -0
  327. data/factorial-presto-parser.gemspec +32 -0
  328. data/lib/presto_parser/ast_visitor.rb +740 -0
  329. data/lib/presto_parser/version.rb +5 -0
  330. data/lib/presto_parser.rb +5 -0
  331. metadata +387 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: b077354c8463640ac88606a9b276cf28b6ab191ad64c9a9045afef4a2a8d4a05
4
+ data.tar.gz: abcd178f52648cd4aae4d838400f83ad1fb82fbfb8f8965687d7ef6cc2877fdc
5
+ SHA512:
6
+ metadata.gz: 0e25a227733e8b0fd5e5781b3a3ae2b863c8e719c8ee0aa221b65125ae755260e80d73b6b4afa128244691cd1e33df51aeb20fa0b400a878211ff524fa2f7047
7
+ data.tar.gz: 966286732dd6c38f7d8995dfae27fee666c3894689a46b604f56c20ac1037befff9f04acb58a9869d5bed815ceffc95fddd8c6a46d5a8cef18d065a7908f5f79
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ group :development do
6
+ gem 'pry-byebug'
7
+ gem 'antlr4-native', '~> 2.0'
8
+ end
9
+
10
+ group :development, :test do
11
+ gem 'rake'
12
+ end
data/README.md ADDED
@@ -0,0 +1,47 @@
1
+ # Factorial Presto Parser
2
+
3
+ This is a Ruby gem containing a parser for the [Presto](https://trino.io/) SQL dialect (now rebranded as Trino). It has been generated using the [antlr4-native gem](https://rubygems.org/gems/antlr4-native) from the [Presto grammar specification](https://github.com/prestodb/presto/blob/0.172/presto-parser/src/main/antlr4/com/facebook/presto/sql/parser/SqlBase.g4), found in the [official Presto repository](https://github.com/prestodb/presto).
4
+
5
+ Note that this gem supports specifically the version 0.172 of Presto, since that's the one used by AWS Athena.
6
+
7
+ ## Building
8
+
9
+ ```ruby
10
+ bundle install
11
+ rake build
12
+ gem install pkg/factorial-presto-parser-[version].gem
13
+ ```
14
+
15
+ ## Trying it out
16
+
17
+ In `irb`:
18
+
19
+ ```ruby
20
+ require 'presto_parser'
21
+
22
+ statement = PrestoParser::Parser.parse('SELECT 1')
23
+ puts statement.singleQuery
24
+ ```
25
+
26
+ ## Messing with the parser's code
27
+
28
+ > #### Note
29
+ > We are using a manually modified version of the original grammar that excludes write operations and only allows database queries. This is accomplished by lowering the grammar's axiom down to the `query` rule, thus making anything else unrecognizable to the parser.
30
+ >
31
+ > Also, some constructs in the grammar prevented C++ compilation, so they have been removed or renamed. The changes made to the original grammar can be found in the `Presto.g4.patch` file.
32
+
33
+ ### Regenerate
34
+ To regenerate the parser code from the grammar file you can use
35
+
36
+ ```sh
37
+ rake generate
38
+ ```
39
+
40
+ Be aware that this will overwrite any changes in the C++ code of the parser, as well as the `Makefile` found in the `ext/presto_parser` directory.
41
+
42
+ ### Compile
43
+ To manually compile the C++ native extension you can do it like this:
44
+
45
+ ```sh
46
+ rake compile
47
+ ```
data/Rakefile ADDED
@@ -0,0 +1,29 @@
1
+
2
+ require 'bundler'
3
+
4
+ require 'antlr4-native'
5
+ require 'etc'
6
+
7
+ def ruby_installer?
8
+ Object.const_defined?(:RubyInstaller)
9
+ end
10
+
11
+ Bundler::GemHelper.install_tasks
12
+
13
+ task :generate do
14
+ generator = Antlr4Native::Generator.new(
15
+ grammar_files: ["./Presto.g4"],
16
+ output_dir: 'ext/',
17
+ parser_root_method: 'singleQuery'
18
+ )
19
+
20
+ generator.generate
21
+ end
22
+
23
+ task :compile do
24
+ Dir.chdir(File.join(%w(ext presto_parser))) do
25
+ load 'extconf.rb'
26
+ RubyInstaller::Runtime.enable_msys_apps if ruby_installer?
27
+ exec "make -j #{Etc.nprocessors}"
28
+ end
29
+ end
@@ -0,0 +1,11 @@
1
+ #include "PrestoErrorListener.h"
2
+
3
+ using namespace std;
4
+ using namespace Rice;
5
+ using namespace antlr4;
6
+
7
+ void PrestoErrorListener::syntaxError(Recognizer * /*recognizer*/, Token * /*offendingSymbol*/,
8
+ size_t line, size_t charPositionInLine, const std::string &msg, std::exception_ptr /*e*/) {
9
+ std::string message = std::string("line ") + std::to_string(line) + ":" + std::to_string(charPositionInLine) + " " + msg;
10
+ throw Exception(rb_exc_new_cstr(this->rbExceptionClass, message.c_str()));
11
+ };
@@ -0,0 +1,19 @@
1
+ #include <antlr4-runtime.h>
2
+ #include <rice/rice.hpp>
3
+ #include <rice/stl.hpp>
4
+
5
+ using namespace std;
6
+ using namespace Rice;
7
+ using namespace antlr4;
8
+
9
+ class PrestoErrorListener : public ConsoleErrorListener {
10
+ public:
11
+ PrestoErrorListener(VALUE rbExceptionClass) {
12
+ this->rbExceptionClass = rbExceptionClass;
13
+ }
14
+ virtual void syntaxError(Recognizer *recognizer, Token * offendingSymbol, size_t line, size_t charPositionInLine,
15
+ const std::string &msg, std::exception_ptr e);
16
+
17
+ private:
18
+ VALUE rbExceptionClass;
19
+ };
@@ -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
+ }
@@ -0,0 +1,121 @@
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 "Token.h"
9
+
10
+ namespace antlr4 {
11
+
12
+ /// <summary>
13
+ /// The interface for defining strategies to deal with syntax errors encountered
14
+ /// during a parse by ANTLR-generated parsers. We distinguish between three
15
+ /// different kinds of errors:
16
+ ///
17
+ /// <ul>
18
+ /// <li>The parser could not figure out which path to take in the ATN (none of
19
+ /// the available alternatives could possibly match)</li>
20
+ /// <li>The current input does not match what we were looking for</li>
21
+ /// <li>A predicate evaluated to false</li>
22
+ /// </ul>
23
+ ///
24
+ /// Implementations of this interface report syntax errors by calling
25
+ /// <seealso cref="Parser#notifyErrorListeners"/>.
26
+ /// <p/>
27
+ /// TODO: what to do about lexers
28
+ /// </summary>
29
+ class ANTLR4CPP_PUBLIC ANTLRErrorStrategy {
30
+ public:
31
+
32
+ /// <summary>
33
+ /// Reset the error handler state for the specified {@code recognizer}. </summary>
34
+ /// <param name="recognizer"> the parser instance </param>
35
+ virtual ~ANTLRErrorStrategy();
36
+
37
+ virtual void reset(Parser *recognizer) = 0;
38
+
39
+ /**
40
+ * This method is called when an unexpected symbol is encountered during an
41
+ * inline match operation, such as {@link Parser#match}. If the error
42
+ * strategy successfully recovers from the match failure, this method
43
+ * returns the {@link Token} instance which should be treated as the
44
+ * successful result of the match.
45
+ *
46
+ * <p>This method handles the consumption of any tokens - the caller should
47
+ * <b>not</b> call {@link Parser#consume} after a successful recovery.</p>
48
+ *
49
+ * <p>Note that the calling code will not report an error if this method
50
+ * returns successfully. The error strategy implementation is responsible
51
+ * for calling {@link Parser#notifyErrorListeners} as appropriate.</p>
52
+ *
53
+ * @param recognizer the parser instance
54
+ * @throws RecognitionException if the error strategy was not able to
55
+ * recover from the unexpected input symbol
56
+ */
57
+ virtual Token* recoverInline(Parser *recognizer) = 0;
58
+
59
+ /// <summary>
60
+ /// This method is called to recover from exception {@code e}. This method is
61
+ /// called after <seealso cref="#reportError"/> by the default exception handler
62
+ /// generated for a rule method.
63
+ /// </summary>
64
+ /// <seealso cref= #reportError
65
+ /// </seealso>
66
+ /// <param name="recognizer"> the parser instance </param>
67
+ /// <param name="e"> the recognition exception to recover from </param>
68
+ /// <exception cref="RecognitionException"> if the error strategy could not recover from
69
+ /// the recognition exception </exception>
70
+ virtual void recover(Parser *recognizer, std::exception_ptr e) = 0;
71
+
72
+ /// <summary>
73
+ /// This method provides the error handler with an opportunity to handle
74
+ /// syntactic or semantic errors in the input stream before they result in a
75
+ /// <seealso cref="RecognitionException"/>.
76
+ /// <p/>
77
+ /// The generated code currently contains calls to <seealso cref="#sync"/> after
78
+ /// entering the decision state of a closure block ({@code (...)*} or
79
+ /// {@code (...)+}).
80
+ /// <p/>
81
+ /// For an implementation based on Jim Idle's "magic sync" mechanism, see
82
+ /// <seealso cref="DefaultErrorStrategy#sync"/>.
83
+ /// </summary>
84
+ /// <seealso cref= DefaultErrorStrategy#sync
85
+ /// </seealso>
86
+ /// <param name="recognizer"> the parser instance </param>
87
+ /// <exception cref="RecognitionException"> if an error is detected by the error
88
+ /// strategy but cannot be automatically recovered at the current state in
89
+ /// the parsing process </exception>
90
+ virtual void sync(Parser *recognizer) = 0;
91
+
92
+ /// <summary>
93
+ /// Tests whether or not {@code recognizer} is in the process of recovering
94
+ /// from an error. In error recovery mode, <seealso cref="Parser#consume"/> adds
95
+ /// symbols to the parse tree by calling
96
+ /// {@link Parser#createErrorNode(ParserRuleContext, Token)} then
97
+ /// {@link ParserRuleContext#addErrorNode(ErrorNode)} instead of
98
+ /// {@link Parser#createTerminalNode(ParserRuleContext, Token)}.
99
+ /// </summary>
100
+ /// <param name="recognizer"> the parser instance </param>
101
+ /// <returns> {@code true} if the parser is currently recovering from a parse
102
+ /// error, otherwise {@code false} </returns>
103
+ virtual bool inErrorRecoveryMode(Parser *recognizer) = 0;
104
+
105
+ /// <summary>
106
+ /// This method is called by when the parser successfully matches an input
107
+ /// symbol.
108
+ /// </summary>
109
+ /// <param name="recognizer"> the parser instance </param>
110
+ virtual void reportMatch(Parser *recognizer) = 0;
111
+
112
+ /// <summary>
113
+ /// Report any kind of <seealso cref="RecognitionException"/>. This method is called by
114
+ /// the default exception handler generated for a rule method.
115
+ /// </summary>
116
+ /// <param name="recognizer"> the parser instance </param>
117
+ /// <param name="e"> the recognition exception to report </param>
118
+ virtual void reportError(Parser *recognizer, const RecognitionException &e) = 0;
119
+ };
120
+
121
+ } // namespace antlr4
@@ -0,0 +1,23 @@
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 "ANTLRFileStream.h"
7
+
8
+ using namespace antlr4;
9
+
10
+ void ANTLRFileStream::loadFromFile(const std::string &fileName) {
11
+ _fileName = fileName;
12
+ if (_fileName.empty()) {
13
+ return;
14
+ }
15
+
16
+ std::ifstream stream(fileName, std::ios::binary);
17
+
18
+ ANTLRInputStream::load(stream);
19
+ }
20
+
21
+ std::string ANTLRFileStream::getSourceName() const {
22
+ return _fileName;
23
+ }
@@ -0,0 +1,30 @@
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 "ANTLRInputStream.h"
9
+
10
+ namespace antlr4 {
11
+
12
+ /// This is an ANTLRInputStream that is loaded from a file all at once
13
+ /// when you construct the object (or call load()).
14
+ // TODO: this class needs testing.
15
+ class ANTLR4CPP_PUBLIC ANTLRFileStream : public ANTLRInputStream {
16
+ public:
17
+ ANTLRFileStream() = default;
18
+ ANTLRFileStream(const std::string &) = delete;
19
+ ANTLRFileStream(const char *data, size_t length) = delete;
20
+ ANTLRFileStream(std::istream &stream) = delete;
21
+
22
+ // Assumes a file name encoded in UTF-8 and file content in the same encoding (with or w/o BOM).
23
+ virtual void loadFromFile(const std::string &fileName);
24
+ virtual std::string getSourceName() const override;
25
+
26
+ private:
27
+ std::string _fileName; // UTF-8 encoded file name.
28
+ };
29
+
30
+ } // namespace antlr4
@@ -0,0 +1,180 @@
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 <string.h>
7
+
8
+ #include "Exceptions.h"
9
+ #include "misc/Interval.h"
10
+ #include "IntStream.h"
11
+
12
+ #include "support/Utf8.h"
13
+ #include "support/CPPUtils.h"
14
+
15
+ #include "ANTLRInputStream.h"
16
+
17
+ using namespace antlr4;
18
+ using namespace antlrcpp;
19
+
20
+ using misc::Interval;
21
+
22
+ ANTLRInputStream::ANTLRInputStream() {
23
+ InitializeInstanceFields();
24
+ }
25
+
26
+ ANTLRInputStream::ANTLRInputStream(std::string_view input): ANTLRInputStream() {
27
+ load(input.data(), input.length());
28
+ }
29
+
30
+ ANTLRInputStream::ANTLRInputStream(const char *data, size_t length) {
31
+ load(data, length);
32
+ }
33
+
34
+ ANTLRInputStream::ANTLRInputStream(std::istream &stream): ANTLRInputStream() {
35
+ load(stream);
36
+ }
37
+
38
+ void ANTLRInputStream::load(const std::string &input, bool lenient) {
39
+ load(input.data(), input.size(), lenient);
40
+ }
41
+
42
+ void ANTLRInputStream::load(const char *data, size_t length, bool lenient) {
43
+ // Remove the UTF-8 BOM if present.
44
+ const char *bom = "\xef\xbb\xbf";
45
+ if (length >= 3 && strncmp(data, bom, 3) == 0) {
46
+ data += 3;
47
+ length -= 3;
48
+ }
49
+ if (lenient) {
50
+ _data = Utf8::lenientDecode(std::string_view(data, length));
51
+ } else {
52
+ auto maybe_utf32 = Utf8::strictDecode(std::string_view(data, length));
53
+ if (!maybe_utf32.has_value()) {
54
+ throw IllegalArgumentException("UTF-8 string contains an illegal byte sequence");
55
+ }
56
+ _data = std::move(maybe_utf32).value();
57
+ }
58
+ p = 0;
59
+ }
60
+
61
+ void ANTLRInputStream::load(std::istream &stream, bool lenient) {
62
+ if (!stream.good() || stream.eof()) // No fail, bad or EOF.
63
+ return;
64
+
65
+ _data.clear();
66
+
67
+ std::string s((std::istreambuf_iterator<char>(stream)), std::istreambuf_iterator<char>());
68
+ load(s.data(), s.length(), lenient);
69
+ }
70
+
71
+ void ANTLRInputStream::reset() {
72
+ p = 0;
73
+ }
74
+
75
+ void ANTLRInputStream::consume() {
76
+ if (p >= _data.size()) {
77
+ assert(LA(1) == IntStream::EOF);
78
+ throw IllegalStateException("cannot consume EOF");
79
+ }
80
+
81
+ if (p < _data.size()) {
82
+ p++;
83
+ }
84
+ }
85
+
86
+ size_t ANTLRInputStream::LA(ssize_t i) {
87
+ if (i == 0) {
88
+ return 0; // undefined
89
+ }
90
+
91
+ ssize_t position = static_cast<ssize_t>(p);
92
+ if (i < 0) {
93
+ i++; // e.g., translate LA(-1) to use offset i=0; then _data[p+0-1]
94
+ if ((position + i - 1) < 0) {
95
+ return IntStream::EOF; // invalid; no char before first char
96
+ }
97
+ }
98
+
99
+ if ((position + i - 1) >= static_cast<ssize_t>(_data.size())) {
100
+ return IntStream::EOF;
101
+ }
102
+
103
+ return _data[static_cast<size_t>((position + i - 1))];
104
+ }
105
+
106
+ size_t ANTLRInputStream::LT(ssize_t i) {
107
+ return LA(i);
108
+ }
109
+
110
+ size_t ANTLRInputStream::index() {
111
+ return p;
112
+ }
113
+
114
+ size_t ANTLRInputStream::size() {
115
+ return _data.size();
116
+ }
117
+
118
+ // Mark/release do nothing. We have entire buffer.
119
+ ssize_t ANTLRInputStream::mark() {
120
+ return -1;
121
+ }
122
+
123
+ void ANTLRInputStream::release(ssize_t /* marker */) {
124
+ }
125
+
126
+ void ANTLRInputStream::seek(size_t index) {
127
+ if (index <= p) {
128
+ p = index; // just jump; don't update stream state (line, ...)
129
+ return;
130
+ }
131
+ // seek forward, consume until p hits index or n (whichever comes first)
132
+ index = std::min(index, _data.size());
133
+ while (p < index) {
134
+ consume();
135
+ }
136
+ }
137
+
138
+ std::string ANTLRInputStream::getText(const Interval &interval) {
139
+ if (interval.a < 0 || interval.b < 0) {
140
+ return "";
141
+ }
142
+
143
+ size_t start = static_cast<size_t>(interval.a);
144
+ size_t stop = static_cast<size_t>(interval.b);
145
+
146
+
147
+ if (stop >= _data.size()) {
148
+ stop = _data.size() - 1;
149
+ }
150
+
151
+ size_t count = stop - start + 1;
152
+ if (start >= _data.size()) {
153
+ return "";
154
+ }
155
+
156
+ auto maybeUtf8 = Utf8::strictEncode(std::u32string_view(_data).substr(start, count));
157
+ if (!maybeUtf8.has_value()) {
158
+ throw IllegalArgumentException("Input stream contains invalid Unicode code points");
159
+ }
160
+ return std::move(maybeUtf8).value();
161
+ }
162
+
163
+ std::string ANTLRInputStream::getSourceName() const {
164
+ if (name.empty()) {
165
+ return IntStream::UNKNOWN_SOURCE_NAME;
166
+ }
167
+ return name;
168
+ }
169
+
170
+ std::string ANTLRInputStream::toString() const {
171
+ auto maybeUtf8 = Utf8::strictEncode(_data);
172
+ if (!maybeUtf8.has_value()) {
173
+ throw IllegalArgumentException("Input stream contains invalid Unicode code points");
174
+ }
175
+ return std::move(maybeUtf8).value();
176
+ }
177
+
178
+ void ANTLRInputStream::InitializeInstanceFields() {
179
+ p = 0;
180
+ }