|
1 | | -import { insertBefore } from '../util/language-util.js'; |
2 | 1 | import clike from './clike.js'; |
3 | 2 |
|
4 | 3 | /** @type {import('../types.d.ts').LanguageProto<'v'>} */ |
5 | 4 | export default { |
6 | 5 | id: 'v', |
7 | 6 | 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 () { |
16 | 8 | const genericInside = { |
17 | 9 | 'punctuation': /[<>]/, |
18 | 10 | 'class-name': /\w+/, |
19 | 11 | }; |
20 | 12 |
|
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 | | - |
52 | 13 | return { |
53 | 14 | 'string': { |
54 | 15 | pattern: /r?(["'])(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/, |
@@ -88,6 +49,41 @@ export default { |
88 | 49 | /~|\?|[*\/%^!=]=?|\+[=+]?|-[=-]?|\|[=|]?|&(?:=|&|\^=?)?|>(?:>=?|=)?|<(?:<=?|=|-)?|:=|\.\.\.?/, |
89 | 50 | 'builtin': |
90 | 51 | /\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 | + }, |
91 | 87 | }; |
92 | 88 | }, |
93 | 89 | }; |
0 commit comments