Skip to content

fix: trailers values and breaking changes values could be multilines #77

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ const SCOPE = /[^\n\r\(\)]+/;
const COMMENT = /[^\n\r]*\r?\n/;
const COMMENT_TITLE = /[^\n\r:\uff1a]+[:\uff1a]\s*\r?\n/;
const TRAILER_TOKEN = /[a-zA-Z-]+[ ]*[:\uff1a] /;
const TRAILER_VALUE = /[^\n\r]+(\r?\n [^\n\r]+)*/;
const GENERATED_COMMENT_TITLE = /[^\n\r:\uff1a]+[:\uff1a][ ]*/;
const NUMBER = /\d+/;
const BREAKING_CHANGE = /BREAKING[- ]CHANGE[ ]*[:\uff1a] /;
const BREAKING_CHANGE_VALUE = /[^\n\r]+(\r?\n [^\n\r]+)*/;

module.exports = grammar({
name: 'gitcommit',
Expand Down Expand Up @@ -53,14 +55,17 @@ module.exports = grammar({
message_line: () => seq(seq(NOT_A_COMMENT, ANYTHING_OR_NONE)),

trailer: ($) =>
seq(alias(TRAILER_TOKEN, $.token), optional(alias(ANYTHING, $.value))),
seq(
alias(TRAILER_TOKEN, $.token),
optional(alias(TRAILER_VALUE, $.value))
),

breaking_change: ($) =>
seq(
// BREAKING_CHANGE conflicts with TRAILER_TOKEN, an so requires higher
// lexical precedence
alias(token(prec(1, BREAKING_CHANGE)), $.token),
optional(alias(ANYTHING, $.value))
optional(alias(BREAKING_CHANGE_VALUE, $.value))
),

comment: ($) =>
Expand Down
9 changes: 5 additions & 4 deletions src/grammar.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49,300 changes: 24,672 additions & 24,628 deletions src/parser.c

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/tree_sitter/array.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 28 additions & 7 deletions src/tree_sitter/parser.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions test/corpus/body.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ BREAKING-CHANGE: also valid
BREAKING CHANGE with overflow
================================================================================

BREAKING CHANGE: My message with a long long text that will overflow with ease.
BREAKING CHANGE: My message with a long long text
with more than one line
that should be parsed as a single value
--------------------------------------------------------------------------------

(source
Expand All @@ -105,9 +107,9 @@ Overflowed summary
================================================================================
This is a simple subject

This is a simple body
This is a simple body
This is a simple body with so muche characters that it will overflow the summary limit
This is a simple body
This is a simple body
--------------------------------------------------------------------------------

(source
Expand Down
4 changes: 2 additions & 2 deletions test/corpus/trailers.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ This is a simple subject

key: This is a very long value, with spaces and
newlines in it.
it should be parsed as a single value.

--------------------------------------------------------------------------------

Expand All @@ -82,8 +83,7 @@ key: This is a very long value, with spaces and
(message
(trailer
(token)
(value))
(message_line)))
(value))))

================================================================================
Mixed
Expand Down
Loading