]>
luflow.net public git repositories - flow-web.git/blob - static/highlight/es/languages/sql.js
1 /*! `sql` grammar compiled for Highlight.js 11.11.1 */
2 var hljsGrammar
= (function () {
7 Website: https://en.wikipedia.org/wiki/SQL
8 Category: common, database
15 SQL is intended to highlight basic/common SQL keywords and expressions
17 - If pretty much every single SQL server includes supports, then it's a canidate.
18 - It is NOT intended to include tons of vendor specific keywords (Oracle, MySQL,
19 PostgreSQL) although the list of data types is purposely a bit more expansive.
20 - For more specific SQL grammars please see:
21 - PostgreSQL and PL/pgSQL - core
22 - T-SQL - https://github.com/highlightjs/highlightjs-tsql
28 const regex
= hljs
.regex
;
29 const COMMENT_MODE
= hljs
.COMMENT('--', '$');
36 contains: [ { match: /''/ } ]
40 const QUOTED_IDENTIFIER
= {
43 contains: [ { match: /""/ } ]
49 // Not sure it's correct to call NULL literal, and clauses like IS [NOT] NULL look strange that way.
54 const MULTI_WORD_TYPES
= [
87 'varying', // modifier (character varying)
91 const NON_RESERVED_WORDS
= [
102 // https://jakewheat.github.io/sql-overview/sql-2016-foundation-grammar.html#reserved-word
103 const RESERVED_WORDS
= [
114 "array_max_cardinality",
175 "current_default_transform_group",
184 "current_transform_group_for_type",
271 "json_table_primitive",
472 // these are reserved words we have identified to be functions
473 // and should only be highlighted in a dispatch-like context
474 // ie, array_agg(...), etc.
475 const RESERVED_FUNCTIONS
= [
507 "json_table_primitive",
563 // these functions can
564 const POSSIBLE_WITHOUT_PARENS
= [
567 "current_default_transform_group",
571 "current_transform_group_for_type",
582 // those exist to boost relevance making these very
583 // "SQL like" keyword combos worth +1 extra relevance
603 const FUNCTIONS
= RESERVED_FUNCTIONS
;
607 ...NON_RESERVED_WORDS
608 ].filter((keyword
) => {
609 return !RESERVED_FUNCTIONS
.includes(keyword
);
614 match: /@[a-z0-9][a-z0-9_]*/,
619 match: /[-+*/=%^~]|&&?|\|\|?|!=?|<(?:=>?|<|>)?|>[>=]?/,
623 const FUNCTION_CALL
= {
624 match: regex
.concat(/\b/, regex
.either(...FUNCTIONS
), /\s*\(/),
626 keywords: { built_in: FUNCTIONS
}
629 // turns a multi-word keyword combo into a regex that doesn't
630 // care about extra whitespace etc.
631 // input: "START QUERY"
632 // output: /\bSTART\s+QUERY\b/
633 function kws_to_regex(list
) {
636 regex
.either(...list
.map((kw
) => {
637 return kw
.replace(/\s+/, "\\s+")
643 const MULTI_WORD_KEYWORDS
= {
645 match: kws_to_regex(COMBOS
),
649 // keywords with less than 3 letters are reduced in relevancy
650 function reduceRelevancy(list
, {
653 const qualifyFn
= when
;
654 exceptions
= exceptions
|| [];
655 return list
.map((item
) => {
656 if (item
.match(/\|\d+$/) || exceptions
.includes(item
)) {
658 } else if (qualifyFn(item
)) {
668 case_insensitive: true,
669 // does not include {} or HTML tags `</`
672 $pattern: /\b[\w\.]+/,
674 reduceRelevancy(KEYWORDS
, { when: (x
) => x
.length
< 3 }),
677 built_in: POSSIBLE_WITHOUT_PARENS
682 match: kws_to_regex(MULTI_WORD_TYPES
)
690 hljs
.C_BLOCK_COMMENT_MODE
,
701 export default hljsGrammar
;