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

Add Tact language #3717

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion components.js

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions components.json
Original file line number Diff line number Diff line change
Expand Up @@ -1413,6 +1413,10 @@
"require": ["t4-templating", "vbnet"],
"owner": "RunDevelopment"
},
"tact": {
"title": "Tact",
"owner": "novusnota"
},
"tap": {
"title": "TAP",
"owner": "isaacs",
Expand Down
147 changes: 147 additions & 0 deletions components/prism-tact.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
(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));
1 change: 1 addition & 0 deletions components/prism-tact.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions examples/prism-tact.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<h2>Full example</h2>
<pre><code>import "@stdlib/ownable";

struct SampleStruct {
message: Int as uint32;
}

message(0x1234) MyMessage {
data: SampleStruct;
}

trait MyTrait {
get fun traitState(): Int {
return 0;
}
}

contract MyContract with MyTrait, Ownable? {
owner: Address; // comment
value: Int as uint32 = 1230;
counters: map&lt;Int, Address> /* Address, "Address" */ ;
map: map&lt;Int as int16, Int as uint32>;
b: bounced&lt;MyMessage>;

init(owner: Address) {
self.owner = owner;
}
bounced() {}
virtual fun overrideMe() {}
}

mutates get fun noName() { /* Multi-line comment */ }</code></pre>
Loading
Loading