Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Tact, FunC, Fift, TL-B support #13

Merged
merged 3 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,12 @@ The new version of `grammars.dat` will appear in the `libprisma/grammars.dat`.
|`F#`|`fsharp`|
|`Factor`|`factor`|
|`False`|`false`|
|`Fift`|`fift`|
|`Firestore security rules`|`firestore-security-rules`|
|`Flow`|`flow`|
|`Fortran`|`fortran`|
|`FreeMarker Template Language`|`ftl`|
|`FunC`|`func`|
|`GameMaker Language`|`gml`,`gamemakerlanguage`|
|`GAP (CAS)`|`gap`|
|`G-code`|`gcode`|
Expand Down Expand Up @@ -290,6 +292,7 @@ The new version of `grammars.dat` will appear in the `libprisma/grammars.dat`.
|`SuperCollider`|`supercollider`,`sclang`|
|`Swift`|`swift`|
|`Systemd configuration file`|`systemd`|
|`Tact`|`tact`|
|`T4 templating`|`t4-templating`|
|`T4 Text Templates (C#)`|`t4-cs`,`t4`|
|`VB.Net`|`vbnet`|
Expand All @@ -299,6 +302,8 @@ The new version of `grammars.dat` will appear in the `libprisma/grammars.dat`.
|`Template Toolkit 2`|`tt2`|
|`TOML`|`toml`|
|`Tremor`|`tremor`,`tremor`,`trickle`,`troy`|
|`Type Language`|`tl`|
|`Type Language - Binary`|`tlb`|
|`TypoScript`|`typoscript`,`tsconfig`|
|`UnrealScript`|`unrealscript`,`unrealscript`,`uscript`,`uc`|
|`UO Razor Script`|`uorazor`|
Expand Down
127 changes: 127 additions & 0 deletions components/prism-fift.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
/**
* @file Prism.js definition for Fift
* @link https://docs.ton.org/develop/fift/overview
* @author Nikita Sobolev (https://github.com/sobolevn)
* @license MIT
*/
Prism.languages.fift = {
'symbol': [
/[xX]\{[0-9a-fA-F_]*\}/,
/[bB]\{[01]*\}/,
/'\S+/,
],
'string': /"([^"\r\n\\]|\\.)*"/,

'comment': [
{
pattern: /\/\*[\s\S]*?(?:\*\/|$)/,
lookbehind: true,
greedy: true,
},
{
pattern: /\/\/.*/,
lookbehind: true,
greedy: true,
},
],

'operator': [
// Full list can be found in
// Appendix A. List of Fift words
// Ordered the same way source code does this.
// Except: shorter words must follow
// longer ones with the same base part.
// Example: `#` comes after `#s`
/#>/, /#s/, /\$#/, /#/,

/\$\+/, /\$,/, /\$\d/, /\$=/, /\$(?=\()/,
/\$>smca/, /\$>s/,
/\$@\+/, /\$@\?\+/, /\$@\?/, /\$@/,
/\$cmp/, /\$len/, /\$pos/, /\$reverse/,

/%1<</,

/\('\)/, /\(-trailing\)/, /\(\.\)/, /\(atom\)/, /\(b\.\)/,
/\(compile\)/, /\(create\)/, /\(def\?\)/, /\(dump\)/, /\(execute\)/,
/\(forget\)/, /\(number\)/, /\(x\.\)/, /\(\{\)/, /\(\}\)/,

/\*\/cmod/, /\*\/c/, /\*\/mod/, /\*\/rmod/, /\*\/r/, /\*\//,
/\*>>c/, /\*>>r/, /\*>>/, /\*mod/, /\*/,

/\+!/, /\+/, /,/, /-!/, /-/, /!/,
/-1<</, /\._/, /\.dump/, /\.l/, /\.sl/, /\.s/, /\.tc/,
/\//, /\/\*/, /\/cmod/, /\/c/, /\/mod/, /\/rmod/, /\/r/,
/0!/, /0<=/, /0<>/, /0</, /0=/, /0>=/, /0>/,
/1\+!/, /1\+/, /1-!/, /1-/, /1<</, /1<<1-/,
/2\*/, /2\+/, /2-/, /2\//, /2=:/,

/::_/, /::/, /:_/, /=:/, /:/,

/<#/, /<<\/c/, /<<\/r/, /<=/, /<>/, /<b/, /<s/, /<<\//,
/<</, /</, /=/,

/>=/, />>c/, />>r/, />>/, />/,

/\?dup/,

/@'/, /@/,

/B\+/, /B,/, /B=/, /B>Li@\+/, /B>Li@/, /B>Lu@\+/, /B>Lu@/, /B>boc/,
/B>file/, /B>i@\+/, /B>i@/, /B>u@\+/, /B>u@/,
/B@\?\+/, /B@\+/, /B@\?/, /B@/,
/Bcmp/, /BhashB/, /Bhashu/, /Bhash/, /Blen/, /Bx\./,
/B\|/, /Li>B/, /Lu>B/,

/\[\]/, /\[compile\]/, /\[/, /\]/,

/atom\?/,

/b\+/, /b\._/, /b\./,
/b>idict!\+/, /b>idict!/, /b>sdict!\+/, /b>sdict!/,
/b>udict!\+/, /b>udict!/,
/b>/, /boc\+>B/, /boc>B/,

/csr\./,
/def\?/,
/empty\?/, /eq\?/,
/file-exists\?/, /file>B/,

/i,/, /i>B/, /i@\+/, /i@\?\+/, /i@\?/, /i@/,
/idict!\+/, /idict!/, /idict-/, /idict@-/, /idict@/,

/null!/, /null\?/,
/pfxdict!\+/, /pfxdict!/, /pfxdict@/, /priv>pub/,
/ref@\+/, /ref@/, /ref@\?\+/, /ref@\?/,

/s,/, /s>c/, /s>/,
/sdict!\+/, /sdict!/, /sdict-/, /sdict@-/, /sdict@/,
/smca>\$/, /sr,/,

/tuple\?/,

/u,/, /u>B/, /u@\+/, /u@\?\+/, /u@\?/,
/udict!\+/, /udict!/, /udict-/, /udict@-/, /udict@/,
/undef\?/,

/x\._/, /x\./,

/\|\+/, /\|/, /\|_/,

/\?\./, /'/,

// Should be the last:
/\./,
],

'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/,
'boolean': /\b(?:false|true)\b/,

'number': [
/(0[xX][0-9a-fA-F]+)/,
/(0[bB][01]+)/,
/(-?\d+(\/-?\d+)?)/,
],
'variable': /[\w$-]+/,

'punctuation': /[\[\{\}\],\(\)]/,
};
60 changes: 60 additions & 0 deletions components/prism-func.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/**
* @file Prism.js definition for FunC
* @link https://docs.ton.org/develop/func/overview
* @version 0.2.0
* @author Nikita Sobolev (https://github.com/sobolevn)
* @license MIT
*/
(function (Prism) {
// 1. Does not start from "
// 2. Can start from ` and end with `, containing any character
// 3. Starts with underscore or { or } and have more than 1 character after it
// 4. Starts with letter, contains letters, numbers and underscores
var identifier = /(?!")(`([^`]+)`|((?=_)_|(?=\{)\{|(?=\})\}|(?![_`{}]))([^;,\[\]\(\)\s~.]+))/;
var string = /"[^\n"]+"[Hhcusa]?/;
var number = /\b([\d_]+|0x[\d_a-fA-F]+|0b[1_0]+)\b/;

Prism.languages.func = {
'include': {
pattern: /#include(.*);/,
inside: {
'keyword': /#include/,
'string': string,
'punctuation': /;/
},
},
'pragma': {
pattern: /#pragma(.*);/,
inside: {
'keyword': /#pragma|not-version|version/,
'number': /(\d+)(.\d+)?(.\d+)?/,
'operator': [/>=/, /<=/, /=/, />/, /</, /\^/],
'punctuation': /;/
}
},

'comment': [
{
pattern: /;;.*/,
lookbehind: true,
greedy: true
},
{
pattern: /\{-[\s\S]*?(?:-\}|$)/,
lookbehind: true,
greedy: true
},
],

'keyword': /\b(?:_(?=\s*:)|asm|const|do|else|elseif|elseifnot|forall|global|if|ifnot|impure|inline|inline_ref|method_id|repeat|return|until|while)\b/,
'boolean': /\b(?:false|true)\b/,
'builtin': /\b(?:_|builder|cell|cont|int|slice|tuple|var)\b/,

'string': string,
'number': number,
'variable': identifier,

'operator': /(<=>|>=|<=|!=|==|~>>=|~>>|\/%|\^%=|\^%|~%|\^\/=|\^\/|~\/=|~\/|\+=|-=|\*=|\/=|%=|<<=|>>=|\^>>=|\^>>|&=|>>|<<|\^=|\|=|\^|=|~|\/|%|-|\*|\+|>|<|&|\||:|\?)/,
'punctuation': /[\.;\(\),\[\]~\{\}]/,
};
}(Prism));
168 changes: 168 additions & 0 deletions components/prism-tact.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
/**
* @file Prism.js definition for Tact
* @link https://tact-lang.org
* @version 1.2.0
* @author Novus Nota (https://github.com/novusnota)
* @license MIT
*/
(function(Prism) {
Prism.languages.tact = {
// reserved keywords
'keyword': [
{
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/,
},
{ // 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: {
'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/,
},
{
pattern: /(\bas\s+)\w+/,
lookbehind: true,
greedy: true,
},
],
},
},
});
}(Prism));
Loading