-
Notifications
You must be signed in to change notification settings - Fork 306
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: update Prism.js definitions of Tact and FunC for syntax highlig…
…hting (#768) * feat(prism): update Tact from 1.2.0 to 1.5.0 * feat(prism): update and enhance FunC from 0.2.0 to 0.4.4
- Loading branch information
Showing
2 changed files
with
170 additions
and
56 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,143 @@ | ||
(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/; | ||
/** | ||
* @file Prism.js definition for FunC | ||
* @link https://docs.ton.org/develop/func/overview | ||
* @version 0.4.4 | ||
* @author Novus Nota (https://github.com/novusnota) | ||
* @author Nikita Sobolev (https://github.com/sobolevn) | ||
* @license MIT | ||
*/ | ||
(function(Prism) { | ||
/** @type {Prism.GrammarValue} */ | ||
var number = /-?\b(?:\d+|0x[\da-fA-F]+)\b(?![^\.~,;\[\]\(\)\s])/; | ||
|
||
Prism.languages.func = { | ||
'include': { | ||
pattern: /#include(.*);/, | ||
/** @type {Prism.GrammarValue} */ | ||
var string = [ | ||
{ // multi-line | ||
pattern: /"""[\s\S]*?"""[Hhcusa]?/, | ||
greedy: true, | ||
inside: { | ||
'keyword': /#include/, | ||
'string': string, | ||
'punctuation': /;/ | ||
// string type | ||
'symbol': { | ||
pattern: /("""[\s\S]*?""")[Hhcusa]/, | ||
lookbehind: true, | ||
greedy: true, | ||
} | ||
}, | ||
}, | ||
'pragma': { | ||
pattern: /#pragma(.*);/, | ||
{ // single-line | ||
pattern: /"[^\n"]*"[Hhcusa]?/, | ||
greedy: true, | ||
inside: { | ||
'keyword': /#pragma|not-version|version/, | ||
'number': /(\d+)(.\d+)?(.\d+)?/, | ||
'operator': [/>=/, /<=/, /=/, />/, /</, /\^/], | ||
'punctuation': /;/ | ||
} | ||
// string type | ||
'symbol': { | ||
pattern: /("[^\n"]*")[Hhcusa]/, | ||
lookbehind: true, | ||
greedy: true, | ||
} | ||
}, | ||
}, | ||
]; | ||
|
||
/** @type {Prism.GrammarValue} */ | ||
var operator = /(?:!=|\?|:|%=|%|&=|&|\*=|\*|\+=|\+|->|-=|-|\/%|\/=|\/|<=>|<<=|<<|<=|<|==|=|>>=|>>|>=|>|\^>>=|\^>>|\^=|\^\/=|\^\/|\^%=|\^%|\^|\|=|\||~>>=|~>>|~\/=|~\/|~%|~)(?=\s)/; | ||
|
||
/** @type {RegExp[]} */ | ||
var var_identifier = [ | ||
// quoted | ||
/`[^`\n]+`/, | ||
// plain | ||
/[^\.~,;\[\]\(\)\s]+/ | ||
]; | ||
|
||
/** Prism.js definition for FunC */ | ||
Prism.languages.func = { | ||
'comment': [ | ||
{ | ||
{ // single-line | ||
pattern: /;;.*/, | ||
lookbehind: true, | ||
greedy: true | ||
greedy: true, | ||
}, | ||
{ | ||
{ // multi-line, not nested (TODO: nesting) | ||
// . isn't used, because it only applies to the single line | ||
pattern: /\{-[\s\S]*?(?:-\}|$)/, | ||
lookbehind: true, | ||
greedy: true | ||
greedy: true, | ||
}, | ||
{ | ||
// unused variable identifier | ||
pattern: /\b_\b(?![^\.~,;\[\]\(\)\s])/ | ||
}, | ||
], | ||
|
||
'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/, | ||
// Custom token for #pragma's | ||
'pragma': { | ||
pattern: /#pragma(.*);/, | ||
inside: { | ||
'keyword': /(?:#pragma|test-version-set|not-version|version|allow-post-modification|compute-asm-ltr)\b/, | ||
'number': /(?:\d+)(?:.\d+)?(?:.\d+)?/, | ||
'operator': /=|\^|<=|>=|<|>/, | ||
'string': string, | ||
'punctuation': /;/, | ||
} | ||
}, | ||
|
||
// Custom token for #include's | ||
'include': { | ||
pattern: /#include(.*);/, | ||
inside: { | ||
'keyword': /#include\b/, | ||
'string': string, | ||
'punctuation': /;/, | ||
} | ||
}, | ||
|
||
// builtin types | ||
'builtin': /\b(?:int|cell|slice|builder|cont|tuple|type)\b/, | ||
|
||
// builtin constants | ||
'boolean': /\b(?:false|true|nil|Nil)\b/, | ||
|
||
'keyword': /\b(?:forall|extern|global|asm|impure|inline_ref|inline|auto_apply|method_id|operator|infixl|infixr|infix|const|return|var|repeat|do|while|until|try|catch|ifnot|if|then|elseifnot|elseif|else)\b/, | ||
|
||
'string': string, | ||
'number': number, | ||
'variable': identifier, | ||
|
||
'operator': /(<=>|>=|<=|!=|==|~>>=|~>>|\/%|\^%=|\^%|~%|\^\/=|\^\/|~\/=|~\/|\+=|-=|\*=|\/=|%=|<<=|>>=|\^>>=|\^>>|&=|>>|<<|\^=|\|=|\^|=|~|\/|%|-|\*|\+|>|<|&|\||:|\?)/, | ||
'punctuation': /[\.;\(\),\[\]~\{\}]/, | ||
'string': string, | ||
|
||
'operator': operator, | ||
|
||
'punctuation': [/[\.,;\(\)\[\]]/, /[\{\}](?![^\.~,;\[\]\(\)\s])/], | ||
|
||
// Function and method names in declarations, definitions and calls | ||
'function': [ | ||
{ // quoted | ||
pattern: new RegExp(var_identifier[0].source + /(?=\s*\()/.source), | ||
greedy: true, | ||
}, | ||
{ // bitwise not operator | ||
pattern: /~_/, | ||
greedy: true, | ||
}, | ||
{ // remaining operators | ||
pattern: new RegExp(/\^?_/.source + operator.source + /_/.source), | ||
greedy: true, | ||
}, | ||
{ // plain function or method name | ||
pattern: new RegExp(/[\.~]?/.source + var_identifier[1].source + /(?=\s*\()/.source), | ||
greedy: true, | ||
}, | ||
{ // builtin functions and methods | ||
pattern: /\b(?:divmod|moddiv|muldiv|muldivr|muldivc|muldivmod|null\?|throw|throw_if|throw_unless|throw_arg|throw_arg_if|throw_arg_unless|load_int|load_uint|preload_int|preload_uint|store_int|store_uint|load_bits|preload_bits|int_at|cell_at|slice_at|tuple_at|at|touch|touch2|run_method0|run_method1|run_method2|run_method3|~divmod|~moddiv|~store_int|~store_uint|~touch|~touch2|~dump|~stdump)\b/, | ||
greedy: true, | ||
}, | ||
], | ||
|
||
// Parametric polymorphism | ||
'class-name': /[A-Z][^\.~,;\[\]\(\)\s]*/, | ||
|
||
// All the rest of identifiers | ||
'variable': var_identifier.map(x => { return { pattern: x, greedy: true } }), | ||
}; | ||
}(Prism)); | ||
|
||
// Adding a fc alias | ||
Prism.languages.fc = Prism.languages.func; | ||
}(Prism)); |
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