From 4aa8e78ca5e3097ffab3513b7c43adb4ab7f3e72 Mon Sep 17 00:00:00 2001 From: dxuian Date: Fri, 30 Aug 2024 08:04:51 +0530 Subject: [PATCH 1/5] fixed the spacing issue in primary key and similar combos --- CHANGES.md | 1 + src/languages/sql.js | 40 ++++++++++++++++++++++++++++++---------- 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 64f81406b2..bd5b371532 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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: diff --git a/src/languages/sql.js b/src/languages/sql.js index 1093f19abc..5664091314 100644 --- a/src/languages/sql.js +++ b/src/languages/sql.js @@ -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 @@ -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, From a788b37f231756da4e417fc1600a614b66f36a8f Mon Sep 17 00:00:00 2001 From: dxuian Date: Fri, 30 Aug 2024 23:55:05 +0530 Subject: [PATCH 2/5] changed C std types --- src/languages/c.js | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/languages/c.js b/src/languages/c.js index 4c502d91c6..5b985a218c 100644 --- a/src/languages/c.js +++ b/src/languages/c.js @@ -181,16 +181,25 @@ export default function(hljs) { keyword: C_KEYWORDS, type: C_TYPES, literal: 'true false NULL', - // TODO: apply hinting work similar to what was done in cpp.js - built_in: 'std string wstring cin cout cerr clog stdin stdout stderr stringstream istringstream ostringstream ' - + 'auto_ptr deque list queue stack vector map set pair bitset multiset multimap unordered_set ' - + 'unordered_map unordered_multiset unordered_multimap priority_queue make_pair array shared_ptr abort terminate abs acos ' - + 'asin atan2 atan calloc ceil cosh cos exit exp fabs floor fmod fprintf fputs free frexp ' - + 'fscanf future isalnum isalpha iscntrl isdigit isgraph islower isprint ispunct isspace isupper ' - + 'isxdigit tolower toupper labs ldexp log10 log malloc realloc memchr memcmp memcpy memset modf pow ' - + 'printf putchar puts scanf sinh sin snprintf sprintf sqrt sscanf strcat strchr strcmp ' - + 'strcpy strcspn strlen strncat strncmp strncpy strpbrk strrchr strspn strstr tanh tan ' - + 'vfprintf vprintf vsprintf endl initializer_list unique_ptr', + built_in: 'stdin stdout stderr' + + 'abs acos asin atan atan2 ceil cos cosh exp fabs floor fmod frexp ldexp log log10 pow sin sinh sqrt tan tanh' + + 'printf scanf puts putchar getchar gets fgets fputs fprintf fscanf sscanf sprintf snprintf' + + 'malloc calloc realloc free' + + 'memcpy memmove memset memcmp memchr strcpy strncpy strcat strncat strcmp strncmp strchr strrchr strstr strlen' + + 'atoi atol atoll strtol strtoll strtoul strtoull' + + 'rand srand' + + 'exit abort assert' + + 'time clock difftime mktime asctime ctime gmtime localtime strftime' + + 'fopen fclose fread fwrite fseek ftell rewind fflush' + + 'isalnum isalpha iscntrl isdigit isgraph islower isprint ispunct isspace isupper isxdigit tolower toupper' + + 'qsort bsearch' + + 'setjmp longjmp' + + 'va_start va_arg va_end' + + 'offsetof' + + 'static_assert' + + 'alignas alignof' + + '_Generic' + + 'atomic_bool atomic_char atomic_schar atomic_uchar atomic_short atomic_ushort atomic_int atomic_uint atomic_long atomic_ulong atomic_llong atomic_ullong atomic_intptr_t atomic_uintptr_t atomic_size_t atomic_ptrdiff_t atomic_intmax_t atomic_uintmax_t' }; const EXPRESSION_CONTAINS = [ From 4a54c4cb692952e9ee8ad42400a0f01f8e6f1360 Mon Sep 17 00:00:00 2001 From: dxuian Date: Sun, 1 Sep 2024 06:04:41 +0530 Subject: [PATCH 3/5] all on one line --- src/languages/c.js | 155 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 135 insertions(+), 20 deletions(-) diff --git a/src/languages/c.js b/src/languages/c.js index 5b985a218c..4ef52150ca 100644 --- a/src/languages/c.js +++ b/src/languages/c.js @@ -180,27 +180,142 @@ export default function(hljs) { const KEYWORDS = { keyword: C_KEYWORDS, type: C_TYPES, - literal: 'true false NULL', - built_in: 'stdin stdout stderr' - + 'abs acos asin atan atan2 ceil cos cosh exp fabs floor fmod frexp ldexp log log10 pow sin sinh sqrt tan tanh' - + 'printf scanf puts putchar getchar gets fgets fputs fprintf fscanf sscanf sprintf snprintf' - + 'malloc calloc realloc free' - + 'memcpy memmove memset memcmp memchr strcpy strncpy strcat strncat strcmp strncmp strchr strrchr strstr strlen' - + 'atoi atol atoll strtol strtoll strtoul strtoull' - + 'rand srand' - + 'exit abort assert' - + 'time clock difftime mktime asctime ctime gmtime localtime strftime' - + 'fopen fclose fread fwrite fseek ftell rewind fflush' - + 'isalnum isalpha iscntrl isdigit isgraph islower isprint ispunct isspace isupper isxdigit tolower toupper' - + 'qsort bsearch' - + 'setjmp longjmp' - + 'va_start va_arg va_end' - + 'offsetof' - + 'static_assert' - + 'alignas alignof' - + '_Generic' - + 'atomic_bool atomic_char atomic_schar atomic_uchar atomic_short atomic_ushort atomic_int atomic_uint atomic_long atomic_ulong atomic_llong atomic_ullong atomic_intptr_t atomic_uintptr_t atomic_size_t atomic_ptrdiff_t atomic_intmax_t atomic_uintmax_t' + literal: + 'true ' + + 'false ' + + 'NULL', + built_in: + 'stdin ' + + 'stdout ' + + 'stderr ' + + 'abs ' + + 'acos ' + + 'asin ' + + 'atan ' + + 'atan2 ' + + 'ceil ' + + 'cos ' + + 'cosh ' + + 'exp ' + + 'fabs ' + + 'floor ' + + 'fmod ' + + 'frexp ' + + 'ldexp ' + + 'log ' + + 'log10 ' + + 'pow ' + + 'sin ' + + 'sinh ' + + 'sqrt ' + + 'tan ' + + 'tanh ' + + 'printf ' + + 'scanf ' + + 'puts ' + + 'putchar ' + + 'getchar ' + + 'gets ' + + 'fgets ' + + 'fputs ' + + 'fprintf ' + + 'fscanf ' + + 'sscanf ' + + 'sprintf ' + + 'snprintf ' + + 'malloc ' + + 'calloc ' + + 'realloc ' + + 'free ' + + 'memcpy ' + + 'memmove ' + + 'memset ' + + 'memcmp ' + + 'memchr ' + + 'strcpy ' + + 'strncpy ' + + 'strcat ' + + 'strncat ' + + 'strcmp ' + + 'strncmp ' + + 'strchr ' + + 'strrchr ' + + 'strstr ' + + 'strlen ' + + 'atoi ' + + 'atol ' + + 'atoll ' + + 'strtol ' + + 'strtoll ' + + 'strtoul ' + + 'strtoull ' + + 'rand ' + + 'srand ' + + 'exit ' + + 'abort ' + + 'assert ' + + 'time ' + + 'clock ' + + 'difftime ' + + 'mktime ' + + 'asctime ' + + 'ctime ' + + 'gmtime ' + + 'localtime ' + + 'strftime ' + + 'fopen ' + + 'fclose ' + + 'fread ' + + 'fwrite ' + + 'fseek ' + + 'ftell ' + + 'rewind ' + + 'fflush ' + + 'isalnum ' + + 'isalpha ' + + 'iscntrl ' + + 'isdigit ' + + 'isgraph ' + + 'islower ' + + 'isprint ' + + 'ispunct ' + + 'isspace ' + + 'isupper ' + + 'isxdigit ' + + 'tolower ' + + 'toupper ' + + 'qsort ' + + 'bsearch ' + + 'setjmp ' + + 'longjmp ' + + 'va_start ' + + 'va_arg ' + + 'va_end ' + + 'offsetof ' + + 'static_assert ' + + 'alignas ' + + 'alignof ' + + '_Generic ' + + 'atomic_bool ' + + 'atomic_char ' + + 'atomic_schar ' + + 'atomic_uchar ' + + 'atomic_short ' + + 'atomic_ushort ' + + 'atomic_int ' + + 'atomic_uint ' + + 'atomic_long ' + + 'atomic_ulong ' + + 'atomic_llong ' + + 'atomic_ullong ' + + 'atomic_intptr_t ' + + 'atomic_uintptr_t ' + + 'atomic_size_t ' + + 'atomic_ptrdiff_t ' + + 'atomic_intmax_t ' + + 'atomic_uintmax_t' }; + const EXPRESSION_CONTAINS = [ PREPROCESSOR, From 531e70049a31acd16591ef23b9d8e7c18f0be7f8 Mon Sep 17 00:00:00 2001 From: dxuian Date: Sun, 1 Sep 2024 06:10:35 +0530 Subject: [PATCH 4/5] original code but on one line --- src/languages/c.js | 196 +++++++++++++++++++++------------------------ 1 file changed, 90 insertions(+), 106 deletions(-) diff --git a/src/languages/c.js b/src/languages/c.js index 4ef52150ca..540e8b05d4 100644 --- a/src/languages/c.js +++ b/src/languages/c.js @@ -184,93 +184,63 @@ export default function(hljs) { 'true ' + 'false ' + 'NULL', + // TODO: apply hinting work similar to what was done in cpp.js built_in: - 'stdin ' + 'std ' + + 'string ' + + 'wstring ' + + 'cin ' + + 'cout ' + + 'cerr ' + + 'clog ' + + 'stdin ' + 'stdout ' - + 'stderr ' + + 'stderr ' + + 'stringstream ' + + 'istringstream ' + + 'ostringstream ' + + 'auto_ptr ' + + 'deque ' + + 'list ' + + 'queue ' + + 'stack ' + + 'vector ' + + 'map ' + + 'set ' + + 'pair ' + + 'bitset ' + + 'multiset ' + + 'multimap ' + + 'unordered_set ' + + 'unordered_map ' + + 'unordered_multiset ' + + 'unordered_multimap ' + + 'priority_queue ' + + 'make_pair ' + + 'array ' + + 'shared_ptr ' + + 'abort ' + + 'terminate ' + 'abs ' - + 'acos ' + + 'acos ' + 'asin ' - + 'atan ' + 'atan2 ' + + 'atan ' + + 'calloc ' + 'ceil ' - + 'cos ' + 'cosh ' + + 'cos ' + + 'exit ' + 'exp ' + 'fabs ' + 'floor ' + 'fmod ' - + 'frexp ' - + 'ldexp ' - + 'log ' - + 'log10 ' - + 'pow ' - + 'sin ' - + 'sinh ' - + 'sqrt ' - + 'tan ' - + 'tanh ' - + 'printf ' - + 'scanf ' - + 'puts ' - + 'putchar ' - + 'getchar ' - + 'gets ' - + 'fgets ' - + 'fputs ' + 'fprintf ' + + 'fputs ' + + 'free ' + + 'frexp ' + 'fscanf ' - + 'sscanf ' - + 'sprintf ' - + 'snprintf ' - + 'malloc ' - + 'calloc ' - + 'realloc ' - + 'free ' - + 'memcpy ' - + 'memmove ' - + 'memset ' - + 'memcmp ' - + 'memchr ' - + 'strcpy ' - + 'strncpy ' - + 'strcat ' - + 'strncat ' - + 'strcmp ' - + 'strncmp ' - + 'strchr ' - + 'strrchr ' - + 'strstr ' - + 'strlen ' - + 'atoi ' - + 'atol ' - + 'atoll ' - + 'strtol ' - + 'strtoll ' - + 'strtoul ' - + 'strtoull ' - + 'rand ' - + 'srand ' - + 'exit ' - + 'abort ' - + 'assert ' - + 'time ' - + 'clock ' - + 'difftime ' - + 'mktime ' - + 'asctime ' - + 'ctime ' - + 'gmtime ' - + 'localtime ' - + 'strftime ' - + 'fopen ' - + 'fclose ' - + 'fread ' - + 'fwrite ' - + 'fseek ' - + 'ftell ' - + 'rewind ' - + 'fflush ' + + 'future ' + 'isalnum ' + 'isalpha ' + 'iscntrl ' @@ -280,42 +250,56 @@ export default function(hljs) { + 'isprint ' + 'ispunct ' + 'isspace ' - + 'isupper ' + + 'isupper ' + 'isxdigit ' + 'tolower ' - + 'toupper ' - + 'qsort ' - + 'bsearch ' - + 'setjmp ' - + 'longjmp ' - + 'va_start ' - + 'va_arg ' - + 'va_end ' - + 'offsetof ' - + 'static_assert ' - + 'alignas ' - + 'alignof ' - + '_Generic ' - + 'atomic_bool ' - + 'atomic_char ' - + 'atomic_schar ' - + 'atomic_uchar ' - + 'atomic_short ' - + 'atomic_ushort ' - + 'atomic_int ' - + 'atomic_uint ' - + 'atomic_long ' - + 'atomic_ulong ' - + 'atomic_llong ' - + 'atomic_ullong ' - + 'atomic_intptr_t ' - + 'atomic_uintptr_t ' - + 'atomic_size_t ' - + 'atomic_ptrdiff_t ' - + 'atomic_intmax_t ' - + 'atomic_uintmax_t' + + 'toupper ' + + 'labs ' + + 'ldexp ' + + 'log10 ' + + 'log ' + + 'malloc ' + + 'realloc ' + + 'memchr ' + + 'memcmp ' + + 'memcpy ' + + 'memset ' + + 'modf ' + + 'pow ' + + 'printf ' + + 'putchar ' + + 'puts ' + + 'scanf ' + + 'sinh ' + + 'sin ' + + 'snprintf ' + + 'sprintf ' + + 'sqrt ' + + 'sscanf ' + + 'strcat ' + + 'strchr ' + + 'strcmp ' + + 'strcpy ' + + 'strcspn ' + + 'strlen ' + + 'strncat ' + + 'strncmp ' + + 'strncpy ' + + 'strpbrk ' + + 'strrchr ' + + 'strspn ' + + 'strstr ' + + 'tanh ' + + 'tan ' + + 'vfprintf ' + + 'vprintf ' + + 'vsprintf ' + + 'endl ' + + 'initializer_list ' + + 'unique_ptr', }; + const EXPRESSION_CONTAINS = [ PREPROCESSOR, From d1217420f97d9af4a0a07009e21132c2dd0f4cc9 Mon Sep 17 00:00:00 2001 From: dxuian Date: Sun, 1 Sep 2024 06:12:34 +0530 Subject: [PATCH 5/5] new words on one line --- src/languages/c.js | 197 ++++++++++++++++++++++++--------------------- 1 file changed, 106 insertions(+), 91 deletions(-) diff --git a/src/languages/c.js b/src/languages/c.js index 540e8b05d4..e267fdd007 100644 --- a/src/languages/c.js +++ b/src/languages/c.js @@ -184,63 +184,93 @@ export default function(hljs) { 'true ' + 'false ' + 'NULL', - // TODO: apply hinting work similar to what was done in cpp.js built_in: - 'std ' - + 'string ' - + 'wstring ' - + 'cin ' - + 'cout ' - + 'cerr ' - + 'clog ' - + 'stdin ' + 'stdin ' + 'stdout ' - + 'stderr ' - + 'stringstream ' - + 'istringstream ' - + 'ostringstream ' - + 'auto_ptr ' - + 'deque ' - + 'list ' - + 'queue ' - + 'stack ' - + 'vector ' - + 'map ' - + 'set ' - + 'pair ' - + 'bitset ' - + 'multiset ' - + 'multimap ' - + 'unordered_set ' - + 'unordered_map ' - + 'unordered_multiset ' - + 'unordered_multimap ' - + 'priority_queue ' - + 'make_pair ' - + 'array ' - + 'shared_ptr ' - + 'abort ' - + 'terminate ' + + 'stderr ' + 'abs ' - + 'acos ' + + 'acos ' + 'asin ' - + 'atan2 ' + 'atan ' - + 'calloc ' + + 'atan2 ' + 'ceil ' - + 'cosh ' + 'cos ' - + 'exit ' + + 'cosh ' + 'exp ' + 'fabs ' + 'floor ' + 'fmod ' - + 'fprintf ' + + 'frexp ' + + 'ldexp ' + + 'log ' + + 'log10 ' + + 'pow ' + + 'sin ' + + 'sinh ' + + 'sqrt ' + + 'tan ' + + 'tanh ' + + 'printf ' + + 'scanf ' + + 'puts ' + + 'putchar ' + + 'getchar ' + + 'gets ' + + 'fgets ' + 'fputs ' - + 'free ' - + 'frexp ' + + 'fprintf ' + 'fscanf ' - + 'future ' + + 'sscanf ' + + 'sprintf ' + + 'snprintf ' + + 'malloc ' + + 'calloc ' + + 'realloc ' + + 'free ' + + 'memcpy ' + + 'memmove ' + + 'memset ' + + 'memcmp ' + + 'memchr ' + + 'strcpy ' + + 'strncpy ' + + 'strcat ' + + 'strncat ' + + 'strcmp ' + + 'strncmp ' + + 'strchr ' + + 'strrchr ' + + 'strstr ' + + 'strlen ' + + 'atoi ' + + 'atol ' + + 'atoll ' + + 'strtol ' + + 'strtoll ' + + 'strtoul ' + + 'strtoull ' + + 'rand ' + + 'srand ' + + 'exit ' + + 'abort ' + + 'assert ' + + 'time ' + + 'clock ' + + 'difftime ' + + 'mktime ' + + 'asctime ' + + 'ctime ' + + 'gmtime ' + + 'localtime ' + + 'strftime ' + + 'fopen ' + + 'fclose ' + + 'fread ' + + 'fwrite ' + + 'fseek ' + + 'ftell ' + + 'rewind ' + + 'fflush ' + 'isalnum ' + 'isalpha ' + 'iscntrl ' @@ -250,57 +280,42 @@ export default function(hljs) { + 'isprint ' + 'ispunct ' + 'isspace ' - + 'isupper ' + + 'isupper ' + 'isxdigit ' + 'tolower ' - + 'toupper ' - + 'labs ' - + 'ldexp ' - + 'log10 ' - + 'log ' - + 'malloc ' - + 'realloc ' - + 'memchr ' - + 'memcmp ' - + 'memcpy ' - + 'memset ' - + 'modf ' - + 'pow ' - + 'printf ' - + 'putchar ' - + 'puts ' - + 'scanf ' - + 'sinh ' - + 'sin ' - + 'snprintf ' - + 'sprintf ' - + 'sqrt ' - + 'sscanf ' - + 'strcat ' - + 'strchr ' - + 'strcmp ' - + 'strcpy ' - + 'strcspn ' - + 'strlen ' - + 'strncat ' - + 'strncmp ' - + 'strncpy ' - + 'strpbrk ' - + 'strrchr ' - + 'strspn ' - + 'strstr ' - + 'tanh ' - + 'tan ' - + 'vfprintf ' - + 'vprintf ' - + 'vsprintf ' - + 'endl ' - + 'initializer_list ' - + 'unique_ptr', + + 'toupper ' + + 'qsort ' + + 'bsearch ' + + 'setjmp ' + + 'longjmp ' + + 'va_start ' + + 'va_arg ' + + 'va_end ' + + 'offsetof ' + + 'static_assert ' + + 'alignas ' + + 'alignof ' + + '_Generic ' + + 'atomic_bool ' + + 'atomic_char ' + + 'atomic_schar ' + + 'atomic_uchar ' + + 'atomic_short ' + + 'atomic_ushort ' + + 'atomic_int ' + + 'atomic_uint ' + + 'atomic_long ' + + 'atomic_ulong ' + + 'atomic_llong ' + + 'atomic_ullong ' + + 'atomic_intptr_t ' + + 'atomic_uintptr_t ' + + 'atomic_size_t ' + + 'atomic_ptrdiff_t ' + + 'atomic_intmax_t ' + + 'atomic_uintmax_t' }; - - const EXPRESSION_CONTAINS = [ PREPROCESSOR, TYPES,