-
Notifications
You must be signed in to change notification settings - Fork 10
/
beancount.sublime-syntax
393 lines (351 loc) · 10.6 KB
/
beancount.sublime-syntax
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
%YAML 1.2
---
name: Beancount
file_extensions: [bean, beancount]
scope: source.beancount
variables:
date: '\d{4}-\d{2}-\d{2}'
flag: '[^a-z\s]'
string: '"(?:[^"]|\\.)*"'
accountroot: '(Assets|Liabilities|Equity|Income|Expenses)'
accountcomponent: '[A-Z0-9][[:alnum:]_-]*'
account: '{{accountroot}}((?::{{accountcomponent}})+)'
number: '[0-9]+(?:,[0-9]{3})*(?:\.[0-9]*)?'
currency: "[A-Z][A-Z0-9_'.-]*"
amount: '[+-]?{{number}}[ \t]+{{currency}}'
linkchars: '[A-z0-9_-]'
tagchars: '[A-z0-9_-]'
contexts:
prototype:
- match: '(?<=\s)(;.*)(?=\n)'
captures:
1: comment.line.beancount
illegal:
- match: '[^\s]'
scope: invalid.illegal.unrecognized.beancount
main:
- match: '(^[*]+)\s*'
comment: headline
captures:
1: punctuation.definition.keyword.beancount
push: headline
- match: '^(?={{date}}[ \t]+)'
comment: dated directive
push: [directive, date]
- match: ';.*'
scope: comment.line.beancount
- match: '\b(option)\b'
comment: option directive
scope: keyword.control.option.beancount
set:
- meta_scope: meta.directive.option.beancount
- match: '(?={{string}}[ \t]+{{string}})'
set: [string, string]
- match: '\b(plugin)\b'
comment: plugin directive
scope: keyword.control.plugin.beancount
set:
- meta_scope: meta.directive.plugin.beancount
- match: '{{string}}'
scope: meta.include.plugin.beancount
pop: true
- match: '\b(include)\b'
comment: option directive
scope: keyword.control.include.beancount
set:
- meta_scope: meta.directive.include.beancount
- match: '{{string}}'
scope: meta.include.path.beancount
pop: true
headline:
- match: '[^\[\]\n]*'
scope: meta.toc-list.beancount
pop: true
directive:
- match: '\b(open)\b'
comment: open directive
scope: keyword.control.open.beancount
set:
- match: '(?={{account}}[ \t]+{{currency}})'
set: [metadata, currency, account]
- match: '(?={{account}})'
set: [metadata, account]
- include: illegal
- match: '\b(close)\b'
comment: close directive
scope: keyword.control.close.beancount
set:
- meta_scope: meta.directive.close.beancount
- match: '(?={{account}})'
set: [metadata, account]
- include: illegal
- match: '\b(commodity)\b'
comment: commodity directive
scope: keyword.control.commodity.beancount
set:
- meta_scope: meta.directive.commodity.beancount
- match: '(?={{currency}})'
set: [metadata, currency]
- include: illegal
- match: '\b(balance)\b'
comment: balance directive
scope: keyword.control.balance.beancount
set:
- meta_scope: meta.directive.balance.beancount
- match: '(?={{account}}([ \t]+({{amount}})?)?)'
set: [metadata, amount, account]
- match: '(?={{accountcomponent}})'
comment: Partial account
push: account
- include: illegal
- match: '\b(pad)\b'
comment: pad directive
scope: keyword.control.pad.beancount
set:
- meta_scope: meta.directive.balance.beancount
- match: '(?={{account}}[ \t]+{{account}})'
set: [metadata, account, account]
- match: '(?={{accountcomponent}})'
comment: Partial account
push: account
- include: illegal
- match: '\b(note)\b'
comment: note directive
scope: keyword.control.note.beancount
set:
- meta_scope: meta.directive.note.beancount
- match: '(?={{account}}[ \t]+{{string}})'
set: [metadata, string, account]
- match: '(?={{accountcomponent}})'
comment: Partial account
push: account
- include: illegal
- match: '\b(document)\b'
comment: document directive
scope: keyword.control.document.beancount
set:
- meta_scope: meta.directive.document.beancount
- match: '(?={{account}}[ \t]+{{string}})'
set: [metadata, string, account]
- include: illegal
- match: '\b(price)\b'
comment: price directive
scope: keyword.control.price.beancount
set:
- meta_scope: meta.directive.price.beancount
- match: '(?={{currency}}[ \t]+{{amount}})'
set: [metadata, amount, currency]
- include: illegal
- match: '\b(event)\b'
comment: event directive
scope: keyword.control.event.beancount
set:
- meta_scope: meta.directive.event.beancount
- match: '(?={{account}}[ \t]+{{string}}[ \t]+{{string}})'
set: [metadata, string, string, account]
- include: illegal
- match: '\b(query)\b'
comment: query directive
scope: keyword.control.query.beancount
set:
- meta_scope: meta.directive.query.beancount
- match: '(?={{string}}[ \t]+{{string}})'
set: [metadata, string, string]
- include: illegal
- match: '\b(custom)\b'
comment: custom directive
scope: keyword.control.custom.beancount
set:
- meta_scope: meta.directive.custom.beancount
- match: '(?={{string}})'
set: [metadata, string]
- include: illegal
- match: '(txn|[*])'
comment: completed transaction
scope: keyword.control.transaction.beancount
set: transaction
- match: '({{flag}})'
comment: flagged transaction
captures:
1: meta.flag.beancount keyword.other.beancount
scope: keyword.control.transaction.flagged.beancount
set: transaction
directive-end:
- match: '(?=(^$|^\S))'
pop: true
transaction:
- meta_scope: meta.directive.transaction.beancount
- match: '({{string}})[ \t]+({{string}})'
captures:
1: string.quoted.double.payee.beancount meta.payee.beancount
2: string.quoted.double.narration.beancount meta.narration.beancount
set: [postings, metadata, linkstags]
- match: '({{string}})'
captures:
1: string.quoted.double.narration.beancount meta.narration.beancount
set: [postings, metadata, linkstags]
- include: illegal
linkstags:
- match: '(?=\^)'
push: link
- match: '(?=#)'
push: tag
- match: '(?=^)'
pop: true
- include: illegal
metadata:
- match: '^[ \t]+([a-z][A-z0-9_-]+)([:])\s+'
captures:
1: keyword.operator.metadata.beancount meta.metadata.key.beancount
2: punctuation.separator.beancount
push: metadata_value
- match: '^[ \t]+([a-z][A-z0-9_-]+)'
captures:
1: keyword.operator.metadata.beancount meta.metadata.key.beancount
push: metadata_value
- match: '(?=^)'
pop: true
- include: illegal
metadata_value:
- match: ''
set:
- meta_scope: meta.metadata.value.beancount
- include: string
- include: account
- include: currency_list
- include: date
- include: tag
- include: amount
- include: number
- match: '([^\s]|$)'
pop: true
postings:
- include: directive-end
- match: '^[ \t]+({{flag}}(?=\t+))?'
captures:
1: meta.flag.beancount keyword.other.beancount
push: posting_leg
- include: illegal
posting_leg:
- match: ''
set:
- meta_scope: meta.posting.beancount
- match: '(?={{account}}[ \t]+([+-]?{{number}}))'
push: [ optional_price, optional_cost, amount, account ]
- match: '(?={{account}}[ \t]*$)'
push: account
- match: '(?={{accountcomponent}})'
comment: Partial account
push: account
- match: '(?=\n)'
pop: true
date:
- match: '(\d{4})(-)(\d{2})(-)(\d{2})'
scope: constant.numeric.date.beancount
comment: YYYY-MM-YY date
captures:
1: constant.numeric.date.year.beancount
2: punctuation.separator.beancount
3: constant.numeric.date.month.beancount
4: punctuation.separator.beancount
5: constant.numeric.date.day.beancount
pop: true
string:
- match: '({{string}})'
comment: double-quoted string
captures:
1: string.quoted.double.beancount
pop: true
account:
- meta_scope: meta.account.beancount
- match: '({{accountroot}})'
captures:
1: meta.account.root.beancount constant.language.beancount
set:
- match: '(:)({{accountcomponent}}*)'
captures:
1: punctuation.separator.beancount
2: variable.account.beancount
scope: meta.account.beancount
- match: (?=\s)
pop: true
account_expected:
- include: account
link:
- match: '(\^)({{linkchars}}*)'
scope: meta.link.beancount
captures:
1: keyword.operator.link.beancount
2: markup.underline.link
pop: true
tag:
- match: '(#)({{tagchars}}*)'
scope: meta.tag.beancount
captures:
1: keyword.operator.tag.beancount
2: entity.name.tag.beancount
pop: true
number:
- meta_scope: meta.number.beancount constant.numeric.beancount
- match: '[+]?{{number}}'
pop: true
- match: '[-]{{number}}'
scope: meta.number.negative.beancount
pop: true
amount:
- match: '([+]?{{number}})\s+({{currency}})'
scope: meta.amount.beancount
captures:
1: meta.number.beancount constant.numeric.beancount
2: meta.currency.beancount storage.type.currency.beancount
pop: true
- match: '([-]{{number}})\s+({{currency}})'
scope: meta.amount.beancount
captures:
1: meta.number.negative.beancount constant.numeric.beancount
2: meta.currency.beancount storage.type.currency.beancount
pop: true
currency:
- match: '{{currency}}'
comment: commodity/currency
scope: meta.currency.beancount storage.type.currency.beancount
pop: true
currency_list:
- match: '{{currency}}'
comment: commodity/currency
scope: meta.currency.beancount storage.type.currency.beancount
- match: '\s*,\s*'
- match: '\n'
pop: true
cost:
- match: '{{'
set:
- include: cost_parameters
- match: '}}'
pop: true
- match: '{'
set:
- include: cost_parameters
- match: '}'
pop: true
cost_parameters:
- match: '(?={{amount}})'
push: amount
- match: '(?={{date}})'
push: date
- match: '(?={{string}})'
push: string
optional_cost:
- include: cost
- match: '\s*'
- match: ''
pop: true
price:
- match: '[@]{1,2}'
scope: keyword.operator.price.beancount
set: amount
optional_price:
- include: price
- match: '\s*'
- match: ''
pop: true