1 | Prism.languages.c = Prism.languages.extend('clike', {
|
2 | 'comment': {
|
3 | pattern: /\/\/(?:[^\r\n\\]|\\(?:\r\n?|\n|(?![\r\n])))*|\/\*[\s\S]*?(?:\*\/|$)/,
|
4 | greedy: true
|
5 | },
|
6 | 'string': {
|
7 |
|
8 | pattern: /"(?:\\(?:\r\n|[\s\S])|[^"\\\r\n])*"/,
|
9 | greedy: true
|
10 | },
|
11 | 'class-name': {
|
12 | pattern: /(\b(?:enum|struct)\s+(?:__attribute__\s*\(\([\s\S]*?\)\)\s*)?)\w+|\b[a-z]\w*_t\b/,
|
13 | lookbehind: true
|
14 | },
|
15 | 'keyword': /\b(?:_Alignas|_Alignof|_Atomic|_Bool|_Complex|_Generic|_Imaginary|_Noreturn|_Static_assert|_Thread_local|__attribute__|asm|auto|break|case|char|const|continue|default|do|double|else|enum|extern|float|for|goto|if|inline|int|long|register|return|short|signed|sizeof|static|struct|switch|typedef|typeof|union|unsigned|void|volatile|while)\b/,
|
16 | 'function': /\b[a-z_]\w*(?=\s*\()/i,
|
17 | 'number': /(?:\b0x(?:[\da-f]+(?:\.[\da-f]*)?|\.[\da-f]+)(?:p[+-]?\d+)?|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[+-]?\d+)?)[ful]{0,4}/i,
|
18 | 'operator': />>=?|<<=?|->|([-+&|:])\1|[?:~]|[-+*/%&|^!=<>]=?/
|
19 | });
|
20 |
|
21 | Prism.languages.insertBefore('c', 'string', {
|
22 | 'char': {
|
23 |
|
24 | pattern: /'(?:\\(?:\r\n|[\s\S])|[^'\\\r\n]){0,32}'/,
|
25 | greedy: true
|
26 | }
|
27 | });
|
28 |
|
29 | Prism.languages.insertBefore('c', 'string', {
|
30 | 'macro': {
|
31 |
|
32 |
|
33 | pattern: /(^[\t ]*)#\s*[a-z](?:[^\r\n\\/]|\/(?!\*)|\/\*(?:[^*]|\*(?!\/))*\*\/|\\(?:\r\n|[\s\S]))*/im,
|
34 | lookbehind: true,
|
35 | greedy: true,
|
36 | alias: 'property',
|
37 | inside: {
|
38 | 'string': [
|
39 | {
|
40 |
|
41 | pattern: /^(#\s*include\s*)<[^>]+>/,
|
42 | lookbehind: true
|
43 | },
|
44 | Prism.languages.c['string']
|
45 | ],
|
46 | 'char': Prism.languages.c['char'],
|
47 | 'comment': Prism.languages.c['comment'],
|
48 | 'macro-name': [
|
49 | {
|
50 | pattern: /(^#\s*define\s+)\w+\b(?!\()/i,
|
51 | lookbehind: true
|
52 | },
|
53 | {
|
54 | pattern: /(^#\s*define\s+)\w+\b(?=\()/i,
|
55 | lookbehind: true,
|
56 | alias: 'function'
|
57 | }
|
58 | ],
|
59 |
|
60 | 'directive': {
|
61 | pattern: /^(#\s*)[a-z]+/,
|
62 | lookbehind: true,
|
63 | alias: 'keyword'
|
64 | },
|
65 | 'directive-hash': /^#/,
|
66 | 'punctuation': /##|\\(?=[\r\n])/,
|
67 | 'expression': {
|
68 | pattern: /\S[\s\S]*/,
|
69 | inside: Prism.languages.c
|
70 | }
|
71 | }
|
72 | }
|
73 | });
|
74 |
|
75 | Prism.languages.insertBefore('c', 'function', {
|
76 |
|
77 | 'constant': /\b(?:EOF|NULL|SEEK_CUR|SEEK_END|SEEK_SET|__DATE__|__FILE__|__LINE__|__TIMESTAMP__|__TIME__|__func__|stderr|stdin|stdout)\b/
|
78 | });
|
79 |
|
80 | delete Prism.languages.c['boolean'];
|