Skip to content
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

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

Open
christianhujer opened this issue Jul 6, 2024 · 0 comments

Comments

@christianhujer
Copy link

christianhujer commented 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:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant