-
Notifications
You must be signed in to change notification settings - Fork 2
/
clarity-prism.js
89 lines (84 loc) · 2.51 KB
/
clarity-prism.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// Clarity language definition to add clarity support to prismjs
// from
// https://github.com/hirosystems/stacks-wallet-web/blob/dev/src/app/common/clarity-prism.ts
function clarity(Prism) {
function primitive(pattern) {
return RegExp(`([\\s([])${pattern}(?=[\\s)])`)
}
const par = '(\\()'
const space = '(?=\\s)'
Prism.languages.clarity = {
// Three or four semicolons are considered a heading.
heading: {
pattern: /;;;.*/,
alias: ['comment', 'title'],
},
comment: /;;.*/,
string: [
{
pattern: /"(?:[^"\\]|\\.)*"/,
greedy: true,
},
{
pattern: /0x[0-9a-fA-F]*/,
greedy: true,
},
],
symbol: {
pattern: /'[^()#'\s]+/,
greedy: true,
},
keyword: [
{
pattern: RegExp(
`${par}(?:or|and|xor|not|begin|let|if|ok|err|unwrap\\!|unwrap-err\\!|unwrap-panic|unwrap-err-panic|match|try\\!|asserts\\!|map-get\\?|var-get|contract-map-get\\?|get|tuple|define-public|define-private|define-constant|define-map|define-data-var|define-fungible-token|define-non-fungible-token|define-read-only)${space}`,
),
lookbehind: true,
},
{
pattern: RegExp(
`${par}(?:var-set|map-set|map-delete|map-insert|ft-transfer\\?|nft-transfer\\?|nft-mint\\?|ft-mint\\?|nft-get-owner\\?|ft-get-balance\\?|contract-call\\?)${space}`,
),
lookbehind: true,
},
{
pattern: RegExp(
`${par}(?:list|map|filter|fold|len|concat|append|as-max-len\\?|to-int|to-uint|buff|hash160|sha256|sha512|sha512/256|keccak256|true|false|none)${space}`,
),
lookbehind: true,
},
{
pattern: RegExp(
`${par}(?:as-contract|contract-caller|tx-sender|block-height|at-block|get-block-info\\?)${space}`,
),
lookbehind: true,
},
{
pattern: RegExp(`${par}(?:is-eq|is-some|is-none|is-ok|is-err)${space}`),
lookbehind: true,
},
],
boolean: /(?:false|true|none)/,
number: {
pattern: primitive('[-]?u?\\d+'),
lookbehind: true,
},
address: {
pattern:
/([\s()])(?:'[0123456789ABCDEFGHJKMNPQRSTVWXYZ]{28,41})(?=[()\s]|$)/,
lookbehind: true,
},
operator: {
pattern: /(\()(?:[-+*/]|[<>]=?|=>?)(?=[()\s]|$)/,
lookbehind: true,
},
function: {
pattern: /(\()[^()'\s]+(?=[()\s]|$)/,
lookbehind: true,
},
punctuation: /[()']/,
}
}
clarity.displayName = 'clarity'
clarity.aliases = ['clar']
module.exports = clarity