Commit
Author: Michael Davis [mcarsondavis@gmail.com]
Hash: 6d7c499bc4d26cdc527ddc2d0026d23aac14f97a
Timestamp: Fri, 16 Sep 2022 10:29:00 +0000 (2 years ago)

+13 -2 +/-2 browse
Fix deletions with multiple leading dashes
Fix deletions with multiple leading dashes

Deleted lines may start with the leading dash "-" but then the line
itself may contain an arbitrary number of dashes. This change parses
any number of leading dashes as a deletion except for the triple
leading dash which is considered to be an old file marker.

These cases should have been valid parse examples before but were
marked as errors because of the contention between the deletion
and old_file rules and error recovery.

Connects #1
1diff --git a/grammar.js b/grammar.js
2index 50c986a..6ec3106 100644
3--- a/grammar.js
4+++ b/grammar.js
5 @@ -53,7 +53,12 @@ module.exports = grammar({
6
7 addition: ($) => iseq("+", optional(ANYTHING)),
8 deletion: ($) =>
9- choice(iseq("-", optional(ANYTHING)), iseq("--", optional(ANYTHING))),
10+ choice(
11+ iseq("-", optional(ANYTHING)),
12+ iseq("--", optional(ANYTHING)),
13+ iseq("---"),
14+ iseq("----", optional(ANYTHING))
15+ ),
16
17 context: ($) => token(prec(-1, ANYTHING)),
18
19 diff --git a/test/corpus/text.txt b/test/corpus/text.txt
20index 2f1f90a..ed5fe30 100644
21--- a/test/corpus/text.txt
22+++ b/test/corpus/text.txt
23 @@ -227,11 +227,17 @@ index 321c90a..b4a5cba 100644
24 (addition))
25
26 ================================================================================
27- Double dash
28+ Leading dash deletions
29 ================================================================================
30 --123
31+ ---
32+ ----1234
33+ -----1234
34
35 --------------------------------------------------------------------------------
36
37 (source
38+ (deletion)
39+ (deletion)
40+ (deletion)
41 (deletion))