-
Notifications
You must be signed in to change notification settings - Fork 273
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #333 from novusnota-forks/main
feat: Updated Tact language highlighting for Prism.js
- Loading branch information
Showing
1 changed file
with
126 additions
and
49 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,53 +1,130 @@ | ||
(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.tact = { | ||
'include': { | ||
pattern: /#include(.*);/, | ||
inside: { | ||
'keyword': /#include/, | ||
'string': string, | ||
'punctuation': /;/ | ||
}, | ||
(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/, | ||
}, | ||
'pragma': { | ||
pattern: /#pragma(.*);/, | ||
inside: { | ||
'keyword': /#pragma|not-version|version/, | ||
'number': /(\d+)(.\d+)?(.\d+)?/, | ||
'operator': [/>=/, /<=/, /=/, />/, /</, /\^/], | ||
'punctuation': /;/ | ||
} | ||
}, | ||
|
||
'comment': [ | ||
{ | ||
pattern: /;;.*/, | ||
lookbehind: true, | ||
greedy: true | ||
}, | ||
{ | ||
pattern: /\{-[\s\S]*?(?:-\}|$)/, | ||
lookbehind: true, | ||
greedy: true | ||
}, | ||
], | ||
{ // keyword after as | ||
pattern: /(\bas\s+)\w+/, | ||
lookbehind: true, | ||
greedy: true, | ||
}, | ||
{ // reserved function names | ||
pattern: /\b(?:init|receive|bounced|external)\b/ | ||
}, | ||
], | ||
|
||
'keyword': /\b(?:_(?=\s*:)|asm|const|do|else|elseif|elseifnot|forall|global|if|ifnot|impure|inline|inline_ref|method_id|repeat|return|until|while)\b/, | ||
'boolean': /\b(?:false|true)\b/, | ||
'builtin': /\b(?:_|builder|cell|cont|int|slice|tuple|var)\b/, | ||
// built-in types | ||
'builtin': { | ||
pattern: /\b(?:Int|Bool|Address|Slice|Cell|Builder|String|StringBuilder)\b/, | ||
}, | ||
|
||
'string': string, | ||
'number': number, | ||
'variable': identifier, | ||
// SCREAMING_SNAKE_CASE for null values and names of constants | ||
'constant': [ | ||
{ | ||
pattern: /\bnull\b/, | ||
}, | ||
{ | ||
pattern: /\b[A-Z][A-Z0-9_]*\b/, | ||
}, | ||
], | ||
|
||
'operator': /(<=>|>=|<=|!=|==|~>>=|~>>|\/%|\^%=|\^%|~%|\^\/=|\^\/|~\/=|~\/|\+=|-=|\*=|\/=|%=|<<=|>>=|\^>>=|\^>>|&=|>>|<<|\^=|\|=|\^|=|~|\/|%|-|\*|\+|>|<|&|\||:|\?)/, | ||
'punctuation': /[\.;\(\),\[\]~\{\}]/, | ||
}; | ||
}(Prism)); | ||
// 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': /![!=]?|\*|\/|%|-|\+|==?|[<>]=|<<?|>>?|\|\|?|&&?/, | ||
}, | ||
|
||
}; | ||
|
||
// 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)); |