Closed ObserverOfTime closed 2 years ago
This grammar focuses only on diff syntax. Patch syntax should be covered in a separate grammar which injects this diff grammar.
Patch syntax is diff syntax with ---
in a context line.
(and some metadata which don't have to be handled by this grammar)
I can't find a formal definition for patch and/or diff (if you can find these, please do link them).
My understanding is that patch syntax is a superset of diff - it's additional metadata surrounding a diff section. There is no way to not handle part of a document with tree-sitter: everything must be parsed as something, so adding support for patch would mean parsing all of the patch syntax.
A separate tree-sitter-patch grammar would be a reasonable way to approach this, and it could parse the metadata.
I can't find a formal definition for patch and/or diff
GNU diffutils
supports several distinct formats:
Ideally, this parser would handle the first three formats. (maybe in separate grammars?)
My understanding is that patch syntax is a superset of diff
I suppose you're right as per the Kernel documentation. It's in fact a combination of mbox and unified diff.
There is no way to not handle part of a document with tree-sitter
I know, but you can parse the ---
marker as a context node to avoid the error.
At least until someone (maybe me?) writes a grammar for the patch format.
Yeah, the error node should be cleaned up. I have fixed the parsing to produce a deletion
node though rather than context
in 6d7c499bc4d26cdc527ddc2d0026d23aac14f97a, since ---
may mark the deletion of a line containing only "--".
I don't use patch format myself so I am uninterested in maintaining a grammar for it. This grammar should serve as a decent example if you would like to tackle it yourself though.
git format-patch
uses---
to separate the commit body from the summary. This parser expects that to be part of anold_file
node and returns an error.Here's a random kernel patch and the syntax tree it produces: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/patch/?id=da3b1c2