]>
luflow.net public git repositories - flow-web.git/blob - static/highlight/languages/sql.js
1 /*! `sql` grammar compiled for Highlight.js 11.11.1 */
3 var hljsGrammar
= (function () {
8 Website: https://en.wikipedia.org/wiki/SQL
9 Category: common, database
16 SQL is intended to highlight basic/common SQL keywords and expressions
18 - If pretty much every single SQL server includes supports, then it's a canidate.
19 - It is NOT intended to include tons of vendor specific keywords (Oracle, MySQL,
20 PostgreSQL) although the list of data types is purposely a bit more expansive.
21 - For more specific SQL grammars please see:
22 - PostgreSQL and PL/pgSQL - core
23 - T-SQL - https://github.com/highlightjs/highlightjs-tsql
29 const regex
= hljs
.regex
;
30 const COMMENT_MODE
= hljs
.COMMENT('--', '$');
37 contains: [ { match: /''/ } ]
41 const QUOTED_IDENTIFIER
= {
44 contains: [ { match: /""/ } ]
50 // Not sure it's correct to call NULL literal, and clauses like IS [NOT] NULL look strange that way.
55 const MULTI_WORD_TYPES
= [
88 'varying', // modifier (character varying)
92 const NON_RESERVED_WORDS
= [
103 // https://jakewheat.github.io/sql-overview/sql-2016-foundation-grammar.html#reserved-word
104 const RESERVED_WORDS
= [
115 "array_max_cardinality",
176 "current_default_transform_group",
185 "current_transform_group_for_type",
272 "json_table_primitive",
473 // these are reserved words we have identified to be functions
474 // and should only be highlighted in a dispatch-like context
475 // ie, array_agg(...), etc.
476 const RESERVED_FUNCTIONS
= [
508 "json_table_primitive",
564 // these functions can
565 const POSSIBLE_WITHOUT_PARENS
= [
568 "current_default_transform_group",
572 "current_transform_group_for_type",
583 // those exist to boost relevance making these very
584 // "SQL like" keyword combos worth +1 extra relevance
604 const FUNCTIONS
= RESERVED_FUNCTIONS
;
608 ...NON_RESERVED_WORDS
609 ].filter((keyword
) => {
610 return !RESERVED_FUNCTIONS
.includes(keyword
);
615 match: /@[a-z0-9][a-z0-9_]*/,
620 match: /[-+*/=%^~]|&&?|\|\|?|!=?|<(?:=>?|<|>)?|>[>=]?/,
624 const FUNCTION_CALL
= {
625 match: regex
.concat(/\b/, regex
.either(...FUNCTIONS
), /\s*\(/),
627 keywords: { built_in: FUNCTIONS
}
630 // turns a multi-word keyword combo into a regex that doesn't
631 // care about extra whitespace etc.
632 // input: "START QUERY"
633 // output: /\bSTART\s+QUERY\b/
634 function kws_to_regex(list
) {
637 regex
.either(...list
.map((kw
) => {
638 return kw
.replace(/\s+/, "\\s+")
644 const MULTI_WORD_KEYWORDS
= {
646 match: kws_to_regex(COMBOS
),
650 // keywords with less than 3 letters are reduced in relevancy
651 function reduceRelevancy(list
, {
654 const qualifyFn
= when
;
655 exceptions
= exceptions
|| [];
656 return list
.map((item
) => {
657 if (item
.match(/\|\d+$/) || exceptions
.includes(item
)) {
659 } else if (qualifyFn(item
)) {
669 case_insensitive: true,
670 // does not include {} or HTML tags `</`
673 $pattern: /\b[\w\.]+/,
675 reduceRelevancy(KEYWORDS
, { when: (x
) => x
.length
< 3 }),
678 built_in: POSSIBLE_WITHOUT_PARENS
683 match: kws_to_regex(MULTI_WORD_TYPES
)
691 hljs
.C_BLOCK_COMMENT_MODE
,
702 hljs
.registerLanguage('sql', hljsGrammar
);