-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for V langauge (#2687)
- Loading branch information
Showing
14 changed files
with
585 additions
and
2 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
(function(Prism) { | ||
var interpolationExpr = { | ||
pattern: /[\s\S]+/, | ||
inside: null | ||
}; | ||
|
||
Prism.languages.v = Prism.languages.extend('clike', { | ||
'string': [ | ||
{ | ||
pattern: /`(?:\\\`|\\?[^\`]{1,2})`/, // using {1,2} instead of `u` flag for compatibility | ||
alias: 'rune' | ||
}, | ||
{ | ||
pattern: /r?(["'])(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/, | ||
alias: 'quoted-string', | ||
greedy: true, | ||
inside: { | ||
'interpolation': { | ||
pattern: /((?:^|[^\\])(?:\\{2})*)\$(?:\{[^{}]*\}|\w+(?:\.\w+(?:\([^\(\)]*\))?|\[[^\[\]]+\])*)/, | ||
lookbehind: true, | ||
inside: { | ||
'interpolation-variable': { | ||
pattern: /^\$\w[\s\S]*$/, | ||
alias: 'variable' | ||
}, | ||
'interpolation-punctuation': { | ||
pattern: /^\${|}$/, | ||
alias: 'punctuation' | ||
}, | ||
'interpolation-expression': interpolationExpr | ||
} | ||
} | ||
} | ||
} | ||
], | ||
'class-name': { | ||
pattern: /(\b(?:enum|interface|struct|type)\s+)(?:C\.)?[\w]+/, | ||
lookbehind: true | ||
}, | ||
'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/, | ||
'number': /\b(?:0x[a-f\d]+(?:_[a-f\d]+)*|0b[01]+(?:_[01]+)*|0o[0-7]+(?:_[0-7]+)*|\d+(?:_\d+)*(?:\.\d+(?:_\d+)*)?)\b/i, | ||
'operator': /~|\?|[*\/%^!=]=?|\+[=+]?|-[=-]?|\|[=|]?|&(?:=|&|\^=?)?|>(?:>=?|=)?|<(?:<=?|=|-)?|:=|\.\.\.?/, | ||
'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/ | ||
}); | ||
|
||
interpolationExpr.inside = Prism.languages.v; | ||
|
||
Prism.languages.insertBefore('v', 'operator', { | ||
'attribute': { | ||
pattern: /^\s*\[(?:deprecated|unsafe_fn|typedef|live|inline|flag|ref_only|windows_stdcall|direct_array_access)\]/m, | ||
alias: 'annotation', | ||
inside: { | ||
'punctuation': /[\[\]]/, | ||
'keyword': /\w+/ | ||
} | ||
}, | ||
'generic': { | ||
pattern: /\<\w+\>(?=\s*[\)\{])/, | ||
inside: { | ||
'punctuation': /[<>]/, | ||
'class-name': /\w+/ | ||
} | ||
} | ||
}); | ||
|
||
Prism.languages.insertBefore('v', 'function', { | ||
'generic-function': { | ||
// e.g. foo<T>( ... | ||
pattern: /\w+\s*<\w+>(?=\()/, | ||
inside: { | ||
'function': /^\w+/, | ||
'generic': { | ||
pattern: /<\w+>/, | ||
inside: Prism.languages.v.generic.inside | ||
} | ||
} | ||
} | ||
}); | ||
})(Prism); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<h2>Comments</h2> | ||
<pre><code>// This is a comment | ||
/* This is a comment | ||
on multiple lines */</code></pre> | ||
|
||
<h2>Numbers</h2> | ||
<pre><code>123 | ||
0x7B | ||
0b01111011 | ||
0o173 | ||
170141183460469231731687303715884105727 | ||
1_000_000 | ||
0b0_11 | ||
3_122.55 | ||
0xF_F | ||
0o17_3 | ||
72.40 | ||
072.40 | ||
2.71828 | ||
</code></pre> | ||
|
||
<h2>Runes and strings</h2> | ||
<pre><code>'\t' | ||
'\000' | ||
'\x07' | ||
'\u12e4' | ||
'\U00101234' | ||
`abc` | ||
`multi-line | ||
string` | ||
"Hello, world!" | ||
"multi-line | ||
string"</code></pre> | ||
|
||
<h2>String interpolation</h2> | ||
<pre><code>'Hello, $name!' | ||
"age = $user.age" | ||
'can register = ${user.age > 13}' | ||
'x = ${x:4.2f}' | ||
'[${x:10}]' | ||
'[${int(x):-10}]' | ||
</code></pre> | ||
|
||
<h2>Struct</h2> | ||
<pre><code>struct Foo { | ||
a int // private immutable (default) | ||
mut: | ||
b int // private mutable | ||
c int // (you can list multiple fields with the same access modifier) | ||
pub: | ||
d int // public immutable (readonly) | ||
pub mut: | ||
e int // public, but mutable only in parent module | ||
__global: | ||
f int // public and mutable both inside and outside parent module | ||
} // (not recommended to use, that's why the 'global' keyword | ||
// starts with __) | ||
</code></pre> | ||
|
||
<h2>Functions</h2> | ||
<pre><code>func(a, b int, z float64) bool { return a*b < int(z) }</code></pre> | ||
|
||
<h2>Full example</h2> | ||
<pre><code> | ||
module mymodule | ||
|
||
import external_module | ||
|
||
fn sqr(n int) int { | ||
return n * n | ||
} | ||
|
||
fn run(value int, op fn (int) int) int { | ||
return op(value) | ||
} | ||
|
||
fn main() { | ||
println(run(5, sqr)) // "25" | ||
// Anonymous functions can be declared inside other functions: | ||
double_fn := fn (n int) int { | ||
return n + n | ||
} | ||
println(run(5, double_fn)) // "10" | ||
// Functions can be passed around without assigning them to variables: | ||
res := run(5, fn (n int) int { | ||
return n + n | ||
}) | ||
|
||
external_module.say_hi() | ||
} | ||
</code></pre> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
true | ||
false | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["boolean", "true"], | ||
["boolean", "false"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Check for boolean |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
struct Abc { } | ||
type Alphabet = Abc | Xyz | ||
enum Token { } | ||
interface Speaker { } | ||
struct Repo<T> { } | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["keyword", "struct"], | ||
["class-name", "Abc"], | ||
["punctuation", "{"], | ||
["punctuation", "}"], | ||
|
||
["keyword", "type"], | ||
["class-name", "Alphabet"], | ||
["operator", "="], | ||
" Abc ", | ||
["operator", "|"], | ||
" Xyz\r\n", | ||
|
||
["keyword", "enum"], | ||
["class-name", "Token"], | ||
["punctuation", "{"], | ||
["punctuation", "}"], | ||
|
||
["keyword", "interface"], | ||
["class-name", "Speaker"], | ||
["punctuation", "{"], | ||
["punctuation", "}"], | ||
|
||
["keyword", "struct"], | ||
["class-name", "Repo"], | ||
["generic", [ | ||
["punctuation", "<"], | ||
["class-name", "T"], | ||
["punctuation", ">"] | ||
]], | ||
["punctuation", "{"], | ||
["punctuation", "}"] | ||
] |
Oops, something went wrong.