-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
prism-odin.js
61 lines (52 loc) · 1.6 KB
/
prism-odin.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
(function (Prism) {
var escapes = /\\(?:["'\\abefnrtv]|0[0-7]{2}|U[\dA-Fa-f]{6}|u[\dA-Fa-f]{4}|x[\dA-Fa-f]{2})/.source;
function withEscapes(pattern, flags) {
return RegExp(pattern.replace(/<escapes>/g, escapes), flags);
}
Prism.languages.odin = {
/**
* The current implementation of multiline comments doesn't support nesting.
*/
'comment': [
{
pattern: /\/\*[\s\S]*?(?:\*\/|$)/,
greedy: true
},
{
pattern: /#![^\n\r]*/,
greedy: true
},
{
pattern: /\/\/[^\n\r]*/,
greedy: true
}
],
/**
* Should be found before strings because of '"'"- and '`'`-like sequences.
*/
'char': {
pattern: withEscapes(/'(?:<escapes>|[^\n\r'\\])'/.source),
inside: {
'symbol': withEscapes(/<escapes>/.source)
}
},
'string': [
{
pattern: /`[^`]*`/,
greedy: true
},
{
pattern: withEscapes(/"(?:<escapes>|[^\n\r"\\])*"/.source),
greedy: true,
inside: {
'symbol': withEscapes(/<escapes>/.source)
}
}
],
'number': /(?:\b0(?:b[01_]+|d[\d_]+|h_*(?:(?:(?:[\dA-Fa-f]_*){8}){1,2}|(?:[\dA-Fa-f]_*){4})|o[0-7_]+|x[\dA-F_a-f]+|z[\dAB_ab]+)\b|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:[Ee][+-]?\d*)?[ijk]?)/,
'boolean': /\b(?:_|false|nil|true)\b/,
'keyword': /\b(?:asm|auto_cast|bit_set|break|case|cast|context|continue|defer|distinct|do|dynamic|else|enum|fallthrough|for|foreign|if|import|in|map|matrix|not_in|or_else|or_return|package|proc|return|struct|switch|transmute|typeid|union|using|when|where)\b/,
'function': /\b\w+(?=\()/,
'operator': /\+\+|---?|->|\.\.[<=]?|(?:&~|[-!*+/=~]|[%&<>|]{1,2})=?|[#$(),.:;?@\[\]^{}]/
};
}(Prism));