tree-sitter-beancount 2.0.0 → 2.1.0

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/grammar.js CHANGED
@@ -3,64 +3,108 @@ module.exports = grammar({
3
3
  * From beancount grammar.y
4
4
  */
5
5
 
6
- name: 'beancount',
6
+ name: "beancount",
7
7
 
8
- extras: $ => [/[ \t\r ]/],
8
+ // Ensure we don't extract keywords from tokens
9
+ //word: ($) => $.identifier,
9
10
 
10
- // TODO look at this to speed up
11
- word: $ => $.identifier,
11
+ inline: ($) => [
12
+ ],
12
13
 
13
- //conflicts: $ => [[$.posting], [$.tags_links]],
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
+ ],
14
26
 
15
27
  rules: {
28
+ file: $ => repeat(
29
+ choice(
30
+ $.section,
31
+ $._declarations,
32
+ $._nl,
33
+ )
34
+ ),
35
+
36
+ _nl: _ => choice('\n', '\r'),
37
+ _eol: $ => choice('\n', '\r', $._eof),
38
+ _any: $ => /.*/,
39
+
40
+
41
+ /*
42
+ * Org Header Sections
43
+ */
44
+ section: $ => seq(
45
+ field('headline', $.headline),
46
+ repeat(choice(
47
+ $._declarations,
48
+ $._nl
49
+ )),
50
+ repeat(field('subsection', $.section)),
51
+ $._sectionend
52
+ ),
53
+ _org_stars: $ => seq($._stars, /\*+/),
54
+ headline: $ => seq(
55
+ $._org_stars,
56
+ /[ \t]+/, // so it's not part of (item)
57
+ optional(field('item', $.item)),
58
+ $._nl,
59
+ ),
60
+ item: $ => $._any,
16
61
 
17
- file: $ => repeat($._declarations),
18
62
 
19
63
  /* Types for terminal symbols */
20
- _indent: $ => token(/[ \r\t]+/),
21
- _eol: $ => token(/\n/),
22
- _pipe: $ => token('|'),
23
- atat: $ => token('@@'),
24
- at: $ => token('@'),
64
+ _indent: $ => token(/[ \r\t]+/),
65
+ _eol: $ => token(/\n/),
66
+ _pipe: $ => token('|'),
67
+ atat: $ => token('@@'),
68
+ at: $ => token('@'),
25
69
  lcurllcurl: $ => token('{{'),
26
70
  rcurlrcurl: $ => token('}}'),
27
- lcurl: $ => token('{'),
28
- rcurl: $ => token('}'),
29
- _equal: $ => token('='),
30
- _comma: $ => token(','),
31
- _tilde: $ => token('~'),
32
- _hash: $ => token('#'),
33
- asterisk: $ => token('*'),
34
- slash: $ => token('/'),
35
- _colon: $ => token(':'),
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: $ =>
71
+ lcurl: $ => token('{'),
72
+ rcurl: $ => token('}'),
73
+ _equal: $ => token('='),
74
+ _comma: $ => token(','),
75
+ _tilde: $ => token('~'),
76
+ _hash: $ => token('#'),
77
+ asterisk: $ => token('*'),
78
+ slash: $ => token('/'),
79
+ _colon: $ => token(':'),
80
+ plus: $ => token('+'),
81
+ minus: $ => token('-'),
82
+ _lparen: $ => token('('),
83
+ _rparen: $ => token(')'),
84
+ flag: $ => token(/[!&?%PSTCURM*#]/),
85
+ TXN: $ => token('txn'),
86
+ BALANCE: $ => token('balance'),
87
+ OPEN: $ => token('open'),
88
+ CLOSE: $ => token('close'),
89
+ COMMODITY: $ => token('commodity'),
90
+ PAD: $ => token('pad'),
91
+ EVENT: $ => token('event'),
92
+ PRICE: $ => token('price'),
93
+ NOTE: $ => token('note'),
94
+ DOCUMENT: $ => token('document'),
95
+ QUERY: $ => token('query'),
96
+ CUSTOM: $ => token('custom'),
97
+ PUSHTAG: $ => token('pushtag'),
98
+ POPTAG: $ => token('poptag'),
99
+ PUSHMETA: $ => token('pushmeta'),
100
+ POPMETA: $ => token('popmeta'),
101
+ OPTION: $ => token('option'),
102
+ INCLUDE: $ => token('include'),
103
+ PLUGIN: $ => token('plugin'),
104
+ _none: $ => token('NULL'),
105
+ bool: $ => token(/TRUE|FALSE/),
106
+ date: $ => token(/([12]\d{3}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01]))/),
107
+ account: $ =>
64
108
  token(
65
109
  seq(
66
110
  /[A-Z]|[^\x00-\x7F]/,
@@ -74,20 +118,20 @@ module.exports = grammar({
74
118
  ),
75
119
  ),
76
120
  ),
77
- currency: $ => token(/[A-Z][A-Z0-9\'\._\-]{0,22}[A-Z0-9]/),
78
- string: $ => token(/"[^"]*"/),
79
- number: $ => token(/([0-9]+|[0-9][0-9,]+[0-9])(\.[0-9]*)?/),
80
- tag: $ => token(/#[A-Za-z0-9\-_/.]+/),
81
- link: $ => token(/\^[A-Za-z0-9\-_/.]+/),
82
- key: $ => token(/[a-z][a-zA-Z0-9\-_]+/),
121
+ currency: $ => token(/[A-Z][A-Z0-9\'\._\-]{0,22}[A-Z0-9]/),
122
+ string: $ => token(/"[^"]*"/),
123
+ number: $ => token(/([0-9]+|[0-9][0-9,]+[0-9])(\.[0-9]*)?/),
124
+ tag: $ => token(/#[A-Za-z0-9\-_/.]+/),
125
+ link: $ => token(/\^[A-Za-z0-9\-_/.]+/),
126
+ key: $ => token(/[a-z][a-zA-Z0-9\-_]+/),
83
127
 
84
128
  /* Operator precedence.
85
129
  * This is pulled straight out of the textbook example:
86
130
  * https://www.gnu.org/software/bison/manual/html_node/Infix-Calc.html#Infix-Calc
87
131
  */
88
- // %left MINUS PLUS
89
- // %left ASTERISK SLASH
90
- // %precedence NEGATIVE /* negation--unary minus */
132
+ // %left MINUS PLUS
133
+ // %left ASTERISK SLASH
134
+ // %precedence NEGATIVE /* negation--unary minus */
91
135
 
92
136
  // Start symbol: file
93
137
  /* We have some number of expected shift/reduce conflicts at 'eol'. */
@@ -133,16 +177,16 @@ module.exports = grammar({
133
177
  prec(3,
134
178
  choice(
135
179
  prec.left(1,
136
- seq( $._number_expr, $.plus, $._number_expr ),
180
+ seq($._number_expr, $.plus, $._number_expr),
137
181
  ),
138
182
  prec.left(1,
139
- seq( $._number_expr, $.minus, $._number_expr ),
183
+ seq($._number_expr, $.minus, $._number_expr),
140
184
  ),
141
185
  prec.left(2,
142
- seq( $._number_expr, $.asterisk, $._number_expr ),
186
+ seq($._number_expr, $.asterisk, $._number_expr),
143
187
  ),
144
188
  prec.left(2,
145
- seq( $._number_expr, $.slash, $._number_expr ),
189
+ seq($._number_expr, $.slash, $._number_expr),
146
190
  ),
147
191
  ),
148
192
  ),
@@ -158,11 +202,11 @@ module.exports = grammar({
158
202
  tags_links: $ =>
159
203
  repeat1(
160
204
  //seq(
161
- // optional($._indent),
162
- choice(
163
- $.link,
164
- $.tag,
165
- ),
205
+ // optional($._indent),
206
+ choice(
207
+ $.link,
208
+ $.tag,
209
+ ),
166
210
  //),
167
211
  ),
168
212
 
@@ -172,6 +216,7 @@ module.exports = grammar({
172
216
  field("txn", $.txn),
173
217
  field("txn_strings", optional($.txn_strings)),
174
218
  field("tags_links", optional($.tags_links)),
219
+ field("comment", optional($.comment)),
175
220
  $._eol,
176
221
  field("posting_or_kv_list", optional($.posting_or_kv_list)),
177
222
  ),
@@ -185,16 +230,16 @@ module.exports = grammar({
185
230
  ),
186
231
 
187
232
  price_annotation: $ => $.incomplete_amount,
188
- //choice(
189
- // seq(
190
- // $.atat,
191
- // $.incomplete_amount
192
- // ),
193
- // seq(
194
- // $.at,
195
- // $.incomplete_amount
196
- // )
197
- //),
233
+ //choice(
234
+ // seq(
235
+ // $.atat,
236
+ // $.incomplete_amount
237
+ // ),
238
+ // seq(
239
+ // $.at,
240
+ // $.incomplete_amount
241
+ // )
242
+ //),
198
243
 
199
244
  //account: $ => $.ACCOUNT,
200
245
 
@@ -206,6 +251,7 @@ module.exports = grammar({
206
251
  field("account", $.account),
207
252
  field("amount", optional($.incomplete_amount)),
208
253
  field("cost_spec", optional($.cost_spec)),
254
+ field("comment", optional($.comment)),
209
255
  $._eol
210
256
  ),
211
257
  seq(
@@ -216,6 +262,7 @@ module.exports = grammar({
216
262
  field("cost_spec", optional($.cost_spec)),
217
263
  $.at,
218
264
  field("price_annotation", optional($.price_annotation)),
265
+ field("comment", optional($.comment)),
219
266
  $._eol
220
267
  ),
221
268
  seq(
@@ -226,6 +273,7 @@ module.exports = grammar({
226
273
  field("cost_spec", optional($.cost_spec)),
227
274
  $.atat,
228
275
  field("price_annotation", optional($.price_annotation)),
276
+ field("comment", optional($.comment)),
229
277
  $._eol
230
278
  ),
231
279
  seq(
@@ -233,6 +281,7 @@ module.exports = grammar({
233
281
  field("optflag", optional($.optflag)),
234
282
  field("account", $.account),
235
283
  field("amount", optional($.incomplete_amount)),
284
+ field("comment", optional($.comment)),
236
285
  $._eol
237
286
  )
238
287
  ),
@@ -278,11 +327,12 @@ module.exports = grammar({
278
327
  $._eol
279
328
  ),
280
329
  $.key_value_line,
281
- $.posting
282
- //seq(
283
- // $._indent,
284
- // $.comment
285
- //)
330
+ $.posting,
331
+ seq(
332
+ $._indent,
333
+ $.comment,
334
+ $._eol
335
+ )
286
336
  )
287
337
  ),
288
338
 
@@ -313,25 +363,25 @@ module.exports = grammar({
313
363
  ),
314
364
 
315
365
  pushtag: $ => seq(
316
- $.PUSHTAG,
366
+ alias($.PUSHTAG, "pushtag"),
317
367
  $.tag,
318
368
  $._eol
319
369
  ),
320
370
 
321
371
  poptag: $ => seq(
322
- $.POPTAG,
372
+ alias($.POPTAG, "poptag"),
323
373
  $.tag,
324
374
  $._eol
325
375
  ),
326
376
 
327
377
  pushmeta: $ => seq(
328
- $.PUSHMETA,
378
+ alias($.PUSHMETA, "pushmeta"),
329
379
  $.key_value,
330
380
  $._eol
331
381
  ),
332
382
 
333
383
  popmeta: $ => seq(
334
- $.POPMETA,
384
+ alias($.POPMETA, "popmeta"),
335
385
  $.key,
336
386
  $._colon,
337
387
  $._eol
@@ -340,10 +390,11 @@ module.exports = grammar({
340
390
  open: $ =>
341
391
  seq(
342
392
  field("date", $.date),
343
- $.OPEN,
393
+ alias($.OPEN, "open"),
344
394
  field("account", $.account),
345
395
  field("currencies", repeat($.currency_list)),
346
396
  field("opt_booking", optional($.opt_booking)),
397
+ field("comment", optional($.comment)),
347
398
  $._eol,
348
399
  optional($.key_value_list)
349
400
  ),
@@ -354,8 +405,9 @@ module.exports = grammar({
354
405
  close: $ =>
355
406
  seq(
356
407
  field("date", $.date),
357
- $.CLOSE,
408
+ alias($.CLOSE, "close"),
358
409
  field("account", $.account),
410
+ field("comment", optional($.comment)),
359
411
  $._eol,
360
412
  optional($.key_value_list)
361
413
  ),
@@ -363,8 +415,9 @@ module.exports = grammar({
363
415
  commodity: $ =>
364
416
  seq(
365
417
  field("date", $.date),
366
- $.COMMODITY,
418
+ alias($.COMMODITY, "commodity"),
367
419
  field("currency", $.currency),
420
+ field("comment", optional($.comment)),
368
421
  $._eol,
369
422
  optional($.key_value_list)
370
423
  ),
@@ -372,9 +425,10 @@ module.exports = grammar({
372
425
  pad: $ =>
373
426
  seq(
374
427
  field("date", $.date),
375
- $.PAD,
428
+ alias($.PAD, "pad"),
376
429
  field("account", $.account),
377
430
  field("from_account", $.account),
431
+ field("comment", optional($.comment)),
378
432
  $._eol,
379
433
  optional($.key_value_list)
380
434
  ),
@@ -382,14 +436,15 @@ module.exports = grammar({
382
436
  balance: $ =>
383
437
  seq(
384
438
  field("date", $.date),
385
- $.BALANCE,
439
+ alias($.BALANCE, "balance"),
386
440
  field("account", $.account),
387
441
  field("amount",
388
442
  //choice(
389
443
  // $.amount,
390
- $.amount_tolerance,
444
+ $.amount_tolerance,
391
445
  //)
392
446
  ),
447
+ field("comment", optional($.comment)),
393
448
  $._eol,
394
449
  optional($.key_value_list)
395
450
  ),
@@ -451,12 +506,12 @@ module.exports = grammar({
451
506
  choice(
452
507
  seq(
453
508
  $.lcurl,
454
- field("cost_comp_list", optional($.cost_comp_list)),
509
+ field("cost_comp_list", optional($.cost_comp_list)),
455
510
  $.rcurl
456
511
  ),
457
512
  seq(
458
513
  $.lcurllcurl,
459
- field("cost_comp_list", optional($.cost_comp_list)),
514
+ field("cost_comp_list", optional($.cost_comp_list)),
460
515
  $.rcurlrcurl
461
516
  ),
462
517
  ),
@@ -484,7 +539,7 @@ module.exports = grammar({
484
539
  price: $ =>
485
540
  seq(
486
541
  field("date", $.date),
487
- $.PRICE,
542
+ alias($.PRICE, "price"),
488
543
  field("currency", $.currency),
489
544
  field("amount", $.amount),
490
545
  $._eol,
@@ -494,7 +549,7 @@ module.exports = grammar({
494
549
  event: $ =>
495
550
  seq(
496
551
  field("date", $.date),
497
- $.EVENT,
552
+ alias($.EVENT, "event"),
498
553
  field("type", $.string),
499
554
  field("desc", $.string),
500
555
  $._eol,
@@ -504,7 +559,7 @@ module.exports = grammar({
504
559
  query: $ =>
505
560
  seq(
506
561
  field("date", $.date),
507
- $.QUERY,
562
+ alias($.QUERY, "query"),
508
563
  field("name", $.string),
509
564
  field("query", $.string),
510
565
  $._eol,
@@ -514,7 +569,7 @@ module.exports = grammar({
514
569
  note: $ =>
515
570
  seq(
516
571
  field("date", $.date),
517
- $.NOTE,
572
+ alias($.NOTE, "note"),
518
573
  field("account", $.account),
519
574
  field("note", $.string),
520
575
  $._eol,
@@ -523,10 +578,10 @@ module.exports = grammar({
523
578
 
524
579
  filename: $ => $.string,
525
580
 
526
- document: $=>
581
+ document: $ =>
527
582
  seq(
528
583
  field("date", $.date),
529
- $.DOCUMENT,
584
+ alias($.DOCUMENT, "document"),
530
585
  field("account", $.account),
531
586
  field("filename", $.filename),
532
587
  field("tags_links", optional($.tags_links)),
@@ -552,7 +607,7 @@ module.exports = grammar({
552
607
  custom: $ =>
553
608
  seq(
554
609
  field("date", $.date),
555
- $.CUSTOM,
610
+ alias($.CUSTOM, "custom"),
556
611
  field("name", $.string),
557
612
  field("custom_value_list", optional($.custom_value_list)),
558
613
  $._eol,
@@ -576,14 +631,14 @@ module.exports = grammar({
576
631
  ),
577
632
 
578
633
  option: $ => seq(
579
- $.OPTION,
634
+ alias($.OPTION, "option"),
580
635
  field("key", $.string),
581
- field("value",$.string),
636
+ field("value", $.string),
582
637
  $._eol,
583
638
  ),
584
639
 
585
640
  include: $ => seq(
586
- $.INCLUDE,
641
+ alias($.INCLUDE, "include"),
587
642
  $.string,
588
643
  $._eol,
589
644
  ),
@@ -591,12 +646,12 @@ module.exports = grammar({
591
646
  plugin: $ =>
592
647
  choice(
593
648
  seq(
594
- $.PLUGIN,
649
+ alias($.PLUGIN, "plugin"),
595
650
  $.string,
596
651
  $._eol
597
652
  ),
598
653
  seq(
599
- $.PLUGIN,
654
+ alias($.PLUGIN, "plugin"),
600
655
  $.string,
601
656
  $.string,
602
657
  $._eol
@@ -619,12 +674,14 @@ module.exports = grammar({
619
674
  $._entry,
620
675
  $._skipped_lines,
621
676
  ),
677
+
622
678
  /* End Grammar Rules */
623
679
  /*--------------------------------------------------------------------------------*/
624
680
 
625
- identifier: $ => /[a-z]+/,
681
+ comment: $ => seq(';', /.*/),
626
682
 
627
- comment: $ => /;.*/,
683
+ // NOTE: includes reserved identifiers
684
+ identifier: $ => /[_a-zA-Z0-9]+/,
628
685
 
629
686
  _skipped_lines: $ =>
630
687
  choice(
@@ -642,7 +699,7 @@ module.exports = grammar({
642
699
  seq(
643
700
  $.comment,
644
701
  $._eol
645
- )
702
+ ),
646
703
  ),
647
704
 
648
705
  _ASCII: $ => /[\x00-\x7f]/,
@@ -694,10 +751,9 @@ module.exports = grammar({
694
751
  $._UTF_8_3,
695
752
  $._UTF_8_4,
696
753
  ),
697
- _UTF_8: $ => choice(
754
+ _UTF_8: $ => choice(
698
755
  $._ASCII,
699
756
  $._UTF_8_ONLY,
700
757
  ),
701
-
702
758
  }
703
- });
759
+ })
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "tree-sitter-beancount",
3
- "version": "2.0.0",
3
+ "version": "2.1.0",
4
4
  "description": "a tree-sitter parser for the beancount syntax",
5
- "main": "index.js",
5
+ "main": "bindings/node",
6
6
  "scripts": {
7
- "tree-sitter": "tree-sitter"
7
+ "build": "tree-sitter generate",
8
+ "test": "tree-sitter test"
8
9
  },
9
10
  "repository": {
10
11
  "type": "git",
@@ -21,9 +22,9 @@
21
22
  },
22
23
  "homepage": "https://github.com/bryall/tree-sitter-beancount#readme",
23
24
  "dependencies": {
24
- "nan": "^2.14.1"
25
+ "nan": "^2.15.0"
25
26
  },
26
27
  "devDependencies": {
27
- "tree-sitter-cli": "^0.17.3"
28
+ "tree-sitter-cli": "0.20.0"
28
29
  }
29
30
  }
package/shell.nix ADDED
@@ -0,0 +1,13 @@
1
+ let
2
+ pkgs = import <nixpkgs> {};
3
+ in
4
+ pkgs.mkShell rec {
5
+ name = "tree-sitter";
6
+
7
+ buildInputs = with pkgs; [
8
+ nodejs-14_x
9
+ python38Full
10
+ tree-sitter
11
+ ];
12
+
13
+ }