-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
prism-tact.js
147 lines (133 loc) · 2.94 KB
/
prism-tact.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
(function (Prism) {
Prism.languages.tact = {
// reserved keywords
'keyword': [
{
pattern: /\b(?:abstract|as|const|contract(?!:)|do|else|extend|extends|fun|get|if|import|initOf|inline|let|message(?!:)|mutates|native|override|primitive|public|repeat|return|self|struct(?!:)|trait(?!:)|until|virtual|while|with)\b/,
},
{ // keyword after as
pattern: /(\bas\s+)\w+/,
lookbehind: true,
greedy: true,
},
{ // reserved function names
pattern: /\b(?:bounced|external|init|receive)\b/
},
],
// built-in types
'builtin': {
pattern: /\b(?:Address|Bool|Builder|Cell|Int|Slice|String|StringBuilder)\b/,
},
// SCREAMING_SNAKE_CASE for null values and names of constants
'constant': [
{
pattern: /\bnull\b/,
},
{
pattern: /\b[A-Z][A-Z0-9_]*\b/,
},
],
// UpperCamelCase for names of contracts, traits, structs, messages
'class-name': {
pattern: /\b[A-Z]\w*\b/,
},
// mappings to FunC
'attribute': [
{ // functions
pattern: /@name/,
inside: {
'function': /.+/,
},
},
{ // contract interfaces
pattern: /@interface/,
inside: {
'function': /.+/,
}
}
],
'function': {
pattern: /\b\w+(?=\()/,
},
'boolean': {
pattern: /\b(?:false|true)\b/,
},
'number': [
{ // hexadecimal, case-insensitive /i
pattern: /\b0x[0-9a-f](?:_?[0-9a-f])*\b/i,
},
{ // octal, case-insensitive /i
pattern: /\b0o[0-7](?:_?[0-7])*\b/i,
},
{ // binary, case-insensitive /i
pattern: /\b0b[01](?:_?[01])*\b/i,
},
{ // decimal integers, starting with 0
pattern: /\b0\d*\b/,
},
{ // other decimal integers
pattern: /\b[1-9](?:_?\d)*\b/,
},
],
'string': undefined,
'punctuation': {
pattern: /[{}[\]();,.:?]/,
},
'comment': [
{ // single-line
pattern: /(^|[^\\:])\/\/.*/,
lookbehind: true,
greedy: true,
},
{ // multi-line
pattern: /(^|[^\\])\/\*[\s\S]*?(?:\*\/|$)/,
lookbehind: true,
greedy: true,
}
],
'operator': {
'pattern': /![!=]?|[+\-*/%=]=?|[<>]=|<<?|>>?|\|\|?|&&?/,
},
};
// strings, made this way to not collide with other entities
Prism.languages.insertBefore('tact', 'string', {
'string-literal': {
pattern: /(?:(")(?:\\.|(?!\1)[^\\\r\n])*\1(?!\1))/,
greedy: true,
inside: {
'string': {
pattern: /[\s\S]+/,
},
},
},
});
// map and bounced message generic type modifiers
Prism.languages.insertBefore('tact', 'keyword', {
'generics': {
pattern: /(?:\b(?:bounced|map)\b<[^\\\r\n]*>)/,
greedy: true,
inside: {
'builtin': [
Prism.languages['tact']['builtin'],
{
pattern: /\b(?:bounced(?=<)|map(?=<))\b/
},
],
'class-name': Prism.languages['tact']['class-name'],
'punctuation': {
pattern: /[<>(),.?]/,
},
'keyword': [
{
pattern: /\bas\b/,
},
{
pattern: /(\bas\s+)\w+/,
lookbehind: true,
greedy: true,
},
],
},
},
});
}(Prism));