1 | (function (Prism) {
|
2 |
|
3 | function literal(str) {
|
4 | return function () { return str; };
|
5 | }
|
6 |
|
7 | var keyword = /\b(?:align|allowzero|and|asm|async|await|break|cancel|catch|comptime|const|continue|defer|else|enum|errdefer|error|export|extern|fn|for|if|inline|linksection|nakedcc|noalias|null|or|orelse|packed|promise|pub|resume|return|stdcallcc|struct|suspend|switch|test|threadlocal|try|undefined|union|unreachable|usingnamespace|var|volatile|while)\b/;
|
8 |
|
9 | var IDENTIFIER = '\\b(?!' + keyword.source + ')(?!\\d)\\w+\\b';
|
10 | var ALIGN = /align\s*\((?:[^()]|\([^()]*\))*\)/.source;
|
11 | var PREFIX_TYPE_OP = /(?:\?|\bpromise->|(?:\[[^[\]]*\]|\*(?!\*)|\*\*)(?:\s*<ALIGN>|\s*const\b|\s*volatile\b|\s*allowzero\b)*)/.source.replace(/<ALIGN>/g, literal(ALIGN));
|
12 | var SUFFIX_EXPR = /(?:\bpromise\b|(?:\berror\.)?<ID>(?:\.<ID>)*(?!\s+<ID>))/.source.replace(/<ID>/g, literal(IDENTIFIER));
|
13 | var TYPE = '(?!\\s)(?:!?\\s*(?:' + PREFIX_TYPE_OP + '\\s*)*' + SUFFIX_EXPR + ')+';
|
14 |
|
15 | |
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 | Prism.languages.zig = {
|
33 | 'comment': [
|
34 | {
|
35 | pattern: /\/{3}.*/,
|
36 | alias: 'doc-comment'
|
37 | },
|
38 | /\/{2}.*/
|
39 | ],
|
40 | 'string': [
|
41 | {
|
42 |
|
43 | pattern: /(^|[^\\@])c?"(?:[^"\\\r\n]|\\.)*"/,
|
44 | lookbehind: true,
|
45 | greedy: true
|
46 | },
|
47 | {
|
48 |
|
49 | pattern: /([\r\n])([ \t]+c?\\{2}).*(?:(?:\r\n?|\n)\2.*)*/,
|
50 | lookbehind: true,
|
51 | greedy: true
|
52 | },
|
53 | {
|
54 |
|
55 | pattern: /(^|[^\\])'(?:[^'\\\r\n]|\\(?:.|x[a-fA-F\d]{2}|u\{[a-fA-F\d]{1,6}\}))'/,
|
56 | lookbehind: true,
|
57 | greedy: true
|
58 | }
|
59 | ],
|
60 | 'builtin': /\B@(?!\d)\w+(?=\s*\()/,
|
61 | 'label': {
|
62 | pattern: /(\b(?:break|continue)\s*:\s*)\w+\b|\b(?!\d)\w+\b(?=\s*:\s*(?:\{|while\b))/,
|
63 | lookbehind: true
|
64 | },
|
65 | 'class-name': [
|
66 |
|
67 | /\b(?!\d)\w+(?=\s*=\s*(?:(?:extern|packed)\s+)?(?:enum|struct|union)\s*[({])/,
|
68 | {
|
69 |
|
70 |
|
71 |
|
72 | pattern: RegExp(/(:\s*)<TYPE>(?=\s*(?:<ALIGN>\s*)?[=;,)])|<TYPE>(?=\s*(?:<ALIGN>\s*)?\{)/.source.replace(/<TYPE>/g, literal(TYPE)).replace(/<ALIGN>/g, literal(ALIGN))),
|
73 | lookbehind: true,
|
74 | inside: null
|
75 | },
|
76 | {
|
77 |
|
78 | pattern: RegExp(/(\)\s*)<TYPE>(?=\s*(?:<ALIGN>\s*)?;)/.source.replace(/<TYPE>/g, literal(TYPE)).replace(/<ALIGN>/g, literal(ALIGN))),
|
79 | lookbehind: true,
|
80 | inside: null
|
81 | }
|
82 | ],
|
83 | 'builtin-types': {
|
84 | pattern: /\b(?:anyerror|bool|c_u?(?:short|int|long|longlong)|c_longdouble|c_void|comptime_(?:float|int)|[iu](?:8|16|32|64|128|size)|f(?:16|32|64|128)|noreturn|type|void)\b/,
|
85 | alias: 'keyword'
|
86 | },
|
87 | 'keyword': keyword,
|
88 | 'function': /\b(?!\d)\w+(?=\s*\()/,
|
89 | 'number': /\b(?:0b[01]+|0o[0-7]+|0x[a-fA-F\d]+(?:\.[a-fA-F\d]*)?(?:[pP][+-]?[a-fA-F\d]+)?|\d+(?:\.\d*)?(?:[eE][+-]?\d+)?)\b/,
|
90 | 'boolean': /\b(?:false|true)\b/,
|
91 | 'operator': /\.[*?]|\.{2,3}|[-=]>|\*\*|\+\+|\|\||(?:<<|>>|[-+*]%|[-+*/%^&|<>!=])=?|[?~]/,
|
92 | 'punctuation': /[.:,;(){}[\]]/
|
93 | };
|
94 |
|
95 | Prism.languages.zig['class-name'].forEach(function (obj) {
|
96 | if (obj.inside === null) {
|
97 | obj.inside = Prism.languages.zig;
|
98 | }
|
99 | });
|
100 |
|
101 | }(Prism));
|