Skip to content

fix: parse triple-marker hunk lines - #27

Merged
clason merged 1 commit into
tree-sitter-grammars:mainfrom
barrettruth:fix/issue-13
Jul 17, 2026
Merged

clason merged 1 commit into
tree-sitter-grammars:mainfrom
barrettruth:fix/issue-13

Conversation

@barrettruth

@barrettruth barrettruth commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor

closes #13

@ribru17 @clason @the-mikedavis

Problem

Deleted/added hunk lines can start w/ the same triple-marker text used by file headers (like +++ /path/to/file). Example in #13. Currently, grammar allows --- as an exact deletion line, but did NOT allow that be followed by source code leading to an error.

Also note that the same issue exists symmetrically for addition - both ought to be addressed. Importantly, do not treat all --- <text>/+++ <text> type-lines as hunk changes.

Solution

Allow this pattern of triple-marker + context when parsing hunk changes ONLY.

The net effect is that inside a hunk, --- C, C++/+++ C, C-- is a deletion/addition. --- a/file, --- /dev/null, +++ b/filethingy are all properly parsed as file headers.

I made some super exhaustive and convoluted test cases in the corpus for this, too.

Comment thread src/parser.c Resolved
@barrettruth
barrettruth marked this pull request as ready for review July 16, 2026 23:30
Comment thread grammar.js
choice(
iseq("+", optional(ANYTHING)),
iseq("++", optional(ANYTHING)),
iseq("+++"),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm assuming the parse tests didn't pass if we just add the changes here? probably because this broadening is only valid within a hunk?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep

@barrettruth

Copy link
Copy Markdown
Contributor Author

FMI, what are we waiting on for this to get merged 🤔

@clason

clason commented Jul 17, 2026

Copy link
Copy Markdown
Collaborator
  1. Your answer to Riley's question.
  2. Me to have a bit of free time (I do have a day job, you know).

@clason
clason merged commit 7d20331 into tree-sitter-grammars:main Jul 17, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Parse error when encountering -- at beginning of deleted line containing ++

3 participants