Skip to content

Commit

Permalink
fixed the spacing issue in primary key and similar combos
Browse files Browse the repository at this point in the history
  • Loading branch information
Dxuian committed Aug 30, 2024
1 parent 07ee351 commit 4aa8e78
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Core Grammars:
- enh(csharp) add Contextual keywords `file`, `args`, `dynamic`, `record`, `required` and `scoped` [Alvin Joy][]
- fix(c) - Fixed hex numbers with decimals [Dxuian]
- fix(ruby) - fix `|=` operator false positives (as block arguments) [Aboobacker MK]
- fix(sql) - Fixed sql primary key and foreign key spacing issue [Dxuian]

New Grammars:

Expand Down
40 changes: 30 additions & 10 deletions src/languages/sql.js
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,35 @@ export default function(hljs) {
keywords: { built_in: FUNCTIONS }
};

//COMBOS generator
// const regexPatterns = COMBOS.map(phrase => {
// const escapedPhrase = phrase.replace(/ /g, "\\s+"); // Replace spaces with \s+ to match any whitespace
// return new RegExp(escapedPhrase, "gi"); // Create case-insensitive regex
// });

const COMBOSLIST = {
className: 'type',
variants: [
{ match: /\bcreate\s+table\b/ },
{ match: /\binsert\s+into\b/ },
{ match: /\bprimary\s+key\b/ },
{ match: /\bforeign\s+key\b/ },
{ match: /\bnot\s+null\b/ },
{ match: /\balter\s+table\b/ },
{ match: /\badd\s+constraint\b/ },
{ match: /\bgrouping\s+sets\b/ },
{ match: /\bon\s+overflow\b/ },
{ match: /\bcharacter\s+set\b/ },
{ match: /\brespect\s+nulls\b/ },
{ match: /\bignore\s+nulls\b/ },
{ match: /\bnulls\s+first\b/ },
{ match: /\bnulls\s+last\b/ },
{ match: /\bdepth\s+first\b/ },
{ match: /\bbreadth\s+first\b/ }
],
relevance: 0
};

// keywords with less than 3 letters are reduced in relevancy
function reduceRelevancy(list, {
exceptions, when
Expand Down Expand Up @@ -653,20 +682,11 @@ export default function(hljs) {
built_in: POSSIBLE_WITHOUT_PARENS
},
contains: [
{
begin: regex.either(...COMBOS),
relevance: 0,
keywords: {
$pattern: /[\w\.]+/,
keyword: KEYWORDS.concat(COMBOS),
literal: LITERALS,
type: TYPES
},
},
{
className: "type",
begin: regex.either(...MULTI_WORD_TYPES)
},
COMBOSLIST,
FUNCTION_CALL,
VARIABLE,
STRING,
Expand Down

0 comments on commit 4aa8e78

Please sign in to comment.