-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
396 additions
and
2 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
(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(?: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 GitHub Actions / lint
|
||
}, | ||
|
||
}; | ||
|
||
// 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)); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.