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