Skip to content

Commit

Permalink
feat: support Tact 1.5.0 (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
novusnota authored Sep 17, 2024
1 parent 61bc9b7 commit d2b803b
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 32 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ Test files are located in `tests/X` folders, where `X` can be one of:

[Once initialized](#initialization), you'll be able to run tests for each language in this repo, namely:

* `yarn test-tact` will run tests for Tact
* `yarn test-func` will run tests for FunC
* `yarn test-fift` will run tests for Fift
* `yarn test-tlb` will run tests for TL-B
* `yarn test:tact` will run tests for Tact
* `yarn test:func` will run tests for FunC
* `yarn test:fift` will run tests for Fift
* `yarn test:tlb` will run tests for TL-B

And `yarn test` runs all those tests in succession.

Expand Down
41 changes: 19 additions & 22 deletions langs/prism-tact.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @file Prism.js definition for Tact
* @link https://tact-lang.org
* @version 1.2.0
* @version 1.5.0
* @author Novus Nota (https://github.com/novusnota)
* @license MIT
*/
Expand All @@ -10,22 +10,26 @@
// 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,
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/,
},
'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,
},
],

// TODO: somehow add this without breaking the maps

// SCREAMING_SNAKE_CASE for null values and names of constants
'constant': [
Expand Down Expand Up @@ -108,7 +112,7 @@
],

'operator': {
'pattern': /![!=]?|[+\-*/%=]=?|[<>]=|<<?|>>?|~|\|[\|=]?|&[&=]?|\^=?/,
'pattern': /![!=]?|->|[+\-*/%=]=?|[<>]=|<<?|>>?|~|\|[\|=]?|&[&=]?|\^=?/,
},

'variable': {
Expand Down Expand Up @@ -151,7 +155,7 @@
greedy: true,
inside: {
'builtin': [
Prism.languages['tact']['builtin'],
...Prism.languages['tact']['builtin'],
{
pattern: /\b(?:bounced(?=<)|map(?=<))\b/
},
Expand All @@ -160,16 +164,9 @@
'punctuation': {
pattern: /[<>(),.?]/,
},
'keyword': [
{
pattern: /\bas\b/,
},
{
pattern: /(\bas\s+)\w+/,
lookbehind: true,
greedy: true,
},
],
'keyword': {
pattern: /\bas\b/,
},
},
},
});
Expand Down
55 changes: 49 additions & 6 deletions tests/tact/complete.test
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import "@stdlib/ownable";

struct SampleStruct {
message: Int as uint32;
message: Int as uint130;
}

asm(a b -> 0 1) fun sum(a: Int, b: Int): Int { WHATEVER }

asm fun inc(a: Int): Int { INC }

@name(store_uint)
native storeUint(s: Builder, value: Int, bits: Int): Builder;

Expand All @@ -23,7 +27,7 @@ contract MyContract with MyTrait, Ownable? {
owner: Address; // comment
value: Int as uint32 = 0b101010 + 0o77;
counters: map<Int, Address> /* Address, "Address" */ ;
map: map<Int as int16, Int as uint32>;
map: map<Int as int10, Int as uint32>;
b: bounced<MyMessage>;
c: map<Bool, Cell>;
a: map<Slice, String>;
Expand Down Expand Up @@ -55,11 +59,50 @@ contract MyContract with MyTrait, Ownable? {
["punctuation", ":"],
["builtin", "Int"],
["keyword", "as"],
["keyword", "uint32"],
["builtin", "uint130"],
["punctuation", ";"],

["punctuation", "}"],

["keyword", "asm"],
["punctuation", "("],
["variable", "a"],
["variable", "b"],
["operator", "->"],
["number", "0"],
["number", "1"],
["punctuation", ")"],
["keyword", "fun"],
["function", "sum"],
["punctuation", "("],
["variable", "a"],
["punctuation", ":"],
["builtin", "Int"],
["punctuation", ","],
["variable", "b"],
["punctuation", ":"],
["builtin", "Int"],
["punctuation", ")"],
["punctuation", ":"],
["builtin", "Int"],
["punctuation", "{"],
["constant", "WHATEVER"],
["punctuation", "}"],

["keyword", "asm"],
["keyword", "fun"],
["function", "inc"],
["punctuation", "("],
["variable", "a"],
["punctuation", ":"],
["builtin", "Int"],
["punctuation", ")"],
["punctuation", ":"],
["builtin", "Int"],
["punctuation", "{"],
["constant", "INC"],
["punctuation", "}"],

["attribute", [
["function", "@name"]
]],
Expand Down Expand Up @@ -163,7 +206,7 @@ contract MyContract with MyTrait, Ownable? {
["punctuation", ":"],
["builtin", "Int"],
["keyword", "as"],
["keyword", "uint32"],
["builtin", "uint32"],
["operator", "="],
["number", "0b101010"],
["operator", "+"],
Expand All @@ -190,11 +233,11 @@ contract MyContract with MyTrait, Ownable? {
["punctuation", "<"],
["builtin", "Int"],
["keyword", "as"],
["keyword", "int16"],
["builtin", "int10"],
["punctuation", ","],
["builtin", "Int"],
["keyword", "as"],
["keyword", "uint32"],
["builtin", "uint32"],
["punctuation", ">"]
]],
["punctuation", ";"],
Expand Down

0 comments on commit d2b803b

Please sign in to comment.