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/c.js b/src/languages/c.js index 4c502d91c6..e267fdd007 100644 --- a/src/languages/c.js +++ b/src/languages/c.js @@ -180,19 +180,142 @@ export default function(hljs) { const KEYWORDS = { 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', + 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, TYPES, 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,