Skip to content

Commit bd15682

Browse files
authored
Added Tact, FunC, Fift, TL-B support (#13)
* Added Tact, FunC, Fift, TL-B support Whose are the common languages of [TON](https://ton.org). * chore: Updated list of supported languages * feat: support Tact 1.3.0
1 parent 5dd5b63 commit bd15682

File tree

6 files changed

+408
-0
lines changed

6 files changed

+408
-0
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,12 @@ The new version of `grammars.dat` will appear in the `libprisma/grammars.dat`.
129129
|`F#`|`fsharp`|
130130
|`Factor`|`factor`|
131131
|`False`|`false`|
132+
|`Fift`|`fift`|
132133
|`Firestore security rules`|`firestore-security-rules`|
133134
|`Flow`|`flow`|
134135
|`Fortran`|`fortran`|
135136
|`FreeMarker Template Language`|`ftl`|
137+
|`FunC`|`func`|
136138
|`GameMaker Language`|`gml`,`gamemakerlanguage`|
137139
|`GAP (CAS)`|`gap`|
138140
|`G-code`|`gcode`|
@@ -290,6 +292,7 @@ The new version of `grammars.dat` will appear in the `libprisma/grammars.dat`.
290292
|`SuperCollider`|`supercollider`,`sclang`|
291293
|`Swift`|`swift`|
292294
|`Systemd configuration file`|`systemd`|
295+
|`Tact`|`tact`|
293296
|`T4 templating`|`t4-templating`|
294297
|`T4 Text Templates (C#)`|`t4-cs`,`t4`|
295298
|`VB.Net`|`vbnet`|
@@ -299,6 +302,8 @@ The new version of `grammars.dat` will appear in the `libprisma/grammars.dat`.
299302
|`Template Toolkit 2`|`tt2`|
300303
|`TOML`|`toml`|
301304
|`Tremor`|`tremor`,`tremor`,`trickle`,`troy`|
305+
|`Type Language`|`tl`|
306+
|`Type Language - Binary`|`tlb`|
302307
|`TypoScript`|`typoscript`,`tsconfig`|
303308
|`UnrealScript`|`unrealscript`,`unrealscript`,`uscript`,`uc`|
304309
|`UO Razor Script`|`uorazor`|

components/prism-fift.js

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
/**
2+
* @file Prism.js definition for Fift
3+
* @link https://docs.ton.org/develop/fift/overview
4+
* @author Nikita Sobolev (https://github.com/sobolevn)
5+
* @license MIT
6+
*/
7+
Prism.languages.fift = {
8+
'symbol': [
9+
/[xX]\{[0-9a-fA-F_]*\}/,
10+
/[bB]\{[01]*\}/,
11+
/'\S+/,
12+
],
13+
'string': /"([^"\r\n\\]|\\.)*"/,
14+
15+
'comment': [
16+
{
17+
pattern: /\/\*[\s\S]*?(?:\*\/|$)/,
18+
lookbehind: true,
19+
greedy: true,
20+
},
21+
{
22+
pattern: /\/\/.*/,
23+
lookbehind: true,
24+
greedy: true,
25+
},
26+
],
27+
28+
'operator': [
29+
// Full list can be found in
30+
// Appendix A. List of Fift words
31+
// Ordered the same way source code does this.
32+
// Except: shorter words must follow
33+
// longer ones with the same base part.
34+
// Example: `#` comes after `#s`
35+
/#>/, /#s/, /\$#/, /#/,
36+
37+
/\$\+/, /\$,/, /\$\d/, /\$=/, /\$(?=\()/,
38+
/\$>smca/, /\$>s/,
39+
/\$@\+/, /\$@\?\+/, /\$@\?/, /\$@/,
40+
/\$cmp/, /\$len/, /\$pos/, /\$reverse/,
41+
42+
/%1<</,
43+
44+
/\('\)/, /\(-trailing\)/, /\(\.\)/, /\(atom\)/, /\(b\.\)/,
45+
/\(compile\)/, /\(create\)/, /\(def\?\)/, /\(dump\)/, /\(execute\)/,
46+
/\(forget\)/, /\(number\)/, /\(x\.\)/, /\(\{\)/, /\(\}\)/,
47+
48+
/\*\/cmod/, /\*\/c/, /\*\/mod/, /\*\/rmod/, /\*\/r/, /\*\//,
49+
/\*>>c/, /\*>>r/, /\*>>/, /\*mod/, /\*/,
50+
51+
/\+!/, /\+/, /,/, /-!/, /-/, /!/,
52+
/-1<</, /\._/, /\.dump/, /\.l/, /\.sl/, /\.s/, /\.tc/,
53+
/\//, /\/\*/, /\/cmod/, /\/c/, /\/mod/, /\/rmod/, /\/r/,
54+
/0!/, /0<=/, /0<>/, /0</, /0=/, /0>=/, /0>/,
55+
/1\+!/, /1\+/, /1-!/, /1-/, /1<</, /1<<1-/,
56+
/2\*/, /2\+/, /2-/, /2\//, /2=:/,
57+
58+
/::_/, /::/, /:_/, /=:/, /:/,
59+
60+
/<#/, /<<\/c/, /<<\/r/, /<=/, /<>/, /<b/, /<s/, /<<\//,
61+
/<</, /</, /=/,
62+
63+
/>=/, />>c/, />>r/, />>/, />/,
64+
65+
/\?dup/,
66+
67+
/@'/, /@/,
68+
69+
/B\+/, /B,/, /B=/, /B>Li@\+/, /B>Li@/, /B>Lu@\+/, /B>Lu@/, /B>boc/,
70+
/B>file/, /B>i@\+/, /B>i@/, /B>u@\+/, /B>u@/,
71+
/B@\?\+/, /B@\+/, /B@\?/, /B@/,
72+
/Bcmp/, /BhashB/, /Bhashu/, /Bhash/, /Blen/, /Bx\./,
73+
/B\|/, /Li>B/, /Lu>B/,
74+
75+
/\[\]/, /\[compile\]/, /\[/, /\]/,
76+
77+
/atom\?/,
78+
79+
/b\+/, /b\._/, /b\./,
80+
/b>idict!\+/, /b>idict!/, /b>sdict!\+/, /b>sdict!/,
81+
/b>udict!\+/, /b>udict!/,
82+
/b>/, /boc\+>B/, /boc>B/,
83+
84+
/csr\./,
85+
/def\?/,
86+
/empty\?/, /eq\?/,
87+
/file-exists\?/, /file>B/,
88+
89+
/i,/, /i>B/, /i@\+/, /i@\?\+/, /i@\?/, /i@/,
90+
/idict!\+/, /idict!/, /idict-/, /idict@-/, /idict@/,
91+
92+
/null!/, /null\?/,
93+
/pfxdict!\+/, /pfxdict!/, /pfxdict@/, /priv>pub/,
94+
/ref@\+/, /ref@/, /ref@\?\+/, /ref@\?/,
95+
96+
/s,/, /s>c/, /s>/,
97+
/sdict!\+/, /sdict!/, /sdict-/, /sdict@-/, /sdict@/,
98+
/smca>\$/, /sr,/,
99+
100+
/tuple\?/,
101+
102+
/u,/, /u>B/, /u@\+/, /u@\?\+/, /u@\?/,
103+
/udict!\+/, /udict!/, /udict-/, /udict@-/, /udict@/,
104+
/undef\?/,
105+
106+
/x\._/, /x\./,
107+
108+
/\|\+/, /\|/, /\|_/,
109+
110+
/\?\./, /'/,
111+
112+
// Should be the last:
113+
/\./,
114+
],
115+
116+
'keyword': /\b(?:-roll|-rot|-trailing|-trailing0|2constant|2drop|2dup|2over|2swap|abort|abs|allot|and|anon|atom|bbitrefs|bbits|bl|box|brefs|brembitrefs|brembits|bremrefs|bye|caddr|cadr|car|cddr|cdr|char|chr|cmp|cond|cons|constant|count|cr|create|depth|dictmap|dictmerge|dictnew|does|drop|dup|ed25519_chksign|ed25519_sign|ed25519_sign_uint|emit|exch|exch2|execute|explode|find|first|fits|forget|gasrunvm|gasrunvmcode|gasrunvmctx|gasrunvmdict|halt|hash|hashB|hashu|hold|hole|if|ifnot|include|list|max|min|minmax|mod|negate|newkeypair|nil|nip|nop|not|now|null|or|over|pair|pick|quit|remaining|reverse|roll|rot|runvm|runvmcode|runvmctx|runvmdict|sbitrefs|sbits|second|sgn|shash|sign|single|skipspc|space|srefs|swap|ten|third|times|triple|tuck|tuple|type|ufits|uncons|unpair|unsingle|until|untriple|untuple|variable|while|word|words|xor)\b/,
117+
'boolean': /\b(?:false|true)\b/,
118+
119+
'number': [
120+
/(0[xX][0-9a-fA-F]+)/,
121+
/(0[bB][01]+)/,
122+
/(-?\d+(\/-?\d+)?)/,
123+
],
124+
'variable': /[\w$-]+/,
125+
126+
'punctuation': /[\[\{\}\],\(\)]/,
127+
};

components/prism-func.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/**
2+
* @file Prism.js definition for FunC
3+
* @link https://docs.ton.org/develop/func/overview
4+
* @version 0.2.0
5+
* @author Nikita Sobolev (https://github.com/sobolevn)
6+
* @license MIT
7+
*/
8+
(function (Prism) {
9+
// 1. Does not start from "
10+
// 2. Can start from ` and end with `, containing any character
11+
// 3. Starts with underscore or { or } and have more than 1 character after it
12+
// 4. Starts with letter, contains letters, numbers and underscores
13+
var identifier = /(?!")(`([^`]+)`|((?=_)_|(?=\{)\{|(?=\})\}|(?![_`{}]))([^;,\[\]\(\)\s~.]+))/;
14+
var string = /"[^\n"]+"[Hhcusa]?/;
15+
var number = /\b([\d_]+|0x[\d_a-fA-F]+|0b[1_0]+)\b/;
16+
17+
Prism.languages.func = {
18+
'include': {
19+
pattern: /#include(.*);/,
20+
inside: {
21+
'keyword': /#include/,
22+
'string': string,
23+
'punctuation': /;/
24+
},
25+
},
26+
'pragma': {
27+
pattern: /#pragma(.*);/,
28+
inside: {
29+
'keyword': /#pragma|not-version|version/,
30+
'number': /(\d+)(.\d+)?(.\d+)?/,
31+
'operator': [/>=/, /<=/, /=/, />/, /</, /\^/],
32+
'punctuation': /;/
33+
}
34+
},
35+
36+
'comment': [
37+
{
38+
pattern: /;;.*/,
39+
lookbehind: true,
40+
greedy: true
41+
},
42+
{
43+
pattern: /\{-[\s\S]*?(?:-\}|$)/,
44+
lookbehind: true,
45+
greedy: true
46+
},
47+
],
48+
49+
'keyword': /\b(?:_(?=\s*:)|asm|const|do|else|elseif|elseifnot|forall|global|if|ifnot|impure|inline|inline_ref|method_id|repeat|return|until|while)\b/,
50+
'boolean': /\b(?:false|true)\b/,
51+
'builtin': /\b(?:_|builder|cell|cont|int|slice|tuple|var)\b/,
52+
53+
'string': string,
54+
'number': number,
55+
'variable': identifier,
56+
57+
'operator': /(<=>|>=|<=|!=|==|~>>=|~>>|\/%|\^%=|\^%|~%|\^\/=|\^\/|~\/=|~\/|\+=|-=|\*=|\/=|%=|<<=|>>=|\^>>=|\^>>|&=|>>|<<|\^=|\|=|\^|=|~|\/|%|-|\*|\+|>|<|&|\||:|\?)/,
58+
'punctuation': /[\.;\(\),\[\]~\{\}]/,
59+
};
60+
}(Prism));

components/prism-tact.js

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
/**
2+
* @file Prism.js definition for Tact
3+
* @link https://tact-lang.org
4+
* @version 1.2.0
5+
* @author Novus Nota (https://github.com/novusnota)
6+
* @license MIT
7+
*/
8+
(function(Prism) {
9+
Prism.languages.tact = {
10+
// reserved keywords
11+
'keyword': [
12+
{
13+
pattern: /\b(?:abstract|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/,
14+
},
15+
{ // keyword after as
16+
pattern: /(\bas\s+)\w+/,
17+
lookbehind: true,
18+
greedy: true,
19+
},
20+
{ // reserved function names
21+
pattern: /\b(?:bounced|external|init|receive)\b/
22+
},
23+
],
24+
25+
// built-in types
26+
'builtin': {
27+
pattern: /\b(?:Address|Bool|Builder|Cell|Int|Slice|String|StringBuilder)\b/,
28+
},
29+
30+
// SCREAMING_SNAKE_CASE for null values and names of constants
31+
'constant': [
32+
{
33+
pattern: /\bnull\b/,
34+
},
35+
{
36+
pattern: /\b[A-Z][A-Z0-9_]*\b/,
37+
},
38+
],
39+
40+
// UpperCamelCase for names of contracts, traits, structs, messages
41+
'class-name': {
42+
pattern: /\b[A-Z]\w*\b/,
43+
},
44+
45+
// mappings to FunC
46+
'attribute': [
47+
{ // functions
48+
pattern: /@name/,
49+
inside: {
50+
'function': /.+/,
51+
},
52+
},
53+
{ // contract interfaces
54+
pattern: /@interface/,
55+
inside: {
56+
'function': /.+/,
57+
}
58+
}
59+
],
60+
61+
'function': {
62+
pattern: /\b\w+(?=\()/,
63+
},
64+
65+
'boolean': {
66+
pattern: /\b(?:false|true)\b/,
67+
},
68+
69+
'number': [
70+
{ // hexadecimal, case-insensitive /i
71+
pattern: /\b0x[0-9a-f](?:_?[0-9a-f])*\b/i,
72+
},
73+
{ // octal, case-insensitive /i
74+
pattern: /\b0o[0-7](?:_?[0-7])*\b/i,
75+
},
76+
{ // binary, case-insensitive /i
77+
pattern: /\b0b[01](?:_?[01])*\b/i,
78+
},
79+
{ // decimal integers, starting with 0
80+
pattern: /\b0\d*\b/,
81+
},
82+
{ // other decimal integers
83+
pattern: /\b[1-9](?:_?\d)*\b/,
84+
},
85+
],
86+
87+
'string': undefined,
88+
89+
'punctuation': {
90+
pattern: /[{}[\]();,.:?]/,
91+
},
92+
93+
'comment': [
94+
{ // single-line
95+
pattern: /(^|[^\\:])\/\/.*/,
96+
lookbehind: true,
97+
greedy: true,
98+
},
99+
{ // multi-line
100+
pattern: /(^|[^\\])\/\*[\s\S]*?(?:\*\/|$)/,
101+
lookbehind: true,
102+
greedy: true,
103+
}
104+
],
105+
106+
'operator': {
107+
'pattern': /![!=]?|[+\-*/%=]=?|[<>]=|<<?|>>?|\|\|?|&&?|\^/,
108+
},
109+
110+
};
111+
112+
// strings, made this way to not collide with other entities
113+
Prism.languages.insertBefore('tact', 'string', {
114+
'string-literal': {
115+
pattern: /(?:(")(?:\\.|(?!\1)[^\\\r\n])*\1(?!\1))/,
116+
greedy: true,
117+
inside: {
118+
'regex': [
119+
{ // \\ \" \n \r \t \v \b \f
120+
pattern: /\\[\\"nrtvbf]/,
121+
},
122+
{ // hexEscape, \x00 through \xFF
123+
pattern: /\\x[0-9a-fA-F]{2}/,
124+
},
125+
{ // unicodeEscape, \u0000 through \uFFFF
126+
pattern: /\\u[0-9a-fA-F]{4}/,
127+
},
128+
{ // unicodeCodePoint, \u{0} through \u{FFFFFF}
129+
pattern: /\\u\{[0-9a-fA-F]{1,6}\}/,
130+
},
131+
],
132+
'string': {
133+
pattern: /[\s\S]+/,
134+
},
135+
},
136+
},
137+
});
138+
139+
// map and bounced message generic type modifiers
140+
Prism.languages.insertBefore('tact', 'keyword', {
141+
'generics': {
142+
pattern: /(?:\b(?:bounced|map)\b<[^\\\r\n]*>)/,
143+
greedy: true,
144+
inside: {
145+
'builtin': [
146+
Prism.languages['tact']['builtin'],
147+
{
148+
pattern: /\b(?:bounced(?=<)|map(?=<))\b/
149+
},
150+
],
151+
'class-name': Prism.languages['tact']['class-name'],
152+
'punctuation': {
153+
pattern: /[<>(),.?]/,
154+
},
155+
'keyword': [
156+
{
157+
pattern: /\bas\b/,
158+
},
159+
{
160+
pattern: /(\bas\s+)\w+/,
161+
lookbehind: true,
162+
greedy: true,
163+
},
164+
],
165+
},
166+
},
167+
});
168+
}(Prism));

0 commit comments

Comments
 (0)