1 | (function (Prism) {
|
2 | var interpolationExpr = {
|
3 | pattern: /[\s\S]+/,
|
4 | inside: null
|
5 | };
|
6 |
|
7 | Prism.languages.v = Prism.languages.extend('clike', {
|
8 | 'string': [
|
9 | {
|
10 | pattern: /`(?:\\`|\\?[^`]{1,2})`/,
|
11 | alias: 'rune'
|
12 | },
|
13 | {
|
14 | pattern: /r?(["'])(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,
|
15 | alias: 'quoted-string',
|
16 | greedy: true,
|
17 | inside: {
|
18 | 'interpolation': {
|
19 | pattern: /((?:^|[^\\])(?:\\{2})*)\$(?:\{[^{}]*\}|\w+(?:\.\w+(?:\([^\(\)]*\))?|\[[^\[\]]+\])*)/,
|
20 | lookbehind: true,
|
21 | inside: {
|
22 | 'interpolation-variable': {
|
23 | pattern: /^\$\w[\s\S]*$/,
|
24 | alias: 'variable'
|
25 | },
|
26 | 'interpolation-punctuation': {
|
27 | pattern: /^\$\{|\}$/,
|
28 | alias: 'punctuation'
|
29 | },
|
30 | 'interpolation-expression': interpolationExpr
|
31 | }
|
32 | }
|
33 | }
|
34 | }
|
35 | ],
|
36 | 'class-name': {
|
37 | pattern: /(\b(?:enum|interface|struct|type)\s+)(?:C\.)?\w+/,
|
38 | lookbehind: true
|
39 | },
|
40 | 'keyword': /(?:\b(?:as|asm|assert|atomic|break|chan|const|continue|defer|else|embed|enum|fn|for|__global|go(?:to)?|if|import|in|interface|is|lock|match|module|mut|none|or|pub|return|rlock|select|shared|sizeof|static|struct|type(?:of)?|union|unsafe)|\$(?:if|else|for)|#(?:include|flag))\b/,
|
41 | 'number': /\b(?:0x[a-f\d]+(?:_[a-f\d]+)*|0b[01]+(?:_[01]+)*|0o[0-7]+(?:_[0-7]+)*|\d+(?:_\d+)*(?:\.\d+(?:_\d+)*)?)\b/i,
|
42 | 'operator': /~|\?|[*\/%^!=]=?|\+[=+]?|-[=-]?|\|[=|]?|&(?:=|&|\^=?)?|>(?:>=?|=)?|<(?:<=?|=|-)?|:=|\.\.\.?/,
|
43 | 'builtin': /\b(?:any(?:_int|_float)?|bool|byte(?:ptr)?|charptr|f(?:32|64)|i(?:8|16|nt|64|128)|rune|size_t|string|u(?:16|32|64|128)|voidptr)\b/
|
44 | });
|
45 |
|
46 | interpolationExpr.inside = Prism.languages.v;
|
47 |
|
48 | Prism.languages.insertBefore('v', 'operator', {
|
49 | 'attribute': {
|
50 | pattern: /(^[\t ]*)\[(?:deprecated|unsafe_fn|typedef|live|inline|flag|ref_only|windows_stdcall|direct_array_access)\]/m,
|
51 | lookbehind: true,
|
52 | alias: 'annotation',
|
53 | inside: {
|
54 | 'punctuation': /[\[\]]/,
|
55 | 'keyword': /\w+/
|
56 | }
|
57 | },
|
58 | 'generic': {
|
59 | pattern: /<\w+>(?=\s*[\)\{])/,
|
60 | inside: {
|
61 | 'punctuation': /[<>]/,
|
62 | 'class-name': /\w+/
|
63 | }
|
64 | }
|
65 | });
|
66 |
|
67 | Prism.languages.insertBefore('v', 'function', {
|
68 | 'generic-function': {
|
69 |
|
70 | pattern: /\b\w+\s*<\w+>(?=\()/,
|
71 | inside: {
|
72 | 'function': /^\w+/,
|
73 | 'generic': {
|
74 | pattern: /<\w+>/,
|
75 | inside: Prism.languages.v.generic.inside
|
76 | }
|
77 | }
|
78 | }
|
79 | });
|
80 | }(Prism));
|