pgsql.ts 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714
  1. /*---------------------------------------------------------------------------------------------
  2. * Copyright (c) Microsoft Corporation. All rights reserved.
  3. * Licensed under the MIT License. See License.txt in the project root for license information.
  4. *--------------------------------------------------------------------------------------------*/
  5. import type { languages } from '../fillers/monaco-editor-core';
  6. export const conf: languages.LanguageConfiguration = {
  7. comments: {
  8. lineComment: '--',
  9. blockComment: ['/*', '*/']
  10. },
  11. brackets: [
  12. ['{', '}'],
  13. ['[', ']'],
  14. ['(', ')']
  15. ],
  16. autoClosingPairs: [
  17. { open: '{', close: '}' },
  18. { open: '[', close: ']' },
  19. { open: '(', close: ')' },
  20. { open: '"', close: '"' },
  21. { open: "'", close: "'" }
  22. ],
  23. surroundingPairs: [
  24. { open: '{', close: '}' },
  25. { open: '[', close: ']' },
  26. { open: '(', close: ')' },
  27. { open: '"', close: '"' },
  28. { open: "'", close: "'" }
  29. ]
  30. };
  31. export const language = <languages.IMonarchLanguage>{
  32. defaultToken: '',
  33. tokenPostfix: '.sql',
  34. ignoreCase: true,
  35. brackets: [
  36. { open: '[', close: ']', token: 'delimiter.square' },
  37. { open: '(', close: ')', token: 'delimiter.parenthesis' }
  38. ],
  39. keywords: [
  40. // This list is generated using `keywords.js`
  41. 'ALL',
  42. 'ANALYSE',
  43. 'ANALYZE',
  44. 'AND',
  45. 'ANY',
  46. 'ARRAY',
  47. 'AS',
  48. 'ASC',
  49. 'ASYMMETRIC',
  50. 'AUTHORIZATION',
  51. 'BINARY',
  52. 'BOTH',
  53. 'CASE',
  54. 'CAST',
  55. 'CHECK',
  56. 'COLLATE',
  57. 'COLLATION',
  58. 'COLUMN',
  59. 'CONCURRENTLY',
  60. 'CONSTRAINT',
  61. 'CREATE',
  62. 'CROSS',
  63. 'CURRENT_CATALOG',
  64. 'CURRENT_DATE',
  65. 'CURRENT_ROLE',
  66. 'CURRENT_SCHEMA',
  67. 'CURRENT_TIME',
  68. 'CURRENT_TIMESTAMP',
  69. 'CURRENT_USER',
  70. 'DEFAULT',
  71. 'DEFERRABLE',
  72. 'DESC',
  73. 'DISTINCT',
  74. 'DO',
  75. 'ELSE',
  76. 'END',
  77. 'EXCEPT',
  78. 'FALSE',
  79. 'FETCH',
  80. 'FOR',
  81. 'FOREIGN',
  82. 'FREEZE',
  83. 'FROM',
  84. 'FULL',
  85. 'GRANT',
  86. 'GROUP',
  87. 'HAVING',
  88. 'ILIKE',
  89. 'IN',
  90. 'INITIALLY',
  91. 'INNER',
  92. 'INTERSECT',
  93. 'INTO',
  94. 'IS',
  95. 'ISNULL',
  96. 'JOIN',
  97. 'LATERAL',
  98. 'LEADING',
  99. 'LEFT',
  100. 'LIKE',
  101. 'LIMIT',
  102. 'LOCALTIME',
  103. 'LOCALTIMESTAMP',
  104. 'NATURAL',
  105. 'NOT',
  106. 'NOTNULL',
  107. 'NULL',
  108. 'OFFSET',
  109. 'ON',
  110. 'ONLY',
  111. 'OR',
  112. 'ORDER',
  113. 'OUTER',
  114. 'OVERLAPS',
  115. 'PLACING',
  116. 'PRIMARY',
  117. 'REFERENCES',
  118. 'RETURNING',
  119. 'RIGHT',
  120. 'SELECT',
  121. 'SESSION_USER',
  122. 'SIMILAR',
  123. 'SOME',
  124. 'SYMMETRIC',
  125. 'TABLE',
  126. 'TABLESAMPLE',
  127. 'THEN',
  128. 'TO',
  129. 'TRAILING',
  130. 'TRUE',
  131. 'UNION',
  132. 'UNIQUE',
  133. 'USER',
  134. 'USING',
  135. 'VARIADIC',
  136. 'VERBOSE',
  137. 'WHEN',
  138. 'WHERE',
  139. 'WINDOW',
  140. 'WITH'
  141. ],
  142. operators: [
  143. 'AND',
  144. 'BETWEEN',
  145. 'IN',
  146. 'LIKE',
  147. 'NOT',
  148. 'OR',
  149. 'IS',
  150. 'NULL',
  151. 'INTERSECT',
  152. 'UNION',
  153. 'INNER',
  154. 'JOIN',
  155. 'LEFT',
  156. 'OUTER',
  157. 'RIGHT'
  158. ],
  159. builtinFunctions: [
  160. 'abbrev',
  161. 'abs',
  162. 'acos',
  163. 'acosd',
  164. 'age',
  165. 'any',
  166. 'area',
  167. 'array_agg',
  168. 'array_append',
  169. 'array_cat',
  170. 'array_dims',
  171. 'array_fill',
  172. 'array_length',
  173. 'array_lower',
  174. 'array_ndims',
  175. 'array_position',
  176. 'array_positions',
  177. 'array_prepend',
  178. 'array_remove',
  179. 'array_replace',
  180. 'array_to_json',
  181. 'array_to_string',
  182. 'array_to_tsvector',
  183. 'array_upper',
  184. 'ascii',
  185. 'asin',
  186. 'asind',
  187. 'atan',
  188. 'atan2',
  189. 'atan2d',
  190. 'atand',
  191. 'avg',
  192. 'bit',
  193. 'bit_and',
  194. 'bit_count',
  195. 'bit_length',
  196. 'bit_or',
  197. 'bit_xor',
  198. 'bool_and',
  199. 'bool_or',
  200. 'bound_box',
  201. 'box',
  202. 'brin_summarize_new_values',
  203. 'broadcast',
  204. 'btrim',
  205. 'cardinality',
  206. 'cbrt',
  207. 'ceil',
  208. 'ceiling',
  209. 'center',
  210. 'char_length',
  211. 'character_length',
  212. 'chr',
  213. 'circle',
  214. 'clock_timestamp',
  215. 'coalesce',
  216. 'col_description',
  217. 'concat',
  218. 'concat_ws',
  219. 'convert',
  220. 'convert_from',
  221. 'convert_to',
  222. 'corr',
  223. 'cos',
  224. 'cosd',
  225. 'cot',
  226. 'cotd',
  227. 'count',
  228. 'covar_pop',
  229. 'covar_samp',
  230. 'cume_dist',
  231. 'current_catalog',
  232. 'current_database',
  233. 'current_date',
  234. 'current_query',
  235. 'current_role',
  236. 'current_schema',
  237. 'current_schemas',
  238. 'current_setting',
  239. 'current_time',
  240. 'current_timestamp',
  241. 'current_user',
  242. 'currval',
  243. 'cursor_to_xml',
  244. 'date_bin',
  245. 'date_part',
  246. 'date_trunc',
  247. 'decode',
  248. 'degrees',
  249. 'dense_rank',
  250. 'diameter',
  251. 'div',
  252. 'encode',
  253. 'enum_first',
  254. 'enum_last',
  255. 'enum_range',
  256. 'every',
  257. 'exp',
  258. 'extract',
  259. 'family',
  260. 'first_value',
  261. 'floor',
  262. 'format',
  263. 'format_type',
  264. 'generate_series',
  265. 'generate_subscripts',
  266. 'get_bit',
  267. 'get_byte',
  268. 'get_current_ts_config',
  269. 'gin_clean_pending_list',
  270. 'greatest',
  271. 'grouping',
  272. 'has_any_column_privilege',
  273. 'has_column_privilege',
  274. 'has_database_privilege',
  275. 'has_foreign_data_wrapper_privilege',
  276. 'has_function_privilege',
  277. 'has_language_privilege',
  278. 'has_schema_privilege',
  279. 'has_sequence_privilege',
  280. 'has_server_privilege',
  281. 'has_table_privilege',
  282. 'has_tablespace_privilege',
  283. 'has_type_privilege',
  284. 'height',
  285. 'host',
  286. 'hostmask',
  287. 'inet_client_addr',
  288. 'inet_client_port',
  289. 'inet_merge',
  290. 'inet_same_family',
  291. 'inet_server_addr',
  292. 'inet_server_port',
  293. 'initcap',
  294. 'isclosed',
  295. 'isempty',
  296. 'isfinite',
  297. 'isopen',
  298. 'json_agg',
  299. 'json_object',
  300. 'json_object_agg',
  301. 'json_populate_record',
  302. 'json_populate_recordset',
  303. 'json_to_record',
  304. 'json_to_recordset',
  305. 'jsonb_agg',
  306. 'jsonb_object_agg',
  307. 'justify_days',
  308. 'justify_hours',
  309. 'justify_interval',
  310. 'lag',
  311. 'last_value',
  312. 'lastval',
  313. 'lead',
  314. 'least',
  315. 'left',
  316. 'length',
  317. 'line',
  318. 'ln',
  319. 'localtime',
  320. 'localtimestamp',
  321. 'log',
  322. 'lower',
  323. 'lower_inc',
  324. 'lower_inf',
  325. 'lpad',
  326. 'lseg',
  327. 'ltrim',
  328. 'make_date',
  329. 'make_interval',
  330. 'make_time',
  331. 'make_timestamp',
  332. 'make_timestamptz',
  333. 'masklen',
  334. 'max',
  335. 'md5',
  336. 'min',
  337. 'mod',
  338. 'mode',
  339. 'netmask',
  340. 'network',
  341. 'nextval',
  342. 'now',
  343. 'npoints',
  344. 'nth_value',
  345. 'ntile',
  346. 'nullif',
  347. 'num_nonnulls',
  348. 'num_nulls',
  349. 'numnode',
  350. 'obj_description',
  351. 'octet_length',
  352. 'overlay',
  353. 'parse_ident',
  354. 'path',
  355. 'pclose',
  356. 'percent_rank',
  357. 'percentile_cont',
  358. 'percentile_disc',
  359. 'pg_advisory_lock',
  360. 'pg_advisory_lock_shared',
  361. 'pg_advisory_unlock',
  362. 'pg_advisory_unlock_all',
  363. 'pg_advisory_unlock_shared',
  364. 'pg_advisory_xact_lock',
  365. 'pg_advisory_xact_lock_shared',
  366. 'pg_backend_pid',
  367. 'pg_backup_start_time',
  368. 'pg_blocking_pids',
  369. 'pg_cancel_backend',
  370. 'pg_client_encoding',
  371. 'pg_collation_is_visible',
  372. 'pg_column_size',
  373. 'pg_conf_load_time',
  374. 'pg_control_checkpoint',
  375. 'pg_control_init',
  376. 'pg_control_recovery',
  377. 'pg_control_system',
  378. 'pg_conversion_is_visible',
  379. 'pg_create_logical_replication_slot',
  380. 'pg_create_physical_replication_slot',
  381. 'pg_create_restore_point',
  382. 'pg_current_xlog_flush_location',
  383. 'pg_current_xlog_insert_location',
  384. 'pg_current_xlog_location',
  385. 'pg_database_size',
  386. 'pg_describe_object',
  387. 'pg_drop_replication_slot',
  388. 'pg_export_snapshot',
  389. 'pg_filenode_relation',
  390. 'pg_function_is_visible',
  391. 'pg_get_constraintdef',
  392. 'pg_get_expr',
  393. 'pg_get_function_arguments',
  394. 'pg_get_function_identity_arguments',
  395. 'pg_get_function_result',
  396. 'pg_get_functiondef',
  397. 'pg_get_indexdef',
  398. 'pg_get_keywords',
  399. 'pg_get_object_address',
  400. 'pg_get_owned_sequence',
  401. 'pg_get_ruledef',
  402. 'pg_get_serial_sequence',
  403. 'pg_get_triggerdef',
  404. 'pg_get_userbyid',
  405. 'pg_get_viewdef',
  406. 'pg_has_role',
  407. 'pg_identify_object',
  408. 'pg_identify_object_as_address',
  409. 'pg_index_column_has_property',
  410. 'pg_index_has_property',
  411. 'pg_indexam_has_property',
  412. 'pg_indexes_size',
  413. 'pg_is_in_backup',
  414. 'pg_is_in_recovery',
  415. 'pg_is_other_temp_schema',
  416. 'pg_is_xlog_replay_paused',
  417. 'pg_last_committed_xact',
  418. 'pg_last_xact_replay_timestamp',
  419. 'pg_last_xlog_receive_location',
  420. 'pg_last_xlog_replay_location',
  421. 'pg_listening_channels',
  422. 'pg_logical_emit_message',
  423. 'pg_logical_slot_get_binary_changes',
  424. 'pg_logical_slot_get_changes',
  425. 'pg_logical_slot_peek_binary_changes',
  426. 'pg_logical_slot_peek_changes',
  427. 'pg_ls_dir',
  428. 'pg_my_temp_schema',
  429. 'pg_notification_queue_usage',
  430. 'pg_opclass_is_visible',
  431. 'pg_operator_is_visible',
  432. 'pg_opfamily_is_visible',
  433. 'pg_options_to_table',
  434. 'pg_postmaster_start_time',
  435. 'pg_read_binary_file',
  436. 'pg_read_file',
  437. 'pg_relation_filenode',
  438. 'pg_relation_filepath',
  439. 'pg_relation_size',
  440. 'pg_reload_conf',
  441. 'pg_replication_origin_create',
  442. 'pg_replication_origin_drop',
  443. 'pg_replication_origin_oid',
  444. 'pg_replication_origin_progress',
  445. 'pg_replication_origin_session_is_setup',
  446. 'pg_replication_origin_session_progress',
  447. 'pg_replication_origin_session_reset',
  448. 'pg_replication_origin_session_setup',
  449. 'pg_replication_origin_xact_reset',
  450. 'pg_replication_origin_xact_setup',
  451. 'pg_rotate_logfile',
  452. 'pg_size_bytes',
  453. 'pg_size_pretty',
  454. 'pg_sleep',
  455. 'pg_sleep_for',
  456. 'pg_sleep_until',
  457. 'pg_start_backup',
  458. 'pg_stat_file',
  459. 'pg_stop_backup',
  460. 'pg_switch_xlog',
  461. 'pg_table_is_visible',
  462. 'pg_table_size',
  463. 'pg_tablespace_databases',
  464. 'pg_tablespace_location',
  465. 'pg_tablespace_size',
  466. 'pg_terminate_backend',
  467. 'pg_total_relation_size',
  468. 'pg_trigger_depth',
  469. 'pg_try_advisory_lock',
  470. 'pg_try_advisory_lock_shared',
  471. 'pg_try_advisory_xact_lock',
  472. 'pg_try_advisory_xact_lock_shared',
  473. 'pg_ts_config_is_visible',
  474. 'pg_ts_dict_is_visible',
  475. 'pg_ts_parser_is_visible',
  476. 'pg_ts_template_is_visible',
  477. 'pg_type_is_visible',
  478. 'pg_typeof',
  479. 'pg_xact_commit_timestamp',
  480. 'pg_xlog_location_diff',
  481. 'pg_xlog_replay_pause',
  482. 'pg_xlog_replay_resume',
  483. 'pg_xlogfile_name',
  484. 'pg_xlogfile_name_offset',
  485. 'phraseto_tsquery',
  486. 'pi',
  487. 'plainto_tsquery',
  488. 'point',
  489. 'polygon',
  490. 'popen',
  491. 'position',
  492. 'power',
  493. 'pqserverversion',
  494. 'query_to_xml',
  495. 'querytree',
  496. 'quote_ident',
  497. 'quote_literal',
  498. 'quote_nullable',
  499. 'radians',
  500. 'radius',
  501. 'random',
  502. 'range_merge',
  503. 'rank',
  504. 'regexp_matches',
  505. 'regexp_replace',
  506. 'regexp_split_to_array',
  507. 'regexp_split_to_table',
  508. 'regr_avgx',
  509. 'regr_avgy',
  510. 'regr_count',
  511. 'regr_intercept',
  512. 'regr_r2',
  513. 'regr_slope',
  514. 'regr_sxx',
  515. 'regr_sxy',
  516. 'regr_syy',
  517. 'repeat',
  518. 'replace',
  519. 'reverse',
  520. 'right',
  521. 'round',
  522. 'row_number',
  523. 'row_security_active',
  524. 'row_to_json',
  525. 'rpad',
  526. 'rtrim',
  527. 'scale',
  528. 'session_user',
  529. 'set_bit',
  530. 'set_byte',
  531. 'set_config',
  532. 'set_masklen',
  533. 'setseed',
  534. 'setval',
  535. 'setweight',
  536. 'shobj_description',
  537. 'sign',
  538. 'sin',
  539. 'sind',
  540. 'split_part',
  541. 'sprintf',
  542. 'sqrt',
  543. 'statement_timestamp',
  544. 'stddev',
  545. 'stddev_pop',
  546. 'stddev_samp',
  547. 'string_agg',
  548. 'string_to_array',
  549. 'string_to_table',
  550. 'strip',
  551. 'strpos',
  552. 'substr',
  553. 'substring',
  554. 'sum',
  555. 'table_to_xml',
  556. 'table_to_xml_and_xmlschema',
  557. 'tan',
  558. 'tand',
  559. 'text',
  560. 'timeofday',
  561. 'timezone',
  562. 'to_ascii',
  563. 'to_char',
  564. 'to_date',
  565. 'to_hex',
  566. 'to_json',
  567. 'to_number',
  568. 'to_regclass',
  569. 'to_regnamespace',
  570. 'to_regoper',
  571. 'to_regoperator',
  572. 'to_regproc',
  573. 'to_regprocedure',
  574. 'to_regrole',
  575. 'to_regtype',
  576. 'to_timestamp',
  577. 'to_tsquery',
  578. 'to_tsvector',
  579. 'transaction_timestamp',
  580. 'translate',
  581. 'trim',
  582. 'trim_array',
  583. 'trunc',
  584. 'ts_debug',
  585. 'ts_delete',
  586. 'ts_filter',
  587. 'ts_headline',
  588. 'ts_lexize',
  589. 'ts_parse',
  590. 'ts_rank',
  591. 'ts_rank_cd',
  592. 'ts_rewrite',
  593. 'ts_stat',
  594. 'ts_token_type',
  595. 'tsquery_phrase',
  596. 'tsvector_to_array',
  597. 'tsvector_update_trigger',
  598. 'tsvector_update_trigger_column',
  599. 'txid_current',
  600. 'txid_current_snapshot',
  601. 'txid_snapshot_xip',
  602. 'txid_snapshot_xmax',
  603. 'txid_snapshot_xmin',
  604. 'txid_visible_in_snapshot',
  605. 'unistr',
  606. 'unnest',
  607. 'upper',
  608. 'upper_inc',
  609. 'upper_inf',
  610. 'user',
  611. 'var_pop',
  612. 'var_samp',
  613. 'variance',
  614. 'version',
  615. 'width',
  616. 'width_bucket',
  617. 'xml_is_well_formed',
  618. 'xml_is_well_formed_content',
  619. 'xml_is_well_formed_document',
  620. 'xmlagg',
  621. 'xmlcomment',
  622. 'xmlconcat',
  623. 'xmlelement',
  624. 'xmlexists',
  625. 'xmlforest',
  626. 'xmlparse',
  627. 'xmlpi',
  628. 'xmlroot',
  629. 'xmlserialize',
  630. 'xpath',
  631. 'xpath_exists'
  632. ],
  633. builtinVariables: [
  634. // NOT SUPPORTED
  635. ],
  636. pseudoColumns: [
  637. // NOT SUPPORTED
  638. ],
  639. tokenizer: {
  640. root: [
  641. { include: '@comments' },
  642. { include: '@whitespace' },
  643. { include: '@pseudoColumns' },
  644. { include: '@numbers' },
  645. { include: '@strings' },
  646. { include: '@complexIdentifiers' },
  647. { include: '@scopes' },
  648. [/[;,.]/, 'delimiter'],
  649. [/[()]/, '@brackets'],
  650. [
  651. /[\w@#$]+/,
  652. {
  653. cases: {
  654. '@operators': 'operator',
  655. '@builtinVariables': 'predefined',
  656. '@builtinFunctions': 'predefined',
  657. '@keywords': 'keyword',
  658. '@default': 'identifier'
  659. }
  660. }
  661. ],
  662. [/[<>=!%&+\-*/|~^]/, 'operator']
  663. ],
  664. whitespace: [[/\s+/, 'white']],
  665. comments: [
  666. [/--+.*/, 'comment'],
  667. [/\/\*/, { token: 'comment.quote', next: '@comment' }]
  668. ],
  669. comment: [
  670. [/[^*/]+/, 'comment'],
  671. // Not supporting nested comments, as nested comments seem to not be standard?
  672. // i.e. http://stackoverflow.com/questions/728172/are-there-multiline-comment-delimiters-in-sql-that-are-vendor-agnostic
  673. // [/\/\*/, { token: 'comment.quote', next: '@push' }], // nested comment not allowed :-(
  674. [/\*\//, { token: 'comment.quote', next: '@pop' }],
  675. [/./, 'comment']
  676. ],
  677. pseudoColumns: [
  678. [
  679. /[$][A-Za-z_][\w@#$]*/,
  680. {
  681. cases: {
  682. '@pseudoColumns': 'predefined',
  683. '@default': 'identifier'
  684. }
  685. }
  686. ]
  687. ],
  688. numbers: [
  689. [/0[xX][0-9a-fA-F]*/, 'number'],
  690. [/[$][+-]*\d*(\.\d*)?/, 'number'],
  691. [/((\d+(\.\d*)?)|(\.\d+))([eE][\-+]?\d+)?/, 'number']
  692. ],
  693. strings: [[/'/, { token: 'string', next: '@string' }]],
  694. string: [
  695. [/[^']+/, 'string'],
  696. [/''/, 'string'],
  697. [/'/, { token: 'string', next: '@pop' }]
  698. ],
  699. complexIdentifiers: [[/"/, { token: 'identifier.quote', next: '@quotedIdentifier' }]],
  700. quotedIdentifier: [
  701. [/[^"]+/, 'identifier'],
  702. [/""/, 'identifier'],
  703. [/"/, { token: 'identifier.quote', next: '@pop' }]
  704. ],
  705. scopes: [
  706. // NOT SUPPORTED
  707. ]
  708. }
  709. };