tree-sitter-sed 0.5.0 → 0.6.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/CMakeLists.txt CHANGED
@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.13)
2
2
 
3
3
  project(
4
4
  tree-sitter-sed
5
- VERSION 0.5.0
5
+ VERSION 0.6.0
6
6
  DESCRIPTION "Tree-sitter grammars for POSIX sed."
7
7
  HOMEPAGE_URL "https://github.com/konomanoasa/tree-sitter-sed"
8
8
  LANGUAGES C
package/Makefile CHANGED
@@ -1,6 +1,6 @@
1
1
  LANGUAGE_NAME := tree-sitter-sed
2
2
  HOMEPAGE_URL := https://github.com/konomanoasa/tree-sitter-sed
3
- VERSION := 0.5.0
3
+ VERSION := 0.6.0
4
4
  DESCRIPTION := Tree-sitter grammars for POSIX sed.
5
5
 
6
6
  PREFIX ?= /usr/local
package/README.md CHANGED
@@ -16,10 +16,18 @@ npm install tree-sitter-sed
16
16
 
17
17
  This repository contains the following two grammars.
18
18
 
19
- | Grammar | Regexp | C function |
20
- | --------- | ------ | ----------------------- |
21
- | `sed` | BRE | `tree_sitter_sed()` |
22
- | `sed_ere` | ERE | `tree_sitter_sed_ere()` |
19
+ | Grammar | Regexp | C function | Rust constant |
20
+ | --------- | ------ | ----------------------- | -------------- |
21
+ | `sed` | BRE | `tree_sitter_sed()` | `LANGUAGE` |
22
+ | `sed_ere` | ERE | `tree_sitter_sed_ere()` | `LANGUAGE_ERE` |
23
+
24
+ ## Development
25
+
26
+ ```sh
27
+ npm install
28
+ npm run parse -- script.sed
29
+ npm run parse:ere -- script.sed
30
+ ```
23
31
 
24
32
  ## Specifications
25
33
 
package/common/regex.js CHANGED
@@ -64,24 +64,21 @@ function intervalExpression($, openingName, closingName) {
64
64
  function compoundBracketExpression(
65
65
  $,
66
66
  openingExternal,
67
- openingName,
67
+ marker,
68
68
  contentField,
69
69
  content,
70
70
  closingExternal,
71
- closingName,
72
71
  ) {
73
- const closing = namedExternal($, closingExternal, closingName);
72
+ const closing = seq(alias(closingExternal, marker), "]");
74
73
  return seq(
75
- field("opening", namedExternal($, openingExternal, openingName)),
74
+ alias(openingExternal, "["),
75
+ marker,
76
76
  choice(
77
77
  seq(
78
78
  field(contentField, content),
79
79
  choice(
80
- field("closing", closing),
81
- seq(
82
- issueField($, "malformed_bracket_term"),
83
- optional(field("closing", closing)),
84
- ),
80
+ closing,
81
+ seq(issueField($, "malformed_bracket_term"), optional(closing)),
85
82
  issueField($, "incomplete_bracket_term"),
86
83
  ),
87
84
  ),
@@ -90,7 +87,7 @@ function compoundBracketExpression(
90
87
  issueField($, "malformed_bracket_term"),
91
88
  issueField($, "incomplete_bracket_term"),
92
89
  ),
93
- optional(field("closing", closing)),
90
+ optional(closing),
94
91
  ),
95
92
  ),
96
93
  );
@@ -255,7 +252,7 @@ function bracketRules() {
255
252
  compoundBracketExpression(
256
253
  $,
257
254
  $._regex_open_dot,
258
- "open_dot",
255
+ ".",
259
256
  "element",
260
257
  choice(
261
258
  namedExternal($, $._regex_coll_elem_single, "coll_elem_single"),
@@ -263,32 +260,29 @@ function bracketRules() {
263
260
  namedExternal($, $._regex_meta_char, "meta_char"),
264
261
  ),
265
262
  $._regex_dot_close,
266
- "dot_close",
267
263
  ),
268
264
 
269
265
  equivalence_class: ($) =>
270
266
  compoundBracketExpression(
271
267
  $,
272
268
  $._regex_open_equal,
273
- "open_equal",
269
+ "=",
274
270
  "element",
275
271
  choice(
276
272
  namedExternal($, $._regex_coll_elem_single, "coll_elem_single"),
277
273
  namedExternal($, $._regex_coll_elem_multi, "coll_elem_multi"),
278
274
  ),
279
275
  $._regex_equal_close,
280
- "equal_close",
281
276
  ),
282
277
 
283
278
  character_class: ($) =>
284
279
  compoundBracketExpression(
285
280
  $,
286
281
  $._regex_open_colon,
287
- "open_colon",
282
+ ":",
288
283
  "name",
289
284
  namedExternal($, $._regex_class_name, "class_name"),
290
285
  $._regex_colon_close,
291
- "colon_close",
292
286
  ),
293
287
  };
294
288
  }
package/common/scanner.h CHANGED
@@ -1234,7 +1234,6 @@ static bool scan_regex_bracket_opener(
1234
1234
  if (!valid_symbols[candidate]) {
1235
1235
  return false;
1236
1236
  }
1237
- consume(lexer);
1238
1237
  begin_compound_bracket_element(state);
1239
1238
  finish_first_bracket_element(state);
1240
1239
  state->regex_bracket_term_state = term_state;
@@ -1386,11 +1385,10 @@ static bool scan_regex_bracket_term_close(
1386
1385
  return false;
1387
1386
  }
1388
1387
 
1389
- advance(lexer);
1388
+ consume(lexer);
1390
1389
  if (lexer->lookahead != ']') {
1391
1390
  return false;
1392
1391
  }
1393
- consume(lexer);
1394
1392
  state->regex_bracket_term_state = REGEX_BRACKET_TERM_NONE;
1395
1393
  finish_compound_bracket_element(state);
1396
1394
  return emit_symbol(valid_symbols, candidate, symbol);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tree-sitter-sed",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "description": "Tree-sitter grammars for POSIX sed.",
5
5
  "license": "MIT",
6
6
  "repository": "git+https://github.com/konomanoasa/tree-sitter-sed.git",
@@ -27,13 +27,15 @@
27
27
  "check": "biome check . && node scripts/check-c.js && node scripts/check-generated.js && npm test",
28
28
  "format": "biome check --write . && node scripts/check-c.js --write",
29
29
  "generate": "npm run tree-sitter -- generate-all",
30
+ "parse": "npm run tree-sitter -- parse --scope source.sed",
31
+ "parse:ere": "npm run tree-sitter -- parse --scope source.sed.ere",
30
32
  "test": "npm run tree-sitter -- test-corpus --rebuild && node --test",
31
33
  "test:fuzz": "npm run tree-sitter -- fuzz-all --iterations 100 --edits 5",
32
34
  "tree-sitter": "node scripts/tree-sitter.js"
33
35
  },
34
36
  "devDependencies": {
35
37
  "@biomejs/biome": "2.5.11",
36
- "tree-sitter-cli": "0.26.13"
38
+ "tree-sitter-cli": "0.27.0"
37
39
  },
38
40
  "allowScripts": {
39
41
  "tree-sitter-cli": true
@@ -65,11 +65,39 @@
65
65
  (back_open_parenthesis)
66
66
  (close_bracket_token)
67
67
  (closing_brace_token)
68
- (colon_close)
69
68
  (open_bracket)
70
- (open_colon)
71
69
  ] @punctuation.bracket
72
70
 
71
+ (character_class
72
+ "[" @punctuation.bracket
73
+ .
74
+ ":" @punctuation.delimiter)
75
+
76
+ (character_class
77
+ ":" @punctuation.delimiter
78
+ .
79
+ "]" @punctuation.bracket)
80
+
81
+ (collating_symbol
82
+ "[" @punctuation.bracket
83
+ .
84
+ "." @punctuation.delimiter)
85
+
86
+ (collating_symbol
87
+ "." @punctuation.delimiter
88
+ .
89
+ "]" @punctuation.bracket)
90
+
91
+ (equivalence_class
92
+ "[" @punctuation.bracket
93
+ .
94
+ "=" @punctuation.delimiter)
95
+
96
+ (equivalence_class
97
+ "=" @punctuation.delimiter
98
+ .
99
+ "]" @punctuation.bracket)
100
+
73
101
  [
74
102
  (nonmatching_list_operator)
75
103
  (range_operator)
@@ -85,11 +113,7 @@
85
113
  (coll_elem_multi)
86
114
  (coll_elem_single)
87
115
  (collating_element_token)
88
- (dot_close)
89
- (equal_close)
90
116
  (meta_char)
91
- (open_dot)
92
- (open_equal)
93
117
  (period_token)
94
118
  ] @character.special
95
119
 
@@ -63,13 +63,41 @@
63
63
  (close_bracket_token)
64
64
  (close_parenthesis_token)
65
65
  (closing_brace_token)
66
- (colon_close)
67
66
  (open_brace)
68
67
  (open_bracket)
69
- (open_colon)
70
68
  (open_parenthesis)
71
69
  ] @punctuation.bracket
72
70
 
71
+ (character_class
72
+ "[" @punctuation.bracket
73
+ .
74
+ ":" @punctuation.delimiter)
75
+
76
+ (character_class
77
+ ":" @punctuation.delimiter
78
+ .
79
+ "]" @punctuation.bracket)
80
+
81
+ (collating_symbol
82
+ "[" @punctuation.bracket
83
+ .
84
+ "." @punctuation.delimiter)
85
+
86
+ (collating_symbol
87
+ "." @punctuation.delimiter
88
+ .
89
+ "]" @punctuation.bracket)
90
+
91
+ (equivalence_class
92
+ "[" @punctuation.bracket
93
+ .
94
+ "=" @punctuation.delimiter)
95
+
96
+ (equivalence_class
97
+ "=" @punctuation.delimiter
98
+ .
99
+ "]" @punctuation.bracket)
100
+
73
101
  [
74
102
  (nonmatching_list_operator)
75
103
  (range_operator)
@@ -85,11 +113,7 @@
85
113
  (coll_elem_multi)
86
114
  (coll_elem_single)
87
115
  (collating_element_token)
88
- (dot_close)
89
- (equal_close)
90
116
  (meta_char)
91
- (open_dot)
92
- (open_equal)
93
117
  (period_token)
94
118
  ] @character.special
95
119
 
@@ -6279,17 +6279,17 @@
6279
6279
  "type": "SEQ",
6280
6280
  "members": [
6281
6281
  {
6282
- "type": "FIELD",
6283
- "name": "opening",
6282
+ "type": "ALIAS",
6284
6283
  "content": {
6285
- "type": "ALIAS",
6286
- "content": {
6287
- "type": "SYMBOL",
6288
- "name": "_regex_open_dot"
6289
- },
6290
- "named": true,
6291
- "value": "open_dot"
6292
- }
6284
+ "type": "SYMBOL",
6285
+ "name": "_regex_open_dot"
6286
+ },
6287
+ "named": false,
6288
+ "value": "["
6289
+ },
6290
+ {
6291
+ "type": "STRING",
6292
+ "value": "."
6293
6293
  },
6294
6294
  {
6295
6295
  "type": "CHOICE",
@@ -6337,17 +6337,22 @@
6337
6337
  "type": "CHOICE",
6338
6338
  "members": [
6339
6339
  {
6340
- "type": "FIELD",
6341
- "name": "closing",
6342
- "content": {
6343
- "type": "ALIAS",
6344
- "content": {
6345
- "type": "SYMBOL",
6346
- "name": "_regex_dot_close"
6340
+ "type": "SEQ",
6341
+ "members": [
6342
+ {
6343
+ "type": "ALIAS",
6344
+ "content": {
6345
+ "type": "SYMBOL",
6346
+ "name": "_regex_dot_close"
6347
+ },
6348
+ "named": false,
6349
+ "value": "."
6347
6350
  },
6348
- "named": true,
6349
- "value": "dot_close"
6350
- }
6351
+ {
6352
+ "type": "STRING",
6353
+ "value": "]"
6354
+ }
6355
+ ]
6351
6356
  },
6352
6357
  {
6353
6358
  "type": "SEQ",
@@ -6369,17 +6374,22 @@
6369
6374
  "type": "CHOICE",
6370
6375
  "members": [
6371
6376
  {
6372
- "type": "FIELD",
6373
- "name": "closing",
6374
- "content": {
6375
- "type": "ALIAS",
6376
- "content": {
6377
- "type": "SYMBOL",
6378
- "name": "_regex_dot_close"
6377
+ "type": "SEQ",
6378
+ "members": [
6379
+ {
6380
+ "type": "ALIAS",
6381
+ "content": {
6382
+ "type": "SYMBOL",
6383
+ "name": "_regex_dot_close"
6384
+ },
6385
+ "named": false,
6386
+ "value": "."
6379
6387
  },
6380
- "named": true,
6381
- "value": "dot_close"
6382
- }
6388
+ {
6389
+ "type": "STRING",
6390
+ "value": "]"
6391
+ }
6392
+ ]
6383
6393
  },
6384
6394
  {
6385
6395
  "type": "BLANK"
@@ -6443,17 +6453,22 @@
6443
6453
  "type": "CHOICE",
6444
6454
  "members": [
6445
6455
  {
6446
- "type": "FIELD",
6447
- "name": "closing",
6448
- "content": {
6449
- "type": "ALIAS",
6450
- "content": {
6451
- "type": "SYMBOL",
6452
- "name": "_regex_dot_close"
6456
+ "type": "SEQ",
6457
+ "members": [
6458
+ {
6459
+ "type": "ALIAS",
6460
+ "content": {
6461
+ "type": "SYMBOL",
6462
+ "name": "_regex_dot_close"
6463
+ },
6464
+ "named": false,
6465
+ "value": "."
6453
6466
  },
6454
- "named": true,
6455
- "value": "dot_close"
6456
- }
6467
+ {
6468
+ "type": "STRING",
6469
+ "value": "]"
6470
+ }
6471
+ ]
6457
6472
  },
6458
6473
  {
6459
6474
  "type": "BLANK"
@@ -6470,17 +6485,17 @@
6470
6485
  "type": "SEQ",
6471
6486
  "members": [
6472
6487
  {
6473
- "type": "FIELD",
6474
- "name": "opening",
6488
+ "type": "ALIAS",
6475
6489
  "content": {
6476
- "type": "ALIAS",
6477
- "content": {
6478
- "type": "SYMBOL",
6479
- "name": "_regex_open_equal"
6480
- },
6481
- "named": true,
6482
- "value": "open_equal"
6483
- }
6490
+ "type": "SYMBOL",
6491
+ "name": "_regex_open_equal"
6492
+ },
6493
+ "named": false,
6494
+ "value": "["
6495
+ },
6496
+ {
6497
+ "type": "STRING",
6498
+ "value": "="
6484
6499
  },
6485
6500
  {
6486
6501
  "type": "CHOICE",
@@ -6519,17 +6534,22 @@
6519
6534
  "type": "CHOICE",
6520
6535
  "members": [
6521
6536
  {
6522
- "type": "FIELD",
6523
- "name": "closing",
6524
- "content": {
6525
- "type": "ALIAS",
6526
- "content": {
6527
- "type": "SYMBOL",
6528
- "name": "_regex_equal_close"
6537
+ "type": "SEQ",
6538
+ "members": [
6539
+ {
6540
+ "type": "ALIAS",
6541
+ "content": {
6542
+ "type": "SYMBOL",
6543
+ "name": "_regex_equal_close"
6544
+ },
6545
+ "named": false,
6546
+ "value": "="
6529
6547
  },
6530
- "named": true,
6531
- "value": "equal_close"
6532
- }
6548
+ {
6549
+ "type": "STRING",
6550
+ "value": "]"
6551
+ }
6552
+ ]
6533
6553
  },
6534
6554
  {
6535
6555
  "type": "SEQ",
@@ -6551,17 +6571,22 @@
6551
6571
  "type": "CHOICE",
6552
6572
  "members": [
6553
6573
  {
6554
- "type": "FIELD",
6555
- "name": "closing",
6556
- "content": {
6557
- "type": "ALIAS",
6558
- "content": {
6559
- "type": "SYMBOL",
6560
- "name": "_regex_equal_close"
6574
+ "type": "SEQ",
6575
+ "members": [
6576
+ {
6577
+ "type": "ALIAS",
6578
+ "content": {
6579
+ "type": "SYMBOL",
6580
+ "name": "_regex_equal_close"
6581
+ },
6582
+ "named": false,
6583
+ "value": "="
6561
6584
  },
6562
- "named": true,
6563
- "value": "equal_close"
6564
- }
6585
+ {
6586
+ "type": "STRING",
6587
+ "value": "]"
6588
+ }
6589
+ ]
6565
6590
  },
6566
6591
  {
6567
6592
  "type": "BLANK"
@@ -6625,17 +6650,22 @@
6625
6650
  "type": "CHOICE",
6626
6651
  "members": [
6627
6652
  {
6628
- "type": "FIELD",
6629
- "name": "closing",
6630
- "content": {
6631
- "type": "ALIAS",
6632
- "content": {
6633
- "type": "SYMBOL",
6634
- "name": "_regex_equal_close"
6653
+ "type": "SEQ",
6654
+ "members": [
6655
+ {
6656
+ "type": "ALIAS",
6657
+ "content": {
6658
+ "type": "SYMBOL",
6659
+ "name": "_regex_equal_close"
6660
+ },
6661
+ "named": false,
6662
+ "value": "="
6635
6663
  },
6636
- "named": true,
6637
- "value": "equal_close"
6638
- }
6664
+ {
6665
+ "type": "STRING",
6666
+ "value": "]"
6667
+ }
6668
+ ]
6639
6669
  },
6640
6670
  {
6641
6671
  "type": "BLANK"
@@ -6652,17 +6682,17 @@
6652
6682
  "type": "SEQ",
6653
6683
  "members": [
6654
6684
  {
6655
- "type": "FIELD",
6656
- "name": "opening",
6685
+ "type": "ALIAS",
6657
6686
  "content": {
6658
- "type": "ALIAS",
6659
- "content": {
6660
- "type": "SYMBOL",
6661
- "name": "_regex_open_colon"
6662
- },
6663
- "named": true,
6664
- "value": "open_colon"
6665
- }
6687
+ "type": "SYMBOL",
6688
+ "name": "_regex_open_colon"
6689
+ },
6690
+ "named": false,
6691
+ "value": "["
6692
+ },
6693
+ {
6694
+ "type": "STRING",
6695
+ "value": ":"
6666
6696
  },
6667
6697
  {
6668
6698
  "type": "CHOICE",
@@ -6687,17 +6717,22 @@
6687
6717
  "type": "CHOICE",
6688
6718
  "members": [
6689
6719
  {
6690
- "type": "FIELD",
6691
- "name": "closing",
6692
- "content": {
6693
- "type": "ALIAS",
6694
- "content": {
6695
- "type": "SYMBOL",
6696
- "name": "_regex_colon_close"
6720
+ "type": "SEQ",
6721
+ "members": [
6722
+ {
6723
+ "type": "ALIAS",
6724
+ "content": {
6725
+ "type": "SYMBOL",
6726
+ "name": "_regex_colon_close"
6727
+ },
6728
+ "named": false,
6729
+ "value": ":"
6697
6730
  },
6698
- "named": true,
6699
- "value": "colon_close"
6700
- }
6731
+ {
6732
+ "type": "STRING",
6733
+ "value": "]"
6734
+ }
6735
+ ]
6701
6736
  },
6702
6737
  {
6703
6738
  "type": "SEQ",
@@ -6719,17 +6754,22 @@
6719
6754
  "type": "CHOICE",
6720
6755
  "members": [
6721
6756
  {
6722
- "type": "FIELD",
6723
- "name": "closing",
6724
- "content": {
6725
- "type": "ALIAS",
6726
- "content": {
6727
- "type": "SYMBOL",
6728
- "name": "_regex_colon_close"
6757
+ "type": "SEQ",
6758
+ "members": [
6759
+ {
6760
+ "type": "ALIAS",
6761
+ "content": {
6762
+ "type": "SYMBOL",
6763
+ "name": "_regex_colon_close"
6764
+ },
6765
+ "named": false,
6766
+ "value": ":"
6729
6767
  },
6730
- "named": true,
6731
- "value": "colon_close"
6732
- }
6768
+ {
6769
+ "type": "STRING",
6770
+ "value": "]"
6771
+ }
6772
+ ]
6733
6773
  },
6734
6774
  {
6735
6775
  "type": "BLANK"
@@ -6793,17 +6833,22 @@
6793
6833
  "type": "CHOICE",
6794
6834
  "members": [
6795
6835
  {
6796
- "type": "FIELD",
6797
- "name": "closing",
6798
- "content": {
6799
- "type": "ALIAS",
6800
- "content": {
6801
- "type": "SYMBOL",
6802
- "name": "_regex_colon_close"
6836
+ "type": "SEQ",
6837
+ "members": [
6838
+ {
6839
+ "type": "ALIAS",
6840
+ "content": {
6841
+ "type": "SYMBOL",
6842
+ "name": "_regex_colon_close"
6843
+ },
6844
+ "named": false,
6845
+ "value": ":"
6803
6846
  },
6804
- "named": true,
6805
- "value": "colon_close"
6806
- }
6847
+ {
6848
+ "type": "STRING",
6849
+ "value": "]"
6850
+ }
6851
+ ]
6807
6852
  },
6808
6853
  {
6809
6854
  "type": "BLANK"