tree-sitter-beancount 2.0.0 → 2.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.clang-format +20 -0
- package/.envrc +1 -0
- package/.github/workflows/cicd.yml +30 -0
- package/.github/workflows/release.yml +72 -0
- package/CHANGELOG.md +31 -0
- package/Cargo.lock +59 -0
- package/Cargo.toml +26 -0
- package/README.md +5 -1
- package/binding.gyp +2 -1
- package/{src → bindings/node}/binding.cc +0 -0
- package/bindings/node/index.js +19 -0
- package/bindings/rust/build.rs +38 -0
- package/bindings/rust/lib.rs +52 -0
- package/flake.lock +67 -0
- package/flake.nix +123 -0
- package/grammar.js +238 -202
- package/package.json +6 -5
- package/shell.nix +13 -0
- package/src/grammar.json +569 -485
- package/src/node-types.json +465 -432
- package/src/parser.c +13350 -4930
- package/src/scanner.cc +163 -0
- package/src/tree_sitter/parser.h +73 -84
- package/test/corpus/arithmetic.txt +71 -53
- package/test/corpus/comment.txt +12 -17
- package/test/corpus/currencies.txt +10 -12
- package/test/corpus/entry_types.txt +17 -31
- package/test/corpus/markdown_orgmode.txt +60 -0
- package/test/corpus/metadata.txt +95 -104
- package/test/corpus/multi_line.txt +2 -4
- package/test/corpus/orgmode_sections.txt +53 -0
- package/test/corpus/parse_lots.txt +31 -87
- package/test/corpus/parser_links.txt +4 -6
- package/test/corpus/push_pop_meta.txt +5 -6
- package/test/corpus/transaction.txt +54 -47
- package/test/corpus/ugly_bugs.txt +4 -4
- package/index.js +0 -13
- package/tree-sitter-beancount.wasm +0 -0
package/grammar.js
CHANGED
|
@@ -3,91 +3,109 @@ module.exports = grammar({
|
|
|
3
3
|
* From beancount grammar.y
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
name:
|
|
6
|
+
name: "beancount",
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
// Ensure we don't extract keywords from tokens
|
|
9
|
+
word: ($) => $.identifier,
|
|
9
10
|
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
inline: ($) => [
|
|
12
|
+
],
|
|
12
13
|
|
|
13
|
-
|
|
14
|
+
conflicts: ($) => [
|
|
15
|
+
],
|
|
16
|
+
|
|
17
|
+
externals: ($) => [
|
|
18
|
+
$._stars,
|
|
19
|
+
$._sectionend,
|
|
20
|
+
$._eof, // Basically just '\0', but allows multiple to be matched
|
|
21
|
+
],
|
|
22
|
+
|
|
23
|
+
extras: ($) => [
|
|
24
|
+
/( |\r|\t)+/,
|
|
25
|
+
],
|
|
26
|
+
|
|
27
|
+
supertypes: $ => [
|
|
28
|
+
$._entry,
|
|
29
|
+
$._directive,
|
|
30
|
+
],
|
|
14
31
|
|
|
15
32
|
rules: {
|
|
33
|
+
file: $ => repeat(
|
|
34
|
+
choice(
|
|
35
|
+
$.section,
|
|
36
|
+
$._declarations,
|
|
37
|
+
$._nl,
|
|
38
|
+
)
|
|
39
|
+
),
|
|
40
|
+
|
|
41
|
+
_nl: _ => choice('\n', '\r'),
|
|
42
|
+
_eol: $ => choice('\n', '\r', $._eof),
|
|
43
|
+
_any: $ => /.*/,
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
/*
|
|
47
|
+
* Org Header Sections
|
|
48
|
+
*/
|
|
49
|
+
section: $ => seq(
|
|
50
|
+
field('headline', $.headline),
|
|
51
|
+
repeat(choice(
|
|
52
|
+
$._declarations,
|
|
53
|
+
$._nl
|
|
54
|
+
)),
|
|
55
|
+
repeat(field('subsection', $.section)),
|
|
56
|
+
$._sectionend
|
|
57
|
+
),
|
|
58
|
+
_org_stars: $ => seq($._stars, /\*+/),
|
|
59
|
+
headline: $ => seq(
|
|
60
|
+
$._org_stars,
|
|
61
|
+
/[ \t]+/, // so it's not part of (item)
|
|
62
|
+
optional(field('item', $.item)),
|
|
63
|
+
$._nl,
|
|
64
|
+
),
|
|
65
|
+
item: $ => $._any,
|
|
16
66
|
|
|
17
|
-
file: $ => repeat($._declarations),
|
|
18
67
|
|
|
19
68
|
/* Types for terminal symbols */
|
|
20
|
-
_indent:
|
|
21
|
-
_eol:
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
plus: $ => token('+'),
|
|
37
|
-
minus: $ => token('-'),
|
|
38
|
-
_lparen: $ => token('('),
|
|
39
|
-
_rparen: $ => token(')'),
|
|
40
|
-
flag: $ => token(/[!&?%PSTCURM*#]/),
|
|
41
|
-
TXN: $ => token('txn'),
|
|
42
|
-
BALANCE: $ => token('balance'),
|
|
43
|
-
OPEN: $ => token('open'),
|
|
44
|
-
CLOSE: $ => token('close'),
|
|
45
|
-
COMMODITY: $ => token('commodity'),
|
|
46
|
-
PAD: $ => token('pad'),
|
|
47
|
-
EVENT: $ => token('event'),
|
|
48
|
-
PRICE: $ => token('price'),
|
|
49
|
-
NOTE: $ => token('note'),
|
|
50
|
-
DOCUMENT: $ => token('docuemnt'),
|
|
51
|
-
QUERY: $ => token('query'),
|
|
52
|
-
CUSTOM: $ => token('custom'),
|
|
53
|
-
PUSHTAG: $ => token('pusgtag'),
|
|
54
|
-
POPTAG: $ => token('poptag'),
|
|
55
|
-
PUSHMETA: $ => token('pushmeta'),
|
|
56
|
-
POPMETA: $ => token('popmeta'),
|
|
57
|
-
OPTION: $ => token('option'),
|
|
58
|
-
INCLUDE: $ => token('include'),
|
|
59
|
-
PLUGIN: $ => token('plugin'),
|
|
60
|
-
_none: $ => token('NULL'),
|
|
61
|
-
bool: $ => token(/TRUE|FALSE/),
|
|
62
|
-
date: $ => token(/([12]\d{3}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01]))/),
|
|
63
|
-
account: $ =>
|
|
69
|
+
_indent: $ => token(/[ \r\t]+/),
|
|
70
|
+
_eol: $ => token(/\n/),
|
|
71
|
+
atat: $ => token('@@'),
|
|
72
|
+
at: $ => token('@'),
|
|
73
|
+
asterisk: $ => token('*'),
|
|
74
|
+
slash: $ => token('/'),
|
|
75
|
+
plus: $ => token('+'),
|
|
76
|
+
minus: $ => token('-'),
|
|
77
|
+
flag: $ => token(/[!&?%PSTCURM*#]/),
|
|
78
|
+
_none: $ => token('NULL'),
|
|
79
|
+
bool: $ => token(/TRUE|FALSE/),
|
|
80
|
+
date: $ => token(/([12]\d{3}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01]))/),
|
|
81
|
+
//An account name is a colon-separated list of capitalized words which begin with a letter, and whose first word must be one of five account types:
|
|
82
|
+
//Each component of the account names begin with a capital letter or a number and are followed by letters, numbers or dash (-) characters.
|
|
83
|
+
//All other characters are disallowed.
|
|
84
|
+
account: $ =>
|
|
64
85
|
token(
|
|
65
86
|
seq(
|
|
66
|
-
/
|
|
67
|
-
repeat(/[A-Za-z0-9\-]|[^\x00-\x7F]/),
|
|
87
|
+
/Assets|Liabilities|Equity|Income|Expenses/,
|
|
68
88
|
repeat1(
|
|
69
89
|
seq(
|
|
70
90
|
":",
|
|
71
|
-
/[
|
|
72
|
-
repeat(/[A-Za-z0-9\-]|[^\x00-\x7F]/),
|
|
91
|
+
/[\p{Lu}\p{N}][\p{L}\p{N}\-]*/,
|
|
73
92
|
),
|
|
74
93
|
),
|
|
75
94
|
),
|
|
76
95
|
),
|
|
77
|
-
currency:
|
|
78
|
-
string:
|
|
79
|
-
number:
|
|
80
|
-
tag:
|
|
81
|
-
link:
|
|
82
|
-
key: $ => token(/[a-z][a-zA-Z0-9\-_]+/),
|
|
96
|
+
currency: $ => token(/[A-Z][A-Z0-9\'\._\-]{0,22}[A-Z0-9]/),
|
|
97
|
+
string: $ => token(/"[^"]*"/),
|
|
98
|
+
number: $ => token(/([0-9]+|[0-9][0-9,]+[0-9])(\.[0-9]*)?/),
|
|
99
|
+
tag: $ => token(/#[A-Za-z0-9\-_/.]+/),
|
|
100
|
+
link: $ => token(/\^[A-Za-z0-9\-_/.]+/),
|
|
83
101
|
|
|
84
102
|
/* Operator precedence.
|
|
85
103
|
* This is pulled straight out of the textbook example:
|
|
86
104
|
* https://www.gnu.org/software/bison/manual/html_node/Infix-Calc.html#Infix-Calc
|
|
87
105
|
*/
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
106
|
+
// %left MINUS PLUS
|
|
107
|
+
// %left ASTERISK SLASH
|
|
108
|
+
// %precedence NEGATIVE /* negation--unary minus */
|
|
91
109
|
|
|
92
110
|
// Start symbol: file
|
|
93
111
|
/* We have some number of expected shift/reduce conflicts at 'eol'. */
|
|
@@ -97,10 +115,10 @@ module.exports = grammar({
|
|
|
97
115
|
/* Grammar Rules */
|
|
98
116
|
|
|
99
117
|
txn: $ => choice(
|
|
100
|
-
|
|
118
|
+
"txn",
|
|
101
119
|
$.flag,
|
|
102
|
-
|
|
103
|
-
|
|
120
|
+
"*",
|
|
121
|
+
"#"
|
|
104
122
|
),
|
|
105
123
|
|
|
106
124
|
_number_expr: $ =>
|
|
@@ -112,9 +130,9 @@ module.exports = grammar({
|
|
|
112
130
|
),
|
|
113
131
|
_paren__number_expr: $ =>
|
|
114
132
|
seq(
|
|
115
|
-
|
|
133
|
+
"(",
|
|
116
134
|
$._number_expr,
|
|
117
|
-
|
|
135
|
+
")",
|
|
118
136
|
),
|
|
119
137
|
unary_number_expr: $ =>
|
|
120
138
|
prec(3,
|
|
@@ -133,36 +151,39 @@ module.exports = grammar({
|
|
|
133
151
|
prec(3,
|
|
134
152
|
choice(
|
|
135
153
|
prec.left(1,
|
|
136
|
-
seq(
|
|
154
|
+
seq($._number_expr, $.plus, $._number_expr),
|
|
137
155
|
),
|
|
138
156
|
prec.left(1,
|
|
139
|
-
seq(
|
|
157
|
+
seq($._number_expr, $.minus, $._number_expr),
|
|
140
158
|
),
|
|
141
159
|
prec.left(2,
|
|
142
|
-
seq(
|
|
160
|
+
seq($._number_expr, $.asterisk, $._number_expr),
|
|
143
161
|
),
|
|
144
162
|
prec.left(2,
|
|
145
|
-
seq(
|
|
163
|
+
seq($._number_expr, $.slash, $._number_expr),
|
|
146
164
|
),
|
|
147
165
|
),
|
|
148
166
|
),
|
|
149
167
|
|
|
150
168
|
// OPTIONAL
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
169
|
+
_txn_strings: $ =>
|
|
170
|
+
choice(
|
|
171
|
+
seq(
|
|
172
|
+
alias($.string, $.payee),
|
|
173
|
+
alias($.string, $.narration),
|
|
174
|
+
),
|
|
175
|
+
alias($.string, $.narration),
|
|
155
176
|
),
|
|
156
177
|
|
|
157
178
|
// OPTIONAL
|
|
158
179
|
tags_links: $ =>
|
|
159
180
|
repeat1(
|
|
160
181
|
//seq(
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
182
|
+
// optional($._indent),
|
|
183
|
+
choice(
|
|
184
|
+
$.link,
|
|
185
|
+
$.tag,
|
|
186
|
+
),
|
|
166
187
|
//),
|
|
167
188
|
),
|
|
168
189
|
|
|
@@ -170,33 +191,54 @@ module.exports = grammar({
|
|
|
170
191
|
seq(
|
|
171
192
|
field("date", $.date),
|
|
172
193
|
field("txn", $.txn),
|
|
173
|
-
|
|
194
|
+
optional($._txn_strings),
|
|
174
195
|
field("tags_links", optional($.tags_links)),
|
|
196
|
+
field("comment", optional($.comment)),
|
|
175
197
|
$._eol,
|
|
176
|
-
|
|
198
|
+
optional(
|
|
199
|
+
repeat1(
|
|
200
|
+
choice(
|
|
201
|
+
seq(
|
|
202
|
+
$._indent,
|
|
203
|
+
$._eol
|
|
204
|
+
),
|
|
205
|
+
seq(
|
|
206
|
+
$._indent,
|
|
207
|
+
$.tags_links,
|
|
208
|
+
$._eol
|
|
209
|
+
),
|
|
210
|
+
$._key_value_line,
|
|
211
|
+
$.posting,
|
|
212
|
+
seq(
|
|
213
|
+
$._indent,
|
|
214
|
+
$.comment,
|
|
215
|
+
$._eol
|
|
216
|
+
)
|
|
217
|
+
)
|
|
218
|
+
),
|
|
219
|
+
),
|
|
220
|
+
|
|
177
221
|
),
|
|
178
222
|
|
|
179
223
|
// OPTIONAL
|
|
180
224
|
optflag: $ =>
|
|
181
225
|
choice(
|
|
182
|
-
|
|
183
|
-
|
|
226
|
+
"*",
|
|
227
|
+
"#",
|
|
184
228
|
$.flag,
|
|
185
229
|
),
|
|
186
230
|
|
|
187
231
|
price_annotation: $ => $.incomplete_amount,
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
//account: $ => $.ACCOUNT,
|
|
232
|
+
//choice(
|
|
233
|
+
// seq(
|
|
234
|
+
// $.atat,
|
|
235
|
+
// $.incomplete_amount
|
|
236
|
+
// ),
|
|
237
|
+
// seq(
|
|
238
|
+
// $.at,
|
|
239
|
+
// $.incomplete_amount
|
|
240
|
+
// )
|
|
241
|
+
//),
|
|
200
242
|
|
|
201
243
|
posting: $ =>
|
|
202
244
|
choice(
|
|
@@ -206,6 +248,7 @@ module.exports = grammar({
|
|
|
206
248
|
field("account", $.account),
|
|
207
249
|
field("amount", optional($.incomplete_amount)),
|
|
208
250
|
field("cost_spec", optional($.cost_spec)),
|
|
251
|
+
field("comment", optional($.comment)),
|
|
209
252
|
$._eol
|
|
210
253
|
),
|
|
211
254
|
seq(
|
|
@@ -216,6 +259,7 @@ module.exports = grammar({
|
|
|
216
259
|
field("cost_spec", optional($.cost_spec)),
|
|
217
260
|
$.at,
|
|
218
261
|
field("price_annotation", optional($.price_annotation)),
|
|
262
|
+
field("comment", optional($.comment)),
|
|
219
263
|
$._eol
|
|
220
264
|
),
|
|
221
265
|
seq(
|
|
@@ -226,6 +270,7 @@ module.exports = grammar({
|
|
|
226
270
|
field("cost_spec", optional($.cost_spec)),
|
|
227
271
|
$.atat,
|
|
228
272
|
field("price_annotation", optional($.price_annotation)),
|
|
273
|
+
field("comment", optional($.comment)),
|
|
229
274
|
$._eol
|
|
230
275
|
),
|
|
231
276
|
seq(
|
|
@@ -233,25 +278,14 @@ module.exports = grammar({
|
|
|
233
278
|
field("optflag", optional($.optflag)),
|
|
234
279
|
field("account", $.account),
|
|
235
280
|
field("amount", optional($.incomplete_amount)),
|
|
281
|
+
field("comment", optional($.comment)),
|
|
236
282
|
$._eol
|
|
237
283
|
)
|
|
238
284
|
),
|
|
239
285
|
|
|
240
|
-
|
|
241
|
-
prec.left(seq(
|
|
242
|
-
$.key,
|
|
243
|
-
$._colon,
|
|
244
|
-
optional($._key_value_value),
|
|
245
|
-
)),
|
|
286
|
+
key: $ => token(/[a-z][a-zA-Z0-9\-_]+/),
|
|
246
287
|
|
|
247
|
-
|
|
248
|
-
$._indent,
|
|
249
|
-
$.key_value,
|
|
250
|
-
$._eol
|
|
251
|
-
),
|
|
252
|
-
|
|
253
|
-
// OPTIONAL
|
|
254
|
-
_key_value_value: $ =>
|
|
288
|
+
value: $ =>
|
|
255
289
|
choice(
|
|
256
290
|
$.string,
|
|
257
291
|
$.account,
|
|
@@ -264,30 +298,26 @@ module.exports = grammar({
|
|
|
264
298
|
$.amount
|
|
265
299
|
),
|
|
266
300
|
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
// $.comment
|
|
285
|
-
//)
|
|
286
|
-
)
|
|
287
|
-
),
|
|
301
|
+
key_value: $ =>
|
|
302
|
+
prec.left(seq(
|
|
303
|
+
$.key,
|
|
304
|
+
":",
|
|
305
|
+
$.value,
|
|
306
|
+
)),
|
|
307
|
+
|
|
308
|
+
_key_value_line: $ => seq(
|
|
309
|
+
$._indent,
|
|
310
|
+
/*prec.left(seq(
|
|
311
|
+
$.key,
|
|
312
|
+
":",
|
|
313
|
+
$.value,
|
|
314
|
+
)),*/
|
|
315
|
+
$.key_value,
|
|
316
|
+
$._eol
|
|
317
|
+
),
|
|
288
318
|
|
|
289
319
|
// OPTIONAL
|
|
290
|
-
|
|
320
|
+
_key_value_list: $ =>
|
|
291
321
|
repeat1(
|
|
292
322
|
choice(
|
|
293
323
|
seq(
|
|
@@ -295,57 +325,58 @@ module.exports = grammar({
|
|
|
295
325
|
$._eol
|
|
296
326
|
),
|
|
297
327
|
seq(
|
|
298
|
-
$.
|
|
328
|
+
$._key_value_line
|
|
299
329
|
)
|
|
300
330
|
)
|
|
301
331
|
),
|
|
302
332
|
|
|
303
333
|
// OPTIONAL
|
|
304
|
-
currency_list: $ =>
|
|
305
|
-
seq(
|
|
306
|
-
$.currency,
|
|
307
|
-
repeat(
|
|
308
|
-
seq(
|
|
309
|
-
$._comma,
|
|
310
|
-
$.currency
|
|
311
|
-
)
|
|
312
|
-
)
|
|
313
|
-
),
|
|
314
334
|
|
|
315
335
|
pushtag: $ => seq(
|
|
316
|
-
|
|
336
|
+
"pushtag",
|
|
317
337
|
$.tag,
|
|
318
338
|
$._eol
|
|
319
339
|
),
|
|
320
340
|
|
|
321
341
|
poptag: $ => seq(
|
|
322
|
-
|
|
342
|
+
"poptag",
|
|
323
343
|
$.tag,
|
|
324
344
|
$._eol
|
|
325
345
|
),
|
|
326
346
|
|
|
327
347
|
pushmeta: $ => seq(
|
|
328
|
-
|
|
348
|
+
"pushmeta",
|
|
329
349
|
$.key_value,
|
|
330
350
|
$._eol
|
|
331
351
|
),
|
|
332
352
|
|
|
333
353
|
popmeta: $ => seq(
|
|
334
|
-
|
|
354
|
+
"popmeta",
|
|
335
355
|
$.key,
|
|
336
|
-
|
|
356
|
+
":",
|
|
337
357
|
$._eol
|
|
338
358
|
),
|
|
339
359
|
|
|
340
360
|
open: $ =>
|
|
341
361
|
seq(
|
|
342
362
|
field("date", $.date),
|
|
343
|
-
|
|
363
|
+
"open",
|
|
344
364
|
field("account", $.account),
|
|
345
|
-
field("currencies", repeat(
|
|
365
|
+
field("currencies", repeat(
|
|
366
|
+
seq(
|
|
367
|
+
$.currency,
|
|
368
|
+
repeat(
|
|
369
|
+
seq(
|
|
370
|
+
",",
|
|
371
|
+
$.currency
|
|
372
|
+
)
|
|
373
|
+
)
|
|
374
|
+
),
|
|
375
|
+
)),
|
|
346
376
|
field("opt_booking", optional($.opt_booking)),
|
|
377
|
+
field("comment", optional($.comment)),
|
|
347
378
|
$._eol,
|
|
348
|
-
optional($.
|
|
379
|
+
optional($._key_value_list)
|
|
349
380
|
),
|
|
350
381
|
|
|
351
382
|
// OPTIONAL
|
|
@@ -354,44 +385,48 @@ module.exports = grammar({
|
|
|
354
385
|
close: $ =>
|
|
355
386
|
seq(
|
|
356
387
|
field("date", $.date),
|
|
357
|
-
|
|
388
|
+
"close",
|
|
358
389
|
field("account", $.account),
|
|
390
|
+
field("comment", optional($.comment)),
|
|
359
391
|
$._eol,
|
|
360
|
-
optional($.
|
|
392
|
+
optional($._key_value_list)
|
|
361
393
|
),
|
|
362
394
|
|
|
363
395
|
commodity: $ =>
|
|
364
396
|
seq(
|
|
365
397
|
field("date", $.date),
|
|
366
|
-
|
|
398
|
+
"commodity",
|
|
367
399
|
field("currency", $.currency),
|
|
400
|
+
field("comment", optional($.comment)),
|
|
368
401
|
$._eol,
|
|
369
|
-
optional($.
|
|
402
|
+
optional($._key_value_list)
|
|
370
403
|
),
|
|
371
404
|
|
|
372
405
|
pad: $ =>
|
|
373
406
|
seq(
|
|
374
407
|
field("date", $.date),
|
|
375
|
-
|
|
408
|
+
"pad",
|
|
376
409
|
field("account", $.account),
|
|
377
410
|
field("from_account", $.account),
|
|
411
|
+
field("comment", optional($.comment)),
|
|
378
412
|
$._eol,
|
|
379
|
-
optional($.
|
|
413
|
+
optional($._key_value_list)
|
|
380
414
|
),
|
|
381
415
|
|
|
382
416
|
balance: $ =>
|
|
383
417
|
seq(
|
|
384
418
|
field("date", $.date),
|
|
385
|
-
|
|
419
|
+
"balance",
|
|
386
420
|
field("account", $.account),
|
|
387
421
|
field("amount",
|
|
388
422
|
//choice(
|
|
389
423
|
// $.amount,
|
|
390
|
-
|
|
424
|
+
$.amount_tolerance,
|
|
391
425
|
//)
|
|
392
426
|
),
|
|
427
|
+
field("comment", optional($.comment)),
|
|
393
428
|
$._eol,
|
|
394
|
-
optional($.
|
|
429
|
+
optional($._key_value_list)
|
|
395
430
|
),
|
|
396
431
|
|
|
397
432
|
amount: $ =>
|
|
@@ -408,7 +443,7 @@ module.exports = grammar({
|
|
|
408
443
|
),
|
|
409
444
|
seq(
|
|
410
445
|
$._number_expr,
|
|
411
|
-
|
|
446
|
+
"~",
|
|
412
447
|
$._number_expr,
|
|
413
448
|
$.currency
|
|
414
449
|
)
|
|
@@ -432,7 +467,7 @@ module.exports = grammar({
|
|
|
432
467
|
),
|
|
433
468
|
seq(
|
|
434
469
|
field("per", optional($._number_expr)),
|
|
435
|
-
|
|
470
|
+
"#",
|
|
436
471
|
field("total", optional($._number_expr)),
|
|
437
472
|
field("currency", $.currency)
|
|
438
473
|
),
|
|
@@ -450,24 +485,24 @@ module.exports = grammar({
|
|
|
450
485
|
cost_spec: $ =>
|
|
451
486
|
choice(
|
|
452
487
|
seq(
|
|
453
|
-
|
|
454
|
-
field("cost_comp_list",
|
|
455
|
-
|
|
488
|
+
"{",
|
|
489
|
+
field("cost_comp_list", optional($._cost_comp_list)),
|
|
490
|
+
"}"
|
|
456
491
|
),
|
|
457
492
|
seq(
|
|
458
|
-
|
|
459
|
-
field("cost_comp_list",
|
|
460
|
-
|
|
493
|
+
"{{",
|
|
494
|
+
field("cost_comp_list", optional($._cost_comp_list)),
|
|
495
|
+
"}}"
|
|
461
496
|
),
|
|
462
497
|
),
|
|
463
498
|
|
|
464
499
|
// OPTIONAL
|
|
465
|
-
|
|
500
|
+
_cost_comp_list: $ =>
|
|
466
501
|
seq(
|
|
467
502
|
$.cost_comp,
|
|
468
503
|
repeat(
|
|
469
504
|
seq(
|
|
470
|
-
|
|
505
|
+
",",
|
|
471
506
|
$.cost_comp
|
|
472
507
|
)
|
|
473
508
|
)
|
|
@@ -478,60 +513,60 @@ module.exports = grammar({
|
|
|
478
513
|
$.compound_amount,
|
|
479
514
|
$.date,
|
|
480
515
|
$.string,
|
|
481
|
-
|
|
516
|
+
"*"
|
|
482
517
|
),
|
|
483
518
|
|
|
484
519
|
price: $ =>
|
|
485
520
|
seq(
|
|
486
521
|
field("date", $.date),
|
|
487
|
-
|
|
522
|
+
"price",
|
|
488
523
|
field("currency", $.currency),
|
|
489
524
|
field("amount", $.amount),
|
|
490
525
|
$._eol,
|
|
491
|
-
optional($.
|
|
526
|
+
optional($._key_value_list)
|
|
492
527
|
),
|
|
493
528
|
|
|
494
529
|
event: $ =>
|
|
495
530
|
seq(
|
|
496
531
|
field("date", $.date),
|
|
497
|
-
|
|
532
|
+
"event",
|
|
498
533
|
field("type", $.string),
|
|
499
534
|
field("desc", $.string),
|
|
500
535
|
$._eol,
|
|
501
|
-
optional($.
|
|
536
|
+
optional($._key_value_list)
|
|
502
537
|
),
|
|
503
538
|
|
|
504
539
|
query: $ =>
|
|
505
540
|
seq(
|
|
506
541
|
field("date", $.date),
|
|
507
|
-
|
|
542
|
+
"query",
|
|
508
543
|
field("name", $.string),
|
|
509
544
|
field("query", $.string),
|
|
510
545
|
$._eol,
|
|
511
|
-
optional($.
|
|
546
|
+
optional($._key_value_list)
|
|
512
547
|
),
|
|
513
548
|
|
|
514
549
|
note: $ =>
|
|
515
550
|
seq(
|
|
516
551
|
field("date", $.date),
|
|
517
|
-
|
|
552
|
+
"note",
|
|
518
553
|
field("account", $.account),
|
|
519
554
|
field("note", $.string),
|
|
520
555
|
$._eol,
|
|
521
|
-
optional($.
|
|
556
|
+
optional($._key_value_list)
|
|
522
557
|
),
|
|
523
558
|
|
|
524
559
|
filename: $ => $.string,
|
|
525
560
|
|
|
526
|
-
document:
|
|
561
|
+
document: $ =>
|
|
527
562
|
seq(
|
|
528
563
|
field("date", $.date),
|
|
529
|
-
|
|
564
|
+
"document",
|
|
530
565
|
field("account", $.account),
|
|
531
566
|
field("filename", $.filename),
|
|
532
567
|
field("tags_links", optional($.tags_links)),
|
|
533
568
|
$._eol,
|
|
534
|
-
optional($.
|
|
569
|
+
optional($._key_value_list)
|
|
535
570
|
),
|
|
536
571
|
|
|
537
572
|
custom_value: $ =>
|
|
@@ -544,19 +579,19 @@ module.exports = grammar({
|
|
|
544
579
|
$.account
|
|
545
580
|
),
|
|
546
581
|
|
|
547
|
-
custom_value_list: $ =>
|
|
548
|
-
repeat1(
|
|
549
|
-
$.custom_value
|
|
550
|
-
),
|
|
551
582
|
|
|
552
583
|
custom: $ =>
|
|
553
584
|
seq(
|
|
554
585
|
field("date", $.date),
|
|
555
|
-
|
|
586
|
+
"custom",
|
|
556
587
|
field("name", $.string),
|
|
557
|
-
field("custom_value_list", optional(
|
|
588
|
+
field("custom_value_list", optional(
|
|
589
|
+
repeat1(
|
|
590
|
+
$.custom_value
|
|
591
|
+
),
|
|
592
|
+
)),
|
|
558
593
|
$._eol,
|
|
559
|
-
optional($.
|
|
594
|
+
optional($._key_value_list)
|
|
560
595
|
),
|
|
561
596
|
|
|
562
597
|
_entry: $ =>
|
|
@@ -576,14 +611,14 @@ module.exports = grammar({
|
|
|
576
611
|
),
|
|
577
612
|
|
|
578
613
|
option: $ => seq(
|
|
579
|
-
|
|
614
|
+
"option",
|
|
580
615
|
field("key", $.string),
|
|
581
|
-
field("value"
|
|
616
|
+
field("value", $.string),
|
|
582
617
|
$._eol,
|
|
583
618
|
),
|
|
584
619
|
|
|
585
620
|
include: $ => seq(
|
|
586
|
-
|
|
621
|
+
"include",
|
|
587
622
|
$.string,
|
|
588
623
|
$._eol,
|
|
589
624
|
),
|
|
@@ -591,12 +626,12 @@ module.exports = grammar({
|
|
|
591
626
|
plugin: $ =>
|
|
592
627
|
choice(
|
|
593
628
|
seq(
|
|
594
|
-
|
|
629
|
+
"plugin",
|
|
595
630
|
$.string,
|
|
596
631
|
$._eol
|
|
597
632
|
),
|
|
598
633
|
seq(
|
|
599
|
-
|
|
634
|
+
"plugin",
|
|
600
635
|
$.string,
|
|
601
636
|
$.string,
|
|
602
637
|
$._eol
|
|
@@ -619,12 +654,14 @@ module.exports = grammar({
|
|
|
619
654
|
$._entry,
|
|
620
655
|
$._skipped_lines,
|
|
621
656
|
),
|
|
657
|
+
|
|
622
658
|
/* End Grammar Rules */
|
|
623
659
|
/*--------------------------------------------------------------------------------*/
|
|
624
660
|
|
|
625
|
-
|
|
661
|
+
comment: $ => seq(';', /.*/),
|
|
626
662
|
|
|
627
|
-
|
|
663
|
+
// NOTE: includes reserved identifiers
|
|
664
|
+
identifier: $ => /[a-z]+/,
|
|
628
665
|
|
|
629
666
|
_skipped_lines: $ =>
|
|
630
667
|
choice(
|
|
@@ -634,7 +671,7 @@ module.exports = grammar({
|
|
|
634
671
|
$._eol
|
|
635
672
|
),
|
|
636
673
|
seq(
|
|
637
|
-
|
|
674
|
+
":",
|
|
638
675
|
/.*/,
|
|
639
676
|
$._eol
|
|
640
677
|
),
|
|
@@ -642,7 +679,7 @@ module.exports = grammar({
|
|
|
642
679
|
seq(
|
|
643
680
|
$.comment,
|
|
644
681
|
$._eol
|
|
645
|
-
)
|
|
682
|
+
),
|
|
646
683
|
),
|
|
647
684
|
|
|
648
685
|
_ASCII: $ => /[\x00-\x7f]/,
|
|
@@ -694,10 +731,9 @@ module.exports = grammar({
|
|
|
694
731
|
$._UTF_8_3,
|
|
695
732
|
$._UTF_8_4,
|
|
696
733
|
),
|
|
697
|
-
_UTF_8: $ =>
|
|
734
|
+
_UTF_8: $ => choice(
|
|
698
735
|
$._ASCII,
|
|
699
736
|
$._UTF_8_ONLY,
|
|
700
737
|
),
|
|
701
|
-
|
|
702
738
|
}
|
|
703
|
-
})
|
|
739
|
+
})
|