tree-sitter-sed 0.13.0 → 0.15.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 +1 -1
- package/bindings/rust/lib.rs +1 -1
- package/common/grammar.js +144 -205
- package/common/regex.js +52 -55
- package/common/scanner.h +175 -175
- package/package.json +1 -1
- package/sed_ere/src/grammar.json +379 -629
- package/sed_ere/src/parser.c +36292 -27606
- package/src/grammar.json +379 -629
- package/src/parser.c +38036 -29331
- package/tree-sitter.json +1 -1
package/Cargo.toml
CHANGED
package/bindings/rust/lib.rs
CHANGED
package/common/grammar.js
CHANGED
|
@@ -47,6 +47,18 @@ function lineOperand($, first, rest) {
|
|
|
47
47
|
);
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
+
function operandAtoms($, literal, ...atoms) {
|
|
51
|
+
return repeat1(
|
|
52
|
+
choice(
|
|
53
|
+
literal,
|
|
54
|
+
seq($._escape_prefix, issueField($, "invalid_encoding")),
|
|
55
|
+
issueField($, "nul_character"),
|
|
56
|
+
issueField($, "invalid_encoding"),
|
|
57
|
+
...atoms,
|
|
58
|
+
),
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
|
|
50
62
|
function commentText($) {
|
|
51
63
|
return choice(
|
|
52
64
|
namedExternal($, $._comment_text, "comment_text"),
|
|
@@ -205,6 +217,14 @@ function editingCommand($, kind) {
|
|
|
205
217
|
return alias($[`_${kind}_editing_command`], $.editing_command);
|
|
206
218
|
}
|
|
207
219
|
|
|
220
|
+
function newlineSeparator($) {
|
|
221
|
+
return alias("\n", $.command_separator);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
function semicolonSeparator($) {
|
|
225
|
+
return alias(";", $.command_separator);
|
|
226
|
+
}
|
|
227
|
+
|
|
208
228
|
function commandListRules() {
|
|
209
229
|
return {
|
|
210
230
|
script: ($) => optional(alias($._script_command_list, $.command_list)),
|
|
@@ -215,9 +235,7 @@ function commandListRules() {
|
|
|
215
235
|
_initial_suppressing_comment_command_list: ($) =>
|
|
216
236
|
seq(
|
|
217
237
|
alias($._initial_suppressing_comment_command, $.editing_command),
|
|
218
|
-
optional(
|
|
219
|
-
seq(alias("\n", $.command_separator), optional($._command_list)),
|
|
220
|
-
),
|
|
238
|
+
optional(seq(newlineSeparator($), optional($._command_list))),
|
|
221
239
|
),
|
|
222
240
|
|
|
223
241
|
_initial_suppressing_comment_command: ($) =>
|
|
@@ -248,116 +266,91 @@ function commandListRules() {
|
|
|
248
266
|
repeat(commentText($)),
|
|
249
267
|
),
|
|
250
268
|
|
|
269
|
+
// Lists are built with repeat so that Tree-sitter balances them; explicit
|
|
270
|
+
// recursion nests hidden nodes as deep as the command count, which makes
|
|
271
|
+
// cursor traversal quadratic.
|
|
251
272
|
_command_list: ($) =>
|
|
252
273
|
choice(
|
|
253
|
-
|
|
274
|
+
seq(
|
|
275
|
+
repeat1($._command_unit),
|
|
276
|
+
optional(choice($._command_item, $._blanks)),
|
|
277
|
+
),
|
|
278
|
+
$._command_item,
|
|
254
279
|
$._blanks,
|
|
255
|
-
seq($._terminated_line, optional($._command_list)),
|
|
256
280
|
),
|
|
257
281
|
|
|
258
|
-
|
|
259
|
-
seq($._command_sequence, alias("\n", $.command_separator)),
|
|
260
|
-
|
|
261
|
-
_command_sequence: ($) =>
|
|
282
|
+
_command_unit: ($) =>
|
|
262
283
|
choice(
|
|
263
284
|
seq(
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
285
|
+
$._separable_command_item,
|
|
286
|
+
choice(
|
|
287
|
+
semicolonSeparator($),
|
|
288
|
+
newlineSeparator($),
|
|
289
|
+
issueNode($, "missing_separator_before_unmatched_brace"),
|
|
290
|
+
),
|
|
270
291
|
),
|
|
271
|
-
seq($._separable_command_item, optional($._command_sequence_tail)),
|
|
272
292
|
seq(
|
|
273
293
|
$._unmatched_closing_brace_item,
|
|
274
|
-
|
|
294
|
+
choice(
|
|
295
|
+
semicolonSeparator($),
|
|
296
|
+
newlineSeparator($),
|
|
297
|
+
issueNode($, "missing_separator_before_unmatched_brace"),
|
|
298
|
+
issueNode($, "missing_separator_after_unmatched_brace"),
|
|
299
|
+
),
|
|
275
300
|
),
|
|
276
|
-
),
|
|
277
|
-
|
|
278
|
-
_command_sequence_tail: ($) =>
|
|
279
|
-
choice(
|
|
280
301
|
seq(
|
|
281
|
-
|
|
282
|
-
|
|
302
|
+
editingCommand($, "line_terminated"),
|
|
303
|
+
choice(
|
|
304
|
+
newlineSeparator($),
|
|
305
|
+
issueNode($, "missing_separator_before_unmatched_brace"),
|
|
306
|
+
),
|
|
283
307
|
),
|
|
284
|
-
|
|
308
|
+
editingCommand($, "recovered_line_terminated"),
|
|
285
309
|
),
|
|
286
310
|
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
311
|
+
_command_item: ($) =>
|
|
312
|
+
choice(
|
|
313
|
+
$._separable_command_item,
|
|
290
314
|
$._unmatched_closing_brace_item,
|
|
291
|
-
|
|
315
|
+
editingCommand($, "line_terminated"),
|
|
292
316
|
),
|
|
293
317
|
|
|
294
318
|
_unmatched_closing_brace_item: ($) =>
|
|
295
|
-
seq(
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
$._command_sequence_tail,
|
|
300
|
-
seq(
|
|
301
|
-
issueNode($, "missing_separator_after_unmatched_brace"),
|
|
302
|
-
$._command_sequence,
|
|
303
|
-
),
|
|
319
|
+
seq(
|
|
320
|
+
optional($._brace_leading_blanks),
|
|
321
|
+
issueNode($, "unmatched_closing_brace"),
|
|
322
|
+
optional($._blanks),
|
|
304
323
|
),
|
|
305
324
|
|
|
306
325
|
_separable_command_item: ($) =>
|
|
307
|
-
choice(
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
326
|
+
choice(
|
|
327
|
+
$.empty_command,
|
|
328
|
+
editingCommand($, "chainable"),
|
|
329
|
+
editingCommand($, "recovered"),
|
|
330
|
+
),
|
|
311
331
|
|
|
312
|
-
|
|
332
|
+
_block_commands: ($) =>
|
|
313
333
|
choice(
|
|
314
|
-
|
|
334
|
+
repeat1($._block_unit),
|
|
315
335
|
seq(
|
|
316
|
-
|
|
317
|
-
optional($.
|
|
318
|
-
|
|
319
|
-
seq(
|
|
320
|
-
$._separable_command_item,
|
|
321
|
-
optional(
|
|
322
|
-
seq(
|
|
323
|
-
alias(";", $.command_separator),
|
|
324
|
-
optional($._block_command_sequence),
|
|
325
|
-
),
|
|
326
|
-
),
|
|
336
|
+
repeat($._block_unit),
|
|
337
|
+
optional($._block_item),
|
|
338
|
+
missingCommandSeparator($),
|
|
327
339
|
),
|
|
328
340
|
),
|
|
329
341
|
|
|
330
|
-
|
|
342
|
+
_block_unit: ($) =>
|
|
331
343
|
choice(
|
|
332
344
|
seq(
|
|
333
345
|
$._separable_command_item,
|
|
334
|
-
|
|
335
|
-
optional($._block_command_sequence_before_close),
|
|
336
|
-
),
|
|
337
|
-
seq(
|
|
338
|
-
editingCommand($, "recovered_line_terminated"),
|
|
339
|
-
optional($._block_command_sequence_before_close),
|
|
346
|
+
choice(semicolonSeparator($), newlineSeparator($)),
|
|
340
347
|
),
|
|
348
|
+
seq(editingCommand($, "line_terminated"), newlineSeparator($)),
|
|
349
|
+
editingCommand($, "recovered_line_terminated"),
|
|
341
350
|
),
|
|
342
351
|
|
|
343
|
-
|
|
344
|
-
choice(
|
|
345
|
-
$._block_command_sequence_before_close,
|
|
346
|
-
seq($._terminated_block_line, optional($._block_command_list)),
|
|
347
|
-
),
|
|
348
|
-
|
|
349
|
-
_block_commands: ($) =>
|
|
350
|
-
choice($._block_command_list, $._block_command_list_missing_separator),
|
|
351
|
-
|
|
352
|
-
_block_command_list_missing_separator: ($) =>
|
|
353
|
-
choice(
|
|
354
|
-
missingCommandSeparator($),
|
|
355
|
-
seq($._block_command_sequence, missingCommandSeparator($)),
|
|
356
|
-
seq($._terminated_block_line, $._block_command_list_missing_separator),
|
|
357
|
-
),
|
|
358
|
-
|
|
359
|
-
_terminated_block_line: ($) =>
|
|
360
|
-
seq($._block_command_sequence, alias("\n", $.command_separator)),
|
|
352
|
+
_block_item: ($) =>
|
|
353
|
+
choice($._separable_command_item, editingCommand($, "line_terminated")),
|
|
361
354
|
|
|
362
355
|
empty_command: ($) => seq(optional($._blanks), $._empty_command_marker),
|
|
363
356
|
|
|
@@ -429,12 +422,9 @@ function addressRules(mode) {
|
|
|
429
422
|
_max2_excess_address_clause: ($) =>
|
|
430
423
|
prec.dynamic(
|
|
431
424
|
1,
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
$._max2_excess_address_clause,
|
|
436
|
-
issueField($, "excess_address_unit2"),
|
|
437
|
-
),
|
|
425
|
+
seq(
|
|
426
|
+
$._double_address_clause,
|
|
427
|
+
repeat1(issueField($, "excess_address_unit2")),
|
|
438
428
|
),
|
|
439
429
|
),
|
|
440
430
|
|
|
@@ -444,29 +434,27 @@ function addressRules(mode) {
|
|
|
444
434
|
_max1_excess_address_clause: ($) =>
|
|
445
435
|
prec.dynamic(
|
|
446
436
|
1,
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
437
|
+
seq(
|
|
438
|
+
choice(
|
|
439
|
+
field("first", $.address),
|
|
450
440
|
issueField($, "omitted_first_address_unit1"),
|
|
451
|
-
issueField($, "excess_address_unit1"),
|
|
452
|
-
),
|
|
453
|
-
seq(
|
|
454
|
-
$._max1_excess_address_clause,
|
|
455
|
-
issueField($, "excess_address_unit1"),
|
|
456
441
|
),
|
|
442
|
+
repeat1(issueField($, "excess_address_unit1")),
|
|
457
443
|
),
|
|
458
444
|
),
|
|
459
445
|
|
|
460
446
|
_max0_address_clause: ($) =>
|
|
461
447
|
prec.dynamic(
|
|
462
448
|
1,
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
449
|
+
seq(
|
|
450
|
+
choice(
|
|
451
|
+
issueField($, "excess_address"),
|
|
452
|
+
seq(
|
|
453
|
+
issueField($, "omitted_first_address_unit0"),
|
|
454
|
+
issueField($, "excess_address_unit0"),
|
|
455
|
+
),
|
|
468
456
|
),
|
|
469
|
-
|
|
457
|
+
repeat(issueField($, "excess_address_unit0")),
|
|
470
458
|
),
|
|
471
459
|
),
|
|
472
460
|
|
|
@@ -567,21 +555,17 @@ function operandRules(mode) {
|
|
|
567
555
|
),
|
|
568
556
|
|
|
569
557
|
replacement: ($) =>
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
$.escaped_newline,
|
|
582
|
-
issueField($, "unspecified_replacement_escape"),
|
|
583
|
-
issueField($, "incomplete_replacement_escape"),
|
|
584
|
-
),
|
|
558
|
+
operandAtoms(
|
|
559
|
+
$,
|
|
560
|
+
$.replacement_literal,
|
|
561
|
+
$.matched_text_reference,
|
|
562
|
+
$.replacement_backreference,
|
|
563
|
+
$.replacement_escaped_delimiter,
|
|
564
|
+
issueField($, "replacement_ampersand_delimiter_escape"),
|
|
565
|
+
$.replacement_escape,
|
|
566
|
+
$.escaped_newline,
|
|
567
|
+
issueField($, "unspecified_replacement_escape"),
|
|
568
|
+
issueField($, "incomplete_replacement_escape"),
|
|
585
569
|
),
|
|
586
570
|
|
|
587
571
|
replacement_literal: ($) => $._replacement_literal,
|
|
@@ -599,16 +583,8 @@ function operandRules(mode) {
|
|
|
599
583
|
_substitution_flags: ($) =>
|
|
600
584
|
prec.right(
|
|
601
585
|
choice(
|
|
602
|
-
|
|
603
|
-
seq(
|
|
604
|
-
),
|
|
605
|
-
),
|
|
606
|
-
|
|
607
|
-
_substitution_flags_without_write: ($) =>
|
|
608
|
-
choice(
|
|
609
|
-
substitutionFlagChoice($),
|
|
610
|
-
prec.left(
|
|
611
|
-
seq($._substitution_flags_without_write, substitutionFlagChoice($)),
|
|
586
|
+
repeat1(substitutionFlagChoice($)),
|
|
587
|
+
seq(repeat(substitutionFlagChoice($)), $.write_flag),
|
|
612
588
|
),
|
|
613
589
|
),
|
|
614
590
|
|
|
@@ -646,17 +622,13 @@ function operandRules(mode) {
|
|
|
646
622
|
),
|
|
647
623
|
|
|
648
624
|
translation_string: ($) =>
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
$.translation_escaped_delimiter,
|
|
657
|
-
issueField($, "undefined_translation_escape"),
|
|
658
|
-
issueField($, "incomplete_translation_escape"),
|
|
659
|
-
),
|
|
625
|
+
operandAtoms(
|
|
626
|
+
$,
|
|
627
|
+
$.translation_literal,
|
|
628
|
+
$.translation_escape,
|
|
629
|
+
$.translation_escaped_delimiter,
|
|
630
|
+
issueField($, "undefined_translation_escape"),
|
|
631
|
+
issueField($, "incomplete_translation_escape"),
|
|
660
632
|
),
|
|
661
633
|
|
|
662
634
|
translation_literal: ($) => $._translate_literal,
|
|
@@ -675,16 +647,12 @@ function functionRules() {
|
|
|
675
647
|
const rules = {
|
|
676
648
|
text: ($) =>
|
|
677
649
|
seq(
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
$.text_backslash_escape,
|
|
685
|
-
$.text_escaped_newline,
|
|
686
|
-
issueField($, "unspecified_text_escape"),
|
|
687
|
-
),
|
|
650
|
+
operandAtoms(
|
|
651
|
+
$,
|
|
652
|
+
$.text_literal,
|
|
653
|
+
$.text_backslash_escape,
|
|
654
|
+
$.text_escaped_newline,
|
|
655
|
+
issueField($, "unspecified_text_escape"),
|
|
688
656
|
),
|
|
689
657
|
$._text_tail,
|
|
690
658
|
),
|
|
@@ -742,6 +710,7 @@ function functionRules() {
|
|
|
742
710
|
const formArguments = {
|
|
743
711
|
block: ($) => [
|
|
744
712
|
field("commands", alias($._block_commands, $.command_list)),
|
|
713
|
+
optional($._brace_leading_blanks),
|
|
745
714
|
choice(
|
|
746
715
|
field("closing", $.closing_brace),
|
|
747
716
|
issueField($, "missing_closing_brace"),
|
|
@@ -935,6 +904,25 @@ function sedRules(mode) {
|
|
|
935
904
|
};
|
|
936
905
|
}
|
|
937
906
|
|
|
907
|
+
const missingCommandDefinitions = [
|
|
908
|
+
{ reason: "missing_function", atBoundary: true },
|
|
909
|
+
{ reason: "missing_label", atBoundary: true },
|
|
910
|
+
{ reason: "missing_rfile", atBoundary: true },
|
|
911
|
+
{ reason: "missing_wfile", atBoundary: true },
|
|
912
|
+
{ reason: "missing_text_introducer", atBoundary: true },
|
|
913
|
+
{
|
|
914
|
+
reason: "incomplete_text_introducer",
|
|
915
|
+
rule: ($) => $._text_incomplete_introducer,
|
|
916
|
+
},
|
|
917
|
+
{ reason: "missing_text" },
|
|
918
|
+
{ reason: "missing_closing_brace" },
|
|
919
|
+
{ reason: "missing_opening_delimiter", atBoundary: true },
|
|
920
|
+
];
|
|
921
|
+
|
|
922
|
+
const boundaryMissingReasons = missingCommandDefinitions
|
|
923
|
+
.filter(({ atBoundary }) => atBoundary)
|
|
924
|
+
.map(({ reason }) => reason);
|
|
925
|
+
|
|
938
926
|
function missingMarkerNames(mode) {
|
|
939
927
|
return [
|
|
940
928
|
"omitted_address",
|
|
@@ -956,12 +944,7 @@ function missingMarkerNames(mode) {
|
|
|
956
944
|
"missing_opening_delimiter",
|
|
957
945
|
"missing_separator_before_unmatched_brace",
|
|
958
946
|
"missing_separator_after_unmatched_brace",
|
|
959
|
-
|
|
960
|
-
"nonconforming_missing_label",
|
|
961
|
-
"nonconforming_missing_rfile",
|
|
962
|
-
"nonconforming_missing_wfile",
|
|
963
|
-
"nonconforming_missing_text_introducer",
|
|
964
|
-
"nonconforming_missing_opening_delimiter",
|
|
947
|
+
...boundaryMissingReasons.map((reason) => `nonconforming_${reason}`),
|
|
965
948
|
"missing_subexpression_placeholder",
|
|
966
949
|
"incomplete_bracket_list",
|
|
967
950
|
"incomplete_bracket_expression",
|
|
@@ -975,15 +958,6 @@ function issueDefinitions(mode) {
|
|
|
975
958
|
return ($) => $[`_${reason}_marker`];
|
|
976
959
|
}
|
|
977
960
|
|
|
978
|
-
const boundaryMissingReasons = [
|
|
979
|
-
"missing_function",
|
|
980
|
-
"missing_label",
|
|
981
|
-
"missing_rfile",
|
|
982
|
-
"missing_wfile",
|
|
983
|
-
"missing_text_introducer",
|
|
984
|
-
"missing_opening_delimiter",
|
|
985
|
-
];
|
|
986
|
-
|
|
987
961
|
return [
|
|
988
962
|
{
|
|
989
963
|
reason: "malformed_bracket_term",
|
|
@@ -1357,7 +1331,11 @@ function issueDefinitions(mode) {
|
|
|
1357
1331
|
reason: "invalid_substitution_flag",
|
|
1358
1332
|
outcome: "nonconforming_syntax",
|
|
1359
1333
|
rule: ($) =>
|
|
1360
|
-
choice(
|
|
1334
|
+
choice(
|
|
1335
|
+
$._invalid_substitution_flag,
|
|
1336
|
+
$._nul_character,
|
|
1337
|
+
issueField($, "invalid_encoding"),
|
|
1338
|
+
),
|
|
1361
1339
|
},
|
|
1362
1340
|
{
|
|
1363
1341
|
reason: "invalid_delimiter",
|
|
@@ -1403,51 +1381,11 @@ function issueDefinitions(mode) {
|
|
|
1403
1381
|
outcome: "nonconforming_syntax",
|
|
1404
1382
|
rule: missing(`nonconforming_${reason}`),
|
|
1405
1383
|
})),
|
|
1406
|
-
{
|
|
1407
|
-
reason
|
|
1408
|
-
outcome: "incomplete_syntax",
|
|
1409
|
-
rule: missing("missing_function"),
|
|
1410
|
-
},
|
|
1411
|
-
{
|
|
1412
|
-
reason: "missing_label",
|
|
1413
|
-
outcome: "incomplete_syntax",
|
|
1414
|
-
rule: missing("missing_label"),
|
|
1415
|
-
},
|
|
1416
|
-
{
|
|
1417
|
-
reason: "missing_rfile",
|
|
1418
|
-
outcome: "incomplete_syntax",
|
|
1419
|
-
rule: missing("missing_rfile"),
|
|
1420
|
-
},
|
|
1421
|
-
{
|
|
1422
|
-
reason: "missing_wfile",
|
|
1423
|
-
outcome: "incomplete_syntax",
|
|
1424
|
-
rule: missing("missing_wfile"),
|
|
1425
|
-
},
|
|
1426
|
-
{
|
|
1427
|
-
reason: "missing_text_introducer",
|
|
1428
|
-
outcome: "incomplete_syntax",
|
|
1429
|
-
rule: missing("missing_text_introducer"),
|
|
1430
|
-
},
|
|
1431
|
-
{
|
|
1432
|
-
reason: "incomplete_text_introducer",
|
|
1433
|
-
outcome: "incomplete_syntax",
|
|
1434
|
-
rule: ($) => $._text_incomplete_introducer,
|
|
1435
|
-
},
|
|
1436
|
-
{
|
|
1437
|
-
reason: "missing_text",
|
|
1438
|
-
outcome: "incomplete_syntax",
|
|
1439
|
-
rule: missing("missing_text"),
|
|
1440
|
-
},
|
|
1441
|
-
{
|
|
1442
|
-
reason: "missing_closing_brace",
|
|
1443
|
-
outcome: "incomplete_syntax",
|
|
1444
|
-
rule: missing("missing_closing_brace"),
|
|
1445
|
-
},
|
|
1446
|
-
{
|
|
1447
|
-
reason: "missing_opening_delimiter",
|
|
1384
|
+
...missingCommandDefinitions.map(({ reason, rule }) => ({
|
|
1385
|
+
reason,
|
|
1448
1386
|
outcome: "incomplete_syntax",
|
|
1449
|
-
rule: missing(
|
|
1450
|
-
},
|
|
1387
|
+
rule: rule ?? missing(reason),
|
|
1388
|
+
})),
|
|
1451
1389
|
{
|
|
1452
1390
|
reason: "missing_subexpression",
|
|
1453
1391
|
outcome: "incomplete_syntax",
|
|
@@ -1651,6 +1589,7 @@ function externalTokens($, mode) {
|
|
|
1651
1589
|
$._line_word,
|
|
1652
1590
|
$._argument_separator,
|
|
1653
1591
|
$._right_brace,
|
|
1592
|
+
$._brace_leading_blanks,
|
|
1654
1593
|
$._block_trailing_blanks,
|
|
1655
1594
|
$._empty_command_marker,
|
|
1656
1595
|
$._reserved_unknown_function_token,
|
package/common/regex.js
CHANGED
|
@@ -123,6 +123,33 @@ function bracketExpression($, ambiguous) {
|
|
|
123
123
|
);
|
|
124
124
|
}
|
|
125
125
|
|
|
126
|
+
// Character and equivalence classes are not portable range endpoints; their
|
|
127
|
+
// ranges keep the range_expression shape with the endpoint inside an issue.
|
|
128
|
+
const nonportableRangeClasses = ["character_class", "equivalence_class"];
|
|
129
|
+
|
|
130
|
+
function rangeOperator($) {
|
|
131
|
+
return field(
|
|
132
|
+
"operator",
|
|
133
|
+
namedExternal($, $._regex_bracket_hyphen, "range_operator"),
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function nonportableRangeRules() {
|
|
138
|
+
const rules = {};
|
|
139
|
+
for (const kind of nonportableRangeClasses) {
|
|
140
|
+
rules[`_${kind}_start_range`] = ($) =>
|
|
141
|
+
seq(
|
|
142
|
+
field("start", issueNode($, `${kind}_range_start`)),
|
|
143
|
+
rangeOperator($),
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
for (const kind of nonportableRangeClasses) {
|
|
147
|
+
rules[`_${kind}_end_range`] = ($) =>
|
|
148
|
+
field("term", issueNode($, `${kind}_range_end`));
|
|
149
|
+
}
|
|
150
|
+
return rules;
|
|
151
|
+
}
|
|
152
|
+
|
|
126
153
|
function bracketRules() {
|
|
127
154
|
return {
|
|
128
155
|
bracket_expression: ($) => bracketExpression($, false),
|
|
@@ -193,8 +220,9 @@ function bracketRules() {
|
|
|
193
220
|
"start",
|
|
194
221
|
choice(
|
|
195
222
|
$.start_range,
|
|
196
|
-
|
|
197
|
-
|
|
223
|
+
...nonportableRangeClasses.map((kind) =>
|
|
224
|
+
alias($[`_${kind}_start_range`], $.start_range),
|
|
225
|
+
),
|
|
198
226
|
),
|
|
199
227
|
),
|
|
200
228
|
choice(
|
|
@@ -202,8 +230,9 @@ function bracketRules() {
|
|
|
202
230
|
"end",
|
|
203
231
|
choice(
|
|
204
232
|
$.end_range,
|
|
205
|
-
|
|
206
|
-
|
|
233
|
+
...nonportableRangeClasses.map((kind) =>
|
|
234
|
+
alias($[`_${kind}_end_range`], $.end_range),
|
|
235
|
+
),
|
|
207
236
|
),
|
|
208
237
|
),
|
|
209
238
|
field(
|
|
@@ -217,38 +246,9 @@ function bracketRules() {
|
|
|
217
246
|
),
|
|
218
247
|
),
|
|
219
248
|
|
|
220
|
-
|
|
221
|
-
seq(
|
|
222
|
-
field("start", issueNode($, "character_class_range_start")),
|
|
223
|
-
field(
|
|
224
|
-
"operator",
|
|
225
|
-
namedExternal($, $._regex_bracket_hyphen, "range_operator"),
|
|
226
|
-
),
|
|
227
|
-
),
|
|
228
|
-
|
|
229
|
-
_equivalence_class_start_range: ($) =>
|
|
230
|
-
seq(
|
|
231
|
-
field("start", issueNode($, "equivalence_class_range_start")),
|
|
232
|
-
field(
|
|
233
|
-
"operator",
|
|
234
|
-
namedExternal($, $._regex_bracket_hyphen, "range_operator"),
|
|
235
|
-
),
|
|
236
|
-
),
|
|
237
|
-
|
|
238
|
-
_character_class_end_range: ($) =>
|
|
239
|
-
field("term", issueNode($, "character_class_range_end")),
|
|
240
|
-
|
|
241
|
-
_equivalence_class_end_range: ($) =>
|
|
242
|
-
field("term", issueNode($, "equivalence_class_range_end")),
|
|
249
|
+
...nonportableRangeRules(),
|
|
243
250
|
|
|
244
|
-
start_range: ($) =>
|
|
245
|
-
seq(
|
|
246
|
-
field("start", $.end_range),
|
|
247
|
-
field(
|
|
248
|
-
"operator",
|
|
249
|
-
namedExternal($, $._regex_bracket_hyphen, "range_operator"),
|
|
250
|
-
),
|
|
251
|
-
),
|
|
251
|
+
start_range: ($) => seq(field("start", $.end_range), rangeOperator($)),
|
|
252
252
|
|
|
253
253
|
end_range: ($) =>
|
|
254
254
|
choice(
|
|
@@ -316,6 +316,20 @@ function regularExpressionEscape($) {
|
|
|
316
316
|
);
|
|
317
317
|
}
|
|
318
318
|
|
|
319
|
+
function oneCharOrCollElem($, ...additional) {
|
|
320
|
+
return choice(
|
|
321
|
+
issueField($, "invalid_regular_expression_character"),
|
|
322
|
+
issueField($, "invalid_encoding"),
|
|
323
|
+
$.ordinary_character,
|
|
324
|
+
regularExpressionEscape($),
|
|
325
|
+
$.sed_newline_escape,
|
|
326
|
+
$.period,
|
|
327
|
+
$._bracket_expression,
|
|
328
|
+
issueField($, "special_delimiter_escape"),
|
|
329
|
+
...additional,
|
|
330
|
+
);
|
|
331
|
+
}
|
|
332
|
+
|
|
319
333
|
function commonRegularExpressionRules() {
|
|
320
334
|
return {
|
|
321
335
|
dup_count: ($) => $._regex_dup_count,
|
|
@@ -432,15 +446,8 @@ function breRules() {
|
|
|
432
446
|
backreference: ($) => $._regex_backreference,
|
|
433
447
|
|
|
434
448
|
one_char_or_coll_elem_bre: ($) =>
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
issueField($, "invalid_encoding"),
|
|
438
|
-
$.ordinary_character,
|
|
439
|
-
regularExpressionEscape($),
|
|
440
|
-
$.sed_newline_escape,
|
|
441
|
-
$.period,
|
|
442
|
-
$._bracket_expression,
|
|
443
|
-
issueField($, "special_delimiter_escape"),
|
|
449
|
+
oneCharOrCollElem(
|
|
450
|
+
$,
|
|
444
451
|
issueField($, "bre_vertical_line_escape"),
|
|
445
452
|
issueField($, "bre_question_mark_escape"),
|
|
446
453
|
issueField($, "bre_plus_escape"),
|
|
@@ -524,17 +531,7 @@ function ereRules() {
|
|
|
524
531
|
field("operator", issueNode($, "leading_duplication_symbol")),
|
|
525
532
|
),
|
|
526
533
|
|
|
527
|
-
one_char_or_coll_elem_ere: ($) =>
|
|
528
|
-
choice(
|
|
529
|
-
issueField($, "invalid_regular_expression_character"),
|
|
530
|
-
issueField($, "invalid_encoding"),
|
|
531
|
-
$.ordinary_character,
|
|
532
|
-
regularExpressionEscape($),
|
|
533
|
-
$.sed_newline_escape,
|
|
534
|
-
$.period,
|
|
535
|
-
$._bracket_expression,
|
|
536
|
-
issueField($, "special_delimiter_escape"),
|
|
537
|
-
),
|
|
534
|
+
one_char_or_coll_elem_ere: ($) => oneCharOrCollElem($),
|
|
538
535
|
|
|
539
536
|
ere_dupl_symbol: ($) =>
|
|
540
537
|
seq(
|