-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprism-tact.js
171 lines (156 loc) · 4.14 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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/**
* @file Prism.js definition for Tact
* @link https://tact-lang.org
* @version 1.5.0
* @author Novus Nota (https://github.com/novusnota)
* @license MIT
*/
(function(Prism) {
Prism.languages.tact = {
// reserved keywords
'keyword': [
{
pattern: /\b(?:abstract|asm|as|catch|const|contract(?!:)|do|else|extend|extends|foreach|fun|get|if|in|import|initOf|inline|let|message(?!:)|mutates|native|override|primitive|public|repeat|return|self|struct(?!:)|trait(?!:)|try|until|virtual|while|with)\b/,
},
{ // 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/,
},
{ // keyword after as, see: https://prismjs.com/extending.html#object-notation
pattern: /(\bas\s+)(?:coins|remaining|bytes32|bytes64|int257|u?int(?:2[0-5][0-6]|1[0-9][0-9]|[1-9][0-9]?))\b/,
lookbehind: true,
greedy: true,
},
],
// 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,
},
{
// unused variable identifier
pattern: /\b_\b/
}
],
'operator': {
'pattern': /![!=]?|->|[+\-*/%=]=?|[<>]=|<<?|>>?|~|\|[\|=]?|&[&=]?|\^=?/,
},
'variable': {
'pattern': /\b[a-zA-Z_]\w*\b/,
},
};
// 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: {
'regex': [
{ // \\ \" \n \r \t \v \b \f
pattern: /\\[\\"nrtvbf]/,
},
{ // hexEscape, \x00 through \xFF
pattern: /\\x[0-9a-fA-F]{2}/,
},
{ // unicodeEscape, \u0000 through \uFFFF
pattern: /\\u[0-9a-fA-F]{4}/,
},
{ // unicodeCodePoint, \u{0} through \u{FFFFFF}
pattern: /\\u\{[0-9a-fA-F]{1,6}\}/,
},
],
'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/,
},
},
},
});
}(Prism));