[GH-ISSUE #192] EBNF grammar #4374

Closed
opened 2026-06-13 12:16:45 -05:00 by GiteaMirror · 9 comments
Owner

Originally created by @christianhujer on GitHub (Apr 14, 2014).
Original GitHub issue: https://github.com/semver/semver/issues/192

The Semantic Versioning Spec could have an EBNF grammar.

Here it is, according to http://www.w3.org/TR/xml/#sec-notation.

version ::= MAJOR '.' MINOR '.' PATCH ('-' PRE)? ('+' BUILD)?
MAJOR ::= decimalnumber
MINOR ::= decimalnumber
PATCH ::= decimalnumber
PRE ::= string
BUILD ::= string
string ::= [0-9A-Za-z-]+
decimalnumber ::= [0-9]+

Originally created by @christianhujer on GitHub (Apr 14, 2014). Original GitHub issue: https://github.com/semver/semver/issues/192 The Semantic Versioning Spec could have an EBNF grammar. Here it is, according to http://www.w3.org/TR/xml/#sec-notation. version ::= MAJOR '.' MINOR '.' PATCH ('-' PRE)? ('+' BUILD)? MAJOR ::= decimalnumber MINOR ::= decimalnumber PATCH ::= decimalnumber PRE ::= string BUILD ::= string string ::= [0-9A-Za-z-]+ decimalnumber ::= [0-9]+
Author
Owner

@rlidwka commented on GitHub (Apr 14, 2014):

it's much more complex than that...

<!-- gh-comment-id:40339829 --> @rlidwka commented on GitHub (Apr 14, 2014): it's much more complex than that...
Author
Owner

@bessarabov commented on GitHub (Apr 14, 2014):

Just in case one hasn't seen it. There is BNF grammar for SemVer: https://github.com/mojombo/semver/blob/master/semver.md#backusnaur-form-grammar-for-valid-semver-versions

<!-- gh-comment-id:40348347 --> @bessarabov commented on GitHub (Apr 14, 2014): Just in case one hasn't seen it. There is BNF grammar for SemVer: https://github.com/mojombo/semver/blob/master/semver.md#backusnaur-form-grammar-for-valid-semver-versions
Author
Owner

@christianhujer commented on GitHub (Apr 17, 2014):

Just found a flaw.
decimalnumber should actually be, to disallow leading zeros:
decimalnumber ::= '0' | [1-9] [0-9]+
I've taken a look at the BNF grammar for SemVer. It is quite verbose because it is plain old BNF, which doesn't have quantifiers and character groups, unlike simple EBNF from the W3C.
But I do not care which BNF language as long as there is a BNF, any BNF is fine with me :)

<!-- gh-comment-id:40678026 --> @christianhujer commented on GitHub (Apr 17, 2014): Just found a flaw. decimalnumber should actually be, to disallow leading zeros: decimalnumber ::= '0' | [1-9] [0-9]+ I've taken a look at the BNF grammar for SemVer. It is quite verbose because it is plain old BNF, which doesn't have quantifiers and character groups, unlike simple EBNF from the W3C. But I do not care which BNF language as long as there is a BNF, any BNF is fine with me :)
Author
Owner

@FichteFoll commented on GitHub (Apr 21, 2014):

FWIW, here is a regular expression I used for my Python implementation. It's not 2.0.0-comform because I allow empty build and pre-release fields to make version selectors more simple but otherwise it should be correct. Furthermore, I added a "whitespace detection" to the regex to allow extracting it from a string, but that doesn't matter when enclosing with ^$ anyway (like I did 2 lines later).

<!-- gh-comment-id:40935547 --> @FichteFoll commented on GitHub (Apr 21, 2014): FWIW, [here](https://github.com/FichteFoll/pysemver/blob/98cc9633e934b2e1817fb26af826af70d4cb1b0a/semver.py#L125-L139) is a regular expression I used for my Python implementation. It's not 2.0.0-comform because I allow empty build and pre-release fields to make version selectors more simple but otherwise it should be correct. Furthermore, I added a "whitespace detection" to the regex to allow extracting it from a string, but that doesn't matter when enclosing with `^$` anyway (like I did 2 lines later).
Author
Owner

@gvlx commented on GitHub (Jun 27, 2018):

Here it is.

Please comment and correct.

<!-- gh-comment-id:400577643 --> @gvlx commented on GitHub (Jun 27, 2018): [Here it is](https://github.com/semver/semver.org/issues/59#issuecomment-393560776). Please comment and correct.
Author
Owner

@glebec commented on GitHub (Oct 2, 2018):

@gvlx my corrections:

  • PreReleaseIdentifier had a spurious + on NumericIdentifier
  • AlphaNumericIdentifier cannot parse as IdentifierCharacter* NonNumericCharacter ... b/c IdentifierCharacter* includes NonNumericCharacter. So a typical parser would consume all of the input using IdentifierCharacter* and then fail because there is no NonNumericCharacter to consume. The correct version is NumericCharacter* NonNumericCharacter ....
Version ::= VersionCore ('-' PreRelease)? ('+' Build)?

VersionCore ::= Major '.' Minor '.' Patch
Major ::= NumericIdentifier  
Minor ::= NumericIdentifier  
Patch ::= NumericIdentifier  
PreRelease ::= CompoundPreReleaseIdentifier 
Build      ::= CompoundBuildIdentifier 

CompoundPreReleaseIdentifier ::= PreReleaseIdentifier ('.' PreReleaseIdentifier)*
CompoundBuildIdentifier      ::= BuildIdentifier      ('.' BuildIdentifier)*

PreReleaseIdentifier     ::= AlphaNumericIdentifier | NumericIdentifier
BuildIdentifier          ::= IdentifierCharacter+

NumericIdentifier        ::= '0' | ( PositiveNumeric NumericCharacter* )
AlphaNumericIdentifier   ::= NumericCharacter* NonNumericCharacter IdentifierCharacter*

IdentifierCharacter ::= NonNumericCharacter | NumericCharacter

NonNumericCharacter ::= [A-Za-z-]
NumericCharacter    ::= '0' | PositiveNumeric
PositiveNumeric     ::= [1-9]
<!-- gh-comment-id:426123552 --> @glebec commented on GitHub (Oct 2, 2018): @gvlx my corrections: - `PreReleaseIdentifier` had a spurious `+` on `NumericIdentifier` - `AlphaNumericIdentifier` cannot parse as `IdentifierCharacter* NonNumericCharacter ...` b/c `IdentifierCharacter*` includes `NonNumericCharacter`. So a typical parser would consume all of the input using `IdentifierCharacter*` and then fail because there is no `NonNumericCharacter` to consume. The correct version is `NumericCharacter* NonNumericCharacter ...`. ```ebnf Version ::= VersionCore ('-' PreRelease)? ('+' Build)? VersionCore ::= Major '.' Minor '.' Patch Major ::= NumericIdentifier Minor ::= NumericIdentifier Patch ::= NumericIdentifier PreRelease ::= CompoundPreReleaseIdentifier Build ::= CompoundBuildIdentifier CompoundPreReleaseIdentifier ::= PreReleaseIdentifier ('.' PreReleaseIdentifier)* CompoundBuildIdentifier ::= BuildIdentifier ('.' BuildIdentifier)* PreReleaseIdentifier ::= AlphaNumericIdentifier | NumericIdentifier BuildIdentifier ::= IdentifierCharacter+ NumericIdentifier ::= '0' | ( PositiveNumeric NumericCharacter* ) AlphaNumericIdentifier ::= NumericCharacter* NonNumericCharacter IdentifierCharacter* IdentifierCharacter ::= NonNumericCharacter | NumericCharacter NonNumericCharacter ::= [A-Za-z-] NumericCharacter ::= '0' | PositiveNumeric PositiveNumeric ::= [1-9] ```
Author
Owner

@gvlx commented on GitHub (Oct 2, 2018):

The EBNF has been corrected by @glebec on https://github.com/semver/semver/issues/192#issuecomment-426123552 .

This issue should now be closed.

<!-- gh-comment-id:426284408 --> @gvlx commented on GitHub (Oct 2, 2018): The EBNF has been corrected by @glebec on https://github.com/semver/semver/issues/192#issuecomment-426123552 . This issue should now be closed.
Author
Owner

@jwdonahue commented on GitHub (Oct 8, 2018):

@christianhujer , unless you have further questions, can you please close this issue at your earliest possible convenience?

<!-- gh-comment-id:427714128 --> @jwdonahue commented on GitHub (Oct 8, 2018): @christianhujer , unless you have further questions, can you please close this issue at your earliest possible convenience?
Author
Owner

@ebkalderon commented on GitHub (Sep 4, 2019):

@christianhujer Looks like the EBNF grammar has already been merged into master. Can this issue be closed?

<!-- gh-comment-id:527722399 --> @ebkalderon commented on GitHub (Sep 4, 2019): @christianhujer Looks like the EBNF grammar has already been merged into `master`. Can this issue be closed?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/semver#4374