tree-sitter-sed 0.9.0 → 0.10.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/Cargo.toml CHANGED
@@ -10,7 +10,7 @@ name = "tree-sitter-sed"
10
10
  publish = false
11
11
  readme = "README.md"
12
12
  repository = "https://github.com/konomanoasa/tree-sitter-sed"
13
- version = "0.9.0"
13
+ version = "0.10.0"
14
14
 
15
15
  build = "bindings/rust/build.rs"
16
16
  include = [
@@ -519,7 +519,7 @@ mod tests {
519
519
  "\\(",
520
520
  "\\)",
521
521
  "back_open_parenthesis",
522
- "back_close_parenthesis_token",
522
+ "back_close_parenthesis",
523
523
  ),
524
524
  (
525
525
  super::LANGUAGE_ERE,
@@ -527,7 +527,7 @@ mod tests {
527
527
  "(",
528
528
  ")",
529
529
  "open_parenthesis",
530
- "close_parenthesis_token",
530
+ "close_parenthesis",
531
531
  ),
532
532
  ] {
533
533
  let mut parser = tree_sitter::Parser::new();
package/common/dsl.js CHANGED
@@ -36,4 +36,4 @@ function issueNode($, id) {
36
36
  return alias($[issueRuleName(id)], $.syntax_issue);
37
37
  }
38
38
 
39
- module.exports = { defineIssueRules, issueField, issueNode, namedExternal };
39
+ export { defineIssueRules, issueField, issueNode, namedExternal };
package/common/grammar.js CHANGED
@@ -1,10 +1,10 @@
1
- const {
1
+ import {
2
2
  defineIssueRules,
3
3
  issueField,
4
4
  issueNode,
5
5
  namedExternal,
6
- } = require("./dsl");
7
- const regularExpressionRules = require("./regex");
6
+ } from "./dsl.js";
7
+ import regularExpressionRules from "./regex.js";
8
8
 
9
9
  function missingAtEndOrBoundary($, reason) {
10
10
  return choice(
@@ -55,30 +55,6 @@ function functionVerb($, spelling) {
55
55
  return field("verb", alias(spelling, $.function_verb));
56
56
  }
57
57
 
58
- const delimiterNames = [
59
- "regex_address_start",
60
- "escaped_regex_address_start",
61
- "regex_address_end",
62
- "substitute_start",
63
- "substitute_middle",
64
- "substitute_end",
65
- "translate_start",
66
- "translate_middle",
67
- "translate_end",
68
- ];
69
-
70
- const missingDelimiterReasons = [
71
- "incomplete_regular_expression",
72
- "unterminated_regular_expression",
73
- "incomplete_replacement",
74
- "unterminated_replacement",
75
- "incomplete_translation",
76
- "unterminated_translation",
77
- "invalid_delimiter",
78
- "missing_opening_delimiter",
79
- "nonconforming_missing_opening_delimiter",
80
- ];
81
-
82
58
  const functionDefinitions = [
83
59
  { rule: "block_function", spelling: "{", form: "block" },
84
60
  {
@@ -196,37 +172,26 @@ function postWriteSubstitutionFlagChoice($) {
196
172
  }
197
173
 
198
174
  function delimiter($, name) {
199
- return alias($[`_${name}_delimiter`], $.delimiter);
175
+ return namedExternal($, $[`_${name}`], "delimiter");
200
176
  }
201
177
 
202
178
  function missingOpeningDelimiter($) {
203
- return field(
204
- "opening",
205
- choice(
206
- delimiter($, "invalid_delimiter"),
207
- delimiter($, "missing_opening_delimiter"),
208
- delimiter($, "nonconforming_missing_opening_delimiter"),
209
- ),
179
+ return choice(
180
+ issueField($, "invalid_delimiter"),
181
+ issueField($, "missing_opening_delimiter"),
182
+ issueField($, "nonconforming_missing_opening_delimiter"),
210
183
  );
211
184
  }
212
185
 
213
186
  function unterminatedDelimiter($, construct) {
214
187
  return choice(
215
- delimiter($, `incomplete_${construct}`),
216
- delimiter($, `unterminated_${construct}`),
188
+ issueField($, `incomplete_${construct}`),
189
+ issueField($, `unterminated_${construct}`),
217
190
  );
218
191
  }
219
192
 
220
- function delimiterRules() {
221
- const rules = {};
222
- for (const name of delimiterNames) {
223
- rules[`_${name}_delimiter`] = ($) =>
224
- field("token", namedExternal($, $[`_${name}`], "delimiter_token"));
225
- }
226
- for (const reason of missingDelimiterReasons) {
227
- rules[`_${reason}_delimiter`] = ($) => issueField($, reason);
228
- }
229
- return rules;
193
+ function editingCommand($, kind) {
194
+ return alias($[`_${kind}_editing_command`], $.editing_command);
230
195
  }
231
196
 
232
197
  function commandListRules() {
@@ -239,7 +204,9 @@ function commandListRules() {
239
204
  _initial_suppressing_comment_command_list: ($) =>
240
205
  seq(
241
206
  alias($._initial_suppressing_comment_command, $.editing_command),
242
- optional(seq($._newline_separator, optional($._command_list))),
207
+ optional(
208
+ seq(alias("\n", $.command_separator), optional($._command_list)),
209
+ ),
243
210
  ),
244
211
 
245
212
  _initial_suppressing_comment_command: ($) =>
@@ -271,20 +238,23 @@ function commandListRules() {
271
238
  ),
272
239
 
273
240
  _command_list: ($) =>
274
- choice($._final_line, seq($._terminated_line, optional($._command_list))),
275
-
276
- _final_line: ($) => choice($._command_sequence, $._blanks),
241
+ choice(
242
+ $._command_sequence,
243
+ $._blanks,
244
+ seq($._terminated_line, optional($._command_list)),
245
+ ),
277
246
 
278
- _terminated_line: ($) => seq($._command_sequence, $._newline_separator),
247
+ _terminated_line: ($) =>
248
+ seq($._command_sequence, alias("\n", $.command_separator)),
279
249
 
280
250
  _command_sequence: ($) =>
281
251
  choice(
282
252
  seq(
283
- $._line_terminated_command_item,
253
+ editingCommand($, "line_terminated"),
284
254
  optional($._unmatched_closing_brace_tail),
285
255
  ),
286
256
  seq(
287
- $._recovered_line_terminated_command_item,
257
+ editingCommand($, "recovered_line_terminated"),
288
258
  optional(choice($._command_sequence, $._blanks)),
289
259
  ),
290
260
  seq($._separable_command_item, optional($._command_sequence_tail)),
@@ -297,7 +267,7 @@ function commandListRules() {
297
267
  _command_sequence_tail: ($) =>
298
268
  choice(
299
269
  seq(
300
- $._semicolon_separator,
270
+ alias(";", $.command_separator),
301
271
  optional(choice($._command_sequence, $._blanks)),
302
272
  ),
303
273
  $._unmatched_closing_brace_tail,
@@ -326,28 +296,22 @@ function commandListRules() {
326
296
  choice($.empty_command, $._chainable_command_item),
327
297
 
328
298
  _chainable_command_item: ($) =>
329
- choice(
330
- alias($._chainable_editing_command, $.editing_command),
331
- alias($._recovered_editing_command, $.editing_command),
332
- ),
333
-
334
- _line_terminated_command_item: ($) =>
335
- alias($._line_terminated_editing_command, $.editing_command),
336
-
337
- _recovered_line_terminated_command_item: ($) =>
338
- alias($._recovered_line_terminated_editing_command, $.editing_command),
299
+ choice(editingCommand($, "chainable"), editingCommand($, "recovered")),
339
300
 
340
301
  _block_command_sequence: ($) =>
341
302
  choice(
342
- $._line_terminated_command_item,
303
+ editingCommand($, "line_terminated"),
343
304
  seq(
344
- $._recovered_line_terminated_command_item,
305
+ editingCommand($, "recovered_line_terminated"),
345
306
  optional($._block_command_sequence),
346
307
  ),
347
308
  seq(
348
309
  $._separable_command_item,
349
310
  optional(
350
- seq($._semicolon_separator, optional($._block_command_sequence)),
311
+ seq(
312
+ alias(";", $.command_separator),
313
+ optional($._block_command_sequence),
314
+ ),
351
315
  ),
352
316
  ),
353
317
  ),
@@ -356,11 +320,11 @@ function commandListRules() {
356
320
  choice(
357
321
  seq(
358
322
  $._separable_command_item,
359
- $._semicolon_separator,
323
+ alias(";", $.command_separator),
360
324
  optional($._block_command_sequence_before_close),
361
325
  ),
362
326
  seq(
363
- $._recovered_line_terminated_command_item,
327
+ editingCommand($, "recovered_line_terminated"),
364
328
  optional($._block_command_sequence_before_close),
365
329
  ),
366
330
  ),
@@ -382,11 +346,7 @@ function commandListRules() {
382
346
  ),
383
347
 
384
348
  _terminated_block_line: ($) =>
385
- seq($._block_command_sequence, $._newline_separator),
386
-
387
- _newline_separator: ($) => alias("\n", $.command_separator),
388
-
389
- _semicolon_separator: ($) => alias(";", $.command_separator),
349
+ seq($._block_command_sequence, alias("\n", $.command_separator)),
390
350
 
391
351
  empty_command: ($) => seq(optional($._blanks), $._empty_command_marker),
392
352
 
@@ -394,6 +354,13 @@ function commandListRules() {
394
354
  };
395
355
  }
396
356
 
357
+ function omittedAddress($) {
358
+ return choice(
359
+ issueField($, "omitted_address"),
360
+ issueField($, "incomplete_omitted_address"),
361
+ );
362
+ }
363
+
397
364
  function addressRules(mode) {
398
365
  const expression = mode === "bre" ? "basic_reg_exp" : "extended_reg_exp";
399
366
 
@@ -409,23 +376,13 @@ function addressRules(mode) {
409
376
  return seq(
410
377
  field("opening", opening),
411
378
  optional(field("expression", $[expression])),
412
- field(
413
- "closing",
414
- choice(
415
- delimiter($, "regex_address_end"),
416
- unterminatedDelimiter($, "regular_expression"),
417
- ),
379
+ choice(
380
+ field("closing", delimiter($, "regex_address_end")),
381
+ unterminatedDelimiter($, "regular_expression"),
418
382
  ),
419
383
  );
420
384
  }
421
385
 
422
- function commaSeparator($) {
423
- return field(
424
- "separator",
425
- alias($._comma_address_separator, $.address_separator),
426
- );
427
- }
428
-
429
386
  return {
430
387
  address_clause: ($) =>
431
388
  choice(
@@ -440,12 +397,12 @@ function addressRules(mode) {
440
397
  choice(
441
398
  seq(
442
399
  field("first", $.address),
443
- field("separator", alias($._address_separator, $.address_separator)),
400
+ $._address_separator,
444
401
  field("second", $.address),
445
402
  ),
446
403
  seq(
447
404
  issueField($, "omitted_first_address"),
448
- commaSeparator($),
405
+ $._comma_address_separator,
449
406
  field("second", $.address),
450
407
  ),
451
408
  seq(
@@ -453,23 +410,20 @@ function addressRules(mode) {
453
410
  field("first", $.address),
454
411
  issueField($, "omitted_first_address"),
455
412
  ),
456
- commaSeparator($),
457
- $._omitted_second_address_issue,
413
+ $._comma_address_separator,
414
+ omittedAddress($),
458
415
  ),
459
416
  ),
460
417
 
461
- _omitted_second_address_issue: ($) =>
462
- choice(
463
- issueField($, "omitted_address"),
464
- issueField($, "incomplete_omitted_address"),
465
- ),
466
-
467
418
  _max2_excess_address_clause: ($) =>
468
419
  prec.dynamic(
469
420
  1,
470
421
  choice(
471
- seq($._double_address_clause, $._max2_excess_address_tail),
472
- seq($._max2_excess_address_clause, $._max2_excess_address_tail),
422
+ seq($._double_address_clause, issueField($, "excess_address_unit2")),
423
+ seq(
424
+ $._max2_excess_address_clause,
425
+ issueField($, "excess_address_unit2"),
426
+ ),
473
427
  ),
474
428
  ),
475
429
 
@@ -480,12 +434,15 @@ function addressRules(mode) {
480
434
  prec.dynamic(
481
435
  1,
482
436
  choice(
483
- seq(field("first", $.address), $._max1_excess_address_tail),
437
+ seq(field("first", $.address), issueField($, "excess_address_unit1")),
484
438
  seq(
485
439
  issueField($, "omitted_first_address_unit1"),
486
- $._max1_excess_address_tail,
440
+ issueField($, "excess_address_unit1"),
441
+ ),
442
+ seq(
443
+ $._max1_excess_address_clause,
444
+ issueField($, "excess_address_unit1"),
487
445
  ),
488
- seq($._max1_excess_address_clause, $._max1_excess_address_tail),
489
446
  ),
490
447
  ),
491
448
 
@@ -496,18 +453,12 @@ function addressRules(mode) {
496
453
  issueField($, "excess_address"),
497
454
  seq(
498
455
  issueField($, "omitted_first_address_unit0"),
499
- $._max0_excess_address_tail,
456
+ issueField($, "excess_address_unit0"),
500
457
  ),
501
- seq($._max0_address_clause, $._max0_excess_address_tail),
458
+ seq($._max0_address_clause, issueField($, "excess_address_unit0")),
502
459
  ),
503
460
  ),
504
461
 
505
- _max0_excess_address_tail: ($) => issueField($, "excess_address_unit0"),
506
-
507
- _max1_excess_address_tail: ($) => issueField($, "excess_address_unit1"),
508
-
509
- _max2_excess_address_tail: ($) => issueField($, "excess_address_unit2"),
510
-
511
462
  _address_separator: ($) =>
512
463
  choice(
513
464
  $._comma_address_separator,
@@ -520,13 +471,10 @@ function addressRules(mode) {
520
471
  _comma_address_separator: ($) =>
521
472
  seq(
522
473
  optional(issueField($, "blanks_around_address_separator")),
523
- $._address_separator_token,
474
+ field("separator", alias(",", $.address_separator)),
524
475
  optional(issueField($, "blanks_around_address_separator")),
525
476
  ),
526
477
 
527
- _address_separator_token: ($) =>
528
- field("token", alias(",", $.address_separator_token)),
529
-
530
478
  address: addressChoice,
531
479
 
532
480
  _max0_address: addressChoice,
@@ -562,7 +510,7 @@ function delimitedFunction($, spelling, name, first, middleReason, rest) {
562
510
  optional(first),
563
511
  choice(
564
512
  seq(field("middle", delimiter($, `${name}_middle`)), ...rest),
565
- field("middle", unterminatedDelimiter($, middleReason)),
513
+ unterminatedDelimiter($, middleReason),
566
514
  ),
567
515
  ),
568
516
  missingOpeningDelimiter($),
@@ -600,7 +548,7 @@ function operandRules(mode) {
600
548
  ),
601
549
  ),
602
550
  ),
603
- field("closing", unterminatedDelimiter($, "replacement")),
551
+ unterminatedDelimiter($, "replacement"),
604
552
  ),
605
553
  ],
606
554
  ),
@@ -673,12 +621,9 @@ function operandRules(mode) {
673
621
  "translation",
674
622
  [
675
623
  optional(field("string2", $.translation_string)),
676
- field(
677
- "closing",
678
- choice(
679
- delimiter($, "translate_end"),
680
- unterminatedDelimiter($, "translation"),
681
- ),
624
+ choice(
625
+ field("closing", delimiter($, "translate_end")),
626
+ unterminatedDelimiter($, "translation"),
682
627
  ),
683
628
  ],
684
629
  ),
@@ -724,9 +669,10 @@ function functionRules() {
724
669
  ),
725
670
 
726
671
  _text_tail: ($) =>
727
- seq(optional(issueField($, "missing_text")), $._text_end),
728
-
729
- _text_end: ($) => choice($._text_line_end, $._text_eof),
672
+ seq(
673
+ optional(issueField($, "missing_text")),
674
+ choice($._text_line_end, $._text_eof),
675
+ ),
730
676
 
731
677
  text_literal: ($) => $._text_literal,
732
678
 
@@ -734,11 +680,7 @@ function functionRules() {
734
680
 
735
681
  text_escaped_newline: ($) => $._text_escaped_newline,
736
682
 
737
- text_introducer: ($) =>
738
- namedExternal($, $._text_command_start, "text_introducer_token"),
739
-
740
- _incomplete_text_introducer: ($) =>
741
- issueField($, "incomplete_text_introducer"),
683
+ text_introducer: ($) => $._text_command_start,
742
684
 
743
685
  rfile: ($) => lineOperand($, $._file_argument, $._line_word),
744
686
 
@@ -761,11 +703,7 @@ function functionRules() {
761
703
  seq(functionVerb($, "#"), optional(field("comment", $.comment))),
762
704
  ),
763
705
 
764
- closing_brace: ($) =>
765
- choice($._present_closing_brace, issueField($, "missing_closing_brace")),
766
-
767
- _present_closing_brace: ($) =>
768
- namedExternal($, $._right_brace, "closing_brace_token"),
706
+ closing_brace: ($) => $._right_brace,
769
707
  };
770
708
 
771
709
  function fileForm(form) {
@@ -775,7 +713,10 @@ function functionRules() {
775
713
  const formArguments = {
776
714
  block: ($) => [
777
715
  field("commands", alias($._block_commands, $.command_list)),
778
- field("closing", $.closing_brace),
716
+ choice(
717
+ field("closing", $.closing_brace),
718
+ issueField($, "missing_closing_brace"),
719
+ ),
779
720
  optional($._blanks),
780
721
  ],
781
722
  text: ($) => [
@@ -784,10 +725,7 @@ function functionRules() {
784
725
  field("introducer", $.text_introducer),
785
726
  choice(field("text", $.text), $._text_tail),
786
727
  ),
787
- field(
788
- "introducer",
789
- alias($._incomplete_text_introducer, $.text_introducer),
790
- ),
728
+ issueField($, "incomplete_text_introducer"),
791
729
  missingAtEndOrBoundary($, "missing_text_introducer"),
792
730
  ),
793
731
  ],
@@ -829,6 +767,13 @@ function functionRules() {
829
767
  return rules;
830
768
  }
831
769
 
770
+ function unknownFunction($, id) {
771
+ return seq(
772
+ issueField($, id),
773
+ optional(issueField($, "unexpected_command_text")),
774
+ );
775
+ }
776
+
832
777
  function editingCommandRules() {
833
778
  const addressClauses = {
834
779
  0: ($) => alias($._max0_address_clause, $.address_clause),
@@ -865,12 +810,12 @@ function editingCommandRules() {
865
810
  return seq(field("addresses", addresses), optional($._blanks));
866
811
  }
867
812
 
868
- function addressedCommand($, addresses, selectedFunction) {
813
+ function addressedCommand($, addresses, body) {
869
814
  return seq(
870
815
  optional($._blanks),
871
816
  optional(addressesPrefix($, addresses)),
872
817
  optional(field("negation", $.negation)),
873
- field("function", selectedFunction),
818
+ body,
874
819
  );
875
820
  }
876
821
 
@@ -882,7 +827,7 @@ function editingCommandRules() {
882
827
  addressedCommand(
883
828
  $,
884
829
  addressClauses[maximum]($),
885
- alias($[name], $.function),
830
+ field("function", alias($[name], $.function)),
886
831
  ),
887
832
  ),
888
833
  );
@@ -908,45 +853,29 @@ function editingCommandRules() {
908
853
  ),
909
854
 
910
855
  _recovered_editing_command: ($) =>
911
- choice(
912
- addressedCommand(
913
- $,
914
- $.address_clause,
915
- alias($._unknown_function, $.function),
916
- ),
917
- seq(
918
- optional($._blanks),
919
- optional(addressesPrefix($, $.address_clause)),
920
- field("negation", $.negation),
921
- field("function", alias($._reserved_unknown_function, $.function)),
922
- ),
923
- seq(
924
- optional($._blanks),
925
- choice(
926
- seq(
927
- addressesPrefix($, $.address_clause),
928
- optional(field("negation", $.negation)),
929
- ),
856
+ seq(
857
+ optional($._blanks),
858
+ choice(
859
+ seq(
860
+ optional(addressesPrefix($, $.address_clause)),
930
861
  field("negation", $.negation),
862
+ choice(
863
+ unknownFunction($, "unknown_function"),
864
+ unknownFunction($, "reserved_unknown_function"),
865
+ missingAtEndOrBoundary($, "missing_function"),
866
+ ),
931
867
  ),
932
- field("function", alias($._missing_function, $.function)),
868
+ seq(
869
+ addressesPrefix($, $.address_clause),
870
+ choice(
871
+ unknownFunction($, "unknown_function"),
872
+ missingAtEndOrBoundary($, "missing_function"),
873
+ ),
874
+ ),
875
+ unknownFunction($, "unknown_function"),
933
876
  ),
934
877
  ),
935
878
 
936
- _unknown_function: ($) =>
937
- seq(
938
- issueField($, "unknown_function"),
939
- optional(issueField($, "unexpected_command_text")),
940
- ),
941
-
942
- _reserved_unknown_function: ($) =>
943
- seq(
944
- issueField($, "reserved_unknown_function"),
945
- optional(issueField($, "unexpected_command_text")),
946
- ),
947
-
948
- _missing_function: ($) => missingAtEndOrBoundary($, "missing_function"),
949
-
950
879
  negation: ($) =>
951
880
  seq(
952
881
  field("operator", alias("!", $.negation_operator)),
@@ -970,7 +899,6 @@ function editingCommandRules() {
970
899
  function sedRules(mode) {
971
900
  return {
972
901
  ...commandListRules(),
973
- ...delimiterRules(),
974
902
  ...addressRules(mode),
975
903
  ...operandRules(mode),
976
904
  ...functionRules(),
@@ -1111,7 +1039,7 @@ function issueDefinitions(mode) {
1111
1039
  namedExternal(
1112
1040
  $,
1113
1041
  $._regex_unmatched_group_close,
1114
- "back_close_parenthesis_token",
1042
+ "back_close_parenthesis",
1115
1043
  ),
1116
1044
  },
1117
1045
  {
@@ -1297,19 +1225,10 @@ function issueDefinitions(mode) {
1297
1225
  rule: ($) =>
1298
1226
  choice(
1299
1227
  seq(
1300
- field(
1301
- "separator",
1302
- alias($._address_separator, $.address_separator),
1303
- ),
1228
+ $._address_separator,
1304
1229
  field("address", alias($[`_max${maximum}_address`], $.address)),
1305
1230
  ),
1306
- seq(
1307
- field(
1308
- "separator",
1309
- alias($._comma_address_separator, $.address_separator),
1310
- ),
1311
- $._omitted_second_address_issue,
1312
- ),
1231
+ seq($._comma_address_separator, omittedAddress($)),
1313
1232
  ),
1314
1233
  })),
1315
1234
  {
@@ -1363,7 +1282,7 @@ function issueDefinitions(mode) {
1363
1282
  {
1364
1283
  reason: "unmatched_closing_brace",
1365
1284
  outcome: "nonconforming_syntax",
1366
- rule: ($) => alias($._present_closing_brace, $.closing_brace),
1285
+ rule: ($) => $.closing_brace,
1367
1286
  },
1368
1287
  {
1369
1288
  reason: "missing_command_separator",
@@ -1390,11 +1309,7 @@ function issueDefinitions(mode) {
1390
1309
  {
1391
1310
  reason: "invalid_delimiter",
1392
1311
  outcome: "nonconforming_syntax",
1393
- rule: ($) =>
1394
- field(
1395
- "token",
1396
- alias(choice("\\", $._invalid_character), $.delimiter_token),
1397
- ),
1312
+ rule: ($) => choice(token(/\\/), $._invalid_character),
1398
1313
  },
1399
1314
  {
1400
1315
  reason: "unterminated_regular_expression",
@@ -1731,4 +1646,4 @@ function defineGrammar(name, mode) {
1731
1646
  });
1732
1647
  }
1733
1648
 
1734
- module.exports = defineGrammar;
1649
+ export default defineGrammar;