Skip to content

Commit

Permalink
Add Tact language
Browse files Browse the repository at this point in the history
  • Loading branch information
novusnota committed Aug 20, 2023
1 parent 59e5a34 commit 0ddcbce
Show file tree
Hide file tree
Showing 9 changed files with 396 additions and 2 deletions.
2 changes: 1 addition & 1 deletion components.js

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions components.json
Original file line number Diff line number Diff line change
Expand Up @@ -1413,6 +1413,11 @@
"require": ["t4-templating", "vbnet"],
"owner": "RunDevelopment"
},
"tact": {
"title": "Tact",
"alias": "Tact",
"owner": "novusnota"
},
"tap": {
"title": "TAP",
"owner": "isaacs",
Expand Down
130 changes: 130 additions & 0 deletions components/prism-tact.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
(function(Prism) {

Check warning on line 1 in components/prism-tact.js

View workflow job for this annotation

GitHub Actions / lint

Missing space before function parentheses
Prism.languages.tact = {

Check warning on line 2 in components/prism-tact.js

View workflow job for this annotation

GitHub Actions / lint

Expected indentation of 1 tab but found 2 spaces
// reserved keywords

Check warning on line 3 in components/prism-tact.js

View workflow job for this annotation

GitHub Actions / lint

Expected indentation of 2 tabs but found 4 spaces
'keyword': [

Check warning on line 4 in components/prism-tact.js

View workflow job for this annotation

GitHub Actions / lint

Expected indentation of 2 tabs but found 4 spaces
{

Check warning on line 5 in components/prism-tact.js

View workflow job for this annotation

GitHub Actions / lint

Expected indentation of 3 tabs but found 6 spaces
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/,

Check warning on line 6 in components/prism-tact.js

View workflow job for this annotation

GitHub Actions / lint

Expected indentation of 4 tabs but found 8 spaces
},

Check warning on line 7 in components/prism-tact.js

View workflow job for this annotation

GitHub Actions / lint

Expected indentation of 3 tabs but found 6 spaces
{ // keyword after as

Check warning on line 8 in components/prism-tact.js

View workflow job for this annotation

GitHub Actions / lint

Expected indentation of 3 tabs but found 6 spaces
pattern: /(\bas\s+)\w+/,

Check warning on line 9 in components/prism-tact.js

View workflow job for this annotation

GitHub Actions / lint

Expected indentation of 4 tabs but found 8 spaces
lookbehind: true,

Check warning on line 10 in components/prism-tact.js

View workflow job for this annotation

GitHub Actions / lint

Expected indentation of 4 tabs but found 8 spaces
greedy: true,
},
{ // reserved function names
pattern: /\b(?:init|receive|bounced|external)\b/
},
],

// built-in types
'builtin': {
pattern: /\b(?:Int|Bool|Address|Slice|Cell|Builder|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/,
},

// native FunC functions mapping
'attribute': {
pattern: /@name/,
inside: {
'function': /.+/,
},
},

'function': {
pattern: /\b[\w]+(?=\()/,
},

'boolean': {
pattern: /\b(?:false|true)\b/,
},

'number': [
{ // hexadecimal, case-insensitive /i
pattern: /\b0x[0-9a-f]+\b/i,
},
{ // decimal integers
pattern: /\b[0-9]+\b/,
}
],

'string': undefined,

'punctuation': {
pattern: /[{}[\]();,.:?]/,
},

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

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

Check failure on line 83 in components/prism-tact.js

View workflow job for this annotation

GitHub Actions / lint

Unexpected useless alternative. This alternative is already covered by '[<>]=?' and can be removed

Check failure on line 83 in components/prism-tact.js

View workflow job for this annotation

GitHub Actions / lint

Unexpected useless alternative. This alternative is already covered by '[<>]=?' and can be removed
},

};

// 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(?:map|bounced)\b<[^\\\r\n]*>)/,
greedy: true,
inside: {
'builtin': [
Prism.languages['tact']['builtin'],
{
pattern: /\b(?:map(?=<)|bounced(?=<))\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<Int, Address> /* Address, "Address" */ ;
map: map<Int as int16, Int as uint32>;
b: bounced<MyMessage>;

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

mutates get fun noName() { /* Multi-line comment */ }</code></pre>
1 change: 1 addition & 0 deletions plugins/autoloader/prism-autoloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@
"rq": "sparql",
"sclang": "supercollider",
"t4": "t4-cs",
"Tact": "tact",
"trickle": "tremor",
"troy": "tremor",
"trig": "turtle",
Expand Down
2 changes: 1 addition & 1 deletion plugins/autoloader/prism-autoloader.min.js

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

Loading

0 comments on commit 0ddcbce

Please sign in to comment.