Development of an internal social media platform with personalised dashboards for students
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

keywords.py 24KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817
  1. # -*- coding: utf-8 -*-
  2. #
  3. # Copyright (C) 2016 Andi Albrecht, albrecht.andi@gmail.com
  4. #
  5. # This module is part of python-sqlparse and is released under
  6. # the BSD License: https://opensource.org/licenses/BSD-3-Clause
  7. import re
  8. from sqlparse import tokens
  9. def is_keyword(value):
  10. val = value.upper()
  11. return (KEYWORDS_COMMON.get(val) or
  12. KEYWORDS_ORACLE.get(val) or
  13. KEYWORDS_PLPGSQL.get(val) or
  14. KEYWORDS.get(val, tokens.Name)), value
  15. SQL_REGEX = {
  16. 'root': [
  17. (r'(--|# )\+.*?(\r\n|\r|\n|$)', tokens.Comment.Single.Hint),
  18. (r'/\*\+[\s\S]*?\*/', tokens.Comment.Multiline.Hint),
  19. (r'(--|# ).*?(\r\n|\r|\n|$)', tokens.Comment.Single),
  20. (r'/\*[\s\S]*?\*/', tokens.Comment.Multiline),
  21. (r'(\r\n|\r|\n)', tokens.Newline),
  22. (r'\s+', tokens.Whitespace),
  23. (r':=', tokens.Assignment),
  24. (r'::', tokens.Punctuation),
  25. (r'\*', tokens.Wildcard),
  26. (r"`(``|[^`])*`", tokens.Name),
  27. (r"´(´´|[^´])*´", tokens.Name),
  28. (r'(\$(?:[_A-ZÀ-Ü]\w*)?\$)[\s\S]*?\1', tokens.Literal),
  29. (r'\?', tokens.Name.Placeholder),
  30. (r'%(\(\w+\))?s', tokens.Name.Placeholder),
  31. (r'(?<!\w)[$:?]\w+', tokens.Name.Placeholder),
  32. # FIXME(andi): VALUES shouldn't be listed here
  33. # see https://github.com/andialbrecht/sqlparse/pull/64
  34. # IN is special, it may be followed by a parenthesis, but
  35. # is never a functino, see issue183
  36. (r'(CASE|IN|VALUES|USING)\b', tokens.Keyword),
  37. (r'(@|##|#)[A-ZÀ-Ü]\w+', tokens.Name),
  38. # see issue #39
  39. # Spaces around period `schema . name` are valid identifier
  40. # TODO: Spaces before period not implemented
  41. (r'[A-ZÀ-Ü]\w*(?=\s*\.)', tokens.Name), # 'Name' .
  42. # FIXME(atronah): never match,
  43. # because `re.match` doesn't work with lookbehind regexp feature
  44. (r'(?<=\.)[A-ZÀ-Ü]\w*', tokens.Name), # .'Name'
  45. (r'[A-ZÀ-Ü]\w*(?=\()', tokens.Name), # side effect: change kw to func
  46. (r'-?0x[\dA-F]+', tokens.Number.Hexadecimal),
  47. (r'-?\d*(\.\d+)?E-?\d+', tokens.Number.Float),
  48. (r'-?(\d+(\.\d*)|\.\d+)', tokens.Number.Float),
  49. (r'-?\d+(?![_A-ZÀ-Ü])', tokens.Number.Integer),
  50. (r"'(''|\\\\|\\'|[^'])*'", tokens.String.Single),
  51. # not a real string literal in ANSI SQL:
  52. (r'(""|".*?[^\\]")', tokens.String.Symbol),
  53. # sqlite names can be escaped with [square brackets]. left bracket
  54. # cannot be preceded by word character or a right bracket --
  55. # otherwise it's probably an array index
  56. (r'(?<![\w\])])(\[[^\]]+\])', tokens.Name),
  57. (r'((LEFT\s+|RIGHT\s+|FULL\s+)?(INNER\s+|OUTER\s+|STRAIGHT\s+)?'
  58. r'|(CROSS\s+|NATURAL\s+)?)?JOIN\b', tokens.Keyword),
  59. (r'END(\s+IF|\s+LOOP|\s+WHILE)?\b', tokens.Keyword),
  60. (r'NOT\s+NULL\b', tokens.Keyword),
  61. (r'UNION\s+ALL\b', tokens.Keyword),
  62. (r'CREATE(\s+OR\s+REPLACE)?\b', tokens.Keyword.DDL),
  63. (r'DOUBLE\s+PRECISION\b', tokens.Name.Builtin),
  64. (r'[0-9_A-ZÀ-Ü][_$#\w]*', is_keyword),
  65. (r'[;:()\[\],\.]', tokens.Punctuation),
  66. (r'[<>=~!]+', tokens.Operator.Comparison),
  67. (r'[+/@#%^&|`?^-]+', tokens.Operator),
  68. ]}
  69. FLAGS = re.IGNORECASE | re.UNICODE
  70. SQL_REGEX = [(re.compile(rx, FLAGS).match, tt) for rx, tt in SQL_REGEX['root']]
  71. KEYWORDS = {
  72. 'ABORT': tokens.Keyword,
  73. 'ABS': tokens.Keyword,
  74. 'ABSOLUTE': tokens.Keyword,
  75. 'ACCESS': tokens.Keyword,
  76. 'ADA': tokens.Keyword,
  77. 'ADD': tokens.Keyword,
  78. 'ADMIN': tokens.Keyword,
  79. 'AFTER': tokens.Keyword,
  80. 'AGGREGATE': tokens.Keyword,
  81. 'ALIAS': tokens.Keyword,
  82. 'ALL': tokens.Keyword,
  83. 'ALLOCATE': tokens.Keyword,
  84. 'ANALYSE': tokens.Keyword,
  85. 'ANALYZE': tokens.Keyword,
  86. 'ANY': tokens.Keyword,
  87. 'ARRAYLEN': tokens.Keyword,
  88. 'ARE': tokens.Keyword,
  89. 'ASC': tokens.Keyword.Order,
  90. 'ASENSITIVE': tokens.Keyword,
  91. 'ASSERTION': tokens.Keyword,
  92. 'ASSIGNMENT': tokens.Keyword,
  93. 'ASYMMETRIC': tokens.Keyword,
  94. 'AT': tokens.Keyword,
  95. 'ATOMIC': tokens.Keyword,
  96. 'AUDIT': tokens.Keyword,
  97. 'AUTHORIZATION': tokens.Keyword,
  98. 'AUTO_INCREMENT': tokens.Keyword,
  99. 'AVG': tokens.Keyword,
  100. 'BACKWARD': tokens.Keyword,
  101. 'BEFORE': tokens.Keyword,
  102. 'BEGIN': tokens.Keyword,
  103. 'BETWEEN': tokens.Keyword,
  104. 'BITVAR': tokens.Keyword,
  105. 'BIT_LENGTH': tokens.Keyword,
  106. 'BOTH': tokens.Keyword,
  107. 'BREADTH': tokens.Keyword,
  108. # 'C': tokens.Keyword, # most likely this is an alias
  109. 'CACHE': tokens.Keyword,
  110. 'CALL': tokens.Keyword,
  111. 'CALLED': tokens.Keyword,
  112. 'CARDINALITY': tokens.Keyword,
  113. 'CASCADE': tokens.Keyword,
  114. 'CASCADED': tokens.Keyword,
  115. 'CAST': tokens.Keyword,
  116. 'CATALOG': tokens.Keyword,
  117. 'CATALOG_NAME': tokens.Keyword,
  118. 'CHAIN': tokens.Keyword,
  119. 'CHARACTERISTICS': tokens.Keyword,
  120. 'CHARACTER_LENGTH': tokens.Keyword,
  121. 'CHARACTER_SET_CATALOG': tokens.Keyword,
  122. 'CHARACTER_SET_NAME': tokens.Keyword,
  123. 'CHARACTER_SET_SCHEMA': tokens.Keyword,
  124. 'CHAR_LENGTH': tokens.Keyword,
  125. 'CHARSET': tokens.Keyword,
  126. 'CHECK': tokens.Keyword,
  127. 'CHECKED': tokens.Keyword,
  128. 'CHECKPOINT': tokens.Keyword,
  129. 'CLASS': tokens.Keyword,
  130. 'CLASS_ORIGIN': tokens.Keyword,
  131. 'CLOB': tokens.Keyword,
  132. 'CLOSE': tokens.Keyword,
  133. 'CLUSTER': tokens.Keyword,
  134. 'COALESCE': tokens.Keyword,
  135. 'COBOL': tokens.Keyword,
  136. 'COLLATE': tokens.Keyword,
  137. 'COLLATION': tokens.Keyword,
  138. 'COLLATION_CATALOG': tokens.Keyword,
  139. 'COLLATION_NAME': tokens.Keyword,
  140. 'COLLATION_SCHEMA': tokens.Keyword,
  141. 'COLLECT': tokens.Keyword,
  142. 'COLUMN': tokens.Keyword,
  143. 'COLUMN_NAME': tokens.Keyword,
  144. 'COMPRESS': tokens.Keyword,
  145. 'COMMAND_FUNCTION': tokens.Keyword,
  146. 'COMMAND_FUNCTION_CODE': tokens.Keyword,
  147. 'COMMENT': tokens.Keyword,
  148. 'COMMIT': tokens.Keyword.DML,
  149. 'COMMITTED': tokens.Keyword,
  150. 'COMPLETION': tokens.Keyword,
  151. 'CONCURRENTLY': tokens.Keyword,
  152. 'CONDITION_NUMBER': tokens.Keyword,
  153. 'CONNECT': tokens.Keyword,
  154. 'CONNECTION': tokens.Keyword,
  155. 'CONNECTION_NAME': tokens.Keyword,
  156. 'CONSTRAINT': tokens.Keyword,
  157. 'CONSTRAINTS': tokens.Keyword,
  158. 'CONSTRAINT_CATALOG': tokens.Keyword,
  159. 'CONSTRAINT_NAME': tokens.Keyword,
  160. 'CONSTRAINT_SCHEMA': tokens.Keyword,
  161. 'CONSTRUCTOR': tokens.Keyword,
  162. 'CONTAINS': tokens.Keyword,
  163. 'CONTINUE': tokens.Keyword,
  164. 'CONVERSION': tokens.Keyword,
  165. 'CONVERT': tokens.Keyword,
  166. 'COPY': tokens.Keyword,
  167. 'CORRESPONTING': tokens.Keyword,
  168. 'COUNT': tokens.Keyword,
  169. 'CREATEDB': tokens.Keyword,
  170. 'CREATEUSER': tokens.Keyword,
  171. 'CROSS': tokens.Keyword,
  172. 'CUBE': tokens.Keyword,
  173. 'CURRENT': tokens.Keyword,
  174. 'CURRENT_DATE': tokens.Keyword,
  175. 'CURRENT_PATH': tokens.Keyword,
  176. 'CURRENT_ROLE': tokens.Keyword,
  177. 'CURRENT_TIME': tokens.Keyword,
  178. 'CURRENT_TIMESTAMP': tokens.Keyword,
  179. 'CURRENT_USER': tokens.Keyword,
  180. 'CURSOR': tokens.Keyword,
  181. 'CURSOR_NAME': tokens.Keyword,
  182. 'CYCLE': tokens.Keyword,
  183. 'DATA': tokens.Keyword,
  184. 'DATABASE': tokens.Keyword,
  185. 'DATETIME_INTERVAL_CODE': tokens.Keyword,
  186. 'DATETIME_INTERVAL_PRECISION': tokens.Keyword,
  187. 'DAY': tokens.Keyword,
  188. 'DEALLOCATE': tokens.Keyword,
  189. 'DECLARE': tokens.Keyword,
  190. 'DEFAULT': tokens.Keyword,
  191. 'DEFAULTS': tokens.Keyword,
  192. 'DEFERRABLE': tokens.Keyword,
  193. 'DEFERRED': tokens.Keyword,
  194. 'DEFINED': tokens.Keyword,
  195. 'DEFINER': tokens.Keyword,
  196. 'DELIMITER': tokens.Keyword,
  197. 'DELIMITERS': tokens.Keyword,
  198. 'DEREF': tokens.Keyword,
  199. 'DESC': tokens.Keyword.Order,
  200. 'DESCRIBE': tokens.Keyword,
  201. 'DESCRIPTOR': tokens.Keyword,
  202. 'DESTROY': tokens.Keyword,
  203. 'DESTRUCTOR': tokens.Keyword,
  204. 'DETERMINISTIC': tokens.Keyword,
  205. 'DIAGNOSTICS': tokens.Keyword,
  206. 'DICTIONARY': tokens.Keyword,
  207. 'DISABLE': tokens.Keyword,
  208. 'DISCONNECT': tokens.Keyword,
  209. 'DISPATCH': tokens.Keyword,
  210. 'DO': tokens.Keyword,
  211. 'DOMAIN': tokens.Keyword,
  212. 'DYNAMIC': tokens.Keyword,
  213. 'DYNAMIC_FUNCTION': tokens.Keyword,
  214. 'DYNAMIC_FUNCTION_CODE': tokens.Keyword,
  215. 'EACH': tokens.Keyword,
  216. 'ENABLE': tokens.Keyword,
  217. 'ENCODING': tokens.Keyword,
  218. 'ENCRYPTED': tokens.Keyword,
  219. 'END-EXEC': tokens.Keyword,
  220. 'ENGINE': tokens.Keyword,
  221. 'EQUALS': tokens.Keyword,
  222. 'ESCAPE': tokens.Keyword,
  223. 'EVERY': tokens.Keyword,
  224. 'EXCEPT': tokens.Keyword,
  225. 'EXCEPTION': tokens.Keyword,
  226. 'EXCLUDING': tokens.Keyword,
  227. 'EXCLUSIVE': tokens.Keyword,
  228. 'EXEC': tokens.Keyword,
  229. 'EXECUTE': tokens.Keyword,
  230. 'EXISTING': tokens.Keyword,
  231. 'EXISTS': tokens.Keyword,
  232. 'EXTERNAL': tokens.Keyword,
  233. 'EXTRACT': tokens.Keyword,
  234. 'FALSE': tokens.Keyword,
  235. 'FETCH': tokens.Keyword,
  236. 'FILE': tokens.Keyword,
  237. 'FINAL': tokens.Keyword,
  238. 'FIRST': tokens.Keyword,
  239. 'FORCE': tokens.Keyword,
  240. 'FOREACH': tokens.Keyword,
  241. 'FOREIGN': tokens.Keyword,
  242. 'FORTRAN': tokens.Keyword,
  243. 'FORWARD': tokens.Keyword,
  244. 'FOUND': tokens.Keyword,
  245. 'FREE': tokens.Keyword,
  246. 'FREEZE': tokens.Keyword,
  247. 'FULL': tokens.Keyword,
  248. 'FUNCTION': tokens.Keyword,
  249. # 'G': tokens.Keyword,
  250. 'GENERAL': tokens.Keyword,
  251. 'GENERATED': tokens.Keyword,
  252. 'GET': tokens.Keyword,
  253. 'GLOBAL': tokens.Keyword,
  254. 'GO': tokens.Keyword,
  255. 'GOTO': tokens.Keyword,
  256. 'GRANT': tokens.Keyword,
  257. 'GRANTED': tokens.Keyword,
  258. 'GROUPING': tokens.Keyword,
  259. 'HANDLER': tokens.Keyword,
  260. 'HAVING': tokens.Keyword,
  261. 'HIERARCHY': tokens.Keyword,
  262. 'HOLD': tokens.Keyword,
  263. 'HOST': tokens.Keyword,
  264. 'IDENTIFIED': tokens.Keyword,
  265. 'IDENTITY': tokens.Keyword,
  266. 'IGNORE': tokens.Keyword,
  267. 'ILIKE': tokens.Keyword,
  268. 'IMMEDIATE': tokens.Keyword,
  269. 'IMMUTABLE': tokens.Keyword,
  270. 'IMPLEMENTATION': tokens.Keyword,
  271. 'IMPLICIT': tokens.Keyword,
  272. 'INCLUDING': tokens.Keyword,
  273. 'INCREMENT': tokens.Keyword,
  274. 'INDEX': tokens.Keyword,
  275. 'INDITCATOR': tokens.Keyword,
  276. 'INFIX': tokens.Keyword,
  277. 'INHERITS': tokens.Keyword,
  278. 'INITIAL': tokens.Keyword,
  279. 'INITIALIZE': tokens.Keyword,
  280. 'INITIALLY': tokens.Keyword,
  281. 'INOUT': tokens.Keyword,
  282. 'INPUT': tokens.Keyword,
  283. 'INSENSITIVE': tokens.Keyword,
  284. 'INSTANTIABLE': tokens.Keyword,
  285. 'INSTEAD': tokens.Keyword,
  286. 'INTERSECT': tokens.Keyword,
  287. 'INTO': tokens.Keyword,
  288. 'INVOKER': tokens.Keyword,
  289. 'IS': tokens.Keyword,
  290. 'ISNULL': tokens.Keyword,
  291. 'ISOLATION': tokens.Keyword,
  292. 'ITERATE': tokens.Keyword,
  293. # 'K': tokens.Keyword,
  294. 'KEY': tokens.Keyword,
  295. 'KEY_MEMBER': tokens.Keyword,
  296. 'KEY_TYPE': tokens.Keyword,
  297. 'LANCOMPILER': tokens.Keyword,
  298. 'LANGUAGE': tokens.Keyword,
  299. 'LARGE': tokens.Keyword,
  300. 'LAST': tokens.Keyword,
  301. 'LATERAL': tokens.Keyword,
  302. 'LEADING': tokens.Keyword,
  303. 'LENGTH': tokens.Keyword,
  304. 'LESS': tokens.Keyword,
  305. 'LEVEL': tokens.Keyword,
  306. 'LIMIT': tokens.Keyword,
  307. 'LISTEN': tokens.Keyword,
  308. 'LOAD': tokens.Keyword,
  309. 'LOCAL': tokens.Keyword,
  310. 'LOCALTIME': tokens.Keyword,
  311. 'LOCALTIMESTAMP': tokens.Keyword,
  312. 'LOCATION': tokens.Keyword,
  313. 'LOCATOR': tokens.Keyword,
  314. 'LOCK': tokens.Keyword,
  315. 'LOWER': tokens.Keyword,
  316. # 'M': tokens.Keyword,
  317. 'MAP': tokens.Keyword,
  318. 'MATCH': tokens.Keyword,
  319. 'MAXEXTENTS': tokens.Keyword,
  320. 'MAXVALUE': tokens.Keyword,
  321. 'MESSAGE_LENGTH': tokens.Keyword,
  322. 'MESSAGE_OCTET_LENGTH': tokens.Keyword,
  323. 'MESSAGE_TEXT': tokens.Keyword,
  324. 'METHOD': tokens.Keyword,
  325. 'MINUTE': tokens.Keyword,
  326. 'MINUS': tokens.Keyword,
  327. 'MINVALUE': tokens.Keyword,
  328. 'MOD': tokens.Keyword,
  329. 'MODE': tokens.Keyword,
  330. 'MODIFIES': tokens.Keyword,
  331. 'MODIFY': tokens.Keyword,
  332. 'MONTH': tokens.Keyword,
  333. 'MORE': tokens.Keyword,
  334. 'MOVE': tokens.Keyword,
  335. 'MUMPS': tokens.Keyword,
  336. 'NAMES': tokens.Keyword,
  337. 'NATIONAL': tokens.Keyword,
  338. 'NATURAL': tokens.Keyword,
  339. 'NCHAR': tokens.Keyword,
  340. 'NCLOB': tokens.Keyword,
  341. 'NEW': tokens.Keyword,
  342. 'NEXT': tokens.Keyword,
  343. 'NO': tokens.Keyword,
  344. 'NOAUDIT': tokens.Keyword,
  345. 'NOCOMPRESS': tokens.Keyword,
  346. 'NOCREATEDB': tokens.Keyword,
  347. 'NOCREATEUSER': tokens.Keyword,
  348. 'NONE': tokens.Keyword,
  349. 'NOT': tokens.Keyword,
  350. 'NOTFOUND': tokens.Keyword,
  351. 'NOTHING': tokens.Keyword,
  352. 'NOTIFY': tokens.Keyword,
  353. 'NOTNULL': tokens.Keyword,
  354. 'NOWAIT': tokens.Keyword,
  355. 'NULL': tokens.Keyword,
  356. 'NULLABLE': tokens.Keyword,
  357. 'NULLIF': tokens.Keyword,
  358. 'OBJECT': tokens.Keyword,
  359. 'OCTET_LENGTH': tokens.Keyword,
  360. 'OF': tokens.Keyword,
  361. 'OFF': tokens.Keyword,
  362. 'OFFLINE': tokens.Keyword,
  363. 'OFFSET': tokens.Keyword,
  364. 'OIDS': tokens.Keyword,
  365. 'OLD': tokens.Keyword,
  366. 'ONLINE': tokens.Keyword,
  367. 'ONLY': tokens.Keyword,
  368. 'OPEN': tokens.Keyword,
  369. 'OPERATION': tokens.Keyword,
  370. 'OPERATOR': tokens.Keyword,
  371. 'OPTION': tokens.Keyword,
  372. 'OPTIONS': tokens.Keyword,
  373. 'ORDINALITY': tokens.Keyword,
  374. 'OUT': tokens.Keyword,
  375. 'OUTPUT': tokens.Keyword,
  376. 'OVERLAPS': tokens.Keyword,
  377. 'OVERLAY': tokens.Keyword,
  378. 'OVERRIDING': tokens.Keyword,
  379. 'OWNER': tokens.Keyword,
  380. 'PAD': tokens.Keyword,
  381. 'PARAMETER': tokens.Keyword,
  382. 'PARAMETERS': tokens.Keyword,
  383. 'PARAMETER_MODE': tokens.Keyword,
  384. 'PARAMATER_NAME': tokens.Keyword,
  385. 'PARAMATER_ORDINAL_POSITION': tokens.Keyword,
  386. 'PARAMETER_SPECIFIC_CATALOG': tokens.Keyword,
  387. 'PARAMETER_SPECIFIC_NAME': tokens.Keyword,
  388. 'PARAMATER_SPECIFIC_SCHEMA': tokens.Keyword,
  389. 'PARTIAL': tokens.Keyword,
  390. 'PASCAL': tokens.Keyword,
  391. 'PCTFREE': tokens.Keyword,
  392. 'PENDANT': tokens.Keyword,
  393. 'PLACING': tokens.Keyword,
  394. 'PLI': tokens.Keyword,
  395. 'POSITION': tokens.Keyword,
  396. 'POSTFIX': tokens.Keyword,
  397. 'PRECISION': tokens.Keyword,
  398. 'PREFIX': tokens.Keyword,
  399. 'PREORDER': tokens.Keyword,
  400. 'PREPARE': tokens.Keyword,
  401. 'PRESERVE': tokens.Keyword,
  402. 'PRIMARY': tokens.Keyword,
  403. 'PRIOR': tokens.Keyword,
  404. 'PRIVILEGES': tokens.Keyword,
  405. 'PROCEDURAL': tokens.Keyword,
  406. 'PROCEDURE': tokens.Keyword,
  407. 'PUBLIC': tokens.Keyword,
  408. 'RAISE': tokens.Keyword,
  409. 'RAW': tokens.Keyword,
  410. 'READ': tokens.Keyword,
  411. 'READS': tokens.Keyword,
  412. 'RECHECK': tokens.Keyword,
  413. 'RECURSIVE': tokens.Keyword,
  414. 'REF': tokens.Keyword,
  415. 'REFERENCES': tokens.Keyword,
  416. 'REFERENCING': tokens.Keyword,
  417. 'REINDEX': tokens.Keyword,
  418. 'RELATIVE': tokens.Keyword,
  419. 'RENAME': tokens.Keyword,
  420. 'REPEATABLE': tokens.Keyword,
  421. 'RESET': tokens.Keyword,
  422. 'RESOURCE': tokens.Keyword,
  423. 'RESTART': tokens.Keyword,
  424. 'RESTRICT': tokens.Keyword,
  425. 'RESULT': tokens.Keyword,
  426. 'RETURN': tokens.Keyword,
  427. 'RETURNED_LENGTH': tokens.Keyword,
  428. 'RETURNED_OCTET_LENGTH': tokens.Keyword,
  429. 'RETURNED_SQLSTATE': tokens.Keyword,
  430. 'RETURNING': tokens.Keyword,
  431. 'RETURNS': tokens.Keyword,
  432. 'REVOKE': tokens.Keyword,
  433. 'RIGHT': tokens.Keyword,
  434. 'ROLE': tokens.Keyword,
  435. 'ROLLBACK': tokens.Keyword.DML,
  436. 'ROLLUP': tokens.Keyword,
  437. 'ROUTINE': tokens.Keyword,
  438. 'ROUTINE_CATALOG': tokens.Keyword,
  439. 'ROUTINE_NAME': tokens.Keyword,
  440. 'ROUTINE_SCHEMA': tokens.Keyword,
  441. 'ROW': tokens.Keyword,
  442. 'ROWS': tokens.Keyword,
  443. 'ROW_COUNT': tokens.Keyword,
  444. 'RULE': tokens.Keyword,
  445. 'SAVE_POINT': tokens.Keyword,
  446. 'SCALE': tokens.Keyword,
  447. 'SCHEMA': tokens.Keyword,
  448. 'SCHEMA_NAME': tokens.Keyword,
  449. 'SCOPE': tokens.Keyword,
  450. 'SCROLL': tokens.Keyword,
  451. 'SEARCH': tokens.Keyword,
  452. 'SECOND': tokens.Keyword,
  453. 'SECURITY': tokens.Keyword,
  454. 'SELF': tokens.Keyword,
  455. 'SENSITIVE': tokens.Keyword,
  456. 'SEQUENCE': tokens.Keyword,
  457. 'SERIALIZABLE': tokens.Keyword,
  458. 'SERVER_NAME': tokens.Keyword,
  459. 'SESSION': tokens.Keyword,
  460. 'SESSION_USER': tokens.Keyword,
  461. 'SETOF': tokens.Keyword,
  462. 'SETS': tokens.Keyword,
  463. 'SHARE': tokens.Keyword,
  464. 'SHOW': tokens.Keyword,
  465. 'SIMILAR': tokens.Keyword,
  466. 'SIMPLE': tokens.Keyword,
  467. 'SIZE': tokens.Keyword,
  468. 'SOME': tokens.Keyword,
  469. 'SOURCE': tokens.Keyword,
  470. 'SPACE': tokens.Keyword,
  471. 'SPECIFIC': tokens.Keyword,
  472. 'SPECIFICTYPE': tokens.Keyword,
  473. 'SPECIFIC_NAME': tokens.Keyword,
  474. 'SQL': tokens.Keyword,
  475. 'SQLBUF': tokens.Keyword,
  476. 'SQLCODE': tokens.Keyword,
  477. 'SQLERROR': tokens.Keyword,
  478. 'SQLEXCEPTION': tokens.Keyword,
  479. 'SQLSTATE': tokens.Keyword,
  480. 'SQLWARNING': tokens.Keyword,
  481. 'STABLE': tokens.Keyword,
  482. 'START': tokens.Keyword.DML,
  483. # 'STATE': tokens.Keyword,
  484. 'STATEMENT': tokens.Keyword,
  485. 'STATIC': tokens.Keyword,
  486. 'STATISTICS': tokens.Keyword,
  487. 'STDIN': tokens.Keyword,
  488. 'STDOUT': tokens.Keyword,
  489. 'STORAGE': tokens.Keyword,
  490. 'STRICT': tokens.Keyword,
  491. 'STRUCTURE': tokens.Keyword,
  492. 'STYPE': tokens.Keyword,
  493. 'SUBCLASS_ORIGIN': tokens.Keyword,
  494. 'SUBLIST': tokens.Keyword,
  495. 'SUBSTRING': tokens.Keyword,
  496. 'SUCCESSFUL': tokens.Keyword,
  497. 'SUM': tokens.Keyword,
  498. 'SYMMETRIC': tokens.Keyword,
  499. 'SYNONYM': tokens.Keyword,
  500. 'SYSID': tokens.Keyword,
  501. 'SYSTEM': tokens.Keyword,
  502. 'SYSTEM_USER': tokens.Keyword,
  503. 'TABLE': tokens.Keyword,
  504. 'TABLE_NAME': tokens.Keyword,
  505. 'TEMP': tokens.Keyword,
  506. 'TEMPLATE': tokens.Keyword,
  507. 'TEMPORARY': tokens.Keyword,
  508. 'TERMINATE': tokens.Keyword,
  509. 'THAN': tokens.Keyword,
  510. 'TIMESTAMP': tokens.Keyword,
  511. 'TIMEZONE_HOUR': tokens.Keyword,
  512. 'TIMEZONE_MINUTE': tokens.Keyword,
  513. 'TO': tokens.Keyword,
  514. 'TOAST': tokens.Keyword,
  515. 'TRAILING': tokens.Keyword,
  516. 'TRANSATION': tokens.Keyword,
  517. 'TRANSACTIONS_COMMITTED': tokens.Keyword,
  518. 'TRANSACTIONS_ROLLED_BACK': tokens.Keyword,
  519. 'TRANSATION_ACTIVE': tokens.Keyword,
  520. 'TRANSFORM': tokens.Keyword,
  521. 'TRANSFORMS': tokens.Keyword,
  522. 'TRANSLATE': tokens.Keyword,
  523. 'TRANSLATION': tokens.Keyword,
  524. 'TREAT': tokens.Keyword,
  525. 'TRIGGER': tokens.Keyword,
  526. 'TRIGGER_CATALOG': tokens.Keyword,
  527. 'TRIGGER_NAME': tokens.Keyword,
  528. 'TRIGGER_SCHEMA': tokens.Keyword,
  529. 'TRIM': tokens.Keyword,
  530. 'TRUE': tokens.Keyword,
  531. 'TRUNCATE': tokens.Keyword,
  532. 'TRUSTED': tokens.Keyword,
  533. 'TYPE': tokens.Keyword,
  534. 'UID': tokens.Keyword,
  535. 'UNCOMMITTED': tokens.Keyword,
  536. 'UNDER': tokens.Keyword,
  537. 'UNENCRYPTED': tokens.Keyword,
  538. 'UNION': tokens.Keyword,
  539. 'UNIQUE': tokens.Keyword,
  540. 'UNKNOWN': tokens.Keyword,
  541. 'UNLISTEN': tokens.Keyword,
  542. 'UNNAMED': tokens.Keyword,
  543. 'UNNEST': tokens.Keyword,
  544. 'UNTIL': tokens.Keyword,
  545. 'UPPER': tokens.Keyword,
  546. 'USAGE': tokens.Keyword,
  547. 'USE': tokens.Keyword,
  548. 'USER': tokens.Keyword,
  549. 'USER_DEFINED_TYPE_CATALOG': tokens.Keyword,
  550. 'USER_DEFINED_TYPE_NAME': tokens.Keyword,
  551. 'USER_DEFINED_TYPE_SCHEMA': tokens.Keyword,
  552. 'USING': tokens.Keyword,
  553. 'VACUUM': tokens.Keyword,
  554. 'VALID': tokens.Keyword,
  555. 'VALIDATE': tokens.Keyword,
  556. 'VALIDATOR': tokens.Keyword,
  557. 'VALUES': tokens.Keyword,
  558. 'VARIABLE': tokens.Keyword,
  559. 'VERBOSE': tokens.Keyword,
  560. 'VERSION': tokens.Keyword,
  561. 'VIEW': tokens.Keyword,
  562. 'VOLATILE': tokens.Keyword,
  563. 'WHENEVER': tokens.Keyword,
  564. 'WITH': tokens.Keyword.CTE,
  565. 'WITHOUT': tokens.Keyword,
  566. 'WORK': tokens.Keyword,
  567. 'WRITE': tokens.Keyword,
  568. 'YEAR': tokens.Keyword,
  569. 'ZONE': tokens.Keyword,
  570. # Name.Builtin
  571. 'ARRAY': tokens.Name.Builtin,
  572. 'BIGINT': tokens.Name.Builtin,
  573. 'BINARY': tokens.Name.Builtin,
  574. 'BIT': tokens.Name.Builtin,
  575. 'BLOB': tokens.Name.Builtin,
  576. 'BOOLEAN': tokens.Name.Builtin,
  577. 'CHAR': tokens.Name.Builtin,
  578. 'CHARACTER': tokens.Name.Builtin,
  579. 'DATE': tokens.Name.Builtin,
  580. 'DEC': tokens.Name.Builtin,
  581. 'DECIMAL': tokens.Name.Builtin,
  582. 'FLOAT': tokens.Name.Builtin,
  583. 'INT': tokens.Name.Builtin,
  584. 'INT8': tokens.Name.Builtin,
  585. 'INTEGER': tokens.Name.Builtin,
  586. 'INTERVAL': tokens.Name.Builtin,
  587. 'LONG': tokens.Name.Builtin,
  588. 'NUMBER': tokens.Name.Builtin,
  589. 'NUMERIC': tokens.Name.Builtin,
  590. 'REAL': tokens.Name.Builtin,
  591. 'ROWID': tokens.Name.Builtin,
  592. 'ROWLABEL': tokens.Name.Builtin,
  593. 'ROWNUM': tokens.Name.Builtin,
  594. 'SERIAL': tokens.Name.Builtin,
  595. 'SERIAL8': tokens.Name.Builtin,
  596. 'SIGNED': tokens.Name.Builtin,
  597. 'SMALLINT': tokens.Name.Builtin,
  598. 'SYSDATE': tokens.Name,
  599. 'TEXT': tokens.Name.Builtin,
  600. 'TINYINT': tokens.Name.Builtin,
  601. 'UNSIGNED': tokens.Name.Builtin,
  602. 'VARCHAR': tokens.Name.Builtin,
  603. 'VARCHAR2': tokens.Name.Builtin,
  604. 'VARYING': tokens.Name.Builtin,
  605. }
  606. KEYWORDS_COMMON = {
  607. 'SELECT': tokens.Keyword.DML,
  608. 'INSERT': tokens.Keyword.DML,
  609. 'DELETE': tokens.Keyword.DML,
  610. 'UPDATE': tokens.Keyword.DML,
  611. 'REPLACE': tokens.Keyword.DML,
  612. 'MERGE': tokens.Keyword.DML,
  613. 'DROP': tokens.Keyword.DDL,
  614. 'CREATE': tokens.Keyword.DDL,
  615. 'ALTER': tokens.Keyword.DDL,
  616. 'WHERE': tokens.Keyword,
  617. 'FROM': tokens.Keyword,
  618. 'INNER': tokens.Keyword,
  619. 'JOIN': tokens.Keyword,
  620. 'STRAIGHT_JOIN': tokens.Keyword,
  621. 'AND': tokens.Keyword,
  622. 'OR': tokens.Keyword,
  623. 'LIKE': tokens.Keyword,
  624. 'ON': tokens.Keyword,
  625. 'IN': tokens.Keyword,
  626. 'SET': tokens.Keyword,
  627. 'BY': tokens.Keyword,
  628. 'GROUP': tokens.Keyword,
  629. 'ORDER': tokens.Keyword,
  630. 'LEFT': tokens.Keyword,
  631. 'OUTER': tokens.Keyword,
  632. 'FULL': tokens.Keyword,
  633. 'IF': tokens.Keyword,
  634. 'END': tokens.Keyword,
  635. 'THEN': tokens.Keyword,
  636. 'LOOP': tokens.Keyword,
  637. 'AS': tokens.Keyword,
  638. 'ELSE': tokens.Keyword,
  639. 'FOR': tokens.Keyword,
  640. 'WHILE': tokens.Keyword,
  641. 'CASE': tokens.Keyword,
  642. 'WHEN': tokens.Keyword,
  643. 'MIN': tokens.Keyword,
  644. 'MAX': tokens.Keyword,
  645. 'DISTINCT': tokens.Keyword,
  646. }
  647. KEYWORDS_ORACLE = {
  648. 'ARCHIVE': tokens.Keyword,
  649. 'ARCHIVELOG': tokens.Keyword,
  650. 'BACKUP': tokens.Keyword,
  651. 'BECOME': tokens.Keyword,
  652. 'BLOCK': tokens.Keyword,
  653. 'BODY': tokens.Keyword,
  654. 'CANCEL': tokens.Keyword,
  655. 'CHANGE': tokens.Keyword,
  656. 'COMPILE': tokens.Keyword,
  657. 'CONTENTS': tokens.Keyword,
  658. 'CONTROLFILE': tokens.Keyword,
  659. 'DATAFILE': tokens.Keyword,
  660. 'DBA': tokens.Keyword,
  661. 'DISMOUNT': tokens.Keyword,
  662. 'DOUBLE': tokens.Keyword,
  663. 'DUMP': tokens.Keyword,
  664. 'EVENTS': tokens.Keyword,
  665. 'EXCEPTIONS': tokens.Keyword,
  666. 'EXPLAIN': tokens.Keyword,
  667. 'EXTENT': tokens.Keyword,
  668. 'EXTERNALLY': tokens.Keyword,
  669. 'FLUSH': tokens.Keyword,
  670. 'FREELIST': tokens.Keyword,
  671. 'FREELISTS': tokens.Keyword,
  672. # groups seems too common as table name
  673. # 'GROUPS': tokens.Keyword,
  674. 'INDICATOR': tokens.Keyword,
  675. 'INITRANS': tokens.Keyword,
  676. 'INSTANCE': tokens.Keyword,
  677. 'LAYER': tokens.Keyword,
  678. 'LINK': tokens.Keyword,
  679. 'LISTS': tokens.Keyword,
  680. 'LOGFILE': tokens.Keyword,
  681. 'MANAGE': tokens.Keyword,
  682. 'MANUAL': tokens.Keyword,
  683. 'MAXDATAFILES': tokens.Keyword,
  684. 'MAXINSTANCES': tokens.Keyword,
  685. 'MAXLOGFILES': tokens.Keyword,
  686. 'MAXLOGHISTORY': tokens.Keyword,
  687. 'MAXLOGMEMBERS': tokens.Keyword,
  688. 'MAXTRANS': tokens.Keyword,
  689. 'MINEXTENTS': tokens.Keyword,
  690. 'MODULE': tokens.Keyword,
  691. 'MOUNT': tokens.Keyword,
  692. 'NOARCHIVELOG': tokens.Keyword,
  693. 'NOCACHE': tokens.Keyword,
  694. 'NOCYCLE': tokens.Keyword,
  695. 'NOMAXVALUE': tokens.Keyword,
  696. 'NOMINVALUE': tokens.Keyword,
  697. 'NOORDER': tokens.Keyword,
  698. 'NORESETLOGS': tokens.Keyword,
  699. 'NORMAL': tokens.Keyword,
  700. 'NOSORT': tokens.Keyword,
  701. 'OPTIMAL': tokens.Keyword,
  702. 'OWN': tokens.Keyword,
  703. 'PACKAGE': tokens.Keyword,
  704. 'PARALLEL': tokens.Keyword,
  705. 'PCTINCREASE': tokens.Keyword,
  706. 'PCTUSED': tokens.Keyword,
  707. 'PLAN': tokens.Keyword,
  708. 'PRIVATE': tokens.Keyword,
  709. 'PROFILE': tokens.Keyword,
  710. 'QUOTA': tokens.Keyword,
  711. 'RECOVER': tokens.Keyword,
  712. 'RESETLOGS': tokens.Keyword,
  713. 'RESTRICTED': tokens.Keyword,
  714. 'REUSE': tokens.Keyword,
  715. 'ROLES': tokens.Keyword,
  716. 'SAVEPOINT': tokens.Keyword,
  717. 'SCN': tokens.Keyword,
  718. 'SECTION': tokens.Keyword,
  719. 'SEGMENT': tokens.Keyword,
  720. 'SHARED': tokens.Keyword,
  721. 'SNAPSHOT': tokens.Keyword,
  722. 'SORT': tokens.Keyword,
  723. 'STATEMENT_ID': tokens.Keyword,
  724. 'STOP': tokens.Keyword,
  725. 'SWITCH': tokens.Keyword,
  726. 'TABLES': tokens.Keyword,
  727. 'TABLESPACE': tokens.Keyword,
  728. 'THREAD': tokens.Keyword,
  729. 'TIME': tokens.Keyword,
  730. 'TRACING': tokens.Keyword,
  731. 'TRANSACTION': tokens.Keyword,
  732. 'TRIGGERS': tokens.Keyword,
  733. 'UNLIMITED': tokens.Keyword,
  734. 'UNLOCK': tokens.Keyword,
  735. }
  736. # PostgreSQL Syntax
  737. KEYWORDS_PLPGSQL = {
  738. 'PARTITION': tokens.Keyword,
  739. 'OVER': tokens.Keyword,
  740. 'PERFORM': tokens.Keyword,
  741. 'NOTICE': tokens.Keyword,
  742. 'PLPGSQL': tokens.Keyword,
  743. 'INHERIT': tokens.Keyword,
  744. 'INDEXES': tokens.Keyword,
  745. 'FOR': tokens.Keyword,
  746. 'IN': tokens.Keyword,
  747. 'LOOP': tokens.Keyword,
  748. }