Skip to content

Commit dfe578b

Browse files
v
1 parent 9c33d43 commit dfe578b

File tree

1 file changed

+36
-40
lines changed

1 file changed

+36
-40
lines changed

src/languages/v.js

Lines changed: 36 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,15 @@
1-
import { insertBefore } from '../util/language-util.js';
21
import clike from './clike.js';
32

43
/** @type {import('../types.d.ts').LanguageProto<'v'>} */
54
export default {
65
id: 'v',
76
base: clike,
8-
grammar ({ base }) {
9-
insertBefore(base, 'string', {
10-
'char': {
11-
pattern: /`(?:\\`|\\?[^`]{1,2})`/, // using {1,2} instead of `u` flag for compatibility
12-
alias: 'rune',
13-
},
14-
});
15-
7+
grammar () {
168
const genericInside = {
179
'punctuation': /[<>]/,
1810
'class-name': /\w+/,
1911
};
2012

21-
insertBefore(base, 'operator', {
22-
'attribute': {
23-
pattern:
24-
/(^[\t ]*)\[(?:deprecated|direct_array_access|flag|inline|live|ref_only|typedef|unsafe_fn|windows_stdcall)\]/m,
25-
lookbehind: true,
26-
alias: 'annotation',
27-
inside: {
28-
'punctuation': /[\[\]]/,
29-
'keyword': /\w+/,
30-
},
31-
},
32-
'generic': {
33-
pattern: /<\w+>(?=\s*[\)\{])/,
34-
inside: genericInside,
35-
},
36-
});
37-
38-
insertBefore(base, 'function', {
39-
'generic-function': {
40-
// e.g. foo<T>( ...
41-
pattern: /\b\w+\s*<\w+>(?=\()/,
42-
inside: {
43-
'function': /^\w+/,
44-
'generic': {
45-
pattern: /<\w+>/,
46-
inside: genericInside,
47-
},
48-
},
49-
},
50-
});
51-
5213
return {
5314
'string': {
5415
pattern: /r?(["'])(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,
@@ -88,6 +49,41 @@ export default {
8849
/~|\?|[*\/%^!=]=?|\+[=+]?|-[=-]?|\|[=|]?|&(?:=|&|\^=?)?|>(?:>=?|=)?|<(?:<=?|=|-)?|:=|\.\.\.?/,
8950
'builtin':
9051
/\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/,
52+
$insert: {
53+
'char': {
54+
$before: 'string',
55+
pattern: /`(?:\\`|\\?[^`]{1,2})`/, // using {1,2} instead of `u` flag for compatibility
56+
alias: 'rune',
57+
},
58+
'attribute': {
59+
$before: 'operator',
60+
pattern:
61+
/(^[\t ]*)\[(?:deprecated|direct_array_access|flag|inline|live|ref_only|typedef|unsafe_fn|windows_stdcall)\]/m,
62+
lookbehind: true,
63+
alias: 'annotation',
64+
inside: {
65+
'punctuation': /[\[\]]/,
66+
'keyword': /\w+/,
67+
},
68+
},
69+
'generic': {
70+
$before: 'operator',
71+
pattern: /<\w+>(?=\s*[\)\{])/,
72+
inside: genericInside,
73+
},
74+
'generic-function': {
75+
$before: 'function',
76+
// e.g. foo<T>( ...
77+
pattern: /\b\w+\s*<\w+>(?=\()/,
78+
inside: {
79+
'function': /^\w+/,
80+
'generic': {
81+
pattern: /<\w+>/,
82+
inside: genericInside,
83+
},
84+
},
85+
},
86+
},
9187
};
9288
},
9389
};

0 commit comments

Comments
 (0)