From e4aae8d269002f4d10174163ab70a2c2a98417c6 Mon Sep 17 00:00:00 2001 From: Novus Nota <68142933+novusnota@users.noreply.github.com> Date: Mon, 18 Mar 2024 08:29:46 +0100 Subject: [PATCH 1/3] Added Tact, FunC, Fift, TL-B support Whose are the common languages of [TON](https://ton.org). --- components/prism-fift.js | 127 ++++++++++++++++++++++++++++++++ components/prism-func.js | 60 +++++++++++++++ components/prism-tact.js | 154 +++++++++++++++++++++++++++++++++++++++ components/prism-tlb.js | 44 +++++++++++ generate.js | 4 + 5 files changed, 389 insertions(+) create mode 100644 components/prism-fift.js create mode 100644 components/prism-func.js create mode 100644 components/prism-tact.js create mode 100644 components/prism-tlb.js diff --git a/components/prism-fift.js b/components/prism-fift.js new file mode 100644 index 0000000..44f3376 --- /dev/null +++ b/components/prism-fift.js @@ -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<>c/, /\*>>r/, /\*>>/, /\*mod/, /\*/, + + /\+!/, /\+/, /,/, /-!/, /-/, /!/, + /-1</, /0=/, /0>/, + /1\+!/, /1\+/, /1-!/, /1-/, /1</, /=/, />>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': /[\[\{\}\],\(\)]/, +}; \ No newline at end of file diff --git a/components/prism-func.js b/components/prism-func.js new file mode 100644 index 0000000..056e0cc --- /dev/null +++ b/components/prism-func.js @@ -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': /[\.;\(\),\[\]~\{\}]/, + }; +}(Prism)); \ No newline at end of file diff --git a/components/prism-tact.js b/components/prism-tact.js new file mode 100644 index 0000000..81075e4 --- /dev/null +++ b/components/prism-tact.js @@ -0,0 +1,154 @@ +/** + * @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|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)); \ No newline at end of file diff --git a/components/prism-tlb.js b/components/prism-tlb.js new file mode 100644 index 0000000..9878908 --- /dev/null +++ b/components/prism-tlb.js @@ -0,0 +1,44 @@ +/** + * @file Prism.js definition for TL-B + * @link https://docs.ton.org/develop/data-formats/tl-b-language + * @author Nikita Sobolev (https://github.com/sobolevn) + * @license MIT + */ +Prism.languages.tlb = { + 'builtin': /\b(?:Bool|Both|Cell|Either|Maybe|Type|Unit|bits256|bits512|int16|int32|int64|int8|uint15|uint16|uint32|uint63|uint64|uint8)\b/, + 'keyword': /\b(?:BoolFalse|BoolTrue|False|Null|True)\b/, + + 'comment': { + pattern: /\/\/(?:[^\r\n\\]|\\(?:\r\n?|\n|(?![\r\n])))*|\/\*[\s\S]*?(?:\*\/|$)/, + greedy: true + }, + 'comment-multiline': [ + { + pattern: /(^|[^\\])\/\*[\s\S]*?(?:\*\/|$)/, + lookbehind: true, + greedy: true, + alias: 'comment' + }, + { + pattern: /(^|[^\\:])\/\/.*/, + lookbehind: true, + greedy: true, + alias: 'comment' + } + ], + + 'symbol': [ + /#[0-9a-f]*_?/, + /\$[01]*_?/, + /\b(?:##|#<|#<=)\b/, + ], + 'variable': /[a-zA-Z_]\w*/, + 'operator': [ + /\+/, /-/, /\*/, /\//, + /!=/, /==/, /=/, + /\?/, /~/, /\./, /\^/, + /<=/, />=/, //, + ], + 'number': /\d+/, + 'punctuation': /[;\(\):\[\]\{\}]/, +}; \ No newline at end of file diff --git a/generate.js b/generate.js index df26e06..d8ea193 100644 --- a/generate.js +++ b/generate.js @@ -223,6 +223,10 @@ async function generate() { // Manually add local definitions loadLocalLanguage('./components/prism-tl.js', 'typelanguage', 'TypeLanguage', 'tl') + loadLocalLanguage('./components/prism-tlb.js', 'tlb', 'TypeLanguage-Binary', 'tlb') + loadLocalLanguage('./components/prism-fift.js', 'fift', 'Fift', 'fift') + loadLocalLanguage('./components/prism-func.js', 'func', 'FunC', 'func') + loadLocalLanguage('./components/prism-tact.js', 'tact', 'Tact', 'tact') Object.keys(Prism.languages).forEach(lng => { if (unsupported.includes(lng) || !components.languages[lng]) { From b46271af23bdf3db11afaaf22b8512b1f4783ab1 Mon Sep 17 00:00:00 2001 From: Novus Nota <68142933+novusnota@users.noreply.github.com> Date: Mon, 18 Mar 2024 08:38:09 +0100 Subject: [PATCH 2/3] chore: Updated list of supported languages --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index f5e307f..8fb403c 100644 --- a/README.md +++ b/README.md @@ -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`| @@ -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`| @@ -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`| From caa589d6004a0dad77543abdd858664007aab5c3 Mon Sep 17 00:00:00 2001 From: Novus Nota <68142933+novusnota@users.noreply.github.com> Date: Sun, 5 May 2024 15:48:21 +0200 Subject: [PATCH 3/3] feat: support Tact 1.3.0 --- components/prism-tact.js | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/components/prism-tact.js b/components/prism-tact.js index 81075e4..80f0832 100644 --- a/components/prism-tact.js +++ b/components/prism-tact.js @@ -5,12 +5,12 @@ * @author Novus Nota (https://github.com/novusnota) * @license MIT */ -(function (Prism) { +(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/, + 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+/, @@ -104,7 +104,7 @@ ], 'operator': { - 'pattern': /![!=]?|[+\-*/%=]=?|[<>]=|<>?|\|\|?|&&?/, + 'pattern': /![!=]?|[+\-*/%=]=?|[<>]=|<>?|\|\|?|&&?|\^/, }, }; @@ -115,6 +115,20 @@ 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]+/, },