Skip to content

Commit ffeb26e

Browse files
committed
C: Regexp optimisation + don't use captures if not needed
1 parent 16979a3 commit ffeb26e

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

components/prism-c.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
11
Prism.languages.c = Prism.languages.extend('clike', {
2-
'keyword': /\b(_Alignas|_Alignof|_Atomic|_Bool|_Complex|_Generic|_Imaginary|_Noreturn|_Static_assert|_Thread_local|asm|typeof|inline|auto|break|case|char|const|continue|default|do|double|else|enum|extern|float|for|goto|if|int|long|register|return|short|signed|sizeof|static|struct|switch|typedef|union|unsigned|void|volatile|while)\b/,
3-
'operator': /\-[>-]?|\+\+?|!=?|<<?=?|>>?=?|==?|&&?|\|?\||[~^%?*\/]/,
2+
'keyword': /\b(?:_Alignas|_Alignof|_Atomic|_Bool|_Complex|_Generic|_Imaginary|_Noreturn|_Static_assert|_Thread_local|asm|typeof|inline|auto|break|case|char|const|continue|default|do|double|else|enum|extern|float|for|goto|if|int|long|register|return|short|signed|sizeof|static|struct|switch|typedef|union|unsigned|void|volatile|while)\b/,
3+
'operator': /-[>-]?|\+\+?|!=?|<<?=?|>>?=?|==?|&&?|\|\|?|[~^%?*\/]/,
44
'number': /\b-?(?:0x[\da-f]+|\d*\.?\d+(?:e[+-]?\d+)?)[ful]*\b/i
55
});
66

77
Prism.languages.insertBefore('c', 'string', {
88
'macro': {
99
// allow for multiline macro definitions
1010
// spaces after the # character compile fine with gcc
11-
pattern: /(^\s*)#\s*[a-z]+([^\r\n\\]|\\.|\\(?:\r\n?|\n))*/im,
11+
pattern: /(^\s*)#\s*[a-z]+(?:[^\r\n\\]|\\(?:\r\n|[\s\S]))*/im,
1212
lookbehind: true,
1313
alias: 'property',
1414
inside: {
1515
// highlight the path of the include statement as a string
1616
'string': {
17-
pattern: /(#\s*include\s*)(<.+?>|("|')(\\?.)+?\3)/,
17+
pattern: /(#\s*include\s*)(?:<.+?>|("|')(?:\\?.)+?\2)/,
1818
lookbehind: true
1919
},
2020
// highlight macro directives as keywords
2121
'directive': {
22-
pattern: /(#\s*)\b(define|defined|elif|else|endif|error|ifdef|ifndef|if|import|include|line|pragma|undef|using)\b/,
22+
pattern: /(#\s*)\b(?:define|defined|elif|else|endif|error|ifdef|ifndef|if|import|include|line|pragma|undef|using)\b/,
2323
lookbehind: true,
2424
alias: 'keyword'
2525
}
2626
}
2727
},
2828
// highlight predefined macros as constants
29-
'constant': /\b(__FILE__|__LINE__|__DATE__|__TIME__|__TIMESTAMP__|__func__|EOF|NULL|SEEK_CUR|SEEK_END|SEEK_SET|stdin|stdout|stderr)\b/
29+
'constant': /\b(?:__FILE__|__LINE__|__DATE__|__TIME__|__TIMESTAMP__|__func__|EOF|NULL|SEEK_CUR|SEEK_END|SEEK_SET|stdin|stdout|stderr)\b/
3030
});
3131

3232
delete Prism.languages.c['class-name'];

components/prism-c.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)