Skip to content

Commit

Permalink
[Diff] Hunks and ranges
Browse files Browse the repository at this point in the history
This commit...

1. scopes `,` in ranges `punctuation.separator.range` as numbers before and
   after denote beginning and end of modified content range, but no sequence
   of arbitrary numbers.

2. scopes diff3 hunks `meta.hunk`

3. scope whole diff3 change markers `meta.range` to achieve same segmentation
   as for `@@ ... @@` range markers in unified diffs.

4. add diff3 modifications to toc-list

   Scope change markers `meta.toc-list`.
   Exclude eol to correctly separate them in symbol list.
  • Loading branch information
deathaxe authored and michaelblyons committed Dec 18, 2024
1 parent 18fb06e commit 13c33f6
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 20 deletions.
31 changes: 19 additions & 12 deletions Diff/Diff.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ contexts:
- match: ( (-) )(.* (={4})){{eol}}
captures:
1: meta.header.diff
2: punctuation.separator.sequence.diff
2: punctuation.separator.range.diff
3: meta.diff.header.to-file meta.header.to-file.diff
4: punctuation.definition.to-file.diff
pop: 1
Expand Down Expand Up @@ -130,9 +130,9 @@ contexts:
- match: ^\d+(?:(,)\d+)*(a|d|c)\d+(?:(,)\d+)*{{eol}}
scope: meta.diff.range.normal meta.range.normal.diff
captures:
1: punctuation.separator.sequence.diff
1: punctuation.separator.range.diff
2: support.function.diff
3: punctuation.separator.sequence.diff
3: punctuation.separator.range.diff

# https://www.gnu.org/software/diffutils/manual/diffutils.html#Example-Context
- match: ^(-){3}(?= .+ -{4}{{eol}})
Expand Down Expand Up @@ -177,21 +177,25 @@ contexts:

# https://www.gnu.org/software/diffutils/manual/diffutils.html#Example-diff3-Normal
diff3-normal:
- match: ^====[1-3]?{{eol}}
scope: punctuation.section.block.diff
- match: ^====([1-3]?){{eol}}
scope: meta.hunk.diff punctuation.section.hunk.diff
captures:
1: constant.numeric.from-file.diff

- match: ^([1-3])(:)(\d+(a)|\d+(?:(,)\d+)?(c)){{eol}}
scope: meta.mapping.diff
- match: ^(([1-3])(:)(?:\d+(a)|\d+(?:(,)\d+)?(c))){{eol}}
scope: meta.diff.range.normal meta.range.normal.diff
captures:
1: meta.mapping.key.diff meta.number.integer.decimal.diff constant.numeric.value.diff
2: punctuation.separator.key-value.diff
3: meta.mapping.value.diff meta.diff.range.normal meta.range.normal.diff
1: meta.toc-list.hunk.diff
2: constant.numeric.from-file.diff
3: punctuation.separator.file.diff
4: support.function.diff
5: punctuation.separator.sequence.diff
5: punctuation.separator.range.diff
6: support.function.diff
push: diff3-normal-change

diff3-normal-change:
- meta_scope: meta.hunk.diff
- meta_content_scope: meta.block.diff
- match: ^(?:\t| )
push: line-changed
- match: ^
Expand All @@ -218,18 +222,21 @@ contexts:
push: diff3-edit-changed

diff3-edit-inserted:
- meta_scope: meta.hunk.diff
- meta_content_scope: meta.block.diff markup.inserted.diff
- include: diff3-edit-end

diff3-edit-deleted:
- meta_scope: meta.hunk.diff
- meta_content_scope: meta.block.diff markup.deleted.diff
- include: diff3-edit-end

diff3-edit-changed:
- meta_scope: meta.hunk.diff
- meta_content_scope: meta.block.diff markup.changed.diff
- include: diff3-edit-end

diff3-edit-end:
- match: ^\.$
scope: punctuation.section.block.end.diff
scope: punctuation.terminator.hunk.diff
pop: 1
67 changes: 59 additions & 8 deletions Diff/tests/syntax_test_diff.diff
Original file line number Diff line number Diff line change
Expand Up @@ -115,18 +115,38 @@ Index: lao

Normal Format https://www.gnu.org/software/diffutils/manual/diffutils.html#Example-Normal
1,2d0
\ <- meta.diff.range.normal meta.range.normal.diff
\^^^^ meta.diff.range.normal meta.range.normal.diff
\^ punctuation.separator.range.diff
\ ^ support.function.diff
< The Way that can be told of is not the eternal Way;
< The name that can be named is not the eternal name.
4c2,3
\ <- meta.diff.range.normal meta.range.normal.diff
\^^^^ meta.diff.range.normal meta.range.normal.diff
\^ support.function.diff
\ ^ punctuation.separator.range.diff
< The Named is the mother of all things.
\ <- markup.deleted.diff punctuation.definition.deleted.diff
\^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ markup.deleted.diff
\^ punctuation.definition.deleted.diff
---
\ <- meta.separator.diff punctuation.separator.block.diff
\^^ meta.separator.diff punctuation.separator.block.diff
> The named is the mother of all things.
>
\^ - meta.whitespace
11a11,13
\ <- meta.diff.range.normal meta.range.normal.diff
\^^^^^^^ meta.diff.range.normal meta.range.normal.diff
\ ^ support.function.diff
\ ^ punctuation.separator.range.diff
> They both may be called deep and profound.
> Deeper and more profound,
> The door of all subtleties!
\ <- markup.inserted.diff punctuation.definition.inserted.diff
\^^^^^^^^^^^^^^^^^^^^^^^^^^^^ markup.inserted.diff
\^ punctuation.definition.inserted.diff


Context Format https://www.gnu.org/software/diffutils/manual/diffutils.html#Example-Context
Expand Down Expand Up @@ -231,25 +251,53 @@ Unified Format https://www.gnu.org/software/diffutils/manual/diffutils.html#Exam

Diff3 Normal Format https://www.gnu.org/software/diffutils/manual/diffutils.html#Example-diff3-Normal
====2
\ <- meta.hunk.diff punctuation.section.hunk.diff
\^^^^^ meta.hunk.diff punctuation.section.hunk.diff
\ ^ constant.numeric.from-file.diff
1:1,2c
\ <- meta.hunk.diff meta.diff.range.normal meta.range.normal.diff meta.toc-list.hunk.diff constant.numeric.from-file.diff
\^^^^^ meta.hunk.diff meta.diff.range.normal meta.range.normal.diff meta.toc-list.hunk.diff
\^ punctuation.separator.file.diff
\ ^ punctuation.separator.range.diff
\ ^ support.function.diff
\ ^ - meta.toc-list
3:1,2c
The Way that can be told of is not the eternal Way;
The name that can be named is not the eternal name.
\^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.hunk.diff meta.block.diff markup.changed.diff
2:0a
\ <- meta.hunk.diff meta.diff.range.normal meta.range.normal.diff meta.toc-list.hunk.diff constant.numeric.from-file.diff
\^^^ meta.hunk.diff meta.diff.range.normal meta.range.normal.diff meta.toc-list.hunk.diff
\^ punctuation.separator.file.diff
\ ^ support.function.diff
\ ^ - meta.toc-list
====1
\ <- meta.hunk.diff punctuation.section.hunk.diff
\^^^^^ meta.hunk.diff punctuation.section.hunk.diff
\ ^ constant.numeric.from-file.diff
1:4c
The Named is the mother of all things.
2:2,3c
3:4,5c
The named is the mother of all things.

====3
\ <- meta.hunk.diff punctuation.section.hunk.diff
\^^^^^ meta.hunk.diff punctuation.section.hunk.diff
\ ^ constant.numeric.from-file.diff
1:8c
\ <- meta.hunk.diff meta.diff.range.normal meta.range.normal.diff meta.toc-list.hunk.diff constant.numeric.from-file.diff
\^^^ meta.hunk.diff meta.diff.range.normal meta.range.normal.diff meta.toc-list.hunk.diff
\^ punctuation.separator.file.diff
\ ^ support.function.diff
\ ^ - meta.toc-list
2:7c
so we may see their outcome.
3:9c
so we may see their result.
====
\ <- meta.hunk.diff punctuation.section.hunk.diff
\^^^^ meta.hunk.diff punctuation.section.hunk.diff
1:11a
2:11,13c
They both may be called deep and profound.
Expand All @@ -258,33 +306,36 @@ Diff3 Normal Format https://www.gnu.org/software/diffutils/manual/diffutils.html
3:13,14c

-- The Way of Lao-Tzu, tr. Wing-tsit Chan
\^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.hunk.diff meta.block.diff markup.changed.diff


Diff3 Edit Format https://www.gnu.org/software/diffutils/manual/diffutils.html#Selecting-Which-Changes-to-Incorporate
11a
\ <- meta.diff.range.normal meta.range.normal.diff
\ <- meta.hunk.diff meta.diff.range.normal meta.range.normal.diff
\^^^ meta.hunk.diff
\^ meta.diff.range.normal meta.range.normal.diff
\ ^ support.function.diff
-- The Way of Lao-Tzu, tr. Wing-tsit Chan
\^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.block.diff markup.inserted.diff
\^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.hunk.diff meta.block.diff markup.inserted.diff
.
\ <- punctuation.section.block.end.diff
\ <- meta.hunk.diff punctuation.terminator.hunk.diff
8c
\ <- meta.diff.range.normal meta.range.normal.diff
\ <- meta.hunk.diff meta.diff.range.normal meta.range.normal.diff
\^^ meta.hunk.diff
\^ support.function.diff
so we may see their result.
\^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.block.diff markup.changed.diff
\^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.hunk.diff meta.block.diff markup.changed.diff
.
\ <- punctuation.section.block.end.diff
\ <- meta.hunk.diff punctuation.terminator.hunk.diff
24d
\ <- meta.diff.range.normal meta.range.normal.diff
\^ meta.diff.range.normal meta.range.normal.diff
\ ^ support.function.diff

This is removed content
\^^^^^^^^^^^^^^^^^^^^^^^^ meta.block.diff markup.deleted.diff
\^^^^^^^^^^^^^^^^^^^^^^^^^ meta.hunk.diff meta.block.diff markup.deleted.diff
.
\ <- punctuation.section.block.end.diff
\ <- meta.hunk.diff punctuation.terminator.hunk.diff


SVN sample https://svnbook.red-bean.com/en/1.7/svn-book.html#idm10685
Expand Down

0 comments on commit 13c33f6

Please sign in to comment.