/
source.pact.js
191 lines (190 loc) · 5.85 KB
/
source.pact.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
// This is a TextMate grammar distributed by `starry-night`.
// This grammar is developed at
// <https://github.com/kadena-io/pact-atom>
// and licensed `bsd-3-clause`.
// See <https://github.com/wooorm/starry-night> for more info.
/** @type {import('../lib/index.js').Grammar} */
const grammar = {
extensions: ['.pact'],
names: ['pact'],
patterns: [
{include: '#comment'},
{include: '#sexp'},
{include: '#reserved'},
{include: '#type'},
{include: '#string'},
{include: '#list'},
{include: '#object'},
{include: '#literal'},
{include: '#symbol'},
{include: '#metas'},
{include: '#let'}
],
repository: {
arglist: {
begin: '(?<=\\()',
end: '(?=\\))',
patterns: [
{
match: '([\\w%#+\\-_&\\$@<>=\\?\\*!\\|/]+)',
name: 'variable.name.arg.pact'
},
{include: '#type'}
]
},
atom: {patterns: [{match: '([\\w%#+-_&\\$@<>=\\?\\*!\\|/]+)'}]},
comment: {
captures: {1: {name: 'punctuation.definition.comment.pact'}},
match: '(;).*$\\n?',
name: 'comment.line.semicolon.pact'
},
deflam: {
begin:
'(?<=\\()(defun|defpact|defcap)\\s+([\\w%#+\\-_&\\$@<>=\\?\\*!\\|/]+)',
beginCaptures: {
1: {name: 'keyword.reserved.pact'},
2: {name: 'entity.function.name.pact'}
},
end: '\\)',
name: 'meta.definition.global.pact',
patterns: [{include: '#arglist'}, {include: '#type'}]
},
defsimple: {
begin:
'(?<=\\()(defconst|defschema|deftable|module|interface)\\s+([\\w%#+-_&\\$@<>=\\?\\*!\\|/]+)\\b',
beginCaptures: {
1: {name: 'keyword.reserved.pact'},
2: {name: 'entity.function.name.pact'}
},
end: '(?=\\))',
name: 'meta.definition.global.pact',
patterns: [{include: '$self'}]
},
let: {
begin: '\\((let\\*?)\\s',
beginCaptures: {1: {name: 'keyword.let.pact'}},
end: '\\)',
name: 'meta.let.declaration.pact',
patterns: [
{
begin: '\\(',
end: '(?=\\))',
name: 'meta.let.bindings.pact',
patterns: [
{
begin: '\\(([\\w%#+\\-_&\\$@<>=\\?\\*!\\|/]+)\\b',
beginCaptures: {1: {name: 'variable.let.pact'}},
end: '\\)',
name: 'meta.let.binding.pact',
patterns: [{include: '$self'}]
}
]
}
]
},
list: {
begin: '(\\[)',
beginCaptures: {1: {name: 'punctuation.section.list.begin.pact'}},
end: '(\\](?=[\\}\\]\\)\\s]*(?:;|$)))|(\\])',
endCaptures: {
1: {name: 'punctuation.section.list.end.trailing.pact'},
2: {name: 'punctuation.section.list.end.pact'}
},
name: 'meta.list.pact',
patterns: [{include: '$self'}]
},
literal: {
patterns: [
{match: '(true|false)', name: 'constant.language.boolean.pact'},
{match: '\\b(-?\\d+\\.\\d+)\\b', name: 'constant.numeric.double.pact'},
{match: '\\b(-?\\d+)\\b', name: 'constant.numeric.integer.pact'},
{match: '(:=?)', name: 'constant.language.binder.pact'}
]
},
metas: {patterns: [{match: '@\\w+', name: 'variable.language.metas.pact'}]},
object: {
begin: '(\\{)',
beginCaptures: {1: {name: 'punctuation.section.object.begin.pact'}},
end: '(\\}(?=[\\}\\]\\)\\s]*(?:;|$)))|(\\})',
endCaptures: {
1: {name: 'punctuation.section.object.end.trailing.pact'},
2: {name: 'punctuation.section.object.end.pact'}
},
name: 'meta.object.pact',
patterns: [
{
begin: '(:=)',
beginCaptures: {1: {name: 'constant.binder.pact'}},
end: '([\\w%#+\\-_&\\$@<>=\\?\\*!\\|/]+)',
endCaptures: {1: {name: 'variable.binder.pact'}}
},
{include: '$self'}
]
},
reserved: {
patterns: [
{
match:
'\\b(module|interface|list|let|let\\*|defun|defpact|defconst|defschema|deftable|defcap|step|use|step-with-rollback|invariants?|properties|property|defproperty|bless|implements)\\b',
name: 'keyword.reserved.pact'
}
]
},
sexp: {
begin: '(\\()',
beginCaptures: {1: {name: 'punctuation.section.expression.begin.pact'}},
end: '(\\))(\\n)|(\\)(?=[\\}\\]\\)\\s]*(?:;|$)))|(\\))',
endCaptures: {
1: {name: 'punctuation.section.expression.end.trailing.pact'},
2: {name: 'meta.after-expression.pact'},
3: {name: 'punctuation.section.expression.end.trailing.pact'},
4: {name: 'punctuation.section.expression.end.pact'}
},
name: 'meta.expression.pact',
patterns: [
{include: '#deflam'},
{include: '#defsimple'},
{include: '#string'},
{include: '#reserved'},
{include: '#literal'},
{include: '#list'},
{include: '#object'},
{include: '#let'},
{include: '#sexp'},
{
captures: {1: {name: 'entity.name.function.pact'}},
match: '(?<=\\()(.+?)(?=\\s|\\))',
patterns: [{include: '$self'}]
},
{include: '$self'}
]
},
string: {
begin: '(?<!\\\\)(")',
beginCaptures: {1: {name: 'punctuation.definition.string.begin.pact'}},
end: '(?<!\\\\)(")',
endCaptures: {1: {name: 'punctuation.definition.string.end.pact'}},
name: 'string.quoted.double.pact'
},
symbol: {
patterns: [
{
begin: "'",
end: '(?=\\s|[],:"\'.)])',
name: 'string.quoted.symbol.pact'
}
]
},
type: {
patterns: [
{
captures: {1: {name: 'keyword.reserved.type.pact'}},
match:
'(?:[:])(integer|decimal|time|bool|string|list|value|keyset|guard|(object|table)?\\{[\\w%#+\\-\\._&\\$@<>=\\?\\*!\\|/]+\\}|object|table)'
}
]
}
},
scopeName: 'source.pact'
}
export default grammar