Skip to content

Commit

Permalink
feat(body): surround body with message node (#4)
Browse files Browse the repository at this point in the history
Ref: #3
  • Loading branch information
gbprod authored Nov 25, 2022
1 parent 49763bd commit d3c15bd
Show file tree
Hide file tree
Showing 10 changed files with 2,166 additions and 1,967 deletions.
Binary file modified build/Release/obj.target/tree_sitter_gitcommit_binding.node
Binary file not shown.
Binary file modified build/Release/obj.target/tree_sitter_gitcommit_binding/src/parser.o
Binary file not shown.
Binary file modified build/Release/tree_sitter_gitcommit_binding.node
Binary file not shown.
83 changes: 40 additions & 43 deletions corpus/body.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ this is a simple subject

(source
(subject)
(comment))
(message
(comment)))

================================================================================
Empty file w/ comments
Expand All @@ -32,7 +33,8 @@ Empty file w/ comments
--------------------------------------------------------------------------------

(source
(comment))
(message
(comment)))

================================================================================
Empty file w/ empty comment
Expand All @@ -43,7 +45,8 @@ Empty file w/ empty comment
--------------------------------------------------------------------------------

(source
(comment))
(message
(comment)))

================================================================================
Multiline body
Expand All @@ -58,8 +61,6 @@ And a paragraph.

(source
(subject)
(message)
(message)
(message))

================================================================================
Expand All @@ -77,10 +78,6 @@ test(trailer): test

(source
(subject)
(message)
(message)
(message)
(message)
(message))

================================================================================
Expand All @@ -93,9 +90,10 @@ Signed-by: gbprod <[email protected]>

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

================================================================================
Multiple trailers
Expand All @@ -112,21 +110,22 @@ Suggested-by: Toto

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

================================================================================
Mixed
Expand All @@ -146,18 +145,16 @@ And go on

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

================================================================================
BREAKING CHANGE
Expand All @@ -170,7 +167,7 @@ BREAKING CHANGE: My message
--------------------------------------------------------------------------------

(source
(message)
(breaking_change
(token)
(value)))
(message
(breaking_change
(token)
(value))))
26 changes: 15 additions & 11 deletions corpus/comments.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ This is a simple subject

(source
(subject)
(comment))
(message
(comment)))

================================================================================
Comment without space
Expand All @@ -22,7 +23,8 @@ This is a simple subject

(source
(subject)
(comment))
(message
(comment)))

================================================================================
Empty comment
Expand All @@ -35,7 +37,8 @@ This is a simple subject

(source
(subject)
(comment))
(message
(comment)))

================================================================================
Multiline comments
Expand All @@ -52,10 +55,11 @@ This is a simple subject

(source
(subject)
(comment)
(comment)
(comment)
(comment))
(message
(comment)
(comment)
(comment)
(comment)))

================================================================================
Comment title
Expand All @@ -67,7 +71,7 @@ Comment title
--------------------------------------------------------------------------------

(source
(comment
(title))
(comment))

(message
(comment
(title))
(comment)))
6 changes: 4 additions & 2 deletions corpus/scissor.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ index 457a414..94b9036 100644

(source
(subject)
(comment)
(message
(comment))
(scissor)
(diff
(generated_comment)
Expand All @@ -37,7 +38,8 @@ This is a simple subject

(source
(subject)
(comment)
(message
(comment))
(scissor)
(diff
(generated_comment)
Expand Down
6 changes: 3 additions & 3 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module.exports = grammar({
seq(
repeat($.comment),
optional(seq(seq($.subject, NEWLINE), repeat($.comment))),
optional(seq(NEWLINE, repeat($._body_line))),
optional(seq(NEWLINE, alias(repeat($._body_line), $.message))),
optional($._generated_comments),
optional($._scissor)
),
Expand All @@ -45,9 +45,9 @@ module.exports = grammar({
),

_body_line: ($) =>
choice($.message, $.breaking_change, $.trailer, $.comment, NEWLINE),
choice($._message, $.breaking_change, $.trailer, $.comment, NEWLINE),

message: () => seq(NOT_A_COMMENT, optional(ANYTHING)),
_message: () => seq(NOT_A_COMMENT, optional(ANYTHING)),

trailer: ($) =>
seq(alias(TRAILER_TOKEN, $.token), alias(ANYTHING, $.value)),
Expand Down
17 changes: 11 additions & 6 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,16 @@
"value": "\\r?\\n"
},
{
"type": "REPEAT",
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "_body_line"
}
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_body_line"
}
},
"named": true,
"value": "message"
}
]
},
Expand Down Expand Up @@ -211,7 +216,7 @@
"members": [
{
"type": "SYMBOL",
"name": "message"
"name": "_message"
},
{
"type": "SYMBOL",
Expand All @@ -231,7 +236,7 @@
}
]
},
"message": {
"_message": {
"type": "SEQ",
"members": [
{
Expand Down
28 changes: 19 additions & 9 deletions src/node-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,25 @@
{
"type": "message",
"named": true,
"fields": {}
"fields": {},
"children": {
"multiple": true,
"required": false,
"types": [
{
"type": "breaking_change",
"named": true
},
{
"type": "comment",
"named": true
},
{
"type": "trailer",
"named": true
}
]
}
},
{
"type": "prefix",
Expand Down Expand Up @@ -137,10 +155,6 @@
"multiple": true,
"required": false,
"types": [
{
"type": "breaking_change",
"named": true
},
{
"type": "comment",
"named": true
Expand All @@ -164,10 +178,6 @@
{
"type": "subject",
"named": true
},
{
"type": "trailer",
"named": true
}
]
}
Expand Down
Loading

0 comments on commit d3c15bd

Please sign in to comment.