tree-sitter-beancount 2.3.3 → 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.
- package/README.md +334 -4
- package/binding.gyp +17 -7
- package/bindings/node/binding.cc +14 -22
- package/bindings/node/index.d.ts +28 -0
- package/bindings/node/index.js +3 -15
- package/grammar.js +38 -125
- package/package.json +35 -5
- package/src/grammar.json +149 -560
- package/src/node-types.json +10 -11
- package/src/parser.c +7615 -9089
- package/src/scanner.c +345 -67
- package/src/tree_sitter/alloc.h +54 -0
- package/src/tree_sitter/array.h +291 -0
- package/src/tree_sitter/parser.h +68 -12
- package/.clang-format +0 -20
- package/.envrc +0 -1
- package/.gitattributes +0 -6
- package/.github/dependabot.yml +0 -26
- package/.github/workflows/cicd.yml +0 -30
- package/.github/workflows/release.yml +0 -72
- package/CHANGELOG.md +0 -80
- package/Cargo.lock +0 -71
- package/Cargo.toml +0 -26
- package/Package.swift +0 -20
- package/bindings/rust/build.rs +0 -39
- package/bindings/rust/lib.rs +0 -52
- package/flake.lock +0 -141
- package/flake.nix +0 -120
- package/test/corpus/arithmetic.txt +0 -373
- package/test/corpus/comment.txt +0 -992
- package/test/corpus/currencies.txt +0 -66
- package/test/corpus/entry_types.txt +0 -389
- package/test/corpus/markdown_orgmode.txt +0 -60
- package/test/corpus/metadata.txt +0 -414
- package/test/corpus/multi_line.txt +0 -27
- package/test/corpus/orgmode_sections.txt +0 -53
- package/test/corpus/parse_lots.txt +0 -417
- package/test/corpus/parser_include.txt +0 -23
- package/test/corpus/parser_links.txt +0 -32
- package/test/corpus/parser_options.txt +0 -39
- package/test/corpus/parser_plugin.txt +0 -35
- package/test/corpus/push_pop_meta.txt +0 -34
- package/test/corpus/push_pop_tag.txt +0 -23
- package/test/corpus/transaction.txt +0 -224
- package/test/corpus/ugly_bugs.txt +0 -91
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
|
-
|
|
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]
|
|
61
|
+
token(/[ \t]+/), // tokenized for performance
|
|
62
62
|
optional(field('item', $.item)),
|
|
63
63
|
$._nl,
|
|
64
64
|
),
|
|
65
|
-
item: $ =>
|
|
65
|
+
item: $ => token(/[^\r\n]+/),
|
|
66
66
|
|
|
67
67
|
|
|
68
|
-
|
|
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}
|
|
81
|
-
//
|
|
82
|
-
//
|
|
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
|
+
currency: $ => token(/[A-Z]([A-Z0-9\'\._\-]{0,22}[A-Z0-9])?/),
|
|
97
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
|
-
/*
|
|
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",
|
|
@@ -241,46 +232,20 @@ module.exports = grammar({
|
|
|
241
232
|
//),
|
|
242
233
|
|
|
243
234
|
posting: $ =>
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
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
|
-
|
|
277
|
-
|
|
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\-_]+/),
|
|
@@ -666,10 +631,11 @@ module.exports = grammar({
|
|
|
666
631
|
$._skipped_lines,
|
|
667
632
|
),
|
|
668
633
|
|
|
669
|
-
|
|
634
|
+
/*--------------------------------------------------------------------------------*/
|
|
635
|
+
/* UTILITY AND LEXICAL RULES */
|
|
670
636
|
/*--------------------------------------------------------------------------------*/
|
|
671
637
|
|
|
672
|
-
comment: $ => seq(';',
|
|
638
|
+
comment: $ => token(seq(';', /[^\r\n]*/)),
|
|
673
639
|
|
|
674
640
|
// NOTE: includes reserved identifiers
|
|
675
641
|
identifier: $ => /[a-z]+/,
|
|
@@ -678,12 +644,12 @@ module.exports = grammar({
|
|
|
678
644
|
choice(
|
|
679
645
|
seq(
|
|
680
646
|
$.flag,
|
|
681
|
-
|
|
647
|
+
/[^\r\n]*/,
|
|
682
648
|
$._eol
|
|
683
649
|
),
|
|
684
650
|
seq(
|
|
685
651
|
":",
|
|
686
|
-
|
|
652
|
+
/[^\r\n]*/,
|
|
687
653
|
$._eol
|
|
688
654
|
),
|
|
689
655
|
$._eol,
|
|
@@ -693,58 +659,5 @@ module.exports = grammar({
|
|
|
693
659
|
),
|
|
694
660
|
),
|
|
695
661
|
|
|
696
|
-
_ASCII: $ => /[\x00-\x7f]/,
|
|
697
|
-
_UTF_8_1: $ => /[\x80-\xbf]/,
|
|
698
|
-
_UTF_8_2: $ => seq(
|
|
699
|
-
/[\xc2-\xdf]/,
|
|
700
|
-
$._UTF_8_1,
|
|
701
|
-
),
|
|
702
|
-
_UTF_8_3: $ => choice(
|
|
703
|
-
seq(
|
|
704
|
-
/\xe0[\xa0-\xbf]/,
|
|
705
|
-
$._UTF_8_1,
|
|
706
|
-
),
|
|
707
|
-
seq(
|
|
708
|
-
/[\xe1-\xec]/,
|
|
709
|
-
$._UTF_8_1,
|
|
710
|
-
$._UTF_8_1,
|
|
711
|
-
),
|
|
712
|
-
seq(
|
|
713
|
-
/\xed[\x80-\x9f]/,
|
|
714
|
-
$._UTF_8_1,
|
|
715
|
-
),
|
|
716
|
-
seq(
|
|
717
|
-
/[\xee-\xef]/,
|
|
718
|
-
$._UTF_8_1,
|
|
719
|
-
$._UTF_8_1,
|
|
720
|
-
),
|
|
721
|
-
),
|
|
722
|
-
_UTF_8_4: $ => choice(
|
|
723
|
-
seq(
|
|
724
|
-
/\xf0[\x90-\xbf]/,
|
|
725
|
-
$._UTF_8_1,
|
|
726
|
-
$._UTF_8_1,
|
|
727
|
-
),
|
|
728
|
-
seq(
|
|
729
|
-
/[\xf1-\xf3]/,
|
|
730
|
-
$._UTF_8_1,
|
|
731
|
-
$._UTF_8_1,
|
|
732
|
-
$._UTF_8_1,
|
|
733
|
-
),
|
|
734
|
-
seq(
|
|
735
|
-
/\xf4[\x80-\x8f]/,
|
|
736
|
-
$._UTF_8_1,
|
|
737
|
-
$._UTF_8_1,
|
|
738
|
-
),
|
|
739
|
-
),
|
|
740
|
-
_UTF_8_ONLY: $ => choice(
|
|
741
|
-
$._UTF_8_2,
|
|
742
|
-
$._UTF_8_3,
|
|
743
|
-
$._UTF_8_4,
|
|
744
|
-
),
|
|
745
|
-
_UTF_8: $ => choice(
|
|
746
|
-
$._ASCII,
|
|
747
|
-
$._UTF_8_ONLY,
|
|
748
|
-
),
|
|
749
662
|
}
|
|
750
663
|
})
|
package/package.json
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tree-sitter-beancount",
|
|
3
|
-
"version": "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
|
-
"
|
|
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.
|
|
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
|
}
|