Add BNF grammar to explain things with less risk of ambiguity and to support implementing parsers #208

Open
opened 2026-02-17 11:53:43 -06:00 by GiteaMirror · 0 comments
Owner

Originally created by @christianhujer on GitHub (Jul 6, 2024).

It would be great to have a BNF grammar to explain things with less risk of ambiguity and to support implementing parsers for checkers and alike.

Here's a start, using the ABNF from RFC5234.

I might come up with a PR if the idea of adding an ABNF grammar is accepted.

ABNF Definition of Conventional Commits

commitMessage = conventionalCommitHeader [body] [blankLine footer*]
conventionalCommitHeader = typePrefix headline LF
typePrefix = typeNoun [scope] [breakingChangeIndicator] ":" SP
typeNoun = "feat" / "fix" / "refactor" / noun
scope = "(" scopeNoun ")"
scopeNoune = noun
breakingChangeIndicator = "!"
headline = text LF
body = blankLine bodyLine bodyLine*
bodyLine = text LF
blankLine = LF
footer = footerToken footerTokenSeparator footerBody
footerTokenSeparator = footerTokenColonSeparator / footerTokenHashSeparator
footerTokenColonSeparator = ":" SP
footerTokenHashSeparator = SP "#"
footerToken = "BREAKING CHANGE" / dashSeparatedToken
dashSeparatedToken = token dashPlusToken*
dashPlusToken = "-" token
footerBody = *(text LF)
noun = token
text = *(WSP / VCHAR)
token = ALNUM *ALNUM
ALNUM = ALPHA / DIGIT

Projects may decide to put further restrictions on typeNoun, scopeNoun, and footerToken as they deem useful.

Declaration of Intended Compatibility

The intention of the ABNF grammar is to reflect what is written in the prose ruleset in the specification section. Any difference of the ABNF grammar from the specification ruleset is unintentional, by accident, and a mistake in the ABNF grammar. The ruleset takes precedence over the ABNF grammar.

References:

Originally created by @christianhujer on GitHub (Jul 6, 2024). It would be great to have a BNF grammar to explain things with less risk of ambiguity and to support implementing parsers for checkers and alike. Here's a start, using the ABNF from RFC5234. I might come up with a PR if the idea of adding an ABNF grammar is accepted. # ABNF Definition of Conventional Commits ```abnf commitMessage = conventionalCommitHeader [body] [blankLine footer*] conventionalCommitHeader = typePrefix headline LF typePrefix = typeNoun [scope] [breakingChangeIndicator] ":" SP typeNoun = "feat" / "fix" / "refactor" / noun scope = "(" scopeNoun ")" scopeNoune = noun breakingChangeIndicator = "!" headline = text LF body = blankLine bodyLine bodyLine* bodyLine = text LF blankLine = LF footer = footerToken footerTokenSeparator footerBody footerTokenSeparator = footerTokenColonSeparator / footerTokenHashSeparator footerTokenColonSeparator = ":" SP footerTokenHashSeparator = SP "#" footerToken = "BREAKING CHANGE" / dashSeparatedToken dashSeparatedToken = token dashPlusToken* dashPlusToken = "-" token footerBody = *(text LF) noun = token text = *(WSP / VCHAR) token = ALNUM *ALNUM ALNUM = ALPHA / DIGIT ``` Projects may decide to put further restrictions on `typeNoun`, `scopeNoun`, and `footerToken` as they deem useful. ## Declaration of Intended Compatibility The intention of the ABNF grammar is to reflect what is written in the prose ruleset in the specification section. Any difference of the ABNF grammar from the specification ruleset is unintentional, by accident, and a mistake in the ABNF grammar. The ruleset takes precedence over the ABNF grammar. ## References: * [RFC5234](https://datatracker.ietf.org/doc/html/rfc5234)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/conventionalcommits.org#208