Skip to content

Commit

Permalink
fix: parse multiline trailer value (#49)
Browse files Browse the repository at this point in the history
Ref: #47
  • Loading branch information
gbprod authored Jan 18, 2024
1 parent 7e3ad5f commit e8d9eda
Show file tree
Hide file tree
Showing 4 changed files with 16,036 additions and 15,994 deletions.
17 changes: 17 additions & 0 deletions corpus/body.txt
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,23 @@ Suggested-by: Toto
(token)
(value))))

================================================================================
Multiline trailers
================================================================================
This is a simple subject

key: This is a very long value, with spaces and
newlines in it.

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

(source
(subject)
(message
(trailer
(token)
(value))))

================================================================================
Mixed
================================================================================
Expand Down
3 changes: 2 additions & 1 deletion grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const SCOPE = /[a-zA-Z0-9_-]+/;
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/;
Expand Down Expand Up @@ -57,7 +58,7 @@ module.exports = grammar({
_message: () => seq(NOT_A_COMMENT, optional(ANYTHING)),

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

breaking_change: ($) =>
seq(
Expand Down
2 changes: 1 addition & 1 deletion src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@
"type": "ALIAS",
"content": {
"type": "PATTERN",
"value": "[^\\n\\r]+"
"value": "[^\\n\\r]+(\\r?\\n [^\\n\\r]+)*"
},
"named": true,
"value": "value"
Expand Down
Loading

0 comments on commit e8d9eda

Please sign in to comment.