tree-sitter-beancount 2.3.2 → 2.4.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.
Files changed (45) hide show
  1. package/README.md +334 -4
  2. package/binding.gyp +17 -7
  3. package/bindings/node/binding.cc +14 -22
  4. package/bindings/node/index.d.ts +28 -0
  5. package/bindings/node/index.js +3 -15
  6. package/grammar.js +52 -128
  7. package/package.json +35 -5
  8. package/src/grammar.json +272 -562
  9. package/src/node-types.json +76 -21
  10. package/src/parser.c +8740 -8678
  11. package/src/scanner.c +345 -67
  12. package/src/tree_sitter/alloc.h +54 -0
  13. package/src/tree_sitter/array.h +291 -0
  14. package/src/tree_sitter/parser.h +68 -12
  15. package/.clang-format +0 -20
  16. package/.envrc +0 -1
  17. package/.gitattributes +0 -6
  18. package/.github/dependabot.yml +0 -11
  19. package/.github/workflows/cicd.yml +0 -30
  20. package/.github/workflows/release.yml +0 -72
  21. package/CHANGELOG.md +0 -72
  22. package/Cargo.lock +0 -59
  23. package/Cargo.toml +0 -26
  24. package/Package.swift +0 -20
  25. package/bindings/rust/build.rs +0 -39
  26. package/bindings/rust/lib.rs +0 -52
  27. package/flake.lock +0 -141
  28. package/flake.nix +0 -120
  29. package/test/corpus/arithmetic.txt +0 -373
  30. package/test/corpus/comment.txt +0 -172
  31. package/test/corpus/currencies.txt +0 -66
  32. package/test/corpus/entry_types.txt +0 -389
  33. package/test/corpus/markdown_orgmode.txt +0 -60
  34. package/test/corpus/metadata.txt +0 -414
  35. package/test/corpus/multi_line.txt +0 -27
  36. package/test/corpus/orgmode_sections.txt +0 -53
  37. package/test/corpus/parse_lots.txt +0 -417
  38. package/test/corpus/parser_include.txt +0 -23
  39. package/test/corpus/parser_links.txt +0 -32
  40. package/test/corpus/parser_options.txt +0 -39
  41. package/test/corpus/parser_plugin.txt +0 -35
  42. package/test/corpus/push_pop_meta.txt +0 -34
  43. package/test/corpus/push_pop_tag.txt +0 -23
  44. package/test/corpus/transaction.txt +0 -224
  45. package/test/corpus/ugly_bugs.txt +0 -52
package/grammar.js CHANGED
@@ -40,32 +40,34 @@ module.exports = grammar({
40
40
 
41
41
  _nl: _ => choice('\n', '\r'),
42
42
  _eol: $ => choice('\n', '\r', $._eof),
43
- _any: $ => /.*/,
43
+ _any: $ => /[^\r\n]*/,
44
44
 
45
45
 
46
- /*
47
- * Org Header Sections
48
- */
46
+ /*--------------------------------------------------------------------------------*/
47
+ /* SECTION AND HEADLINE RULES (Org-mode/Markdown support) */
48
+ /*--------------------------------------------------------------------------------*/
49
49
  section: $ => seq(
50
50
  field('headline', $.headline),
51
51
  repeat(choice(
52
52
  $._declarations,
53
- $._nl
53
+ $._nl,
54
+ field('subsection', $.section)
54
55
  )),
55
- repeat(field('subsection', $.section)),
56
56
  $._sectionend
57
57
  ),
58
- _org_stars: $ => seq($._stars, /\*+/),
58
+ _org_stars: $ => seq($._stars, /(\*|#)+/),
59
59
  headline: $ => seq(
60
60
  $._org_stars,
61
- /[ \t]+/, // so it's not part of (item)
61
+ token(/[ \t]+/), // tokenized for performance
62
62
  optional(field('item', $.item)),
63
63
  $._nl,
64
64
  ),
65
- item: $ => $._any,
65
+ item: $ => token(/[^\r\n]+/),
66
66
 
67
67
 
68
- /* Types for terminal symbols */
68
+ /*--------------------------------------------------------------------------------*/
69
+ /* TERMINAL SYMBOLS */
70
+ /*--------------------------------------------------------------------------------*/
69
71
  _indent: $ => token(/[ \r\t]+/),
70
72
  _eol: $ => token(/\n/),
71
73
  atat: $ => token('@@'),
@@ -77,10 +79,9 @@ module.exports = grammar({
77
79
  flag: $ => token(/[!&?%PSTCURM*#]/),
78
80
  _none: $ => token('NULL'),
79
81
  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.
82
+ date: $ => token(/([12]\d{3}[-\/](0[1-9]|1[0-2])[-\/](0[1-9]|[12]\d|3[01]))/),
83
+ // Account names: Assets|Liabilities|Equity|Income|Expenses followed by colon-separated components
84
+ // Components can contain Unicode letters/numbers including CJK characters
84
85
  account: $ =>
85
86
  token(
86
87
  seq(
@@ -88,31 +89,21 @@ module.exports = grammar({
88
89
  repeat1(
89
90
  seq(
90
91
  ":",
91
- /[\p{Lu}\p{N}][\p{L}\p{N}\-]*/,
92
+ /[\p{Lu}\p{N}\u3040-\u309f\u30a0-\u30ff\u4e00-\u9fff\uac00-\ud7a3][\p{L}\p{N}\u3040-\u309f\u30a0-\u30ff\u4e00-\u9fff\uac00-\ud7a3\-]*/,
92
93
  ),
93
94
  ),
94
95
  ),
95
96
  ),
96
- currency: $ => token(/[A-Z][A-Z0-9\'\._\-]{0,22}[A-Z0-9]/),
97
- string: $ => token(/"[^"]*"/),
97
+ currency: $ => token(/[A-Z]([A-Z0-9\'\._\-]{0,22}[A-Z0-9])?/),
98
+ string: $ => token(/"([^"]|\\")*"/),
98
99
  number: $ => token(/([0-9]+|[0-9][0-9,]+[0-9])(\.[0-9]*)?/),
99
100
  tag: $ => token(/#[A-Za-z0-9\-_/.]+/),
100
101
  link: $ => token(/\^[A-Za-z0-9\-_/.]+/),
101
102
 
102
- /* Operator precedence.
103
- * This is pulled straight out of the textbook example:
104
- * https://www.gnu.org/software/bison/manual/html_node/Infix-Calc.html#Infix-Calc
105
- */
106
- // %left MINUS PLUS
107
- // %left ASTERISK SLASH
108
- // %precedence NEGATIVE /* negation--unary minus */
109
-
110
- // Start symbol: file
111
- /* We have some number of expected shift/reduce conflicts at 'eol'. */
112
- //%expect 7
113
-
114
103
  /*--------------------------------------------------------------------------------*/
115
- /* Grammar Rules */
104
+ /* ARITHMETIC EXPRESSIONS */
105
+ /*--------------------------------------------------------------------------------*/
106
+ // Operator precedence: PLUS/MINUS (left, 1), MULTIPLY/DIVIDE (left, 2), UNARY (3)
116
107
 
117
108
  txn: $ => choice(
118
109
  "txn",
@@ -211,7 +202,7 @@ module.exports = grammar({
211
202
  $.posting,
212
203
  seq(
213
204
  $._indent,
214
- $.comment,
205
+ field("comment", $.comment),
215
206
  $._eol
216
207
  )
217
208
  )
@@ -241,46 +232,20 @@ module.exports = grammar({
241
232
  //),
242
233
 
243
234
  posting: $ =>
244
- choice(
245
- seq(
246
- $._indent,
247
- field("optflag", optional($.optflag)),
248
- field("account", $.account),
249
- field("amount", optional($.incomplete_amount)),
250
- field("cost_spec", optional($.cost_spec)),
251
- field("comment", optional($.comment)),
252
- $._eol
253
- ),
254
- seq(
255
- $._indent,
256
- field("optflag", optional($.optflag)),
257
- field("account", $.account),
258
- field("amount", optional($.incomplete_amount)),
259
- field("cost_spec", optional($.cost_spec)),
260
- $.at,
261
- field("price_annotation", optional($.price_annotation)),
262
- field("comment", optional($.comment)),
263
- $._eol
264
- ),
265
- seq(
266
- $._indent,
267
- field("optflag", optional($.optflag)),
268
- field("account", $.account),
269
- field("amount", optional($.incomplete_amount)),
270
- field("cost_spec", optional($.cost_spec)),
271
- $.atat,
272
- field("price_annotation", optional($.price_annotation)),
273
- field("comment", optional($.comment)),
274
- $._eol
235
+ seq(
236
+ $._indent,
237
+ field("optflag", optional($.optflag)),
238
+ field("account", $.account),
239
+ field("amount", optional($.incomplete_amount)),
240
+ field("cost_spec", optional($.cost_spec)),
241
+ optional(
242
+ seq(
243
+ choice($.at, $.atat),
244
+ field("price_annotation", optional($.price_annotation))
245
+ )
275
246
  ),
276
- seq(
277
- $._indent,
278
- field("optflag", optional($.optflag)),
279
- field("account", $.account),
280
- field("amount", optional($.incomplete_amount)),
281
- field("comment", optional($.comment)),
282
- $._eol
283
- )
247
+ field("comment", optional($.comment)),
248
+ $._eol
284
249
  ),
285
250
 
286
251
  key: $ => token(/[a-z][a-zA-Z0-9\-_]+/),
@@ -326,7 +291,12 @@ module.exports = grammar({
326
291
  ),
327
292
  seq(
328
293
  $._key_value_line
329
- )
294
+ ),
295
+ seq(
296
+ $._indent,
297
+ field("comment", $.comment),
298
+ $._eol
299
+ ),
330
300
  )
331
301
  ),
332
302
 
@@ -522,6 +492,7 @@ module.exports = grammar({
522
492
  "price",
523
493
  field("currency", $.currency),
524
494
  field("amount", $.amount),
495
+ field("comment", optional($.comment)),
525
496
  $._eol,
526
497
  optional($._key_value_list)
527
498
  ),
@@ -532,6 +503,7 @@ module.exports = grammar({
532
503
  "event",
533
504
  field("type", $.string),
534
505
  field("desc", $.string),
506
+ field("comment", optional($.comment)),
535
507
  $._eol,
536
508
  optional($._key_value_list)
537
509
  ),
@@ -542,6 +514,7 @@ module.exports = grammar({
542
514
  "query",
543
515
  field("name", $.string),
544
516
  field("query", $.string),
517
+ field("comment", optional($.comment)),
545
518
  $._eol,
546
519
  optional($._key_value_list)
547
520
  ),
@@ -552,6 +525,7 @@ module.exports = grammar({
552
525
  "note",
553
526
  field("account", $.account),
554
527
  field("note", $.string),
528
+ field("comment", optional($.comment)),
555
529
  $._eol,
556
530
  optional($._key_value_list)
557
531
  ),
@@ -565,6 +539,7 @@ module.exports = grammar({
565
539
  field("account", $.account),
566
540
  field("filename", $.filename),
567
541
  field("tags_links", optional($.tags_links)),
542
+ field("comment", optional($.comment)),
568
543
  $._eol,
569
544
  optional($._key_value_list)
570
545
  ),
@@ -590,6 +565,7 @@ module.exports = grammar({
590
565
  $.custom_value
591
566
  ),
592
567
  )),
568
+ field("comment", optional($.comment)),
593
569
  $._eol,
594
570
  optional($._key_value_list)
595
571
  ),
@@ -655,10 +631,11 @@ module.exports = grammar({
655
631
  $._skipped_lines,
656
632
  ),
657
633
 
658
- /* End Grammar Rules */
634
+ /*--------------------------------------------------------------------------------*/
635
+ /* UTILITY AND LEXICAL RULES */
659
636
  /*--------------------------------------------------------------------------------*/
660
637
 
661
- comment: $ => seq(';', /.*/),
638
+ comment: $ => token(seq(';', /[^\r\n]*/)),
662
639
 
663
640
  // NOTE: includes reserved identifiers
664
641
  identifier: $ => /[a-z]+/,
@@ -667,12 +644,12 @@ module.exports = grammar({
667
644
  choice(
668
645
  seq(
669
646
  $.flag,
670
- /.*/,
647
+ /[^\r\n]*/,
671
648
  $._eol
672
649
  ),
673
650
  seq(
674
651
  ":",
675
- /.*/,
652
+ /[^\r\n]*/,
676
653
  $._eol
677
654
  ),
678
655
  $._eol,
@@ -682,58 +659,5 @@ module.exports = grammar({
682
659
  ),
683
660
  ),
684
661
 
685
- _ASCII: $ => /[\x00-\x7f]/,
686
- _UTF_8_1: $ => /[\x80-\xbf]/,
687
- _UTF_8_2: $ => seq(
688
- /[\xc2-\xdf]/,
689
- $._UTF_8_1,
690
- ),
691
- _UTF_8_3: $ => choice(
692
- seq(
693
- /\xe0[\xa0-\xbf]/,
694
- $._UTF_8_1,
695
- ),
696
- seq(
697
- /[\xe1-\xec]/,
698
- $._UTF_8_1,
699
- $._UTF_8_1,
700
- ),
701
- seq(
702
- /\xed[\x80-\x9f]/,
703
- $._UTF_8_1,
704
- ),
705
- seq(
706
- /[\xee-\xef]/,
707
- $._UTF_8_1,
708
- $._UTF_8_1,
709
- ),
710
- ),
711
- _UTF_8_4: $ => choice(
712
- seq(
713
- /\xf0[\x90-\xbf]/,
714
- $._UTF_8_1,
715
- $._UTF_8_1,
716
- ),
717
- seq(
718
- /[\xf1-\xf3]/,
719
- $._UTF_8_1,
720
- $._UTF_8_1,
721
- $._UTF_8_1,
722
- ),
723
- seq(
724
- /\xf4[\x80-\x8f]/,
725
- $._UTF_8_1,
726
- $._UTF_8_1,
727
- ),
728
- ),
729
- _UTF_8_ONLY: $ => choice(
730
- $._UTF_8_2,
731
- $._UTF_8_3,
732
- $._UTF_8_4,
733
- ),
734
- _UTF_8: $ => choice(
735
- $._ASCII,
736
- $._UTF_8_ONLY,
737
- ),
738
662
  }
739
663
  })
package/package.json CHANGED
@@ -1,11 +1,14 @@
1
1
  {
2
2
  "name": "tree-sitter-beancount",
3
- "version": "2.3.2",
3
+ "version": "2.4.0",
4
4
  "description": "a tree-sitter parser for the beancount syntax",
5
5
  "main": "bindings/node",
6
+ "types": "bindings/node",
6
7
  "scripts": {
7
8
  "build": "tree-sitter generate",
8
- "test": "tree-sitter test"
9
+ "test": "tree-sitter test",
10
+ "install": "node-gyp-build",
11
+ "prebuildify": "prebuildify --napi --strip"
9
12
  },
10
13
  "repository": {
11
14
  "type": "git",
@@ -15,6 +18,14 @@
15
18
  "tree-sitter",
16
19
  "beancount"
17
20
  ],
21
+ "files": [
22
+ "grammar.js",
23
+ "binding.gyp",
24
+ "prebuilds/**",
25
+ "bindings/node/*",
26
+ "queries/*",
27
+ "src/**"
28
+ ],
18
29
  "author": "Brian Ryall",
19
30
  "license": "MIT",
20
31
  "bugs": {
@@ -22,9 +33,28 @@
22
33
  },
23
34
  "homepage": "https://github.com/bryall/tree-sitter-beancount#readme",
24
35
  "dependencies": {
25
- "nan": "^2.15.0"
36
+ "node-addon-api": "^7.1.0",
37
+ "node-gyp-build": "^4.8.0"
38
+ },
39
+ "peerDependencies": {
40
+ "tree-sitter": "^0.25.0"
41
+ },
42
+ "peerDependenciesMeta": {
43
+ "tree_sitter": {
44
+ "optional": true
45
+ }
26
46
  },
27
47
  "devDependencies": {
28
- "tree-sitter-cli": "^0.20.0"
29
- }
48
+ "tree-sitter-cli": "^0.25.0",
49
+ "prebuildify": "^6.0.0"
50
+ },
51
+ "engines": {
52
+ "node": ">=22.0.0"
53
+ },
54
+ "tree-sitter": [
55
+ {
56
+ "scope": "source.beancount",
57
+ "injection-regex": "^beancount$"
58
+ }
59
+ ]
30
60
  }