Skip to content

Commit 7296270

Browse files
authored
Added support for V langauge (#2687)
1 parent 6e34771 commit 7296270

14 files changed

+585
-2
lines changed

components.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components.json

+5
Original file line numberDiff line numberDiff line change
@@ -1199,6 +1199,11 @@
11991199
"alias": ["uscript", "uc"],
12001200
"owner": "RunDevelopment"
12011201
},
1202+
"v": {
1203+
"title": "V",
1204+
"require": "clike",
1205+
"owner": "taggon"
1206+
},
12021207
"vala": {
12031208
"title": "Vala",
12041209
"require": "clike",

components/prism-v.js

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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})`/, // using {1,2} instead of `u` flag for compatibility
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: /^\s*\[(?:deprecated|unsafe_fn|typedef|live|inline|flag|ref_only|windows_stdcall|direct_array_access)\]/m,
51+
alias: 'annotation',
52+
inside: {
53+
'punctuation': /[\[\]]/,
54+
'keyword': /\w+/
55+
}
56+
},
57+
'generic': {
58+
pattern: /\<\w+\>(?=\s*[\)\{])/,
59+
inside: {
60+
'punctuation': /[<>]/,
61+
'class-name': /\w+/
62+
}
63+
}
64+
});
65+
66+
Prism.languages.insertBefore('v', 'function', {
67+
'generic-function': {
68+
// e.g. foo<T>( ...
69+
pattern: /\w+\s*<\w+>(?=\()/,
70+
inside: {
71+
'function': /^\w+/,
72+
'generic': {
73+
pattern: /<\w+>/,
74+
inside: Prism.languages.v.generic.inside
75+
}
76+
}
77+
}
78+
});
79+
})(Prism);

components/prism-v.min.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/prism-v.html

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<h2>Comments</h2>
2+
<pre><code>// This is a comment
3+
/* This is a comment
4+
on multiple lines */</code></pre>
5+
6+
<h2>Numbers</h2>
7+
<pre><code>123
8+
0x7B
9+
0b01111011
10+
0o173
11+
170141183460469231731687303715884105727
12+
1_000_000
13+
0b0_11
14+
3_122.55
15+
0xF_F
16+
0o17_3
17+
72.40
18+
072.40
19+
2.71828
20+
</code></pre>
21+
22+
<h2>Runes and strings</h2>
23+
<pre><code>'\t'
24+
'\000'
25+
'\x07'
26+
'\u12e4'
27+
'\U00101234'
28+
`abc`
29+
`multi-line
30+
string`
31+
"Hello, world!"
32+
"multi-line
33+
string"</code></pre>
34+
35+
<h2>String interpolation</h2>
36+
<pre><code>'Hello, $name!'
37+
"age = $user.age"
38+
'can register = ${user.age > 13}'
39+
'x = ${x:4.2f}'
40+
'[${x:10}]'
41+
'[${int(x):-10}]'
42+
</code></pre>
43+
44+
<h2>Struct</h2>
45+
<pre><code>struct Foo {
46+
a int // private immutable (default)
47+
mut:
48+
b int // private mutable
49+
c int // (you can list multiple fields with the same access modifier)
50+
pub:
51+
d int // public immutable (readonly)
52+
pub mut:
53+
e int // public, but mutable only in parent module
54+
__global:
55+
f int // public and mutable both inside and outside parent module
56+
} // (not recommended to use, that's why the 'global' keyword
57+
// starts with __)
58+
</code></pre>
59+
60+
<h2>Functions</h2>
61+
<pre><code>func(a, b int, z float64) bool { return a*b &lt; int(z) }</code></pre>
62+
63+
<h2>Full example</h2>
64+
<pre><code>
65+
module mymodule
66+
67+
import external_module
68+
69+
fn sqr(n int) int {
70+
return n * n
71+
}
72+
73+
fn run(value int, op fn (int) int) int {
74+
return op(value)
75+
}
76+
77+
fn main() {
78+
println(run(5, sqr)) // "25"
79+
// Anonymous functions can be declared inside other functions:
80+
double_fn := fn (n int) int {
81+
return n + n
82+
}
83+
println(run(5, double_fn)) // "10"
84+
// Functions can be passed around without assigning them to variables:
85+
res := run(5, fn (n int) int {
86+
return n + n
87+
})
88+
89+
external_module.say_hi()
90+
}
91+
</code></pre>

plugins/autoloader/prism-autoloader.js

+1
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@
141141
"textile": "markup",
142142
"twig": "markup",
143143
"typescript": "javascript",
144+
"v": "clike",
144145
"vala": "clike",
145146
"vbnet": "basic",
146147
"velocity": "markup",

plugins/autoloader/prism-autoloader.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
true
2+
false
3+
4+
----------------------------------------------------
5+
6+
[
7+
["boolean", "true"],
8+
["boolean", "false"]
9+
]
10+
11+
----------------------------------------------------
12+
13+
Check for boolean
+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
struct Abc { }
2+
type Alphabet = Abc | Xyz
3+
enum Token { }
4+
interface Speaker { }
5+
struct Repo<T> { }
6+
7+
----------------------------------------------------
8+
9+
[
10+
["keyword", "struct"],
11+
["class-name", "Abc"],
12+
["punctuation", "{"],
13+
["punctuation", "}"],
14+
15+
["keyword", "type"],
16+
["class-name", "Alphabet"],
17+
["operator", "="],
18+
" Abc ",
19+
["operator", "|"],
20+
" Xyz\r\n",
21+
22+
["keyword", "enum"],
23+
["class-name", "Token"],
24+
["punctuation", "{"],
25+
["punctuation", "}"],
26+
27+
["keyword", "interface"],
28+
["class-name", "Speaker"],
29+
["punctuation", "{"],
30+
["punctuation", "}"],
31+
32+
["keyword", "struct"],
33+
["class-name", "Repo"],
34+
["generic", [
35+
["punctuation", "<"],
36+
["class-name", "T"],
37+
["punctuation", ">"]
38+
]],
39+
["punctuation", "{"],
40+
["punctuation", "}"]
41+
]

0 commit comments

Comments
 (0)