SQLiteLexer.g4 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. /*
  2. * The MIT License (MIT)
  3. *
  4. * Copyright (c) 2020 by Martin Mirchev
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
  7. * associated documentation files (the "Software"), to deal in the Software without restriction,
  8. * including without limitation the rights to use, copy, modify, merge, publish, distribute,
  9. * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
  10. * furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be included in all copies or
  13. * substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
  16. * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  17. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  18. * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  20. *
  21. * Project : sqlite-parser; an ANTLR4 grammar for SQLite https://github.com/bkiers/sqlite-parser
  22. * Developed by : Bart Kiers, bart@big-o.nl
  23. */
  24. // $antlr-format alignTrailingComments on, columnLimit 150, maxEmptyLinesToKeep 1, reflowComments off, useTab off
  25. // $antlr-format allowShortRulesOnASingleLine on, alignSemicolons ownLine
  26. lexer grammar SQLiteLexer;
  27. SCOL: ';';
  28. DOT: '.';
  29. OPEN_PAR: '(';
  30. CLOSE_PAR: ')';
  31. COMMA: ',';
  32. ASSIGN: '=';
  33. STAR: '*';
  34. PLUS: '+';
  35. PTR2: '->>';
  36. PTR: '->';
  37. MINUS: '-';
  38. TILDE: '~';
  39. PIPE2: '||';
  40. DIV: '/';
  41. MOD: '%';
  42. LT2: '<<';
  43. GT2: '>>';
  44. AMP: '&';
  45. PIPE: '|';
  46. LT: '<';
  47. LT_EQ: '<=';
  48. GT: '>';
  49. GT_EQ: '>=';
  50. EQ: '==';
  51. NOT_EQ1: '!=';
  52. NOT_EQ2: '<>';
  53. // http://www.sqlite.org/lang_keywords.html
  54. ABORT_: A B O R T;
  55. ACTION_: A C T I O N;
  56. ADD_: A D D;
  57. AFTER_: A F T E R;
  58. ALL_: A L L;
  59. ALTER_: A L T E R;
  60. ANALYZE_: A N A L Y Z E;
  61. AND_: A N D;
  62. AS_: A S;
  63. ASC_: A S C;
  64. ATTACH_: A T T A C H;
  65. AUTOINCREMENT_: A U T O I N C R E M E N T;
  66. BEFORE_: B E F O R E;
  67. BEGIN_: B E G I N;
  68. BETWEEN_: B E T W E E N;
  69. BY_: B Y;
  70. CASCADE_: C A S C A D E;
  71. CASE_: C A S E;
  72. CAST_: C A S T;
  73. CHECK_: C H E C K;
  74. COLLATE_: C O L L A T E;
  75. COLUMN_: C O L U M N;
  76. COMMIT_: C O M M I T;
  77. CONFLICT_: C O N F L I C T;
  78. CONSTRAINT_: C O N S T R A I N T;
  79. CREATE_: C R E A T E;
  80. CROSS_: C R O S S;
  81. CURRENT_DATE_: C U R R E N T '_' D A T E;
  82. CURRENT_TIME_: C U R R E N T '_' T I M E;
  83. CURRENT_TIMESTAMP_: C U R R E N T '_' T I M E S T A M P;
  84. DATABASE_: D A T A B A S E;
  85. DEFAULT_: D E F A U L T;
  86. DEFERRABLE_: D E F E R R A B L E;
  87. DEFERRED_: D E F E R R E D;
  88. DELETE_: D E L E T E;
  89. DESC_: D E S C;
  90. DETACH_: D E T A C H;
  91. DISTINCT_: D I S T I N C T;
  92. DROP_: D R O P;
  93. EACH_: E A C H;
  94. ELSE_: E L S E;
  95. END_: E N D;
  96. ESCAPE_: E S C A P E;
  97. EXCEPT_: E X C E P T;
  98. EXCLUSIVE_: E X C L U S I V E;
  99. EXISTS_: E X I S T S;
  100. EXPLAIN_: E X P L A I N;
  101. FAIL_: F A I L;
  102. FOR_: F O R;
  103. FOREIGN_: F O R E I G N;
  104. FROM_: F R O M;
  105. FULL_: F U L L;
  106. GLOB_: G L O B;
  107. GROUP_: G R O U P;
  108. HAVING_: H A V I N G;
  109. IF_: I F;
  110. IGNORE_: I G N O R E;
  111. IMMEDIATE_: I M M E D I A T E;
  112. IN_: I N;
  113. INDEX_: I N D E X;
  114. INDEXED_: I N D E X E D;
  115. INITIALLY_: I N I T I A L L Y;
  116. INNER_: I N N E R;
  117. INSERT_: I N S E R T;
  118. INSTEAD_: I N S T E A D;
  119. INTERSECT_: I N T E R S E C T;
  120. INTO_: I N T O;
  121. IS_: I S;
  122. ISNULL_: I S N U L L;
  123. JOIN_: J O I N;
  124. KEY_: K E Y;
  125. LEFT_: L E F T;
  126. LIKE_: L I K E;
  127. LIMIT_: L I M I T;
  128. MATCH_: M A T C H;
  129. NATURAL_: N A T U R A L;
  130. NO_: N O;
  131. NOT_: N O T;
  132. NOTNULL_: N O T N U L L;
  133. NULL_: N U L L;
  134. OF_: O F;
  135. OFFSET_: O F F S E T;
  136. ON_: O N;
  137. OR_: O R;
  138. ORDER_: O R D E R;
  139. OUTER_: O U T E R;
  140. PLAN_: P L A N;
  141. PRAGMA_: P R A G M A;
  142. PRIMARY_: P R I M A R Y;
  143. QUERY_: Q U E R Y;
  144. RAISE_: R A I S E;
  145. RECURSIVE_: R E C U R S I V E;
  146. REFERENCES_: R E F E R E N C E S;
  147. REGEXP_: R E G E X P;
  148. REINDEX_: R E I N D E X;
  149. RELEASE_: R E L E A S E;
  150. RENAME_: R E N A M E;
  151. REPLACE_: R E P L A C E;
  152. RESTRICT_: R E S T R I C T;
  153. RETURNING_: R E T U R N I N G;
  154. RIGHT_: R I G H T;
  155. ROLLBACK_: R O L L B A C K;
  156. ROW_: R O W;
  157. ROWS_: R O W S;
  158. SAVEPOINT_: S A V E P O I N T;
  159. SELECT_: S E L E C T;
  160. SET_: S E T;
  161. STRICT_: S T R I C T;
  162. TABLE_: T A B L E;
  163. TEMP_: T E M P;
  164. TEMPORARY_: T E M P O R A R Y;
  165. THEN_: T H E N;
  166. TO_: T O;
  167. TRANSACTION_: T R A N S A C T I O N;
  168. TRIGGER_: T R I G G E R;
  169. UNION_: U N I O N;
  170. UNIQUE_: U N I Q U E;
  171. UPDATE_: U P D A T E;
  172. USING_: U S I N G;
  173. VACUUM_: V A C U U M;
  174. VALUES_: V A L U E S;
  175. VIEW_: V I E W;
  176. VIRTUAL_: V I R T U A L;
  177. WHEN_: W H E N;
  178. WHERE_: W H E R E;
  179. WITH_: W I T H;
  180. WITHOUT_: W I T H O U T;
  181. FIRST_VALUE_: F I R S T '_' V A L U E;
  182. OVER_: O V E R;
  183. PARTITION_: P A R T I T I O N;
  184. RANGE_: R A N G E;
  185. PRECEDING_: P R E C E D I N G;
  186. UNBOUNDED_: U N B O U N D E D;
  187. CURRENT_: C U R R E N T;
  188. FOLLOWING_: F O L L O W I N G;
  189. CUME_DIST_: C U M E '_' D I S T;
  190. DENSE_RANK_: D E N S E '_' R A N K;
  191. LAG_: L A G;
  192. LAST_VALUE_: L A S T '_' V A L U E;
  193. LEAD_: L E A D;
  194. NTH_VALUE_: N T H '_' V A L U E;
  195. NTILE_: N T I L E;
  196. PERCENT_RANK_: P E R C E N T '_' R A N K;
  197. RANK_: R A N K;
  198. ROW_NUMBER_: R O W '_' N U M B E R;
  199. GENERATED_: G E N E R A T E D;
  200. ALWAYS_: A L W A Y S;
  201. STORED_: S T O R E D;
  202. TRUE_: T R U E;
  203. FALSE_: F A L S E;
  204. WINDOW_: W I N D O W;
  205. NULLS_: N U L L S;
  206. FIRST_: F I R S T;
  207. LAST_: L A S T;
  208. FILTER_: F I L T E R;
  209. GROUPS_: G R O U P S;
  210. EXCLUDE_: E X C L U D E;
  211. TIES_: T I E S;
  212. OTHERS_: O T H E R S;
  213. DO_: D O;
  214. NOTHING_: N O T H I N G;
  215. IDENTIFIER:
  216. '"' (~'"' | '""')* '"'
  217. | '`' (~'`' | '``')* '`'
  218. | '[' ~']'* ']'
  219. | [a-zA-Z_] [a-zA-Z_0-9]*
  220. ; // TODO check: needs more chars in set
  221. NUMERIC_LITERAL: ((DIGIT+ ('.' DIGIT*)?) | ('.' DIGIT+)) (E [-+]? DIGIT+)? | '0x' HEX_DIGIT+;
  222. NUMBERED_BIND_PARAMETER: '?' DIGIT*;
  223. NAMED_BIND_PARAMETER: [:@$] IDENTIFIER;
  224. STRING_LITERAL: '\'' ( ~'\'' | '\'\'')* '\'';
  225. BLOB_LITERAL: X STRING_LITERAL;
  226. SINGLE_LINE_COMMENT: '--' ~[\r\n]* (('\r'? '\n') | EOF) -> channel(HIDDEN);
  227. MULTILINE_COMMENT: '/*' .*? '*/' -> channel(HIDDEN);
  228. SPACES: [ \u000B\t\r\n] -> channel(HIDDEN);
  229. UNEXPECTED_CHAR: .;
  230. fragment HEX_DIGIT: [0-9a-fA-F];
  231. fragment DIGIT: [0-9];
  232. fragment A: [aA];
  233. fragment B: [bB];
  234. fragment C: [cC];
  235. fragment D: [dD];
  236. fragment E: [eE];
  237. fragment F: [fF];
  238. fragment G: [gG];
  239. fragment H: [hH];
  240. fragment I: [iI];
  241. fragment J: [jJ];
  242. fragment K: [kK];
  243. fragment L: [lL];
  244. fragment M: [mM];
  245. fragment N: [nN];
  246. fragment O: [oO];
  247. fragment P: [pP];
  248. fragment Q: [qQ];
  249. fragment R: [rR];
  250. fragment S: [sS];
  251. fragment T: [tT];
  252. fragment U: [uU];
  253. fragment V: [vV];
  254. fragment W: [wW];
  255. fragment X: [xX];
  256. fragment Y: [yY];
  257. fragment Z: [zZ];