Skip to content

Commit

Permalink
Archetype language formatter (#337)
Browse files Browse the repository at this point in the history
* Add support for jsligo and cameligo

* Copy formatter from opentezos

* No, use the version from completium

* wip style matching

* use c-like commenting

* Get styles closer to Archetype docs

* git commit -a fail

* Rename for consistency with other repos

* Rename for consistency with other repos

* correct link

* use red for sections because the orange is hard to see

* Differentiate entry from other keywords

* tweaking colors
  • Loading branch information
timothymcmackin authored Feb 29, 2024
1 parent e05dfe0 commit 7f62905
Show file tree
Hide file tree
Showing 3 changed files with 161 additions and 0 deletions.
66 changes: 66 additions & 0 deletions src/css/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -211,3 +211,69 @@ article a[target="_blank"]:after {
content: url("/img/external_link.svg");
padding-left: 5px;
}


/* Syntax highlighting */
.language-archetype .token.prolog,
.language-archetype .token.constant {
color: rgb(189, 147, 249);
font-style: italic;
}
.language-archetype .token.inserted,
.language-archetype .token.function {
color: rgb(80, 250, 123);
}
.language-archetype .token.deleted,
.language-archetype .token.error {
color: #8B0000;
}
.language-archetype .token.changed {
color: rgb(255, 184, 108);
}
.language-archetype .token.string,
.language-archetype .token.char,
.language-archetype .token.tag,
.language-archetype .token.selector {
color: rgb(255, 121, 198);
}
.language-archetype .token.keyword,
.language-archetype .token.variable {
color: rgb(189, 147, 249);
font-style: italic;
}
.language-archetype .token.comment {
color: rgb(98, 114, 164);
}
.language-archetype .token.archetype,
.language-archetype .token.function {
color: #2FCAC3 !important;
}
.language-archetype .token.entry,
.language-archetype .token.declaration,
.language-archetype .token.verif {
color: rgb(47, 202, 195);
}
.language-archetype .token.section {
color: rgb(233, 72, 21);
}
.language-archetype .token.control,
.language-archetype .token.decl {
color: rgb(189, 147, 249);
}
.language-archetype .token.boolean,
.language-archetype .token.builtin,
.language-archetype .token.logic,
.language-archetype .token.asset,
.language-archetype .token.access,
.language-archetype .token.crypto,
.language-archetype .token.arith {
color: rgb(68, 134, 255);
}
.language-archetype .token.transfer,
.language-archetype .token.fail {
color: rgb(255, 85, 85);
}
.language-archetype .token.instr,
.language-archetype .token.expr {
font-style: italic;
}
94 changes: 94 additions & 0 deletions src/theme/languages/prism-archetype.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
// Taken from https://github.com/completium/completium-landing/tree/master/src/theme

(function (Prism) {

Prism.languages.archetype = {
'comment': [
{
pattern: /(^|[^\\])\/\*[\s\S]*?(?:\*\/|$)/,
lookbehind: true,
greedy: true
},
{
pattern: /(^|[^\\:])\/\/.*/,
lookbehind: true,
greedy: true
}
],
'string': [
{
pattern: /"(?:\\.|[^\\\r\n"])*"/,
greedy: true
},
{
pattern: /(['`])(?:\\(?:\d+|x[\da-f]+|.)|(?!\1)[^\\\r\n])\1/i,
greedy: true
}
],
'identifier': /%[a-z]+/,
'number': /\b(?:0x[\da-f][\da-f_]+|(?:0[bo])?\d[\d_]*%\.?[\d_]*(?:e[+-]?[\d_]+)?)/i,
'label': {
pattern: /\B~\w+/,
alias: 'function'
},
'transfer-rule': {
pattern: /transfer\s+(.*)\s+to\s+(entry)?/,
inside: {
'builtin': {
pattern: /transfer|to\s+entry?|to/,
},
'constant': {
pattern: /\b(?:now|balance|transferred|self|caller|sender|self_address|state|operations)\b/,
}
},
},
'constant-rule': {
pattern: /(constant) {/,
inside: {
'section': {
pattern: /\b(constant)\b/,
}
}
},
'iter-rule': {
pattern: /iter\s+(((?!to).)*)\s+to/,
inside: {
'control': {
pattern: /\b(?:iter|from|to)\b/,
}
}
},
'instr' : /\b(?:instr([0-9]|n))\b/,
'expr' : /\b(?:expr[0-9]|E([0-9]|n))\b/,
'unkeyworded' : /%(?:.*)/,
'archetype': /\b(?:archetype|with metadata)\b/,
'builtin': /\b(?:put|make_map|make_list|blake2b|key_to_address|check_signature|int_to_nat|call_view|slice|mutez_to_nat|fold|get_entrypoint|reverse|require_entrypoint|exec_lambda|apply_lambda|get_some|is_some|left|right|some|none|isempty|length|put|get|transfer|call|emit|prepend|make_operation)\b/,
'section': /\b(?:is|no transfer|state is|called by|sourced by|require|fail if|effect|with effect|from|to|when|otherwise|shadow|postcondition|fails)\b/,
'declaration': /\b(?:event|constant|archetype|enum|states|variable|asset|to big_map|to iterable_big_map|record|as|initial|identified by|initialized by)\b/,
'entry': /\b(?:entry|transition|function|getter|view)\b/,
'verif': /\b(?:invariant|specification)\b/,
'type': /\b(?:unit|lambda|contract|big_map|map|set|option|list|int|nat|tez|string|rational|bytes|key|key_hash|address|sapling|signature|date|duration|bool|operation|aggregate|partition|asset_view|asset_key|asset_value|iterable_big_map)\b/,
'constant': /\b(?:self_chain_id|now|balance|transferred|self|caller|source|self_address|state|operations|metadata)\b/,
'control': /\b(?:assert|iter|begin|end|do|done|else|return|before|for|if|in|match|in|forall|added|removed|exists|then|the|from|to|while|with)\b/,
'decl': /\b(?:const|var|let some|let)\b/,
'boolean': /\b(?:false|true)\b/,
'logic': /\b(?:and|or|=|not|asr|land|lor|lsl|lsr|lxor)\b/,
'asset': /\b(?:update_all|clear|count|sum|asc|desc|remove_if|remove_aggregate|remove|update|contains|remove_all|select|sort|head|nth|add|put|add_update|get)\b/,
'access': /(?:\[|\]|\?|::)/,
'crypto': /\b(?:pack|unpack|open_chest)\b/,
'arith': /\b(?:mod|abs|min|max)\b/,
'fail': /\b(?:fail|do_require|do_fail_if)\b/,
'error': /\b([A-Z|0-9][A-Z|0-9|_]+)\b/,
// Custom operators are allowed
'function': /:=|\+=|\-=|[=<>@^|&+\-*\/$%!~][!$%&*+\-.\/:<=>?@^|~]*\b/,
'punctuation': /[(){}|.,:;]|\b_\b/,
'archetype-function': {
pattern: /([a-z][a-z|_]+)\(/,
inside: {
'archetype': {
pattern : /\b([a-z][a-z|_]+)\b/
}
}
},
};
}(Prism));
1 change: 1 addition & 0 deletions src/theme/prism-include-languages.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@ export default function prismIncludeLanguages(PrismObject) {

require(`./languages/prism-cameligo`);
require(`./languages/prism-jsligo`);
require(`./languages/prism-archetype`);
delete globalThis.Prism;
}

0 comments on commit 7f62905

Please sign in to comment.