Skip to content

Commit a716678

Browse files
authored
fix: trailers values and breaking changes values could be multilines (#77)
Ref: #76
1 parent db0e0c4 commit a716678

File tree

7 files changed

+24721
-24647
lines changed

7 files changed

+24721
-24647
lines changed

grammar.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ const SCOPE = /[^\n\r\(\)]+/;
1111
const COMMENT = /[^\n\r]*\r?\n/;
1212
const COMMENT_TITLE = /[^\n\r:\uff1a]+[:\uff1a]\s*\r?\n/;
1313
const TRAILER_TOKEN = /[a-zA-Z-]+[ ]*[:\uff1a] /;
14+
const TRAILER_VALUE = /[^\n\r]+(\r?\n [^\n\r]+)*/;
1415
const GENERATED_COMMENT_TITLE = /[^\n\r:\uff1a]+[:\uff1a][ ]*/;
1516
const NUMBER = /\d+/;
1617
const BREAKING_CHANGE = /BREAKING[- ]CHANGE[ ]*[:\uff1a] /;
18+
const BREAKING_CHANGE_VALUE = /[^\n\r]+(\r?\n [^\n\r]+)*/;
1719

1820
module.exports = grammar({
1921
name: 'gitcommit',
@@ -53,14 +55,17 @@ module.exports = grammar({
5355
message_line: () => seq(seq(NOT_A_COMMENT, ANYTHING_OR_NONE)),
5456

5557
trailer: ($) =>
56-
seq(alias(TRAILER_TOKEN, $.token), optional(alias(ANYTHING, $.value))),
58+
seq(
59+
alias(TRAILER_TOKEN, $.token),
60+
optional(alias(TRAILER_VALUE, $.value))
61+
),
5762

5863
breaking_change: ($) =>
5964
seq(
6065
// BREAKING_CHANGE conflicts with TRAILER_TOKEN, an so requires higher
6166
// lexical precedence
6267
alias(token(prec(1, BREAKING_CHANGE)), $.token),
63-
optional(alias(ANYTHING, $.value))
68+
optional(alias(BREAKING_CHANGE_VALUE, $.value))
6469
),
6570

6671
comment: ($) =>

src/grammar.json

Lines changed: 5 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/parser.c

Lines changed: 24672 additions & 24628 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/tree_sitter/array.h

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/tree_sitter/parser.h

Lines changed: 28 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/corpus/body.txt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ BREAKING-CHANGE: also valid
9191
BREAKING CHANGE with overflow
9292
================================================================================
9393

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

9799
(source
@@ -105,9 +107,9 @@ Overflowed summary
105107
================================================================================
106108
This is a simple subject
107109

108-
This is a simple body
110+
This is a simple body
109111
This is a simple body with so muche characters that it will overflow the summary limit
110-
This is a simple body
112+
This is a simple body
111113
--------------------------------------------------------------------------------
112114

113115
(source

test/corpus/trailers.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ This is a simple subject
7474

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

7879
--------------------------------------------------------------------------------
7980

@@ -82,8 +83,7 @@ key: This is a very long value, with spaces and
8283
(message
8384
(trailer
8485
(token)
85-
(value))
86-
(message_line)))
86+
(value))))
8787

8888
================================================================================
8989
Mixed

0 commit comments

Comments
 (0)