keywords.py 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111
  1. #
  2. # Copyright (C) 2009-2020 the sqlparse authors and contributors
  3. # <see AUTHORS file>
  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 bisect import bisect_left
  9. from collections import defaultdict
  10. from sqlparse import tokens
  11. # object() only supports "is" and is useful as a marker
  12. # use this marker to specify that the given regex in SQL_REGEX
  13. # shall be processed further through a lookup in the KEYWORDS dictionaries
  14. PROCESS_AS_KEYWORD = object()
  15. # Dollar-quoted literals (`$tag$...$tag$`) and multiline comments
  16. # (`/*...*/`, `/*+...*/`) used to be matched with per-position regexes
  17. # using a lazy dot-all quantifier (`[\s\S]*?`) terminated by a
  18. # backreference or a literal delimiter. Applied at every text position by
  19. # the lexer loop, that shape is O(n^2) on adversarial input with many
  20. # unclosed openers, since each failed attempt re-scans to the end of the
  21. # remaining text (GHSA-prg7-hcfm-mfcr). find_delimited_spans() collects
  22. # all opener and closer positions in a single pass instead, so the lexer
  23. # can pair them with a binary search when it actually reaches an opener.
  24. #
  25. # The delimiter regex is wrapped in a lookahead so that overlapping
  26. # occurrences are reported too: in `$$$$` the closing `$$` starts inside
  27. # the match of the opening one, and a non-overlapping scan would miss it.
  28. _DOLLAR_QUOTE_DELIM = re.compile(
  29. r'(?=(\$(?:[_A-ZÀ-Ü]\w*)?\$))', re.IGNORECASE | re.UNICODE)
  30. _DOLLAR_QUOTE_OPENER_OK = re.compile(r'(?<![\w"$])', re.UNICODE)
  31. _COMMENT_HINT_OPEN = re.compile(r'/\*\+')
  32. _COMMENT_OPEN = re.compile(r'/\*(?!\+)')
  33. _COMMENT_CLOSE = re.compile(r'\*/')
  34. # All multiline comments share a single closer (`*/`), so one bucket is
  35. # enough; dollar-quoted literals are bucketed by their tag.
  36. _COMMENT_TAG = '/*'
  37. class DelimitedSpans:
  38. """Opener and closer positions of dollar-quoted literals and multiline
  39. comments, resolved on demand by :meth:`resolve`.
  40. Pairing has to happen at the position the lexer has actually reached,
  41. not upfront: a `/*`, `*/` or `$$` inside a string literal or behind a
  42. `--` comment is not a delimiter at all, and resolving it eagerly would
  43. consume the partner of the next real delimiter.
  44. """
  45. __slots__ = ('_closers', 'openers')
  46. def __init__(self, openers, closers):
  47. #: start offset -> (offset behind the opener, tag, token type)
  48. self.openers = openers
  49. #: tag -> ([closer start, ...], [closer end, ...]), both ascending
  50. self._closers = closers
  51. def resolve(self, pos):
  52. """Return ``(end offset, token type)`` for the span opening at
  53. `pos`, or None if its closing delimiter is missing -- just as a
  54. regex that never finds its closing delimiter fails to match.
  55. """
  56. opener_end, tag, ttype = self.openers[pos]
  57. starts, ends = self._closers[tag]
  58. idx = bisect_left(starts, opener_end)
  59. if idx == len(starts):
  60. return None
  61. return ends[idx], ttype
  62. _NO_SPANS = DelimitedSpans({}, {})
  63. def find_delimited_spans(text):
  64. """Locate the delimiters of dollar-quoted literals and multiline
  65. comments in `text` and return them as a :class:`DelimitedSpans`.
  66. """
  67. has_dollar = '$' in text
  68. # A comment can only ever open on "/*"; without it "*/" alone can
  69. # never pair with anything, so gating on "/*" alone is sufficient to
  70. # skip all three comment-related regex passes below.
  71. has_comment_open = '/*' in text
  72. if not has_dollar and not has_comment_open:
  73. return _NO_SPANS
  74. openers = {}
  75. closers = defaultdict(lambda: ([], []))
  76. if has_dollar:
  77. for m in _DOLLAR_QUOTE_DELIM.finditer(text):
  78. start = m.start()
  79. tag = m.group(1)
  80. end = start + len(tag)
  81. # Every delimiter can close a literal, but one preceded by a
  82. # word character, `"` or `$` cannot open one.
  83. starts, ends = closers[tag]
  84. starts.append(start)
  85. ends.append(end)
  86. if _DOLLAR_QUOTE_OPENER_OK.match(text, start) is not None:
  87. openers[start] = (end, tag, tokens.Literal)
  88. if has_comment_open:
  89. for m in _COMMENT_HINT_OPEN.finditer(text):
  90. openers[m.start()] = (
  91. m.end(), _COMMENT_TAG, tokens.Comment.Multiline.Hint)
  92. for m in _COMMENT_OPEN.finditer(text):
  93. openers[m.start()] = (
  94. m.end(), _COMMENT_TAG, tokens.Comment.Multiline)
  95. starts, ends = closers[_COMMENT_TAG]
  96. for m in _COMMENT_CLOSE.finditer(text):
  97. starts.append(m.start())
  98. ends.append(m.end())
  99. return DelimitedSpans(openers, closers)
  100. SQL_REGEX = [
  101. (r'(--|# )\+.*?(\r\n|\r|\n|$)', tokens.Comment.Single.Hint),
  102. (r'(--|# ).*?(\r\n|\r|\n|$)', tokens.Comment.Single),
  103. (r'(\r\n|\r|\n)', tokens.Newline),
  104. (r'\s+?', tokens.Whitespace),
  105. (r':=', tokens.Assignment),
  106. (r'::', tokens.Punctuation),
  107. (r'\*', tokens.Wildcard),
  108. (r"`(``|[^`])*`", tokens.Name),
  109. (r"´(´´|[^´])*´", tokens.Name),
  110. (r'\?', tokens.Name.Placeholder),
  111. (r'%(\(\w+\))?s', tokens.Name.Placeholder),
  112. (r'(?<!\w)[$:?]\w+', tokens.Name.Placeholder),
  113. (r'\\\w+', tokens.Command),
  114. # FIXME(andi): VALUES shouldn't be listed here
  115. # see https://github.com/andialbrecht/sqlparse/pull/64
  116. # AS and IN are special, it may be followed by a parenthesis, but
  117. # are never functions, see issue183 and issue507
  118. (r'(CASE|IN|VALUES|USING|FROM|AS)\b', tokens.Keyword),
  119. (r'(@|##|#)[A-ZÀ-Ü]\w+', tokens.Name),
  120. # see issue #39
  121. # Spaces around period `schema . name` are valid identifier
  122. # TODO: Spaces before period not implemented
  123. # The negative lookahead ``(?!\d)`` keeps a following floating point
  124. # literal such as ``.03`` from being mistaken for a member access, so a
  125. # preceding keyword (e.g. ``BETWEEN``) is not reclassified as a name.
  126. # See issue #601.
  127. (r'[A-ZÀ-Ü]\w*(?=\s*\.(?!\d))', tokens.Name), # 'Name'.
  128. # FIXME(atronah): never match,
  129. # because `re.match` doesn't work with look-behind regexp feature
  130. (r'(?<=\.)[A-ZÀ-Ü]\w*', tokens.Name), # .'Name'
  131. (r'[A-ZÀ-Ü]\w*(?=\()', tokens.Name), # side effect: change kw to func
  132. (r'-?0x[\dA-F]+', tokens.Number.Hexadecimal),
  133. (r'-?\d+(\.\d+)?E-?\d+', tokens.Number.Float),
  134. (r'(?![_A-ZÀ-Ü])-?(\d+(\.\d*)|\.\d+)(?![_A-ZÀ-Ü])',
  135. tokens.Number.Float),
  136. (r'(?![_A-ZÀ-Ü])-?\d+(?![_A-ZÀ-Ü])', tokens.Number.Integer),
  137. (r"'(''|\\'|[^'])*'", tokens.String.Single),
  138. # not a real string literal in ANSI SQL:
  139. (r'"(""|\\"|[^"])*"', tokens.String.Symbol),
  140. (r'(""|".*?[^\\]")', tokens.String.Symbol),
  141. # sqlite names can be escaped with [square brackets]. left bracket
  142. # cannot be preceded by word character or a right bracket --
  143. # otherwise it's probably an array index
  144. (r'(?<![\w\])])(\[[^\]\[]+\])', tokens.Name),
  145. (r'((LEFT\s+|RIGHT\s+|FULL\s+)?(INNER\s+|OUTER\s+|STRAIGHT\s+)?'
  146. r'|(CROSS\s+|NATURAL\s+)?)?JOIN\b', tokens.Keyword),
  147. (r'END(\s+IF|\s+LOOP|\s+WHILE|\s+FOR|\s+CASE)?\b', tokens.Keyword),
  148. (r'IF\s+(NOT\s+)?EXISTS\b', tokens.Keyword),
  149. (r'NOT\s+NULL\b', tokens.Keyword),
  150. (r'(ASC|DESC)(\s+NULLS\s+(FIRST|LAST))?\b', tokens.Keyword.Order),
  151. (r'(ASC|DESC)\b', tokens.Keyword.Order),
  152. (r'NULLS\s+(FIRST|LAST)\b', tokens.Keyword.Order),
  153. (r'UNION\s+ALL\b', tokens.Keyword),
  154. (r'CREATE(\s+OR\s+REPLACE)?\b', tokens.Keyword.DDL),
  155. (r'DOUBLE\s+PRECISION\b', tokens.Name.Builtin),
  156. (r'GROUP\s+BY\b', tokens.Keyword),
  157. (r'ORDER\s+BY\b', tokens.Keyword),
  158. (r'PRIMARY\s+KEY\b', tokens.Keyword),
  159. (r'HANDLER\s+FOR\b', tokens.Keyword),
  160. (r'GO(\s\d+)\b', tokens.Keyword),
  161. (r'(LATERAL\s+VIEW\s+)'
  162. r'(EXPLODE|INLINE|PARSE_URL_TUPLE|POSEXPLODE|STACK)\b',
  163. tokens.Keyword),
  164. (r"(AT|WITH')\s+TIME\s+ZONE\s+'[^']+'", tokens.Keyword.TZCast),
  165. (r'(NOT\s+)?(LIKE|ILIKE|RLIKE)\b', tokens.Operator.Comparison),
  166. (r'(NOT\s+)?(REGEXP)(\s+(BINARY))?\b', tokens.Operator.Comparison),
  167. # Check for keywords, also returns tokens.Name if regex matches
  168. # but the match isn't a keyword.
  169. (r'\w[$#\w]*', PROCESS_AS_KEYWORD),
  170. (r'[;:()\[\],\.]', tokens.Punctuation),
  171. # JSON operators
  172. (r'(\->>?|#>>?|@>|<@|\?\|?|\?&|\-|#\-)', tokens.Operator),
  173. (r'[<>=~!]+', tokens.Operator.Comparison),
  174. (r'[+/@#%^&|^-]+', tokens.Operator),
  175. ]
  176. KEYWORDS = {
  177. 'ABORT': tokens.Keyword,
  178. 'ABS': tokens.Keyword,
  179. 'ABSOLUTE': tokens.Keyword,
  180. 'ACCESS': tokens.Keyword,
  181. 'ADA': tokens.Keyword,
  182. 'ADD': tokens.Keyword,
  183. 'ADMIN': tokens.Keyword,
  184. 'AFTER': tokens.Keyword,
  185. 'AGGREGATE': tokens.Keyword,
  186. 'ALIAS': tokens.Keyword,
  187. 'ALL': tokens.Keyword,
  188. 'ALLOCATE': tokens.Keyword,
  189. 'ANALYSE': tokens.Keyword,
  190. 'ANALYZE': tokens.Keyword,
  191. 'ANY': tokens.Keyword,
  192. 'ARRAYLEN': tokens.Keyword,
  193. 'ARE': tokens.Keyword,
  194. 'ASENSITIVE': tokens.Keyword,
  195. 'ASSERTION': tokens.Keyword,
  196. 'ASSIGNMENT': tokens.Keyword,
  197. 'ASYMMETRIC': tokens.Keyword,
  198. 'AT': tokens.Keyword,
  199. 'ATOMIC': tokens.Keyword,
  200. 'AUDIT': tokens.Keyword,
  201. 'AUTHORIZATION': tokens.Keyword,
  202. 'AUTO_INCREMENT': tokens.Keyword,
  203. 'AVG': tokens.Keyword,
  204. 'BACKWARD': tokens.Keyword,
  205. 'BEFORE': tokens.Keyword,
  206. 'BEGIN': tokens.Keyword,
  207. 'BETWEEN': tokens.Keyword,
  208. 'BITVAR': tokens.Keyword,
  209. 'BIT_LENGTH': tokens.Keyword,
  210. 'BOTH': tokens.Keyword,
  211. 'BREADTH': tokens.Keyword,
  212. # 'C': tokens.Keyword, # most likely this is an alias
  213. 'CACHE': tokens.Keyword,
  214. 'CALL': tokens.Keyword,
  215. 'CALLED': tokens.Keyword,
  216. 'CARDINALITY': tokens.Keyword,
  217. 'CASCADE': tokens.Keyword,
  218. 'CASCADED': tokens.Keyword,
  219. 'CAST': tokens.Keyword,
  220. 'CATALOG': tokens.Keyword,
  221. 'CATALOG_NAME': tokens.Keyword,
  222. 'CHAIN': tokens.Keyword,
  223. 'CHARACTERISTICS': tokens.Keyword,
  224. 'CHARACTER_LENGTH': tokens.Keyword,
  225. 'CHARACTER_SET_CATALOG': tokens.Keyword,
  226. 'CHARACTER_SET_NAME': tokens.Keyword,
  227. 'CHARACTER_SET_SCHEMA': tokens.Keyword,
  228. 'CHAR_LENGTH': tokens.Keyword,
  229. 'CHARSET': tokens.Keyword,
  230. 'CHECK': tokens.Keyword,
  231. 'CHECKED': tokens.Keyword,
  232. 'CHECKPOINT': tokens.Keyword,
  233. 'CLASS': tokens.Keyword,
  234. 'CLASS_ORIGIN': tokens.Keyword,
  235. 'CLOB': tokens.Keyword,
  236. 'CLOSE': tokens.Keyword,
  237. 'CLUSTER': tokens.Keyword,
  238. 'COALESCE': tokens.Keyword,
  239. 'COBOL': tokens.Keyword,
  240. 'COLLATE': tokens.Keyword,
  241. 'COLLATION': tokens.Keyword,
  242. 'COLLATION_CATALOG': tokens.Keyword,
  243. 'COLLATION_NAME': tokens.Keyword,
  244. 'COLLATION_SCHEMA': tokens.Keyword,
  245. 'COLLECT': tokens.Keyword,
  246. 'COLUMN': tokens.Keyword,
  247. 'COLUMN_NAME': tokens.Keyword,
  248. 'COMPRESS': tokens.Keyword,
  249. 'COMMAND_FUNCTION': tokens.Keyword,
  250. 'COMMAND_FUNCTION_CODE': tokens.Keyword,
  251. 'COMMENT': tokens.Keyword,
  252. 'COMMIT': tokens.Keyword.DML,
  253. 'COMMITTED': tokens.Keyword,
  254. 'COMPLETION': tokens.Keyword,
  255. 'CONCURRENTLY': tokens.Keyword,
  256. 'CONDITION_NUMBER': tokens.Keyword,
  257. 'CONNECT': tokens.Keyword,
  258. 'CONNECTION': tokens.Keyword,
  259. 'CONNECTION_NAME': tokens.Keyword,
  260. 'CONSTRAINT': tokens.Keyword,
  261. 'CONSTRAINTS': tokens.Keyword,
  262. 'CONSTRAINT_CATALOG': tokens.Keyword,
  263. 'CONSTRAINT_NAME': tokens.Keyword,
  264. 'CONSTRAINT_SCHEMA': tokens.Keyword,
  265. 'CONSTRUCTOR': tokens.Keyword,
  266. 'CONTAINS': tokens.Keyword,
  267. 'CONTINUE': tokens.Keyword,
  268. 'CONVERSION': tokens.Keyword,
  269. 'CONVERT': tokens.Keyword,
  270. 'COPY': tokens.Keyword,
  271. 'CORRESPONDING': tokens.Keyword,
  272. 'COUNT': tokens.Keyword,
  273. 'CREATEDB': tokens.Keyword,
  274. 'CREATEUSER': tokens.Keyword,
  275. 'CROSS': tokens.Keyword,
  276. 'CUBE': tokens.Keyword,
  277. 'CURRENT': tokens.Keyword,
  278. 'CURRENT_DATE': tokens.Keyword,
  279. 'CURRENT_PATH': tokens.Keyword,
  280. 'CURRENT_ROLE': tokens.Keyword,
  281. 'CURRENT_TIME': tokens.Keyword,
  282. 'CURRENT_TIMESTAMP': tokens.Keyword,
  283. 'CURRENT_USER': tokens.Keyword,
  284. 'CURSOR': tokens.Keyword,
  285. 'CURSOR_NAME': tokens.Keyword,
  286. 'CYCLE': tokens.Keyword,
  287. 'DATA': tokens.Keyword,
  288. 'DATABASE': tokens.Keyword,
  289. 'DATETIME_INTERVAL_CODE': tokens.Keyword,
  290. 'DATETIME_INTERVAL_PRECISION': tokens.Keyword,
  291. 'DAY': tokens.Keyword,
  292. 'DEALLOCATE': tokens.Keyword,
  293. 'DECLARE': tokens.Keyword,
  294. 'DEFAULT': tokens.Keyword,
  295. 'DEFAULTS': tokens.Keyword,
  296. 'DEFERRABLE': tokens.Keyword,
  297. 'DEFERRED': tokens.Keyword,
  298. 'DEFINED': tokens.Keyword,
  299. 'DEFINER': tokens.Keyword,
  300. 'DELIMITER': tokens.Keyword,
  301. 'DELIMITERS': tokens.Keyword,
  302. 'DEREF': tokens.Keyword,
  303. 'DESCRIBE': tokens.Keyword,
  304. 'DESCRIPTOR': tokens.Keyword,
  305. 'DESTROY': tokens.Keyword,
  306. 'DESTRUCTOR': tokens.Keyword,
  307. 'DETERMINISTIC': tokens.Keyword,
  308. 'DIAGNOSTICS': tokens.Keyword,
  309. 'DICTIONARY': tokens.Keyword,
  310. 'DISABLE': tokens.Keyword,
  311. 'DISCONNECT': tokens.Keyword,
  312. 'DISPATCH': tokens.Keyword,
  313. 'DIV': tokens.Operator,
  314. 'DO': tokens.Keyword,
  315. 'DOMAIN': tokens.Keyword,
  316. 'DYNAMIC': tokens.Keyword,
  317. 'DYNAMIC_FUNCTION': tokens.Keyword,
  318. 'DYNAMIC_FUNCTION_CODE': tokens.Keyword,
  319. 'EACH': tokens.Keyword,
  320. 'ENABLE': tokens.Keyword,
  321. 'ENCODING': tokens.Keyword,
  322. 'ENCRYPTED': tokens.Keyword,
  323. 'END-EXEC': tokens.Keyword,
  324. 'ENGINE': tokens.Keyword,
  325. 'EQUALS': tokens.Keyword,
  326. 'ESCAPE': tokens.Keyword,
  327. 'EVERY': tokens.Keyword,
  328. 'EXCEPT': tokens.Keyword,
  329. 'EXCEPTION': tokens.Keyword,
  330. 'EXCLUDING': tokens.Keyword,
  331. 'EXCLUSIVE': tokens.Keyword,
  332. 'EXEC': tokens.Keyword,
  333. 'EXECUTE': tokens.Keyword,
  334. 'EXISTING': tokens.Keyword,
  335. 'EXISTS': tokens.Keyword,
  336. 'EXPLAIN': tokens.Keyword,
  337. 'EXTERNAL': tokens.Keyword,
  338. 'EXTRACT': tokens.Keyword,
  339. 'FALSE': tokens.Keyword,
  340. 'FETCH': tokens.Keyword,
  341. 'FILE': tokens.Keyword,
  342. 'FINAL': tokens.Keyword,
  343. 'FIRST': tokens.Keyword,
  344. 'FORCE': tokens.Keyword,
  345. 'FOREACH': tokens.Keyword,
  346. 'FOREIGN': tokens.Keyword,
  347. 'FORTRAN': tokens.Keyword,
  348. 'FORWARD': tokens.Keyword,
  349. 'FOUND': tokens.Keyword,
  350. 'FREE': tokens.Keyword,
  351. 'FREEZE': tokens.Keyword,
  352. 'FULL': tokens.Keyword,
  353. 'FUNCTION': tokens.Keyword,
  354. # 'G': tokens.Keyword,
  355. 'GENERAL': tokens.Keyword,
  356. 'GENERATED': tokens.Keyword,
  357. 'GET': tokens.Keyword,
  358. 'GLOBAL': tokens.Keyword,
  359. 'GO': tokens.Keyword,
  360. 'GOTO': tokens.Keyword,
  361. 'GRANTED': tokens.Keyword,
  362. 'GROUPING': tokens.Keyword,
  363. 'HAVING': tokens.Keyword,
  364. 'HIERARCHY': tokens.Keyword,
  365. 'HOLD': tokens.Keyword,
  366. 'HOUR': tokens.Keyword,
  367. 'HOST': tokens.Keyword,
  368. 'IDENTIFIED': tokens.Keyword,
  369. 'IDENTITY': tokens.Keyword,
  370. 'IGNORE': tokens.Keyword,
  371. 'ILIKE': tokens.Keyword,
  372. 'IMMEDIATE': tokens.Keyword,
  373. 'IMMUTABLE': tokens.Keyword,
  374. 'IMPLEMENTATION': tokens.Keyword,
  375. 'IMPLICIT': tokens.Keyword,
  376. 'INCLUDING': tokens.Keyword,
  377. 'INCREMENT': tokens.Keyword,
  378. 'INDEX': tokens.Keyword,
  379. 'INDICATOR': tokens.Keyword,
  380. 'INFIX': tokens.Keyword,
  381. 'INHERITS': tokens.Keyword,
  382. 'INITIAL': tokens.Keyword,
  383. 'INITIALIZE': tokens.Keyword,
  384. 'INITIALLY': tokens.Keyword,
  385. 'INOUT': tokens.Keyword,
  386. 'INPUT': tokens.Keyword,
  387. 'INSENSITIVE': tokens.Keyword,
  388. 'INSTANTIABLE': tokens.Keyword,
  389. 'INSTEAD': tokens.Keyword,
  390. 'INTERSECT': tokens.Keyword,
  391. 'INTO': tokens.Keyword,
  392. 'INVOKER': tokens.Keyword,
  393. 'IS': tokens.Keyword,
  394. 'ISNULL': tokens.Keyword,
  395. 'ISOLATION': tokens.Keyword,
  396. 'ITERATE': tokens.Keyword,
  397. # 'K': tokens.Keyword,
  398. 'KEY': tokens.Keyword,
  399. 'KEY_MEMBER': tokens.Keyword,
  400. 'KEY_TYPE': tokens.Keyword,
  401. 'LANCOMPILER': tokens.Keyword,
  402. 'LANGUAGE': tokens.Keyword,
  403. 'LARGE': tokens.Keyword,
  404. 'LAST': tokens.Keyword,
  405. 'LATERAL': tokens.Keyword,
  406. 'LEADING': tokens.Keyword,
  407. 'LENGTH': tokens.Keyword,
  408. 'LESS': tokens.Keyword,
  409. 'LEVEL': tokens.Keyword,
  410. 'LIMIT': tokens.Keyword,
  411. 'LISTEN': tokens.Keyword,
  412. 'LOAD': tokens.Keyword,
  413. 'LOCAL': tokens.Keyword,
  414. 'LOCALTIME': tokens.Keyword,
  415. 'LOCALTIMESTAMP': tokens.Keyword,
  416. 'LOCATION': tokens.Keyword,
  417. 'LOCATOR': tokens.Keyword,
  418. 'LOCK': tokens.Keyword,
  419. 'LOWER': tokens.Keyword,
  420. # 'M': tokens.Keyword,
  421. 'MAP': tokens.Keyword,
  422. 'MATCH': tokens.Keyword,
  423. 'MATERIALIZED': tokens.Keyword,
  424. 'MAXEXTENTS': tokens.Keyword,
  425. 'MAXVALUE': tokens.Keyword,
  426. 'MESSAGE_LENGTH': tokens.Keyword,
  427. 'MESSAGE_OCTET_LENGTH': tokens.Keyword,
  428. 'MESSAGE_TEXT': tokens.Keyword,
  429. 'METHOD': tokens.Keyword,
  430. 'MINUTE': tokens.Keyword,
  431. 'MINUS': tokens.Keyword,
  432. 'MINVALUE': tokens.Keyword,
  433. 'MOD': tokens.Keyword,
  434. 'MODE': tokens.Keyword,
  435. 'MODIFIES': tokens.Keyword,
  436. 'MODIFY': tokens.Keyword,
  437. 'MONTH': tokens.Keyword,
  438. 'MORE': tokens.Keyword,
  439. 'MOVE': tokens.Keyword,
  440. 'MUMPS': tokens.Keyword,
  441. 'NAMES': tokens.Keyword,
  442. 'NATIONAL': tokens.Keyword,
  443. 'NATURAL': tokens.Keyword,
  444. 'NCHAR': tokens.Keyword,
  445. 'NCLOB': tokens.Keyword,
  446. 'NEW': tokens.Keyword,
  447. 'NEXT': tokens.Keyword,
  448. 'NO': tokens.Keyword,
  449. 'NOAUDIT': tokens.Keyword,
  450. 'NOCOMPRESS': tokens.Keyword,
  451. 'NOCREATEDB': tokens.Keyword,
  452. 'NOCREATEUSER': tokens.Keyword,
  453. 'NONE': tokens.Keyword,
  454. 'NOT': tokens.Keyword,
  455. 'NOTFOUND': tokens.Keyword,
  456. 'NOTHING': tokens.Keyword,
  457. 'NOTIFY': tokens.Keyword,
  458. 'NOTNULL': tokens.Keyword,
  459. 'NOWAIT': tokens.Keyword,
  460. 'NULL': tokens.Keyword,
  461. 'NULLABLE': tokens.Keyword,
  462. 'NULLIF': tokens.Keyword,
  463. 'OBJECT': tokens.Keyword,
  464. 'OCTET_LENGTH': tokens.Keyword,
  465. 'OF': tokens.Keyword,
  466. 'OFF': tokens.Keyword,
  467. 'OFFLINE': tokens.Keyword,
  468. 'OFFSET': tokens.Keyword,
  469. 'OIDS': tokens.Keyword,
  470. 'OLD': tokens.Keyword,
  471. 'ONLINE': tokens.Keyword,
  472. 'ONLY': tokens.Keyword,
  473. 'OPEN': tokens.Keyword,
  474. 'OPERATION': tokens.Keyword,
  475. 'OPERATOR': tokens.Keyword,
  476. 'OPTION': tokens.Keyword,
  477. 'OPTIONS': tokens.Keyword,
  478. 'ORDINALITY': tokens.Keyword,
  479. 'OUT': tokens.Keyword,
  480. 'OUTPUT': tokens.Keyword,
  481. 'OVERLAPS': tokens.Keyword,
  482. 'OVERLAY': tokens.Keyword,
  483. 'OVERRIDING': tokens.Keyword,
  484. 'OWNER': tokens.Keyword,
  485. 'QUARTER': tokens.Keyword,
  486. 'PAD': tokens.Keyword,
  487. 'PARAMETER': tokens.Keyword,
  488. 'PARAMETERS': tokens.Keyword,
  489. 'PARAMETER_MODE': tokens.Keyword,
  490. 'PARAMETER_NAME': tokens.Keyword,
  491. 'PARAMETER_ORDINAL_POSITION': tokens.Keyword,
  492. 'PARAMETER_SPECIFIC_CATALOG': tokens.Keyword,
  493. 'PARAMETER_SPECIFIC_NAME': tokens.Keyword,
  494. 'PARAMETER_SPECIFIC_SCHEMA': tokens.Keyword,
  495. 'PARTIAL': tokens.Keyword,
  496. 'PASCAL': tokens.Keyword,
  497. 'PCTFREE': tokens.Keyword,
  498. 'PENDANT': tokens.Keyword,
  499. 'PLACING': tokens.Keyword,
  500. 'PLI': tokens.Keyword,
  501. 'POSITION': tokens.Keyword,
  502. 'POSTFIX': tokens.Keyword,
  503. 'PRECISION': tokens.Keyword,
  504. 'PREFIX': tokens.Keyword,
  505. 'PREORDER': tokens.Keyword,
  506. 'PREPARE': tokens.Keyword,
  507. 'PRESERVE': tokens.Keyword,
  508. 'PRIMARY': tokens.Keyword,
  509. 'PRIOR': tokens.Keyword,
  510. 'PRIVILEGES': tokens.Keyword,
  511. 'PROCEDURAL': tokens.Keyword,
  512. 'PROCEDURE': tokens.Keyword,
  513. 'PUBLIC': tokens.Keyword,
  514. 'RAISE': tokens.Keyword,
  515. 'RAW': tokens.Keyword,
  516. 'READ': tokens.Keyword,
  517. 'READS': tokens.Keyword,
  518. 'RECHECK': tokens.Keyword,
  519. 'RECURSIVE': tokens.Keyword,
  520. 'REF': tokens.Keyword,
  521. 'REFERENCES': tokens.Keyword,
  522. 'REFERENCING': tokens.Keyword,
  523. 'REINDEX': tokens.Keyword,
  524. 'RELATIVE': tokens.Keyword,
  525. 'RENAME': tokens.Keyword,
  526. 'REPEATABLE': tokens.Keyword,
  527. 'RESET': tokens.Keyword,
  528. 'RESOURCE': tokens.Keyword,
  529. 'RESTART': tokens.Keyword,
  530. 'RESTRICT': tokens.Keyword,
  531. 'RESULT': tokens.Keyword,
  532. 'RETURN': tokens.Keyword,
  533. 'RETURNED_LENGTH': tokens.Keyword,
  534. 'RETURNED_OCTET_LENGTH': tokens.Keyword,
  535. 'RETURNED_SQLSTATE': tokens.Keyword,
  536. 'RETURNING': tokens.Keyword,
  537. 'RETURNS': tokens.Keyword,
  538. 'RIGHT': tokens.Keyword,
  539. 'ROLE': tokens.Keyword,
  540. 'ROLLBACK': tokens.Keyword.DML,
  541. 'ROLLUP': tokens.Keyword,
  542. 'ROUTINE': tokens.Keyword,
  543. 'ROUTINE_CATALOG': tokens.Keyword,
  544. 'ROUTINE_NAME': tokens.Keyword,
  545. 'ROUTINE_SCHEMA': tokens.Keyword,
  546. 'ROWS': tokens.Keyword,
  547. 'ROW_COUNT': tokens.Keyword,
  548. 'ROW_FORMAT': tokens.Keyword,
  549. 'RULE': tokens.Keyword,
  550. 'SAVE_POINT': tokens.Keyword,
  551. 'SCALE': tokens.Keyword,
  552. 'SCHEMA': tokens.Keyword,
  553. 'SCHEMA_NAME': tokens.Keyword,
  554. 'SCOPE': tokens.Keyword,
  555. 'SCROLL': tokens.Keyword,
  556. 'SEARCH': tokens.Keyword,
  557. 'SECOND': tokens.Keyword,
  558. 'SECURITY': tokens.Keyword,
  559. 'SELF': tokens.Keyword,
  560. 'SENSITIVE': tokens.Keyword,
  561. 'SEQUENCE': tokens.Keyword,
  562. 'SERIALIZABLE': tokens.Keyword,
  563. 'SERVER_NAME': tokens.Keyword,
  564. 'SESSION': tokens.Keyword,
  565. 'SESSION_USER': tokens.Keyword,
  566. 'SETOF': tokens.Keyword,
  567. 'SETS': tokens.Keyword,
  568. 'SHARE': tokens.Keyword,
  569. 'SHOW': tokens.Keyword,
  570. 'SIMILAR': tokens.Keyword,
  571. 'SIMPLE': tokens.Keyword,
  572. 'SIZE': tokens.Keyword,
  573. 'SOME': tokens.Keyword,
  574. 'SOURCE': tokens.Keyword,
  575. 'SPACE': tokens.Keyword,
  576. 'SPECIFIC': tokens.Keyword,
  577. 'SPECIFICTYPE': tokens.Keyword,
  578. 'SPECIFIC_NAME': tokens.Keyword,
  579. 'SQL': tokens.Keyword,
  580. 'SQLBUF': tokens.Keyword,
  581. 'SQLCODE': tokens.Keyword,
  582. 'SQLERROR': tokens.Keyword,
  583. 'SQLEXCEPTION': tokens.Keyword,
  584. 'SQLSTATE': tokens.Keyword,
  585. 'SQLWARNING': tokens.Keyword,
  586. 'STABLE': tokens.Keyword,
  587. 'START': tokens.Keyword.DML,
  588. # 'STATE': tokens.Keyword,
  589. 'STATEMENT': tokens.Keyword,
  590. 'STATIC': tokens.Keyword,
  591. 'STATISTICS': tokens.Keyword,
  592. 'STDIN': tokens.Keyword,
  593. 'STDOUT': tokens.Keyword,
  594. 'STORAGE': tokens.Keyword,
  595. 'STRICT': tokens.Keyword,
  596. 'STRUCTURE': tokens.Keyword,
  597. 'STYPE': tokens.Keyword,
  598. 'SUBCLASS_ORIGIN': tokens.Keyword,
  599. 'SUBLIST': tokens.Keyword,
  600. 'SUBSTRING': tokens.Keyword,
  601. 'SUCCESSFUL': tokens.Keyword,
  602. 'SUM': tokens.Keyword,
  603. 'SYMMETRIC': tokens.Keyword,
  604. 'SYNONYM': tokens.Keyword,
  605. 'SYSID': tokens.Keyword,
  606. 'SYSTEM': tokens.Keyword,
  607. 'SYSTEM_USER': tokens.Keyword,
  608. 'TABLE': tokens.Keyword,
  609. 'TABLE_NAME': tokens.Keyword,
  610. 'TEMP': tokens.Keyword,
  611. 'TEMPLATE': tokens.Keyword,
  612. 'TEMPORARY': tokens.Keyword,
  613. 'TERMINATE': tokens.Keyword,
  614. 'THAN': tokens.Keyword,
  615. 'TIMESTAMP': tokens.Keyword,
  616. 'TIMEZONE_HOUR': tokens.Keyword,
  617. 'TIMEZONE_MINUTE': tokens.Keyword,
  618. 'TO': tokens.Keyword,
  619. 'TOAST': tokens.Keyword,
  620. 'TRAILING': tokens.Keyword,
  621. 'TRANSATION': tokens.Keyword,
  622. 'TRANSACTIONS_COMMITTED': tokens.Keyword,
  623. 'TRANSACTIONS_ROLLED_BACK': tokens.Keyword,
  624. 'TRANSATION_ACTIVE': tokens.Keyword,
  625. 'TRANSFORM': tokens.Keyword,
  626. 'TRANSFORMS': tokens.Keyword,
  627. 'TRANSLATE': tokens.Keyword,
  628. 'TRANSLATION': tokens.Keyword,
  629. 'TREAT': tokens.Keyword,
  630. 'TRIGGER': tokens.Keyword,
  631. 'TRIGGER_CATALOG': tokens.Keyword,
  632. 'TRIGGER_NAME': tokens.Keyword,
  633. 'TRIGGER_SCHEMA': tokens.Keyword,
  634. 'TRIM': tokens.Keyword,
  635. 'TRUE': tokens.Keyword,
  636. 'TRUSTED': tokens.Keyword,
  637. 'TYPE': tokens.Keyword,
  638. 'UID': tokens.Keyword,
  639. 'UNCOMMITTED': tokens.Keyword,
  640. 'UNDER': tokens.Keyword,
  641. 'UNENCRYPTED': tokens.Keyword,
  642. 'UNION': tokens.Keyword,
  643. 'UNIQUE': tokens.Keyword,
  644. 'UNKNOWN': tokens.Keyword,
  645. 'UNLISTEN': tokens.Keyword,
  646. 'UNNAMED': tokens.Keyword,
  647. 'UNNEST': tokens.Keyword,
  648. 'UNTIL': tokens.Keyword,
  649. 'UPPER': tokens.Keyword,
  650. 'USAGE': tokens.Keyword,
  651. 'USE': tokens.Keyword,
  652. 'USER': tokens.Keyword,
  653. 'USER_DEFINED_TYPE_CATALOG': tokens.Keyword,
  654. 'USER_DEFINED_TYPE_NAME': tokens.Keyword,
  655. 'USER_DEFINED_TYPE_SCHEMA': tokens.Keyword,
  656. 'USING': tokens.Keyword,
  657. 'VACUUM': tokens.Keyword,
  658. 'VALID': tokens.Keyword,
  659. 'VALIDATE': tokens.Keyword,
  660. 'VALIDATOR': tokens.Keyword,
  661. 'VALUES': tokens.Keyword,
  662. 'VARIABLE': tokens.Keyword,
  663. 'VERBOSE': tokens.Keyword,
  664. 'VERSION': tokens.Keyword,
  665. 'VIEW': tokens.Keyword,
  666. 'VOLATILE': tokens.Keyword,
  667. 'WEEK': tokens.Keyword,
  668. 'WHENEVER': tokens.Keyword,
  669. 'WITH': tokens.Keyword.CTE,
  670. 'WITHOUT': tokens.Keyword,
  671. 'WORK': tokens.Keyword,
  672. 'WRITE': tokens.Keyword,
  673. 'YEAR': tokens.Keyword,
  674. 'ZONE': tokens.Keyword,
  675. # Name.Builtin
  676. 'ARRAY': tokens.Name.Builtin,
  677. 'BIGINT': tokens.Name.Builtin,
  678. 'BINARY': tokens.Name.Builtin,
  679. 'BIT': tokens.Name.Builtin,
  680. 'BLOB': tokens.Name.Builtin,
  681. 'BOOLEAN': tokens.Name.Builtin,
  682. 'CHAR': tokens.Name.Builtin,
  683. 'CHARACTER': tokens.Name.Builtin,
  684. 'DATE': tokens.Name.Builtin,
  685. 'DEC': tokens.Name.Builtin,
  686. 'DECIMAL': tokens.Name.Builtin,
  687. 'FILE_TYPE': tokens.Name.Builtin,
  688. 'FLOAT': tokens.Name.Builtin,
  689. 'INT': tokens.Name.Builtin,
  690. 'INT8': tokens.Name.Builtin,
  691. 'INTEGER': tokens.Name.Builtin,
  692. 'INTERVAL': tokens.Name.Builtin,
  693. 'LONG': tokens.Name.Builtin,
  694. 'NATURALN': tokens.Name.Builtin,
  695. 'NVARCHAR': tokens.Name.Builtin,
  696. 'NUMBER': tokens.Name.Builtin,
  697. 'NUMERIC': tokens.Name.Builtin,
  698. 'PLS_INTEGER': tokens.Name.Builtin,
  699. 'POSITIVE': tokens.Name.Builtin,
  700. 'POSITIVEN': tokens.Name.Builtin,
  701. 'REAL': tokens.Name.Builtin,
  702. 'ROWID': tokens.Name.Builtin,
  703. 'ROWLABEL': tokens.Name.Builtin,
  704. 'ROWNUM': tokens.Name.Builtin,
  705. 'SERIAL': tokens.Name.Builtin,
  706. 'SERIAL8': tokens.Name.Builtin,
  707. 'SIGNED': tokens.Name.Builtin,
  708. 'SIGNTYPE': tokens.Name.Builtin,
  709. 'SIMPLE_DOUBLE': tokens.Name.Builtin,
  710. 'SIMPLE_FLOAT': tokens.Name.Builtin,
  711. 'SIMPLE_INTEGER': tokens.Name.Builtin,
  712. 'SMALLINT': tokens.Name.Builtin,
  713. 'SYS_REFCURSOR': tokens.Name.Builtin,
  714. 'SYSDATE': tokens.Name,
  715. 'TEXT': tokens.Name.Builtin,
  716. 'TINYINT': tokens.Name.Builtin,
  717. 'UNSIGNED': tokens.Name.Builtin,
  718. 'UROWID': tokens.Name.Builtin,
  719. 'UTL_FILE': tokens.Name.Builtin,
  720. 'VARCHAR': tokens.Name.Builtin,
  721. 'VARCHAR2': tokens.Name.Builtin,
  722. 'VARYING': tokens.Name.Builtin,
  723. }
  724. KEYWORDS_COMMON = {
  725. 'SELECT': tokens.Keyword.DML,
  726. 'INSERT': tokens.Keyword.DML,
  727. 'DELETE': tokens.Keyword.DML,
  728. 'UPDATE': tokens.Keyword.DML,
  729. 'UPSERT': tokens.Keyword.DML,
  730. 'REPLACE': tokens.Keyword.DML,
  731. 'MERGE': tokens.Keyword.DML,
  732. 'DROP': tokens.Keyword.DDL,
  733. 'CREATE': tokens.Keyword.DDL,
  734. 'ALTER': tokens.Keyword.DDL,
  735. 'TRUNCATE': tokens.Keyword.DDL,
  736. 'GRANT': tokens.Keyword.DCL,
  737. 'REVOKE': tokens.Keyword.DCL,
  738. 'WHERE': tokens.Keyword,
  739. 'FROM': tokens.Keyword,
  740. 'INNER': tokens.Keyword,
  741. 'JOIN': tokens.Keyword,
  742. 'STRAIGHT_JOIN': tokens.Keyword,
  743. 'AND': tokens.Keyword,
  744. 'OR': tokens.Keyword,
  745. 'LIKE': tokens.Keyword,
  746. 'ON': tokens.Keyword,
  747. 'IN': tokens.Keyword,
  748. 'SET': tokens.Keyword,
  749. 'BY': tokens.Keyword,
  750. 'GROUP': tokens.Keyword,
  751. 'ORDER': tokens.Keyword,
  752. 'LEFT': tokens.Keyword,
  753. 'OUTER': tokens.Keyword,
  754. 'FULL': tokens.Keyword,
  755. 'IF': tokens.Keyword,
  756. 'END': tokens.Keyword,
  757. 'THEN': tokens.Keyword,
  758. 'LOOP': tokens.Keyword,
  759. 'AS': tokens.Keyword,
  760. 'ELSE': tokens.Keyword,
  761. 'FOR': tokens.Keyword,
  762. 'WHILE': tokens.Keyword,
  763. 'CASE': tokens.Keyword,
  764. 'WHEN': tokens.Keyword,
  765. 'MIN': tokens.Keyword,
  766. 'MAX': tokens.Keyword,
  767. 'DISTINCT': tokens.Keyword,
  768. }
  769. KEYWORDS_ORACLE = {
  770. 'ARCHIVE': tokens.Keyword,
  771. 'ARCHIVELOG': tokens.Keyword,
  772. 'BACKUP': tokens.Keyword,
  773. 'BECOME': tokens.Keyword,
  774. 'BLOCK': tokens.Keyword,
  775. 'BODY': tokens.Keyword,
  776. 'CANCEL': tokens.Keyword,
  777. 'CHANGE': tokens.Keyword,
  778. 'COMPILE': tokens.Keyword,
  779. 'CONTENTS': tokens.Keyword,
  780. 'CONTROLFILE': tokens.Keyword,
  781. 'DATAFILE': tokens.Keyword,
  782. 'DBA': tokens.Keyword,
  783. 'DISMOUNT': tokens.Keyword,
  784. 'DOUBLE': tokens.Keyword,
  785. 'DUMP': tokens.Keyword,
  786. 'ELSIF': tokens.Keyword,
  787. 'EVENTS': tokens.Keyword,
  788. 'EXCEPTIONS': tokens.Keyword,
  789. 'EXPLAIN': tokens.Keyword,
  790. 'EXTENT': tokens.Keyword,
  791. 'EXTERNALLY': tokens.Keyword,
  792. 'FLUSH': tokens.Keyword,
  793. 'FREELIST': tokens.Keyword,
  794. 'FREELISTS': tokens.Keyword,
  795. # groups seems too common as table name
  796. # 'GROUPS': tokens.Keyword,
  797. 'INDICATOR': tokens.Keyword,
  798. 'INITRANS': tokens.Keyword,
  799. 'INSTANCE': tokens.Keyword,
  800. 'LAYER': tokens.Keyword,
  801. 'LINK': tokens.Keyword,
  802. 'LISTS': tokens.Keyword,
  803. 'LOGFILE': tokens.Keyword,
  804. 'MANAGE': tokens.Keyword,
  805. 'MANUAL': tokens.Keyword,
  806. 'MAXDATAFILES': tokens.Keyword,
  807. 'MAXINSTANCES': tokens.Keyword,
  808. 'MAXLOGFILES': tokens.Keyword,
  809. 'MAXLOGHISTORY': tokens.Keyword,
  810. 'MAXLOGMEMBERS': tokens.Keyword,
  811. 'MAXTRANS': tokens.Keyword,
  812. 'MINEXTENTS': tokens.Keyword,
  813. 'MODULE': tokens.Keyword,
  814. 'MOUNT': tokens.Keyword,
  815. 'NOARCHIVELOG': tokens.Keyword,
  816. 'NOCACHE': tokens.Keyword,
  817. 'NOCYCLE': tokens.Keyword,
  818. 'NOMAXVALUE': tokens.Keyword,
  819. 'NOMINVALUE': tokens.Keyword,
  820. 'NOORDER': tokens.Keyword,
  821. 'NORESETLOGS': tokens.Keyword,
  822. 'NORMAL': tokens.Keyword,
  823. 'NOSORT': tokens.Keyword,
  824. 'OPTIMAL': tokens.Keyword,
  825. 'OWN': tokens.Keyword,
  826. 'PACKAGE': tokens.Keyword,
  827. 'PARALLEL': tokens.Keyword,
  828. 'PCTINCREASE': tokens.Keyword,
  829. 'PCTUSED': tokens.Keyword,
  830. 'PLAN': tokens.Keyword,
  831. 'PRIVATE': tokens.Keyword,
  832. 'PROFILE': tokens.Keyword,
  833. 'QUOTA': tokens.Keyword,
  834. 'RECOVER': tokens.Keyword,
  835. 'RESETLOGS': tokens.Keyword,
  836. 'RESTRICTED': tokens.Keyword,
  837. 'REUSE': tokens.Keyword,
  838. 'ROLES': tokens.Keyword,
  839. 'SAVEPOINT': tokens.Keyword,
  840. 'SCN': tokens.Keyword,
  841. 'SECTION': tokens.Keyword,
  842. 'SEGMENT': tokens.Keyword,
  843. 'SHARED': tokens.Keyword,
  844. 'SNAPSHOT': tokens.Keyword,
  845. 'SORT': tokens.Keyword,
  846. 'STATEMENT_ID': tokens.Keyword,
  847. 'STOP': tokens.Keyword,
  848. 'SWITCH': tokens.Keyword,
  849. 'TABLES': tokens.Keyword,
  850. 'TABLESPACE': tokens.Keyword,
  851. 'THREAD': tokens.Keyword,
  852. 'TIME': tokens.Keyword,
  853. 'TRACING': tokens.Keyword,
  854. 'TRANSACTION': tokens.Keyword,
  855. 'TRIGGERS': tokens.Keyword,
  856. 'UNLIMITED': tokens.Keyword,
  857. 'UNLOCK': tokens.Keyword,
  858. }
  859. # MySQL
  860. KEYWORDS_MYSQL = {
  861. 'ROW': tokens.Keyword,
  862. }
  863. # PostgreSQL Syntax
  864. KEYWORDS_PLPGSQL = {
  865. 'CONFLICT': tokens.Keyword,
  866. 'WINDOW': tokens.Keyword,
  867. 'PARTITION': tokens.Keyword,
  868. 'ATTACH': tokens.Keyword,
  869. 'DETACH': tokens.Keyword,
  870. 'OVER': tokens.Keyword,
  871. 'PERFORM': tokens.Keyword,
  872. 'NOTICE': tokens.Keyword,
  873. 'PLPGSQL': tokens.Keyword,
  874. 'INHERIT': tokens.Keyword,
  875. 'INDEXES': tokens.Keyword,
  876. 'ON_ERROR_STOP': tokens.Keyword,
  877. 'EXTENSION': tokens.Keyword,
  878. 'BYTEA': tokens.Keyword,
  879. 'BIGSERIAL': tokens.Keyword,
  880. 'BIT VARYING': tokens.Keyword,
  881. 'BOX': tokens.Keyword,
  882. 'CHARACTER': tokens.Keyword,
  883. 'CHARACTER VARYING': tokens.Keyword,
  884. 'CIDR': tokens.Keyword,
  885. 'CIRCLE': tokens.Keyword,
  886. 'DOUBLE PRECISION': tokens.Keyword,
  887. 'INET': tokens.Keyword,
  888. 'JSON': tokens.Keyword,
  889. 'JSONB': tokens.Keyword,
  890. 'LINE': tokens.Keyword,
  891. 'LSEG': tokens.Keyword,
  892. 'MACADDR': tokens.Keyword,
  893. 'MONEY': tokens.Keyword,
  894. 'PATH': tokens.Keyword,
  895. 'PG_LSN': tokens.Keyword,
  896. 'POINT': tokens.Keyword,
  897. 'POLYGON': tokens.Keyword,
  898. 'SMALLSERIAL': tokens.Keyword,
  899. 'TSQUERY': tokens.Keyword,
  900. 'TSVECTOR': tokens.Keyword,
  901. 'TXID_SNAPSHOT': tokens.Keyword,
  902. 'UUID': tokens.Keyword,
  903. 'XML': tokens.Keyword,
  904. 'FOR': tokens.Keyword,
  905. 'IN': tokens.Keyword,
  906. 'LOOP': tokens.Keyword,
  907. }
  908. # Hive Syntax
  909. KEYWORDS_HQL = {
  910. 'EXPLODE': tokens.Keyword,
  911. 'DIRECTORY': tokens.Keyword,
  912. 'DISTRIBUTE': tokens.Keyword,
  913. 'INCLUDE': tokens.Keyword,
  914. 'LOCATE': tokens.Keyword,
  915. 'OVERWRITE': tokens.Keyword,
  916. 'POSEXPLODE': tokens.Keyword,
  917. 'ARRAY_CONTAINS': tokens.Keyword,
  918. 'CMP': tokens.Keyword,
  919. 'COLLECT_LIST': tokens.Keyword,
  920. 'CONCAT': tokens.Keyword,
  921. 'CONDITION': tokens.Keyword,
  922. 'DATE_ADD': tokens.Keyword,
  923. 'DATE_SUB': tokens.Keyword,
  924. 'DECODE': tokens.Keyword,
  925. 'DBMS_OUTPUT': tokens.Keyword,
  926. 'ELEMENTS': tokens.Keyword,
  927. 'EXCHANGE': tokens.Keyword,
  928. 'EXTENDED': tokens.Keyword,
  929. 'FLOOR': tokens.Keyword,
  930. 'FOLLOWING': tokens.Keyword,
  931. 'FROM_UNIXTIME': tokens.Keyword,
  932. 'FTP': tokens.Keyword,
  933. 'HOUR': tokens.Keyword,
  934. 'INLINE': tokens.Keyword,
  935. 'INSTR': tokens.Keyword,
  936. 'LEN': tokens.Keyword,
  937. 'MAP': tokens.Name.Builtin,
  938. 'MAXELEMENT': tokens.Keyword,
  939. 'MAXINDEX': tokens.Keyword,
  940. 'MAX_PART_DATE': tokens.Keyword,
  941. 'MAX_PART_INT': tokens.Keyword,
  942. 'MAX_PART_STRING': tokens.Keyword,
  943. 'MINELEMENT': tokens.Keyword,
  944. 'MININDEX': tokens.Keyword,
  945. 'MIN_PART_DATE': tokens.Keyword,
  946. 'MIN_PART_INT': tokens.Keyword,
  947. 'MIN_PART_STRING': tokens.Keyword,
  948. 'NOW': tokens.Keyword,
  949. 'NVL': tokens.Keyword,
  950. 'NVL2': tokens.Keyword,
  951. 'PARSE_URL_TUPLE': tokens.Keyword,
  952. 'PART_LOC': tokens.Keyword,
  953. 'PART_COUNT': tokens.Keyword,
  954. 'PART_COUNT_BY': tokens.Keyword,
  955. 'PRINT': tokens.Keyword,
  956. 'PUT_LINE': tokens.Keyword,
  957. 'RANGE': tokens.Keyword,
  958. 'REDUCE': tokens.Keyword,
  959. 'REGEXP_REPLACE': tokens.Keyword,
  960. 'RESIGNAL': tokens.Keyword,
  961. 'RTRIM': tokens.Keyword,
  962. 'SIGN': tokens.Keyword,
  963. 'SIGNAL': tokens.Keyword,
  964. 'SIN': tokens.Keyword,
  965. 'SPLIT': tokens.Keyword,
  966. 'SQRT': tokens.Keyword,
  967. 'STACK': tokens.Keyword,
  968. 'STR': tokens.Keyword,
  969. 'STRING': tokens.Name.Builtin,
  970. 'STRUCT': tokens.Name.Builtin,
  971. 'SUBSTR': tokens.Keyword,
  972. 'SUMMARY': tokens.Keyword,
  973. 'TBLPROPERTIES': tokens.Keyword,
  974. 'TIMESTAMP': tokens.Name.Builtin,
  975. 'TIMESTAMP_ISO': tokens.Keyword,
  976. 'TO_CHAR': tokens.Keyword,
  977. 'TO_DATE': tokens.Keyword,
  978. 'TO_TIMESTAMP': tokens.Keyword,
  979. 'TRUNC': tokens.Keyword,
  980. 'UNBOUNDED': tokens.Keyword,
  981. 'UNIQUEJOIN': tokens.Keyword,
  982. 'UNIX_TIMESTAMP': tokens.Keyword,
  983. 'UTC_TIMESTAMP': tokens.Keyword,
  984. 'VIEWS': tokens.Keyword,
  985. 'EXIT': tokens.Keyword,
  986. 'BREAK': tokens.Keyword,
  987. 'LEAVE': tokens.Keyword,
  988. }
  989. KEYWORDS_MSACCESS = {
  990. 'DISTINCTROW': tokens.Keyword,
  991. }
  992. KEYWORDS_SNOWFLAKE = {
  993. 'ACCOUNT': tokens.Keyword,
  994. 'GSCLUSTER': tokens.Keyword,
  995. 'ISSUE': tokens.Keyword,
  996. 'ORGANIZATION': tokens.Keyword,
  997. 'PIVOT': tokens.Keyword,
  998. 'QUALIFY': tokens.Keyword,
  999. 'REGEXP': tokens.Keyword,
  1000. 'RLIKE': tokens.Keyword,
  1001. 'SAMPLE': tokens.Keyword,
  1002. 'TRY_CAST': tokens.Keyword,
  1003. 'UNPIVOT': tokens.Keyword,
  1004. 'VARIANT': tokens.Name.Builtin,
  1005. }
  1006. KEYWORDS_BIGQUERY = {
  1007. 'ASSERT_ROWS_MODIFIED': tokens.Keyword,
  1008. 'DEFINE': tokens.Keyword,
  1009. 'ENUM': tokens.Keyword,
  1010. 'HASH': tokens.Keyword,
  1011. 'LOOKUP': tokens.Keyword,
  1012. 'PRECEDING': tokens.Keyword,
  1013. 'PROTO': tokens.Keyword,
  1014. 'RESPECT': tokens.Keyword,
  1015. 'TABLESAMPLE': tokens.Keyword,
  1016. 'BIGNUMERIC': tokens.Name.Builtin,
  1017. }