tree-sitter-hledger 0.1.3 → 0.1.4
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 +14 -1
- package/grammar.js +48 -1
- package/package.json +1 -1
- package/src/grammar.json +171 -1
- package/src/node-types.json +167 -0
- package/src/parser.c +2397 -1831
package/README.md
CHANGED
|
@@ -16,6 +16,7 @@ This parser complements the existing [hledger-lsp](../hledger-lsp) language serv
|
|
|
16
16
|
## Features
|
|
17
17
|
|
|
18
18
|
**Transactions:**
|
|
19
|
+
|
|
19
20
|
- Dates with flexible formats (`2024-01-15`, `2024.1.5`, `01/15`, `1-5`)
|
|
20
21
|
- Status markers (`*` cleared, `!` pending)
|
|
21
22
|
- Transaction codes (`(#123)`)
|
|
@@ -23,6 +24,7 @@ This parser complements the existing [hledger-lsp](../hledger-lsp) language serv
|
|
|
23
24
|
- Inline comments with tags (`; category:food, project:home`)
|
|
24
25
|
|
|
25
26
|
**Postings:**
|
|
27
|
+
|
|
26
28
|
- Account names (including spaces)
|
|
27
29
|
- Amounts with various formats:
|
|
28
30
|
- Symbol on left: `$100`, `-$50`, `$-25`
|
|
@@ -33,31 +35,38 @@ This parser complements the existing [hledger-lsp](../hledger-lsp) language serv
|
|
|
33
35
|
- Inline comments with tags
|
|
34
36
|
|
|
35
37
|
**Commodities:**
|
|
38
|
+
|
|
36
39
|
- Currency symbols: `$`, `€`, `£`, `¥`, etc.
|
|
37
40
|
- Alphabetic codes: `USD`, `EUR`, `BTC`
|
|
38
41
|
- Quoted symbols: `"AAPL US Equity"`
|
|
39
42
|
|
|
40
43
|
**Directives:**
|
|
44
|
+
|
|
41
45
|
- `account` - Account declarations
|
|
42
46
|
- `commodity` - Commodity declarations
|
|
43
47
|
- `include` - File includes
|
|
44
48
|
- `payee` - Payee declarations
|
|
45
49
|
- `tag` - Tag declarations
|
|
50
|
+
- `P` - Market price declarations
|
|
51
|
+
- `alias` - Alias declarations
|
|
52
|
+
- `decimal-mark` - Decimal mark declarations
|
|
46
53
|
|
|
47
54
|
**Comments:**
|
|
55
|
+
|
|
48
56
|
- Line comments: `;` or `#`
|
|
49
57
|
- Block comments: `comment` ... `end comment`
|
|
50
58
|
- Inline comments with tag parsing
|
|
51
59
|
|
|
52
60
|
**Structure:**
|
|
61
|
+
|
|
53
62
|
- Indentation-based posting blocks
|
|
54
63
|
- Code folding support
|
|
55
64
|
- Syntax highlighting queries
|
|
56
65
|
|
|
57
66
|
## Future Enhancements
|
|
67
|
+
|
|
58
68
|
- Automated transaction rules (`=`)
|
|
59
69
|
- Periodic transactions (`~`)
|
|
60
|
-
- Additional directives (alias, apply account, etc.)
|
|
61
70
|
- Multi-line commodity format blocks
|
|
62
71
|
|
|
63
72
|
## Usage
|
|
@@ -87,6 +96,7 @@ npm test
|
|
|
87
96
|
## Grammar Overview
|
|
88
97
|
|
|
89
98
|
**Transactions:**
|
|
99
|
+
|
|
90
100
|
```hledger
|
|
91
101
|
2024-01-05 * Groceries ; category:food
|
|
92
102
|
Expenses:Food:Groceries $50.00
|
|
@@ -94,6 +104,7 @@ npm test
|
|
|
94
104
|
```
|
|
95
105
|
|
|
96
106
|
**Costs and Assertions:**
|
|
107
|
+
|
|
97
108
|
```hledger
|
|
98
109
|
2024-01-10 * Currency Exchange
|
|
99
110
|
Assets:EUR 100 EUR @ $1.10
|
|
@@ -101,6 +112,7 @@ npm test
|
|
|
101
112
|
```
|
|
102
113
|
|
|
103
114
|
**Directives:**
|
|
115
|
+
|
|
104
116
|
```hledger
|
|
105
117
|
account Assets:Checking
|
|
106
118
|
commodity $1000.00
|
|
@@ -109,6 +121,7 @@ include expenses.journal
|
|
|
109
121
|
```
|
|
110
122
|
|
|
111
123
|
**Comments:**
|
|
124
|
+
|
|
112
125
|
```hledger
|
|
113
126
|
; Line comment
|
|
114
127
|
# Another style
|
package/grammar.js
CHANGED
|
@@ -125,11 +125,58 @@ module.exports = grammar({
|
|
|
125
125
|
$.include_directive,
|
|
126
126
|
$.payee_directive,
|
|
127
127
|
$.tag_directive,
|
|
128
|
+
$.alias_directive,
|
|
129
|
+
$.decimal_mark_directive,
|
|
130
|
+
$.market_price_directive,
|
|
131
|
+
$.apply_account_directive,
|
|
132
|
+
$.default_commodity_directive,
|
|
133
|
+
$.default_year_directive,
|
|
128
134
|
),
|
|
129
135
|
optional($.inline_comment),
|
|
130
136
|
$._newline,
|
|
131
137
|
),
|
|
132
138
|
|
|
139
|
+
alias_directive: $ => seq(
|
|
140
|
+
'alias',
|
|
141
|
+
field('old_name', $.account),
|
|
142
|
+
'=',
|
|
143
|
+
field('new_name', $.account),
|
|
144
|
+
),
|
|
145
|
+
|
|
146
|
+
decimal_mark_directive: $ => seq(
|
|
147
|
+
'decimal-mark',
|
|
148
|
+
field('decimal_mark', $.decimal_mark),
|
|
149
|
+
),
|
|
150
|
+
|
|
151
|
+
decimal_mark: _$ => /[.,]/,
|
|
152
|
+
|
|
153
|
+
market_price_directive: $ => seq(
|
|
154
|
+
'P',
|
|
155
|
+
field('date', $.date),
|
|
156
|
+
field('commodity_1_symbol', $.commodity),
|
|
157
|
+
field('commodity_2_amount', $.amount),
|
|
158
|
+
),
|
|
159
|
+
|
|
160
|
+
default_commodity_directive: $ => seq(
|
|
161
|
+
'D',
|
|
162
|
+
/[ \t]+/,
|
|
163
|
+
field('default_commodity', $.amount),
|
|
164
|
+
),
|
|
165
|
+
|
|
166
|
+
default_year_directive: _$ => seq(
|
|
167
|
+
'Y',
|
|
168
|
+
/[ \t]+/,
|
|
169
|
+
field('default_year', /\d{4}/),
|
|
170
|
+
),
|
|
171
|
+
|
|
172
|
+
apply_account_directive: $ => seq(
|
|
173
|
+
'apply account',
|
|
174
|
+
/[ \t]+/,
|
|
175
|
+
field('account', $.account),
|
|
176
|
+
),
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
|
|
133
180
|
account_directive: $ => seq(
|
|
134
181
|
'account',
|
|
135
182
|
field('name', $.account),
|
|
@@ -184,7 +231,7 @@ module.exports = grammar({
|
|
|
184
231
|
description: _ => /[^*!=(;\s][^;\n]*/,
|
|
185
232
|
|
|
186
233
|
|
|
187
|
-
account: _ => /([^\s;#\n]+([ \t][^;\s\n
|
|
234
|
+
account: _ => /([^\s;#\n=]+([ \t][^;\s\n#=]+)*?)/,
|
|
188
235
|
|
|
189
236
|
// Amount: quantity with optional commodity
|
|
190
237
|
amount: $ => choice(
|
package/package.json
CHANGED
package/src/grammar.json
CHANGED
|
@@ -438,6 +438,30 @@
|
|
|
438
438
|
{
|
|
439
439
|
"type": "SYMBOL",
|
|
440
440
|
"name": "tag_directive"
|
|
441
|
+
},
|
|
442
|
+
{
|
|
443
|
+
"type": "SYMBOL",
|
|
444
|
+
"name": "alias_directive"
|
|
445
|
+
},
|
|
446
|
+
{
|
|
447
|
+
"type": "SYMBOL",
|
|
448
|
+
"name": "decimal_mark_directive"
|
|
449
|
+
},
|
|
450
|
+
{
|
|
451
|
+
"type": "SYMBOL",
|
|
452
|
+
"name": "market_price_directive"
|
|
453
|
+
},
|
|
454
|
+
{
|
|
455
|
+
"type": "SYMBOL",
|
|
456
|
+
"name": "apply_account_directive"
|
|
457
|
+
},
|
|
458
|
+
{
|
|
459
|
+
"type": "SYMBOL",
|
|
460
|
+
"name": "default_commodity_directive"
|
|
461
|
+
},
|
|
462
|
+
{
|
|
463
|
+
"type": "SYMBOL",
|
|
464
|
+
"name": "default_year_directive"
|
|
441
465
|
}
|
|
442
466
|
]
|
|
443
467
|
},
|
|
@@ -459,6 +483,152 @@
|
|
|
459
483
|
}
|
|
460
484
|
]
|
|
461
485
|
},
|
|
486
|
+
"alias_directive": {
|
|
487
|
+
"type": "SEQ",
|
|
488
|
+
"members": [
|
|
489
|
+
{
|
|
490
|
+
"type": "STRING",
|
|
491
|
+
"value": "alias"
|
|
492
|
+
},
|
|
493
|
+
{
|
|
494
|
+
"type": "FIELD",
|
|
495
|
+
"name": "old_name",
|
|
496
|
+
"content": {
|
|
497
|
+
"type": "SYMBOL",
|
|
498
|
+
"name": "account"
|
|
499
|
+
}
|
|
500
|
+
},
|
|
501
|
+
{
|
|
502
|
+
"type": "STRING",
|
|
503
|
+
"value": "="
|
|
504
|
+
},
|
|
505
|
+
{
|
|
506
|
+
"type": "FIELD",
|
|
507
|
+
"name": "new_name",
|
|
508
|
+
"content": {
|
|
509
|
+
"type": "SYMBOL",
|
|
510
|
+
"name": "account"
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
]
|
|
514
|
+
},
|
|
515
|
+
"decimal_mark_directive": {
|
|
516
|
+
"type": "SEQ",
|
|
517
|
+
"members": [
|
|
518
|
+
{
|
|
519
|
+
"type": "STRING",
|
|
520
|
+
"value": "decimal-mark"
|
|
521
|
+
},
|
|
522
|
+
{
|
|
523
|
+
"type": "FIELD",
|
|
524
|
+
"name": "decimal_mark",
|
|
525
|
+
"content": {
|
|
526
|
+
"type": "SYMBOL",
|
|
527
|
+
"name": "decimal_mark"
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
]
|
|
531
|
+
},
|
|
532
|
+
"decimal_mark": {
|
|
533
|
+
"type": "PATTERN",
|
|
534
|
+
"value": "[.,]"
|
|
535
|
+
},
|
|
536
|
+
"market_price_directive": {
|
|
537
|
+
"type": "SEQ",
|
|
538
|
+
"members": [
|
|
539
|
+
{
|
|
540
|
+
"type": "STRING",
|
|
541
|
+
"value": "P"
|
|
542
|
+
},
|
|
543
|
+
{
|
|
544
|
+
"type": "FIELD",
|
|
545
|
+
"name": "date",
|
|
546
|
+
"content": {
|
|
547
|
+
"type": "SYMBOL",
|
|
548
|
+
"name": "date"
|
|
549
|
+
}
|
|
550
|
+
},
|
|
551
|
+
{
|
|
552
|
+
"type": "FIELD",
|
|
553
|
+
"name": "commodity_1_symbol",
|
|
554
|
+
"content": {
|
|
555
|
+
"type": "SYMBOL",
|
|
556
|
+
"name": "commodity"
|
|
557
|
+
}
|
|
558
|
+
},
|
|
559
|
+
{
|
|
560
|
+
"type": "FIELD",
|
|
561
|
+
"name": "commodity_2_amount",
|
|
562
|
+
"content": {
|
|
563
|
+
"type": "SYMBOL",
|
|
564
|
+
"name": "amount"
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
]
|
|
568
|
+
},
|
|
569
|
+
"default_commodity_directive": {
|
|
570
|
+
"type": "SEQ",
|
|
571
|
+
"members": [
|
|
572
|
+
{
|
|
573
|
+
"type": "STRING",
|
|
574
|
+
"value": "D"
|
|
575
|
+
},
|
|
576
|
+
{
|
|
577
|
+
"type": "PATTERN",
|
|
578
|
+
"value": "[ \\t]+"
|
|
579
|
+
},
|
|
580
|
+
{
|
|
581
|
+
"type": "FIELD",
|
|
582
|
+
"name": "default_commodity",
|
|
583
|
+
"content": {
|
|
584
|
+
"type": "SYMBOL",
|
|
585
|
+
"name": "amount"
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
]
|
|
589
|
+
},
|
|
590
|
+
"default_year_directive": {
|
|
591
|
+
"type": "SEQ",
|
|
592
|
+
"members": [
|
|
593
|
+
{
|
|
594
|
+
"type": "STRING",
|
|
595
|
+
"value": "Y"
|
|
596
|
+
},
|
|
597
|
+
{
|
|
598
|
+
"type": "PATTERN",
|
|
599
|
+
"value": "[ \\t]+"
|
|
600
|
+
},
|
|
601
|
+
{
|
|
602
|
+
"type": "FIELD",
|
|
603
|
+
"name": "default_year",
|
|
604
|
+
"content": {
|
|
605
|
+
"type": "PATTERN",
|
|
606
|
+
"value": "\\d{4}"
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
]
|
|
610
|
+
},
|
|
611
|
+
"apply_account_directive": {
|
|
612
|
+
"type": "SEQ",
|
|
613
|
+
"members": [
|
|
614
|
+
{
|
|
615
|
+
"type": "STRING",
|
|
616
|
+
"value": "apply account"
|
|
617
|
+
},
|
|
618
|
+
{
|
|
619
|
+
"type": "PATTERN",
|
|
620
|
+
"value": "[ \\t]+"
|
|
621
|
+
},
|
|
622
|
+
{
|
|
623
|
+
"type": "FIELD",
|
|
624
|
+
"name": "account",
|
|
625
|
+
"content": {
|
|
626
|
+
"type": "SYMBOL",
|
|
627
|
+
"name": "account"
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
]
|
|
631
|
+
},
|
|
462
632
|
"account_directive": {
|
|
463
633
|
"type": "SEQ",
|
|
464
634
|
"members": [
|
|
@@ -691,7 +861,7 @@
|
|
|
691
861
|
},
|
|
692
862
|
"account": {
|
|
693
863
|
"type": "PATTERN",
|
|
694
|
-
"value": "([^\\s;#\\n]+([ \\t][^;\\s\\n
|
|
864
|
+
"value": "([^\\s;#\\n=]+([ \\t][^;\\s\\n#=]+)*?)"
|
|
695
865
|
},
|
|
696
866
|
"amount": {
|
|
697
867
|
"type": "CHOICE",
|
package/src/node-types.json
CHANGED
|
@@ -15,6 +15,32 @@
|
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
},
|
|
18
|
+
{
|
|
19
|
+
"type": "alias_directive",
|
|
20
|
+
"named": true,
|
|
21
|
+
"fields": {
|
|
22
|
+
"new_name": {
|
|
23
|
+
"multiple": false,
|
|
24
|
+
"required": true,
|
|
25
|
+
"types": [
|
|
26
|
+
{
|
|
27
|
+
"type": "account",
|
|
28
|
+
"named": true
|
|
29
|
+
}
|
|
30
|
+
]
|
|
31
|
+
},
|
|
32
|
+
"old_name": {
|
|
33
|
+
"multiple": false,
|
|
34
|
+
"required": true,
|
|
35
|
+
"types": [
|
|
36
|
+
{
|
|
37
|
+
"type": "account",
|
|
38
|
+
"named": true
|
|
39
|
+
}
|
|
40
|
+
]
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
},
|
|
18
44
|
{
|
|
19
45
|
"type": "amount",
|
|
20
46
|
"named": true,
|
|
@@ -51,6 +77,22 @@
|
|
|
51
77
|
}
|
|
52
78
|
}
|
|
53
79
|
},
|
|
80
|
+
{
|
|
81
|
+
"type": "apply_account_directive",
|
|
82
|
+
"named": true,
|
|
83
|
+
"fields": {
|
|
84
|
+
"account": {
|
|
85
|
+
"multiple": false,
|
|
86
|
+
"required": true,
|
|
87
|
+
"types": [
|
|
88
|
+
{
|
|
89
|
+
"type": "account",
|
|
90
|
+
"named": true
|
|
91
|
+
}
|
|
92
|
+
]
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
},
|
|
54
96
|
{
|
|
55
97
|
"type": "assertion",
|
|
56
98
|
"named": true,
|
|
@@ -141,6 +183,43 @@
|
|
|
141
183
|
"named": true,
|
|
142
184
|
"fields": {}
|
|
143
185
|
},
|
|
186
|
+
{
|
|
187
|
+
"type": "decimal_mark_directive",
|
|
188
|
+
"named": true,
|
|
189
|
+
"fields": {
|
|
190
|
+
"decimal_mark": {
|
|
191
|
+
"multiple": false,
|
|
192
|
+
"required": true,
|
|
193
|
+
"types": [
|
|
194
|
+
{
|
|
195
|
+
"type": "decimal_mark",
|
|
196
|
+
"named": true
|
|
197
|
+
}
|
|
198
|
+
]
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
},
|
|
202
|
+
{
|
|
203
|
+
"type": "default_commodity_directive",
|
|
204
|
+
"named": true,
|
|
205
|
+
"fields": {
|
|
206
|
+
"default_commodity": {
|
|
207
|
+
"multiple": false,
|
|
208
|
+
"required": true,
|
|
209
|
+
"types": [
|
|
210
|
+
{
|
|
211
|
+
"type": "amount",
|
|
212
|
+
"named": true
|
|
213
|
+
}
|
|
214
|
+
]
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
},
|
|
218
|
+
{
|
|
219
|
+
"type": "default_year_directive",
|
|
220
|
+
"named": true,
|
|
221
|
+
"fields": {}
|
|
222
|
+
},
|
|
144
223
|
{
|
|
145
224
|
"type": "include_directive",
|
|
146
225
|
"named": true,
|
|
@@ -177,6 +256,42 @@
|
|
|
177
256
|
"named": true,
|
|
178
257
|
"fields": {}
|
|
179
258
|
},
|
|
259
|
+
{
|
|
260
|
+
"type": "market_price_directive",
|
|
261
|
+
"named": true,
|
|
262
|
+
"fields": {
|
|
263
|
+
"commodity_1_symbol": {
|
|
264
|
+
"multiple": false,
|
|
265
|
+
"required": true,
|
|
266
|
+
"types": [
|
|
267
|
+
{
|
|
268
|
+
"type": "commodity",
|
|
269
|
+
"named": true
|
|
270
|
+
}
|
|
271
|
+
]
|
|
272
|
+
},
|
|
273
|
+
"commodity_2_amount": {
|
|
274
|
+
"multiple": false,
|
|
275
|
+
"required": true,
|
|
276
|
+
"types": [
|
|
277
|
+
{
|
|
278
|
+
"type": "amount",
|
|
279
|
+
"named": true
|
|
280
|
+
}
|
|
281
|
+
]
|
|
282
|
+
},
|
|
283
|
+
"date": {
|
|
284
|
+
"multiple": false,
|
|
285
|
+
"required": true,
|
|
286
|
+
"types": [
|
|
287
|
+
{
|
|
288
|
+
"type": "date",
|
|
289
|
+
"named": true
|
|
290
|
+
}
|
|
291
|
+
]
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
},
|
|
180
295
|
{
|
|
181
296
|
"type": "payee_directive",
|
|
182
297
|
"named": true,
|
|
@@ -272,6 +387,14 @@
|
|
|
272
387
|
"type": "account_directive",
|
|
273
388
|
"named": true
|
|
274
389
|
},
|
|
390
|
+
{
|
|
391
|
+
"type": "alias_directive",
|
|
392
|
+
"named": true
|
|
393
|
+
},
|
|
394
|
+
{
|
|
395
|
+
"type": "apply_account_directive",
|
|
396
|
+
"named": true
|
|
397
|
+
},
|
|
275
398
|
{
|
|
276
399
|
"type": "block_comment",
|
|
277
400
|
"named": true
|
|
@@ -280,6 +403,18 @@
|
|
|
280
403
|
"type": "commodity_directive",
|
|
281
404
|
"named": true
|
|
282
405
|
},
|
|
406
|
+
{
|
|
407
|
+
"type": "decimal_mark_directive",
|
|
408
|
+
"named": true
|
|
409
|
+
},
|
|
410
|
+
{
|
|
411
|
+
"type": "default_commodity_directive",
|
|
412
|
+
"named": true
|
|
413
|
+
},
|
|
414
|
+
{
|
|
415
|
+
"type": "default_year_directive",
|
|
416
|
+
"named": true
|
|
417
|
+
},
|
|
283
418
|
{
|
|
284
419
|
"type": "include_directive",
|
|
285
420
|
"named": true
|
|
@@ -292,6 +427,10 @@
|
|
|
292
427
|
"type": "line_comment",
|
|
293
428
|
"named": true
|
|
294
429
|
},
|
|
430
|
+
{
|
|
431
|
+
"type": "market_price_directive",
|
|
432
|
+
"named": true
|
|
433
|
+
},
|
|
295
434
|
{
|
|
296
435
|
"type": "payee_directive",
|
|
297
436
|
"named": true
|
|
@@ -461,6 +600,18 @@
|
|
|
461
600
|
"type": "@@",
|
|
462
601
|
"named": false
|
|
463
602
|
},
|
|
603
|
+
{
|
|
604
|
+
"type": "D",
|
|
605
|
+
"named": false
|
|
606
|
+
},
|
|
607
|
+
{
|
|
608
|
+
"type": "P",
|
|
609
|
+
"named": false
|
|
610
|
+
},
|
|
611
|
+
{
|
|
612
|
+
"type": "Y",
|
|
613
|
+
"named": false
|
|
614
|
+
},
|
|
464
615
|
{
|
|
465
616
|
"type": "account",
|
|
466
617
|
"named": false
|
|
@@ -469,6 +620,14 @@
|
|
|
469
620
|
"type": "account",
|
|
470
621
|
"named": true
|
|
471
622
|
},
|
|
623
|
+
{
|
|
624
|
+
"type": "alias",
|
|
625
|
+
"named": false
|
|
626
|
+
},
|
|
627
|
+
{
|
|
628
|
+
"type": "apply account",
|
|
629
|
+
"named": false
|
|
630
|
+
},
|
|
472
631
|
{
|
|
473
632
|
"type": "comment",
|
|
474
633
|
"named": false
|
|
@@ -477,6 +636,14 @@
|
|
|
477
636
|
"type": "commodity",
|
|
478
637
|
"named": false
|
|
479
638
|
},
|
|
639
|
+
{
|
|
640
|
+
"type": "decimal-mark",
|
|
641
|
+
"named": false
|
|
642
|
+
},
|
|
643
|
+
{
|
|
644
|
+
"type": "decimal_mark",
|
|
645
|
+
"named": true
|
|
646
|
+
},
|
|
480
647
|
{
|
|
481
648
|
"type": "dedent",
|
|
482
649
|
"named": true
|